S-Parameter File

Load S-parameters from a Touchstone file (.snp) for black-box modeling.

using CircuitSim
using GLMakie

circ = Circuit()

# Components
port1 = ACPowerSource("P1", port_num=1, impedance=50.0)

# Load S-parameters from file (1-port antenna)
spf = SPfile("ANT1", file="../assets/test_files/70 mm L1 L5 Single feed.s1p", data_format="rectangular", interpolator="linear")

gnd = Ground("GND")

add_component!(circ, port1)
add_component!(circ, spf)
add_component!(circ, gnd)

# Connect 1-port S-parameter file
@connect circ port1.nplus spf.n1
@connect circ port1.nminus gnd
@connect circ spf.ref gnd

sparam = SParameterAnalysis(start=1e9, stop=2e9, points=601,
    sweep_type="linear",
    z0=50.0
)

sp_result = simulate_qucsator(circ, sparam)
SParameterResult([1.0e9, 1.0016666666666666e9, 1.0033333333333334e9, 1.005e9, 1.0066666666666666e9, 1.0083333333333334e9, 1.01e9, 1.0116666666666666e9, 1.0133333333333334e9, 1.015e9  …  1.985e9, 1.9866666666666667e9, 1.9883333333333335e9, 1.99e9, 1.9916666666666667e9, 1.9933333333333335e9, 1.995e9, 1.9966666666666667e9, 1.9983333333333335e9, 2.0e9], 1, Dict{Tuple{Int64, Int64}, Vector{ComplexF64}}((1, 1) => [0.17756583608565324 + 0.9592848285467628im, 0.18395459976243367 + 0.9582633940896698im, 0.19023808050447444 + 0.9567513558342644im, 0.1962720076891239 + 0.9552587693223326im, 0.20278901880694716 + 0.953998460988043im, 0.20929782882740505 + 0.9526222873502307im, 0.21575837910319245 + 0.9514600013022023im, 0.22204861537518808 + 0.9499418472878884im, 0.2286416640142912 + 0.9485993115447645im, 0.23523685374757894 + 0.9473789552751626im  …  0.0798409525525573 - 0.9522205415924128im, 0.07306101849813096 - 0.9529890860646526im, 0.06621852999257444 - 0.9536801153601155im, 0.05954334855250204 - 0.954221346244457im, 0.05257856521761947 - 0.9546113544206599im, 0.045724276050322116 - 0.954695425855931im, 0.03903261981722608 - 0.9548764141720765im, 0.032353420988414316 - 0.954966292353928im, 0.02570482705924676 - 0.9549747999837173im, 0.019244998334822377 - 0.9550469169241356im]), 50.0, nothing, nothing, nothing, nothing)
# Get frequency vector in MHz
freq_mhz = sp_result.frequencies_Hz ./ 1e6

# Extract S-parameters from typed result
s11_complex = sp_result.s_matrix[(1,1)]

# Convert to dB
s11_db = 20 .* log10.(abs.(s11_complex))

Plot S-Parameter Magnitude

fig = Figure(size=(900, 600), fontsize=14)

ax1 = Axis(fig[1, 1],
    xlabel = "Frequency [MHz]",
    ylabel = "Magnitude [dB]",
    title = "",
)

lines!(ax1, freq_mhz, s11_db, label="S₁₁ (Return Loss)", linewidth=2)

ylims!(ax1, -25, 5)
xlims!(ax1, 1000, 2000)
axislegend(ax1, position=:lb)

fig
Example block output