-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_snp_rw.jl
101 lines (78 loc) · 2.95 KB
/
demo_snp_rw.jl
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
#demo_snp_rw.jl: sNp (Touchstone) file tests
#-------------------------------------------------------------------------------
using CMDimCircuits
CMDimCircuits.@using_CData()
#Get a demo display:
include(CMDimCircuits.demoplotcfgscript)
#Normally use something like:
#CMDimData.@includepkg EasyPlotInspect
#==Constants
===============================================================================#
LBLAX_MAGDB = "Magnitude (dB)"
LBLAX_FREQ = "Frequency (Hz)"
color1 = cons(:a, line = set(color=:red, width=2))
color2 = cons(:a, line = set(color=:blue, width=2))
#==Input data
===============================================================================#
Z0 = 50 #Ohms (reference impedance)
ℓ = 5e-3 #Meters
Zc = 200 #Ohms (line impedance)
μ0 = 4pi*1e-7 #F/m
ϵ0 = 8.854e-12 #H/m
f = collect(1:.1:100)*1e9
#==Computations
===============================================================================#
len_mm = ℓ/1e-3
filepath_S = "lineS_$(len_mm)m.s2p"
filepath_Z = "lineZ_$(len_mm)m.s2p"
ω = 2pi*f
α = 0
β = ω*sqrt(μ0*ϵ0)
γ = α .+ im*β
#Convert γ type to DataF1 (function of 1 argument):
γ = DataF1(f, γ)
#ABCD matrix:
A = cosh(γ*ℓ) ;B = sinh(γ*ℓ)*Zc;
C = sinh(γ*ℓ)/Zc ;D = cosh(γ*ℓ);
T = Network(:ABCD, [A B; C D])
#Convert to S-paramters:
data = Network(:S, T)
#Save data to .s2p file:
EDAData.write_snp(filepath_S, data)
EDAData.write_snp(filepath_Z, Network(:Z, data))
#Re-load data:
data = EDAData.read_snp(filepath_S, numports=2)
(s11, s12, s21, s22) = mx2elem(data)
@show Symbol(NPType(data))
#==Generate plot
===============================================================================#
i𝛤 = 1; i𝛵 = 2; #Strip indices
plot = cons(:plot, nstrips=2,
ystrip1 = set(axislabel=LBLAX_MAGDB, striplabel="Reflection Coefficients (𝛤)"),
ystrip2 = set(axislabel=LBLAX_MAGDB, striplabel="Transmission Coefficients (𝛵)"),
xaxis = set(label=LBLAX_FREQ),
)
push!(plot,
cons(:wfrm, dB20(s11), color1, label="s11", strip=i𝛤),
cons(:wfrm, dB20(s22), color2, label="s22", strip=i𝛤),
cons(:wfrm, dB20(s12), color1, label="s12", strip=i𝛵),
cons(:wfrm, dB20(s21), color2, label="s21", strip=i𝛵),
)
#Overlay result of reading/writing Z-parameters:
data = EDAData.read_snp(filepath_Z, numports=2)
@show s = Symbol(NPType(data))
(s11, s12, s21, s22) = mx2elem(Network(:S, data))
push!(plot,
cons(:wfrm, dB20(s11), color1, label="s11 ($(s)P)", strip=i𝛤),
cons(:wfrm, dB20(s22), color2, label="s22 ($(s)P)", strip=i𝛤),
cons(:wfrm, dB20(s12), color1, label="s12 ($(s)P)", strip=i𝛵),
cons(:wfrm, dB20(s21), color2, label="s21 ($(s)P)", strip=i𝛵),
)
pcoll = push!(cons(:plotcoll, title="EDAData Tests: sNp (Touchstone) Format"), plot)
pcoll.ncolumns = 1
#==Display results as a plot
===============================================================================#
EasyPlot.displaygui(pcoll)
#==Return pcoll to user (call evalfile(...))
===============================================================================#
pcoll