Corrected gain variation results, and added a helper script to automate plotting all results.
This commit is contained in:
parent
5c3f6902cc
commit
581a05201e
4 changed files with 176 additions and 55 deletions
|
@ -6,6 +6,7 @@
|
|||
# enviornment.
|
||||
################################################################################
|
||||
|
||||
import matplotlib
|
||||
from matplotlib import rcParams, pyplot as pp
|
||||
from cycler import cycler
|
||||
|
||||
|
@ -32,11 +33,54 @@ COLOR_CYCLE_LIST = [
|
|||
# [0, 1, 1],
|
||||
# [1, 0, 0],
|
||||
# [0, 1, 0]]
|
||||
|
||||
|
||||
rcParams['axes.prop_cycle'] = (cycler('linestyle',['-','--'])*cycler(color=COLOR_CYCLE_LIST))
|
||||
|
||||
|
||||
for tri in COLOR_CYCLE_LIST:
|
||||
color = '0x' + ''.join([ "%02x" % int(255*x) for x in tri])
|
||||
|
||||
figures_directory='figures'
|
||||
|
||||
def figAnnotateCorner(hfig, msg, corner=1, clear=True):
|
||||
if clear:
|
||||
figAnnotateClear(hfig)
|
||||
if corner in [1,2]:
|
||||
loc_x = 0.01
|
||||
algn_h = 'left'
|
||||
else:
|
||||
loc_x = 0.99
|
||||
algn_h = 'right'
|
||||
if corner in [1,4]:
|
||||
loc_y = 0.01
|
||||
algn_v = 'bottom'
|
||||
else:
|
||||
loc_y = 0.99
|
||||
algn_v = 'top'
|
||||
ax = hfig.get_axes()[0]
|
||||
hfig.text(loc_x, loc_y, msg, transform=ax.transAxes,
|
||||
va=algn_v, ha=algn_h)
|
||||
|
||||
def axAnnotateCorner(ha, msg, corner=1):
|
||||
if corner in [1,2]:
|
||||
loc_x = 0.01
|
||||
algn_h = 'left'
|
||||
else:
|
||||
loc_x = 0.99
|
||||
algn_h = 'right'
|
||||
if corner in [1,4]:
|
||||
loc_y = 0.01
|
||||
algn_v = 'bottom'
|
||||
else:
|
||||
loc_y = 0.99
|
||||
algn_v = 'top'
|
||||
#ax = ha.get_axes()[0]
|
||||
ha.text(loc_x, loc_y, msg, transform=ha.transAxes,
|
||||
va=algn_v, ha=algn_h)
|
||||
|
||||
def figAnnotateClear(hobj):
|
||||
if type(hobj == matplotlib.figure.Figure):
|
||||
hfig = hobj
|
||||
children = hfig.get_children()
|
||||
for child in children:
|
||||
if type(child) == matplotlib.text.Text:
|
||||
child.remove()
|
||||
|
|
|
@ -11,10 +11,16 @@ def g1_map_default(system):
|
|||
# compute correction factor for g1 that will produce common gain at f0
|
||||
g1_swp = system.g1 * np.sin(np.pi/2-system.phase_swp) / system.alpha_swp
|
||||
return g1_swp
|
||||
|
||||
|
||||
def g1_map_flat(system):
|
||||
return system.g1*np.ones(system.phase_swp.shape)
|
||||
|
||||
def gamma_map_default(system):
|
||||
return np.cos(np.pi/2-system.phase_swp) / system.Q1 / system.alpha_swp
|
||||
|
||||
def gamma_map_flat(system):
|
||||
return np.tan(np.pi/2-system.phase_swp) / system.Q1 / system.alpha_swp
|
||||
|
||||
# Operating Enviornment
|
||||
#####
|
||||
class ampSystem:
|
||||
|
@ -43,9 +49,10 @@ class ampSystem:
|
|||
print(' Rp = %.3f Ohm' % (1/self.g1))
|
||||
print(' Q = %.1f' % (self.Q1))
|
||||
self._gamma_warn = False
|
||||
|
||||
|
||||
self._g1_map_function = g1_map_default
|
||||
|
||||
self._gamma_map_function = gamma_map_default
|
||||
|
||||
@property
|
||||
def w0(self):
|
||||
return self.f0*2*np.pi
|
||||
|
@ -53,7 +60,7 @@ class ampSystem:
|
|||
def fbw(self): # fractional bandwidth
|
||||
return self.bw0/self.f0
|
||||
|
||||
# Compute system
|
||||
# Compute system
|
||||
#####
|
||||
@property
|
||||
def c1(self):
|
||||
|
@ -81,7 +88,7 @@ class ampSystem:
|
|||
|
||||
# Verify gamma is valid
|
||||
#####
|
||||
gamma_max = 1/(self.alpha_min*self.Q1)
|
||||
gamma_max = 1/(np.min((1, self.alpha_min))*self.Q1)
|
||||
if gamma > (self._gamma_cap_ratio * gamma_max):
|
||||
if not self._gamma_warn:
|
||||
self._gamma_warn = True
|
||||
|
@ -99,9 +106,12 @@ class ampSystem:
|
|||
else np.concatenate((lhs,rhs))
|
||||
return np.power(swp,2)
|
||||
|
||||
def set_gamma_swp(self, gamma_swp_function):
|
||||
self._gamma_map_function = gamma_swp_function
|
||||
@property
|
||||
def gamma_swp(self):
|
||||
return np.cos(np.pi/2-self.phase_swp) / self.Q1 / self.alpha_swp
|
||||
return self._gamma_map_function(self)
|
||||
|
||||
@property
|
||||
def phase_swp(self):
|
||||
#def phaseSweepGenerate(g1, gamma, c, l, phase_extreme, phase_steps):
|
||||
|
@ -128,18 +138,18 @@ class ampSystem:
|
|||
|
||||
# This gives us our equal phase spacing points
|
||||
return phase_swp
|
||||
|
||||
|
||||
@property
|
||||
def c1_swp(self):
|
||||
return self.c1 * (1 + self.gamma_swp)
|
||||
|
||||
|
||||
def set_g1_swp(self, g1_swp_function):
|
||||
self._g1_map_function = g1_swp_function
|
||||
|
||||
|
||||
@property
|
||||
def g1_swp(self):
|
||||
return self._g1_map_function(self)
|
||||
|
||||
|
||||
def compute_block(self, f_dat):
|
||||
g1_swp = self.g1_swp
|
||||
c1_swp = self.c1_swp
|
||||
|
@ -158,7 +168,7 @@ class ampSystem:
|
|||
y_tank = self.g1 + f_dat.jw*self.c1 + 1/(f_dat.jw * self.l1)
|
||||
tf = self.__class__.tf_compute(f_dat.delta, 0, self.g1, self.gm1, self.l1, self.c1)
|
||||
return (y_tank, tf)
|
||||
|
||||
|
||||
@classmethod
|
||||
def tf_compute(cls, delta, gamma, gx, gm, l, c):
|
||||
Q = np.sqrt(c/l)/gx
|
||||
|
@ -195,7 +205,7 @@ class bufferSystem:
|
|||
def fbw(self): # fractional bandwidth
|
||||
return self.bw0/self.f0
|
||||
|
||||
# Compute system
|
||||
# Compute system
|
||||
#####
|
||||
@property
|
||||
def c2(self):
|
||||
|
@ -220,4 +230,3 @@ class bufferSystem:
|
|||
return gm / gx \
|
||||
* 1j*(1+delta) \
|
||||
/ (1j*(1+delta) + Q*(1-np.power(1+delta,2)))
|
||||
|
||||
|
|
16
runAll.sh
Normal file
16
runAll.sh
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
MAX_JOBS=4
|
||||
|
||||
echo "Starting:"
|
||||
for n in 1 2 3 4 5 6; do
|
||||
while [[ $MAX_JOBS -le $(jobs -l | wc -l) ]]; do sleep 0.1; done
|
||||
(
|
||||
echo " start $n →"
|
||||
./tankPlot.py -n $n -sq &>/dev/null
|
||||
./tankPlot.py -n $n -rq &>/dev/null
|
||||
echo " 止 end $n"
|
||||
) &
|
||||
done
|
||||
while [[ $(jobs -l | wc -l) -gt 1 ]]; do sleep 0.1; done
|
||||
echo "DONE!"
|
132
tankPlot.py
132
tankPlot.py
|
@ -5,26 +5,26 @@ import matplotlib
|
|||
import argparse
|
||||
import os
|
||||
import code
|
||||
|
||||
import pdb
|
||||
################################################################################
|
||||
args_parser = argparse.ArgumentParser()
|
||||
args_parser.add_argument('-n', type=int, default=1,\
|
||||
args_parser.add_argument('-n', type=int, default=1,
|
||||
help='plot testing number')
|
||||
args_parser.add_argument('--save','-s', action='store_true',\
|
||||
args_parser.add_argument('--save','-s', action='store_true',
|
||||
help='save to files')
|
||||
args_parser.add_argument('--raster','-r', action='store_true',\
|
||||
args_parser.add_argument('--raster','-r', action='store_true',
|
||||
help='save as raster')
|
||||
args_parser.add_argument('--debug','-d', action='store_true',\
|
||||
args_parser.add_argument('--debug','-d', action='store_true',
|
||||
help='hold for debugging')
|
||||
args_parser.add_argument('--headless','-q', action='store_true',\
|
||||
args_parser.add_argument('--headless','-q', action='store_true',
|
||||
help='Remain neadless even if we aren\'t saving files.')
|
||||
args = args_parser.parse_args()
|
||||
|
||||
#exit()
|
||||
|
||||
HEADLESS = not 'DISPLAY' in os.environ.keys()
|
||||
if args.headless: HEADLESS = True # Overide Manually if request
|
||||
if HEADLESS: matplotlib.use('Agg');
|
||||
if args.headless: HEADLESS = True # Override Manually if request
|
||||
if HEADLESS: matplotlib.use('Agg')
|
||||
|
||||
################################################################################
|
||||
from matplotlib import rcParams, pyplot as pp
|
||||
|
@ -49,7 +49,8 @@ else:
|
|||
|
||||
################################################################################
|
||||
# Override the defaults for this script
|
||||
rcParams['figure.figsize'] = [3.4,2.2]
|
||||
figScaleSize = 1.0 if args.save else 1.6
|
||||
rcParams['figure.figsize'] = [3.4*figScaleSize,2.25*figScaleSize]
|
||||
default_window_position=['+20+80', '+120+80']
|
||||
|
||||
################################################################################
|
||||
|
@ -61,12 +62,20 @@ freq_pts = 501
|
|||
|
||||
S=TankGlobals.ampSystem()
|
||||
B=TankGlobals.bufferSystem()
|
||||
|
||||
S.q1_L = 15
|
||||
if plot_list[0] in [11, 12, 13, 14]:
|
||||
gain_variation = +4 # dB
|
||||
else:
|
||||
gain_variation = 0 # dB
|
||||
|
||||
if plot_list[0] in [4, 5]:
|
||||
S.bw_plt = 0.5
|
||||
B.bw_plt = S.bw_plt
|
||||
freq_pts = 51
|
||||
if plot_list[0] == 5:
|
||||
S.set_g1_swp(TankGlobals.g1_map_flat)
|
||||
S.set_gamma_swp(TankGlobals.gamma_map_flat)
|
||||
|
||||
f=FreqClass(freq_pts, S.f0, S.bw_plt)
|
||||
|
||||
|
@ -74,7 +83,7 @@ f=FreqClass(freq_pts, S.f0, S.bw_plt)
|
|||
# We want a smooth transition out to alpha. So For now assume a squares
|
||||
# weighting out to the maximum alpha at the edges.
|
||||
# This gain variation function is the default function baked into the method.
|
||||
gain_variation = 0 # dB
|
||||
#gain_variation = 0 # dB
|
||||
S.alpha_min = dB2Vlt(gain_variation)
|
||||
|
||||
# and compute how much of a negative gm this requres, and it's relative
|
||||
|
@ -115,7 +124,7 @@ y_tank = y_tank.T
|
|||
################################################################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
mgr = pp.get_current_fig_manager()
|
||||
#mgr = pp.get_current_fig_manager()
|
||||
|
||||
################################################################################
|
||||
if 6 in plot_list:
|
||||
|
@ -134,7 +143,6 @@ if 6 in plot_list:
|
|||
axT.set_ylabel('Phase (deg)')
|
||||
setLimitsTicks(axT, ang_unwrap(tf_buf), 6)
|
||||
|
||||
|
||||
for i,axT in enumerate(ax6):
|
||||
if i==0: axT.grid()
|
||||
axT.set_xlim(f.hz_range)
|
||||
|
@ -145,15 +153,15 @@ if 6 in plot_list:
|
|||
axT.tick_params('y', colors=c_color)
|
||||
h6.tight_layout()
|
||||
if args.save:
|
||||
h6.savefig('%s/%s.%s' % (figdir, 'NA-6.0', fig_ext))
|
||||
h6.savefig('%s/%s.%s' % (figdir, 'NA-06.0', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
h6.show()
|
||||
|
||||
################################################################################
|
||||
if 1 in plot_list:
|
||||
if 1 in plot_list or 11 in plot_list:
|
||||
h1 = [pp.figure() for x in range(2)]
|
||||
ax1 = [hT.add_subplot(1,1,1) for hT in h1]
|
||||
ax1[0].plot(f.hz,dB20(tf))
|
||||
|
@ -163,23 +171,32 @@ if 1 in plot_list:
|
|||
ax1[0].set_ylabel('Gain (dB)')
|
||||
ax1[1].set_title('TF Phase')
|
||||
ax1[1].set_ylabel('Phase (deg)')
|
||||
|
||||
|
||||
for axT in ax1:
|
||||
axT.grid()
|
||||
axT.set_xlabel('Freq (GHz)')
|
||||
axT.set_xlim(f.hz_range)
|
||||
|
||||
|
||||
[hT.tight_layout() for hT in h1]
|
||||
if 11 in plot_list:
|
||||
for hT in h1:
|
||||
LPRDefaultPlotting.figAnnotateCorner(hT,
|
||||
'%g dB gain variation' % (gain_variation))
|
||||
|
||||
if args.save:
|
||||
h1[0].savefig('%s/%s.%s' % (figdir, 'NA-1.0', fig_ext))
|
||||
h1[1].savefig('%s/%s.%s' % (figdir, 'NA-1.1', fig_ext))
|
||||
if 11 in plot_list:
|
||||
h1[0].savefig('%s/%s.%s' % (figdir, 'NA-11.0', fig_ext))
|
||||
h1[1].savefig('%s/%s.%s' % (figdir, 'NA-11.1', fig_ext))
|
||||
else:
|
||||
h1[0].savefig('%s/%s.%s' % (figdir, 'NA-01.0', fig_ext))
|
||||
h1[1].savefig('%s/%s.%s' % (figdir, 'NA-01.1', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
[hT.show() for hT in h1]
|
||||
|
||||
if 4 in plot_list:
|
||||
if 4 in plot_list or 14 in plot_list:
|
||||
h4 = [pp.figure(figsize=(3.4,3.4)) for x in range(2)]
|
||||
ax4 = []
|
||||
ax4.append(h4[0].add_subplot(1,1,1, projection='smith'))
|
||||
|
@ -194,14 +211,27 @@ if 4 in plot_list:
|
|||
old_pos = ax4[1].title.get_position()
|
||||
ax4[1].title.set_position((old_pos[0], 1.1))
|
||||
h4[1].tight_layout()
|
||||
|
||||
if 14 in plot_list:
|
||||
for hT in h4:
|
||||
LPRDefaultPlotting.figAnnotateCorner(hT,
|
||||
'%g dB gain variation' % (gain_variation))
|
||||
#[hT.tight_layout() for hT in h4]
|
||||
if args.save:
|
||||
h4[0].savefig('%s/%s.%s' % (figdir, 'ideal-smith_tank_impedance', fig_ext))
|
||||
h4[1].savefig('%s/%s.%s' % (figdir, 'ideal-polar_gain_plot', fig_ext))
|
||||
if 14 in plot_list:
|
||||
h4[0].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-smith_tank_impedance_wgv', fig_ext))
|
||||
h4[1].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-polar_gain_plot_wgv', fig_ext))
|
||||
else:
|
||||
h4[0].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-smith_tank_impedance', fig_ext))
|
||||
h4[1].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-polar_gain_plot', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
[hT.show() for hT in h4]
|
||||
|
||||
if 5 in plot_list:
|
||||
|
@ -221,24 +251,26 @@ if 5 in plot_list:
|
|||
h5[1].tight_layout()
|
||||
#[hT.tight_layout() for hT in h5]
|
||||
if args.save:
|
||||
h5[0].savefig('%s/%s.%s' % (figdir, 'ideal-flat_g1-smith_tank_impedance', fig_ext))
|
||||
h5[1].savefig('%s/%s.%s' % (figdir, 'ideal-flat_g1-polar_gain_plot', fig_ext))
|
||||
h5[0].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-flat_g1-smith_tank_impedance', fig_ext))
|
||||
h5[1].savefig('%s/%s.%s' % (figdir,
|
||||
'ideal-flat_g1-polar_gain_plot', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
[hT.show() for hT in h5]
|
||||
|
||||
|
||||
################################################################################
|
||||
if 2 in plot_list:
|
||||
if 2 in plot_list or 12 in plot_list:
|
||||
h2 = [pp.figure() for x in range(2)]
|
||||
|
||||
|
||||
ax2 = [hT.add_subplot(1,1,1) for hT in h2]
|
||||
ax2[0].plot(f.hz,dB20(tf_r))
|
||||
setLimitsTicks(ax2[0], dB20(tf_r), 6)
|
||||
ax2[1].plot(f.hz,ang_unwrap(tf_r.T).T)
|
||||
setLimitsTicks(ax2[1], ang_unwrap(tf_r.T), 6)
|
||||
|
||||
|
||||
ax2[0].set_title('Relative Gain')
|
||||
ax2[0].set_ylabel('Gain (dB)')
|
||||
ax2[1].set_title('Relative Phase')
|
||||
|
@ -249,40 +281,60 @@ if 2 in plot_list:
|
|||
axT.set_xlabel('Freq (GHz)')
|
||||
axT.set_xlim(f.hz_range)
|
||||
[hT.tight_layout() for hT in h2]
|
||||
if 12 in plot_list:
|
||||
for hT in h2:
|
||||
LPRDefaultPlotting.figAnnotateCorner(hT,
|
||||
'%g dB gain variation' % (gain_variation))
|
||||
|
||||
if args.save:
|
||||
h2[0].savefig('%s/%s.%s' % (figdir, 'NA-2.0', fig_ext))
|
||||
h2[1].savefig('%s/%s.%s' % (figdir, 'NA-2.1', fig_ext))
|
||||
if 12 in plot_list:
|
||||
h2[0].savefig('%s/%s.%s' % (figdir, 'NA-12.0', fig_ext))
|
||||
h2[1].savefig('%s/%s.%s' % (figdir, 'NA-12.1', fig_ext))
|
||||
else:
|
||||
h2[0].savefig('%s/%s.%s' % (figdir, 'NA-02.0', fig_ext))
|
||||
h2[1].savefig('%s/%s.%s' % (figdir, 'NA-02.1', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
[hT.show() for hT in h2]
|
||||
|
||||
################################################################################
|
||||
if 3 in plot_list:
|
||||
if 3 in plot_list or 13 in plot_list:
|
||||
h3 = [pp.figure() for x in range(2)]
|
||||
|
||||
|
||||
ax3 = [hT.add_subplot(1,1,1) for hT in h3]
|
||||
ax3[0].plot(bw_mag,dB20(rms_gain_swp))
|
||||
ax3[1].plot(bw_ang,rms_ang_swp*180/np.pi)
|
||||
|
||||
|
||||
ax3[0].set_title('RMS Gain Error')
|
||||
ax3[0].set_ylabel('RMS Gain Error (dB)')
|
||||
ax3[1].set_title('RMS Phase Error')
|
||||
ax3[1].set_ylabel('RMS Phase Error (deg)')
|
||||
|
||||
for axT in ax3:
|
||||
axT.grid()
|
||||
axT.set_xlim((0,S.bw_plt))
|
||||
axT.set_xlabel('Bandwidth (GHz)')
|
||||
|
||||
[hT.tight_layout() for hT in h3]
|
||||
[hT.tight_layout() for hT in h3]
|
||||
if 13 in plot_list:
|
||||
for hT in h3:
|
||||
LPRDefaultPlotting.figAnnotateCorner(hT,
|
||||
'%g dB gain variation' % (gain_variation))
|
||||
|
||||
if args.save:
|
||||
h3[0].savefig('%s/%s.%s' % (figdir, 'NA-3.0', fig_ext))
|
||||
h3[1].savefig('%s/%s.%s' % (figdir, 'NA-3.1', fig_ext))
|
||||
if 13 in plot_list:
|
||||
h3[0].savefig('%s/%s.%s' % (figdir, 'NA-13.0', fig_ext))
|
||||
h3[1].savefig('%s/%s.%s' % (figdir, 'NA-13.1', fig_ext))
|
||||
else:
|
||||
h3[0].savefig('%s/%s.%s' % (figdir, 'NA-03.0', fig_ext))
|
||||
h3[1].savefig('%s/%s.%s' % (figdir, 'NA-03.1', fig_ext))
|
||||
if HEADLESS:
|
||||
pp.close()
|
||||
else:
|
||||
mgr.window.geometry(default_window_position[0])
|
||||
#mgr.window.geometry(default_window_position[0])
|
||||
[hT.show() for hT in h3]
|
||||
|
||||
if args.debug:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue