-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_inductor.py
More file actions
294 lines (226 loc) · 7.76 KB
/
Copy pathplot_inductor.py
File metadata and controls
294 lines (226 loc) · 7.76 KB
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
import skrf as rf
import math
import sys
from matplotlib import pyplot as plt
print('Read S1P, S2P files and plot inductor parameters')
# evaluate commandline
networks = []
global_fmin = 0
global_fmax = math.inf
# read all files specified in command line
for arg in sys.argv[1:]:
network = rf.Network(arg)
f = network.frequency.f
networks.append(network)
global_fmin = max(global_fmin, min(f))
global_fmax = min(global_fmax, max(f))
# shorted name if file name is too long
if len(arg)>17:
network.name = network.name[:10] + '..' + network.name[-7:]
# set minimum frequency no lower than 100 MHz, to avoid 'divide by zero'
global_fmin = 100e6
# create string with frequency spec for shared frequency range (covered by all data sets)
fspec = str(int(global_fmin/1e6)) + '-' + str(int(global_fmax/1e6)) + 'mhz'
# ---------------------------------------------------------
# function to get differential Zin from one- or twoport data
def get_diff_model (sub):
if sub.number_of_ports == 1:
Zdiff=sub.z[0::,0,0]
elif sub.number_of_ports == 2:
z11=sub.z[0::,0,0]
z21=sub.z[0::,1,0]
z12=sub.z[0::,0,1]
z22=sub.z[0::,1,1]
Zdiff = z11-z12-z21+z22
else:
print('S-parameter files with ', sub.number_of_ports, ' ports not supported')
exit(1)
freq = sub.frequency.f
omega = freq*2*math.pi
Ldiff = Zdiff.imag/omega
Rdiff = Zdiff.real
Qdiff = Zdiff.imag/Zdiff.real
return freq, Rdiff, Ldiff, Qdiff
# find value of SRF where L=0 for first file
Lmin = math.inf
Rmin = math.inf
Qmax = 0
for network in networks:
freq0, Rdiff0, Ldiff0, Qdiff0 = get_diff_model(network[fspec])
Lmin = min(Lmin, Ldiff0[1]*1e9)
Rmin = min(Rmin, Rdiff0[1])
Qmax = max (Qmax, max(Qdiff0))
srf_index = rf.find_nearest_index(Ldiff0,min(Ldiff0))
if srf_index>20:
# limit plots slightly above SRF
print('SRF found at index ', srf_index, ' f=', freq0[srf_index]/1e9, ' GHz')
plot_fmax_ghz = 1.2*freq0[srf_index]/1e9
else:
plot_fmax_ghz = global_fmax/1e9
# ---------------------------------------------------------
# Do the plotting for differential parameters
fig, axes = plt.subplots(2, 2, figsize=(12, 8)) # NxN grid
fig.suptitle("Differential Inductor Parameters")
colors = ['b', 'r', 'm', 'c', 'g', 'y', 'k', 'w']
linestyles = ['solid', 'dashed', 'dashdot', 'dotted','solid', 'dashed', 'dashdot', 'dotted']
# Inductance
ax = axes[0,0]
ax.set_ylim (0, 3*Lmin)
ax.set_xlim (0, plot_fmax_ghz)
for n,network in enumerate(networks):
nw = network[fspec]
freq, Rdiff, Ldiff, Qdiff = get_diff_model(nw[fspec])
ax.plot(freq / 1e9, Ldiff*1e9, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Diff. Inductance (nH)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Q factor
ax = axes[0,1]
ax.set_ylim (0, 1.2*Qmax)
ax.set_xlim (0, plot_fmax_ghz)
for n,network in enumerate(networks):
nw = network[fspec]
freq, Rdiff, Ldiff, Qdiff = get_diff_model(nw[fspec])
ax.plot(freq / 1e9, Qdiff, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Diff. Q factor")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Resistance
ax = axes[1,0]
ax.set_ylim (0, 5*Rmin)
ax.set_xlim (0, plot_fmax_ghz)
for n,network in enumerate(networks):
nw = network[fspec]
freq, Rdiff, Ldiff, Qdiff = get_diff_model(nw[fspec])
ax.plot(freq / 1e9, Rdiff, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Diff. Resistance (Ohm)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Resistance detail
ax = axes[1,1]
ax.set_ylim (0.5*Rmin, 3*Rmin)
network = networks[0]
Rs = rf.find_nearest(Rdiff0, 3*Rmin)
Rs_index = rf.find_nearest_index(Rdiff0,Rs)
ax.set_xlim (0, freq0[Rs_index]/1e9)
for n,network in enumerate(networks):
nw = network[fspec]
freq, Rdiff, Ldiff, Qdiff = get_diff_model(nw[fspec])
ax.plot(nw.frequency.f / 1e9, Rdiff, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Diff. Resistance (Ohm)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# ---------------------------------------------------------
# calculate Pi model parameters
# Zser = series element
# Zshunt1 = left shunt element
# Zshunt2 = right shunt element
def get_pi_model (sub):
y11=sub.y[0::,0,0]
y21=sub.y[0::,1,0]
y12=sub.y[0::,0,1]
y22=sub.y[0::,1,1]
ymn = (y12+y21)/2
Zshunt1 = 1 / (y11 + ymn)
Zshunt2 = 1 / (y22 + ymn)
Zseries = -1 / (ymn)
# values over frequency
freq = sub.frequency.f
omega = freq*2*math.pi
Rseries = Zseries.real
Lseries = Zseries.imag/omega
Cshunt1 = -1 / (omega*Zshunt1.imag)
Cshunt2 = -1 / (omega*Zshunt2.imag)
Rshunt1 = (1 / (y11+ymn)).real
Rshunt2 = (1 / (y22+ymn)).real
Rshunt = (Rshunt1+Rshunt2)/2
return freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt
# ---------------------------------------------------------
# Do the plotting for Pi model parameters
fig, axes = plt.subplots(2, 3, figsize=(16, 8)) # NxN grid
fig.suptitle("Pi model Parameters")
# Inductance in series path
ax = axes[0,0]
ax.set_ylim (0, 3*Lmin)
ax.set_xlim (0, plot_fmax_ghz)
for n,network in enumerate(networks):
if network.number_of_ports == 2:
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
ax.plot(freq / 1e9, Lseries*1e9, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Series path L (nH)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Resistance in series path
ax = axes[0,1]
ax.set_ylim (0, 5*Rmin)
ax.set_xlim (0, plot_fmax_ghz)
for n,network in enumerate(networks):
if network.number_of_ports == 2:
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
ax.plot(freq / 1e9, Rseries, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Series path tesistance (Ohm)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Get limits for plotting shunt elements
Cmin = 1e12
Rmin = 1e12
for n,network in enumerate(networks):
if network.number_of_ports == 2:
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
Cmin = min(Cmin, min(Cshunt1) )
Rmin = min(Rmin, min(Rshunt))
# Shunt path C1
ax = axes[1,0]
ax.set_ylim (0, 5*Cmin*1e15)
for n,network in enumerate(networks):
if network.number_of_ports == 2:
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
ax.plot(freq / 1e9, Cshunt1*1e15, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Shunt path Capacitance 1 (fF)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Shunt path C2
ax = axes[1,1]
ax.set_ylim (0, 5*Cmin*1e15)
for n,network in enumerate(networks):
if network.number_of_ports == 2:
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
ax.plot(freq / 1e9, Cshunt2*1e15, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Shunt path Capacitance 2 (fF)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
# Shunt path R
ax = axes[1,2]
ax.set_ylim (0, 20*Rmin)
for n,network in enumerate(networks):
nw = network[fspec]
freq, Rseries, Lseries, Cshunt1, Cshunt2, Rshunt = get_pi_model(nw)
ax.plot(freq / 1e9, Rshunt, color = colors[n %8], linestyle=linestyles[n %8], label=nw.name)
ax.set_xlabel("Frequency (GHz)")
ax.set_ylabel("Shunt path resistance (Ohm)")
ax.set_xmargin(0)
ax.legend()
ax.grid()
plt.tight_layout()
plt.show()