-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
157 lines (106 loc) · 3.71 KB
/
test.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
from __future__ import division
from pylab import *
from inductor import *
def main():
params = dict(N=6, diam_former=3e-3, diam_wire=1.2e-3, f=100e6, len_coil=5e-3)
params.update(MATERIALS['Cu, annealed'])
ind = Inductor(**params)
#print ind.analyze()
L_target = 200e-9
diam_wires = linspace(5, 10)
fres = []
qs = []
lens = []
temp_sensi = []
for d in diam_wires:
print d
ind.N = d
ind.tune_parameter('len_coil', L_target, param_range=(ind.N*ind.diam_wire, 1))
result = ind.analyze()
fres.append(result['res_freq'])
qs.append(result['Q_eff'])
lens.append(ind.len_coil)
s = ind.sensitivity('temperature', normalize=False)
temp_sensi.append(s)
figure()
plot(diam_wires/1e-3, array(fres)/1e6, color='red')
ylabel('Self-resonant frequency (MHz)', color='red')
xlabel('Wire diameter (mm)')
title('L = 80 nH (fixed, coil length varies), Q @ 100 MHz')
twinx()
#figure()
plot(diam_wires/1e-3, qs, color='blue')
ylabel('Q factor', color='blue')
figure()
plot(diam_wires/1e-3, array(temp_sensi)*1e6)
ylabel('Temperature coefficient (ppm/$\degree$C)')
xlabel('Wire diameter (mm)')
show()
def main3():
params = dict(N=6, diam_former=3e-3, diam_wire=1e-3, f=10e6, len_coil=8e-3)
params.update(MATERIALS['Cu, annealed'])
ind = Inductor(**params)
print ind.analyze()
print 'current Ls', ind.analyze()['Ls_eff']
print 'current Q', ind.analyze()['Q_eff']
#return
#print 'param tunes to', ind.tune_parameter('len_coil', 50e-9, param_range=(0, 50e-3))
print 'Q_eff sensi', 100*ind.sensitivity('N', 'Q_eff')
print 'Ls_eff sensi', 100*ind.sensitivity('N', 'Ls_eff')
input_values = linspace(1, 1000, 50)*1e6
qs = zeros(len(input_values))
sensi = zeros(len(input_values))
coil_len = zeros(len(input_values))
Ls = zeros(len(input_values))
for i, inp in enumerate(input_values):
ind.f = inp
'''try:
ind.tune_parameter('len_coil', 100e-9, param_range=(ind.N*ind.diam_wire, 100e-3))
except:
continue'''
results = ind.analyze()
qs[i] = results['Q_eff']
Ls[i] = results['Ls_eff']
sensi[i] = ind.sensitivity('temperature', 'Ls_eff', normalize=False)
coil_len[i] = ind.turn_spacing
figure()
plot(input_values, qs)
title('Q')
figure()
plot(input_values, 1e6*sensi)
title('Sensitivity')
figure()
plot(input_values, coil_len)
title('coil spacing')
figure()
plot(input_values, Ls/1e-9)
title('induct')
show()
def main2():
params = dict(N=4, diam_former=5e-3, diam_wire=1.2e-3, f=100e6, len_coil=51e-3)
params.update(MATERIALS['Cu, annealed'])
L_desired = 50e-9
ind = Inductor(**params)
print 'Initial length = %0.3f mm -> inductance = %0.3f nH' % (ind.len_coil/1e-3, ind.analyze()['Ls_eff']/1e-9)
#ind.tune_parameter('len_coil', L_desired, input_range=(ind.N*ind.diam_wire, 1))
ind.tune_parameter('len_coil', L_desired, input_range=(1e-3, 1))
print ind.N*ind.diam_wire
print '> Tuned length = %0.3f mm -> inductance = %0.3f nH' % (ind.len_coil/1e-3, ind.analyze()['Ls_eff']/1e-9)
print ind.analyze()
lens = linspace(ind.N*ind.diam_wire, 100e-3, 100)
inds = [ind.analyze(len_coil=el)['Ls_eff'] for el in lens]
qs = [ind.analyze(len_coil=el)['Q_eff'] for el in lens]
if 0:
inds = []
for el in lens:
ind.len_coil = el
inds.append(ind.sensitivity('len_coil'))
figure()
plot(lens/1e-3, inds)
figure()
plot(lens/1e-3, qs)
figure()
plot(inds, qs)
show()
if __name__ == '__main__':
main3()