-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
91 lines (66 loc) · 2.12 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
from __future__ import division
import pylab as pyl
from twoport import *
from twoport.networks import *
def basic():
f = linspace(100e6, 1000e6)
r = Resistor(100)
c = Capacitor(10e-12, f=f)
terminator = Resistor(50)
filter = Series(c) * Shunt(r)
input_equiv = filter.inp()
g = filter.transducer_gain(terminator, terminator)
print filter[200e6]
print 'Zin @ 200 MHz:', input_equiv[200e6].z
pyl.figure()
pyl.plot(f/1e6, utils.db(g))
pyl.xlabel('Frequency (MHz)')
pyl.ylabel('Gain (dB)')
pyl.show()
def amplifier():
file_name = 'BFR93A.s2p'
analysis_freq = 400e6
## load a transistor model
q = load_snp(file_name)
f = linspace(q.f[0], q.f[-1], 1000) # new f axis with 1000 points
q = q[f] # interpolate to new f axis
## plot input reflection coefficient (S11) on Smith chart
pyl.figure()
sc = SmithChart(show_cursor=False, labels=True)
sc.plot_s_param(q.inp().s)
# calculate various stability factors
k = q.rollett_k()
kt = q.rollett_kt()
mu = q.mu_stability_source()
pyl.figure()
pyl.plot(f/1e6, kt, label='EL Tan\'s modified Rollett $k$')
pyl.plot(f/1e6, mu, label='$\mu_i$')
pyl.xlabel('Frequency (MHz)')
pyl.ylabel('Stability factor')
pyl.axhline(1.0, color='black') # line at stability limit
pyl.legend(loc='lower right')
## plot gains
# We can do this manually using:
# terminator = Resistor(50)
# gt = q.transducer_gain(terminator, terminator)
# gmsg = q.max_stable_gain()
# gmax = q.max_gain()
# etc. or just:
pyl.figure()
plot_gains(q)
## plot stability circles
q_desired = q[analysis_freq]
pyl.figure()
sc = SmithChart(show_cursor=False, labels=True)
sc.two_port = q_desired # need this for cursors to work
sc.draw_stability_circles(q_desired, plane='both')
sc.plot_gain_circles(q_desired, surface=True, gain_cursor=True)
# enable cursor
# note green circle will show optimal termination at other (load) port
sc.enable_cursor()
pyl.show()
def main():
basic()
amplifier()
if __name__ == '__main__':
main()