-
Notifications
You must be signed in to change notification settings - Fork 0
/
vco_cmos_sf.py
376 lines (327 loc) · 16.3 KB
/
vco_cmos_sf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# matplotlib, multi-label, on-plot annotation of result summary, pandas, curve_fit,
# - Using self-defined styles for different lines in the plots
# - cable loss determinitation function (from .s2p file) and its use to deembed cable losses.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
from scipy import optimize
from functools import partial
import skrf as rf
do_pn = False
do_title = True
suffix = "cmos_sf"
# meas_dir = "/mnt/home/documents/Measurements/MPW2215_VCO/"
meas_dir = "/home/zoltan/ccn/Measurements/MPW2215_VCO/"
# sim_dir = "/mnt/home/documents/Measurements/MPW2215_VCO/sim/"
sim_dir = "/home/zoltan/ccn/Measurements/MPW2215_VCO/sim/"
style_sim = {"linestyle":"--", "color":"grey", "marker":"None", 'alpha':0.5} #, "label":"sim"} # for plot
style_meas = {"linestyle":":", "color":"black", "marker":"o","s":40} # , "label":"meas"} # for scatter
style_meas1 = {"linestyle":"-", "edgecolor":None,"facecolor":"blue", "s":20, "marker":"o"} #, "label":"meas", "marker":"o"}
style_meas2 = {"linestyle":"-", "edgecolor":None,"facecolor":"green", "s":20, "marker":"v"} #, "label":"meas", "marker":"o"}
style_meas3 = {"linestyle":"-", "edgecolor":None,"facecolor":"orange", "s":20, "marker":"s"} #, "label":"meas", "marker":"o"}
style_meas4 = {"linestyle":"-", "edgecolor":None,"facecolor":"purple", "s":20, "marker":"^"} #, "label":"meas", "marker":"o"}
# style_meas = {"linestyle":":", "color":"black", "marker":"o","s":75, "label":"meas"}
legend_style = {"frameon":False, "fontsize":7, "handletextpad":0.4, "borderaxespad":0, "ncol":3, "loc":'lower center', "mode":"expand", "handlelength":2}
legend_style2 = {"frameon":False, "fontsize":7, "handletextpad":0.4, "borderaxespad":0, "ncol":1, "loc":'lower center', "mode":"expand", "handlelength":2}
legend_style2_ncol2 = {"frameon":False, "fontsize":7, "handletextpad":0.4, "borderaxespad":0, "ncol":2, "loc":'lower center', "mode":"expand", "handlelength":2}
legend_style2_ncol2_ul = {"frameon":False, "fontsize":7, "handletextpad":0.4, "borderaxespad":0, "ncol":2, "loc":'upper left', "mode":"expand", "handlelength":0.6}
l_style_meas = [style_meas1, style_meas2, style_meas3, style_meas4]
plot_style = {"figsize":(3.3914487339144874, 2.0960305886619515*0.7)}
xlabel = {"xlabel":r"Frequency $\left[\si{\GHz}\right]$", "labelpad":0}
opt_vcsv = {'header':None, 'skiprows':6, 'dtype':np.float64, 'usecols':[0,1,3,7],'names':['vtune','freq','pout','pdc']}
def eff(pout, vdc, idc, in_dBm=False):
""" Calculating the DC-to-RF efficiency.
Paramters
---------
pout: float
output power
vdc: float
dc supply voltage
idc: float
dc suply current
in_dBm: boolean, optional
is pout value in dBm?
Returns
-------
float
DC-to-RF efficiency in percentage.
"""
if in_dBm:
ret = (10**(pout/10))*1e-3/vdc/idc*100
else:
ret = pout/vdc/idc*100
return ret
latex=True
if latex:
matplotlib.use('pgf')
pgf_with_custom_preamble = {
"font.family": "serif", # use serif/main font for text elements
"text.usetex": True, # use inline math for ticks
"pgf.rcfonts": False, # don't setup fonts from rc parameters
# Use 10pt font in plots, to match 10pt font in document
# "axes.labelsize": 10,
"axes.labelsize": 8,
"font.size": 10,
# Make the legend/label fonts a little smaller
"legend.fontsize": 8,
"legend.title_fontsize": 8,
"xtick.labelsize": 8,
"ytick.labelsize": 8,
"pgf.preamble": [
"\\usepackage{siunitx}", # load additional packages
"\\usepackage{amsmath}", # load additional packages
"\\usepackage{metalogo}",
"\\usepackage{unicode-math}", # unicode math setup
r"\DeclareSIUnit{\Bm}{Bm}",
r"\DeclareSIUnit{\dBm}{\deci\Bm}",
r"\sisetup{detect-weight=true, detect-family=true, per-mode=fraction, fraction-function=\tfrac,range-phrase=--, range-units=single}",
r"\newcommand{\da}{\textsuperscript{$\dagger$}}"
# I do not understand why, but lately plots are not created when these commands are used. I was not able to found out the reason.
# r"\setmathfont{xits-math.otf}",
# r"\setmainfont{DejaVu Serif}", # serif font via preamble
]
}
matplotlib.rcParams.update(pgf_with_custom_preamble)
matplotlib.rcParams['lines.markersize'] = 4
IEEE_width = 516 #pt
def set_size(width, fraction=1):
""" Set aesthetic figure dimensions to avoid scaling in latex.
Parameters
----------
width: float
Width in pts
fraction: float
Fraction of the width which you wish the figure to occupy
Returns
-------
fig_dim: tuple
Dimensions of figure in inches
"""
fig_width_pt = width * fraction # Width of figure
inches_per_pt = 1 / 72.27 # Convert from pt to inches
golden_ratio = (5**.5 - 1) / 2 # Golden ratio to set aesthetic figure height
fig_width_in = fig_width_pt * inches_per_pt # Figure width in inches
fig_height_in = fig_width_in * golden_ratio # Figure height in inches
return (fig_width_in, fig_height_in)
#######################################
# Cable loss interpolation
#######################################
f_loss = "Probe_842922_cable_05439601_dcblock_avg.s2p"
nw_loss = rf.Network(meas_dir + f_loss)
def loss_func(f, dc,sq,lin):
return dc + sq*np.sqrt(f) + lin*f
x = nw_loss.f
y = nw_loss.s_db[:,1,0]
par, cov = optimize.curve_fit(loss_func, x, y)
cable_loss = partial(loss_func, dc=par[0], sq=par[1], lin=par[2])
#################################
# Measurement results from Excel
#################################
# sim = "/mnt/home/documents/Design/pictures/vco_mpw2215/sf_20200209.vcsv"
sim = "/home/zoltan/ccn/Design/pictures/vco_mpw2215/sf_20200209.vcsv"
# sim_cmos_60G = "/mnt/home/documents/Design/pictures/vco_mpw2215/cmos_60G_20200208.vcsv"
# meas_dir = "/mnt/home/documents/Measurements/MPW2215_VCO/"
meas_dir = "/home/zoltan/ccn/Measurements/MPW2215_VCO/"
meas_xlsx = meas_dir + "vco_cmos_60G_SF.xlsx"
df_meas = pd.read_excel(meas_xlsx, usecols="B:H", sheet_name="combined", header=0).rename(columns={"IDD":"idd", "Pout":"pout", "Vtune":"vtune", "VDD":"vdd", "Ib":"ib", "Ibuf":"ibuf"})
# p_out supposed to be the DIFFERENTIAL output power available at the PADS
# The single ended output was measured
df_meas.pout += 3 - cable_loss(df_meas.freq*1e9) # it should be moved to the common part
df_meas["eff"] = eff(df_meas.pout, df_meas.vdd, df_meas.idd*1e-3, in_dBm=True)
l_cond = [{"vdd":0.8, "ib":3},
{"vdd":1, "ib":3},
{"vdd":1.2, "ib":3},
{"vdd":1.4, "ib":3}
]
# Read in the different simulation resutls and add the operation point information to them
df_sim0p8 = pd.read_csv(sim_dir + 'cmos_sf_vdd0p8V_ib3mA.vcsv', **opt_vcsv)
df_sim0p8['vdd'] = 0.8
df_sim0p8['ib'] = 3
df_sim1 = pd.read_csv(sim_dir + 'cmos_sf_vdd1V_ib3mA.vcsv', **opt_vcsv)
df_sim1['vdd'] = 1
df_sim1['ib'] = 3
df_sim1p2 = pd.read_csv(sim_dir + 'cmos_sf_vdd1p2V_ib3mA.vcsv', **opt_vcsv)
df_sim1p2['vdd'] = 1.2
df_sim1p2['ib'] = 3
df_sim1p4 = pd.read_csv(sim_dir + 'cmos_sf_vdd1p4V_ib3mA.vcsv', **opt_vcsv)
df_sim1p4['vdd'] = 1.4
df_sim1p4['ib'] = 3
# Create one dataframe for easier use
df_sim = pd.concat([df_sim0p8, df_sim1, df_sim1p2, df_sim1p4], ignore_index=True)
df_sim.loc[:,'freq'] *= 1e-9
df_sim.loc[:,'pout'] += 3
df_sim["eff"] = np.power(10,(df_sim.pout-df_sim.pdc)/10) * 100
######################################
# Tuning range
######################################
# fig_s, ax_s = plt.subplots(figsize=(3.3914487339144874, 2.0960305886619515))
fig_s, ax_s = plt.subplots(**plot_style)
tr_label = []
cnt = 0
for cond in l_cond:
mask = pd.DataFrame([df_meas[key] == val for key, val in cond.items()]).T.all(axis=1)
dfm = df_meas[mask]
mask = pd.DataFrame([df_sim[key] == val for key, val in cond.items()]).T.all(axis=1)
dfs = df_sim[mask]
assert dfm.ib.nunique()==1, "Multiple bias current values"
ax_s.plot(dfs.vtune, dfs.freq,**style_sim)
ax_s.scatter(dfm.vtune, dfm.freq, **l_style_meas[cnt], label=r"\SI{%.1f}{\volt} \SI{%d}{\mA}" % (cond["vdd"],cond["ib"]))
cnt +=1
fmin, fmax = dfm.freq.min(), dfm.freq.max()
favg = (fmin+fmax)/2
fper = (fmax-fmin)/favg*100/2
print(cond, fmin, fmax, favg, fmax-fmin, fper*2)
tr_label.append(r"$\SI{%.1f}{\GHz}\pm\SI{%.1f}{\percent}$" % (favg,fper))
ax_s.plot([],[],**style_sim, label="sim") # to add label
ax_s.set_xlim(-0.5, 1.6)
ax_s.set_ylim(45, None)
ax_s.set_xlabel(r"Tuning voltage $\left[\si{\volt}\right]$", labelpad=0)
ax_s.set_ylabel(r"Frequency $\left [ \si{\GHz} \right ]$")
ax_s.grid()
handles, labels = ax_s.get_legend_handles_labels()
# # checking order of the labels; DEBUG only
# print(handles)
# print(labels)
hand = [*handles[1:], handles[0]]
lab = [*labels[1:], labels[0]]
leg = ax_s.legend(handles=hand, labels=lab, bbox_to_anchor=(0.16,1.0,0.86,0.04), **legend_style)
ax_s.legend(handles=handles[1:], labels=tr_label, **legend_style2, bbox_to_anchor=(0.55,0.02,0.4,0.2), title="Tuning range", labelspacing=0.3)
ax_s.add_artist(leg)
ax_s.annotate(r"V\textsubscript{DD} I\textsubscript{b}:",xy=(0,1.08),xycoords="axes fraction",fontsize=8)
for ext in ["png","pgf"]:
fig_s.savefig(meas_dir + suffix + "_tune." + ext, bbox_inches='tight', pad_inches = 0)
######################################
# Output power
######################################
# The differential output power is plotted
fig_s,ax_s = plt.subplots(**plot_style)
pout_label = []
cnt = 0
for cond in l_cond:
mask = pd.DataFrame([df_meas[key] == val for key, val in cond.items()]).T.all(axis=1)
dfm = df_meas[mask]
mask = pd.DataFrame([df_sim[key] == val for key, val in cond.items()]).T.all(axis=1)
dfs = df_sim[mask]
assert dfm.ib.nunique()==1, "Multiple bias current values"
ax_s.plot(dfs.freq, dfs.pout, **style_sim)
ax_s.scatter(dfm.freq, dfm.pout, **l_style_meas[cnt], label=r"\SI{%.1f}{\volt} \SI{%d}{\mA}" % (cond["vdd"],cond["ib"]))
cnt += 1
p_avg = 10*np.log10(sum(10**(dfm.pout/10))/float(len(dfm.pout)))
# Use LaTeX/SIunitx or not to use?
# pout_label.append(r"\SIrange[range-phrase=..]{%.1f}{%.1f}{}; \SI{%.1f}{\dBm}" % (dfm.pout.min(), dfm.pout.max(), p_avg) )
pout_label.append("%.1f..%.1f; %.1f\,dBm" % (dfm.pout.min(), dfm.pout.max(), p_avg) )
ax_s.plot([],[],**style_sim, label="sim") # to add label
ax_s.set_xlabel(**xlabel)
ax_s.set_ylabel(r"P\textsubscript{out} $\left[ \si{\dBm} \right ]$")
ax_s.set_xlim(45,65)
ax_s.set_ylim(-22,0)
ax_s.grid()
handles, labels = ax_s.get_legend_handles_labels()
# # checking order of the labels; DEBUG only
# print(handles)
# print(labels)
handles = [*handles[1:], handles[0]]
labels = [*labels[1:], labels[0]]
leg = ax_s.legend(handles=handles, labels=labels, bbox_to_anchor=(0.16,1.0,0.86,0.04), **legend_style)
ax_s.legend(handles=handles[:len(handles)-1], labels=pout_label, **legend_style2_ncol2, bbox_to_anchor=(0,-0.02,1,0.2), title="P\\textsubscript{out}: min-max; avg", labelspacing=0.3)
ax_s.add_artist(leg)
ax_s.annotate(r"V\textsubscript{DD} I\textsubscript{b}:",xy=(0,1.08),xycoords="axes fraction",fontsize=8)
for ext in ["png","pgf"]:
fig_s.savefig(meas_dir + suffix + "_pout." + ext, bbox_inches='tight', pad_inches = 0)
######################################
# Power consumption
######################################
# The differential output power is plotted
fig_s,ax_s = plt.subplots(**plot_style)
fig_s2,ax_s2 = plt.subplots(**plot_style)
pdc_label = []
pdc_label2 = []
cnt = 0
for cond in l_cond:
mask = pd.DataFrame([df_meas[key] == val for key, val in cond.items()]).T.all(axis=1)
dfm = df_meas[mask]
mask = pd.DataFrame([df_sim[key] == val for key, val in cond.items()]).T.all(axis=1)
dfs = df_sim[mask]
assert dfm.ib.nunique()==1, "Multiple bias current values"
ax_s.plot(dfs.freq, dfs.pdc, **style_sim)
ax_s2.plot(dfs.freq, np.power(10,dfs.pdc/10), **style_sim)
meas_pdc_mW = dfm.vdd * dfm.idd
meas_pdc = 10*np.log10(meas_pdc_mW)
ax_s.scatter(dfm.freq, meas_pdc, **l_style_meas[cnt], label=r"\SI{%.1f}{\volt} \SI{%d}{\mA}" % (cond["vdd"],cond["ib"]))
ax_s2.scatter(dfm.freq, meas_pdc_mW, **l_style_meas[cnt], label=r"\SI{%.1f}{\volt} \SI{%d}{\mA}" % (cond["vdd"],cond["ib"]))
cnt += 1
# p_avg = 10*np.log10(sum(10**(dfm.pdc/10))/float(len(dfm.pdc)))
# pout_label.append(r"\SIrange[range-phrase=..]{%.1f}{%.1f}{}; \SI{%.1f}{\dBm}" % (dfm.pout.min(), dfm.pout.max(), p_avg) )
pdc_label.append("\SIrange{%.1f}{%.1f}{}; \SI{%.1f}{\dBm}" % (meas_pdc.min(), meas_pdc.max(), meas_pdc.mean()) )
pdc_label2.append("\SIrange{%.1f}{%.1f}{}; \SI{%.1f}{\mW}" % (meas_pdc_mW.min(), meas_pdc_mW.max(), meas_pdc_mW.mean()) )
ax_s.plot([],[],**style_sim, label="sim") # to add label
ax_s2.plot([],[],**style_sim, label="sim") # to add label
ax_s.set_xlabel(**xlabel)
ax_s.set_ylabel(r"P\textsubscript{DC} $\left [ \si{\dBm} \right ]$")
ax_s.set_xlim(45,65)
ax_s.set_ylim(0,11)
ax_s.grid()
ax_s2.set_xlabel(**xlabel)
ax_s2.set_ylabel(r"P\textsubscript{DC} $\left [ \si{\mW} \right ]$")
ax_s2.set_xlim(45,65)
ax_s2.set_ylim(0,11)
ax_s2.grid()
handles, labels = ax_s.get_legend_handles_labels()
# # checking order of the labels
# print(handles)
# print(labels)
hand = [*handles[1:], handles[0]]
lab = [*labels[1:], labels[0]]
leg = ax_s.legend(handles=hand, labels=lab, bbox_to_anchor=(0.16,1.0,0.86,0.04), **legend_style)
ax_s.legend(handles=handles[1:], labels=pdc_label, **legend_style2_ncol2, bbox_to_anchor=(0,-0.02,1,0.2), title="P\\textsubscript{DC}: min-max; avg", labelspacing=0.3)
ax_s.add_artist(leg)
leg = ax_s2.legend(handles=hand, labels=lab, bbox_to_anchor=(0.16,1.0,0.86,0.04), **legend_style)
ax_s2.legend(handles=handles[1:], labels=pdc_label2, **legend_style2_ncol2, bbox_to_anchor=(0,-0.02,1,0.2), title="P\\textsubscript{DC}: min-max; avg", labelspacing=0.3)
ax_s2.add_artist(leg)
ax_s.annotate(r"V\textsubscript{DD} I\textsubscript{b}:",xy=(0,1.08),xycoords="axes fraction",fontsize=8)
ax_s2.annotate(r"V\textsubscript{DD} I\textsubscript{b}:",xy=(0,1.08),xycoords="axes fraction",fontsize=8)
for ext in ["png","pgf"]:
fig_s.savefig(meas_dir + suffix + "_pdc." + ext, bbox_inches='tight', pad_inches = 0)
fig_s2.savefig(meas_dir + suffix + "_pdc_mW." + ext, bbox_inches='tight', pad_inches = 0)
######################################
# DC to RF efficiency
######################################
# l_eff = [eff(p_out[i], VDD, IDD[i], in_dBm=True) for i in range(len(p_out))]
fig_s,ax_s = plt.subplots(**plot_style)
ax_s.plot([],[],**style_sim, label="sim") # to add label
eff_label = []
cnt = 0
for cond in l_cond:
mask = pd.DataFrame([df_meas[key] == val for key, val in cond.items()]).T.all(axis=1)
dfm = df_meas[mask]
mask = pd.DataFrame([df_sim[key] == val for key, val in cond.items()]).T.all(axis=1)
dfs = df_sim[mask]
assert dfm.ib.nunique()==1, "Multiple bias current values"
ax_s.plot(dfs.freq, dfs.eff,**style_sim)
ax_s.scatter(dfm.freq, dfm.eff, **l_style_meas[cnt], label=r"\SI{%.1f}{\volt} \SI{%d}{\mA}" % (cond["vdd"],cond["ib"]))
cnt +=1
eff_min, eff_max, eff_mean = dfm.eff.min(), dfm.eff.max(), dfm.eff.mean()
eff_label.append("%.1f-%.1f%%; %.1f%%" % (eff_min, eff_max, eff_mean))
ax_s.set_xlabel(**xlabel)
ax_s.set_ylabel(r"${\eta \left[ \si{\percent} \right] }$")
ax_s.set_ylim(1,8)
ax_s.set_xlim(45,65)
ax_s.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1))
# ax_s.set_ylabel("eff [%]")
ax_s.grid()
handles, labels = ax_s.get_legend_handles_labels()
# # checking order of the labels
# print(handles)
# print(labels)
# label_order = [1, 2, 3, 4, 0]
# handles = [handles[i] for i in label_order]
# labels = [labels[i] for i in label_order]
new_handles = [*handles[1:], handles[0]]
new_labels = [*labels[1:], labels[0]]
leg = ax_s.legend(handles=new_handles, labels=new_labels, bbox_to_anchor=(0.16,1.0,0.86,0.04), **legend_style)
ax_s.legend(handles=handles[1:], labels=eff_label, **legend_style2_ncol2_ul, bbox_to_anchor=(0.02,0.62,0.7,0.4), title="$\eta$: min-max; avg", labelspacing=0.3)
ax_s.add_artist(leg)
ax_s.annotate(r"V\textsubscript{DD} I\textsubscript{b}:",xy=(0,1.08),xycoords="axes fraction",fontsize=8)
for ext in ["png","pgf"]:
fig_s.savefig(meas_dir + suffix + "_eff." + ext, bbox_inches='tight', pad_inches = 0)