Impedances from Touchstone files by gnuplot

Touchstone S1p files include columns of complex S11 values,
while many folks want complex impedance values.

For alternating current circuits, including RF, phase and magnitude are both important.
No power is consumed when potential across a load is sine and current thru it is cosine.
Complex arithmatic accounts for that.

To minimize getting too wrapped around an axle
by complex real with square root of minus one times imaginary,
let us instead focus on sin S and cos C.

Normalized impedance Zin is defined for S1p value S11:

Zin = (1 + S11)/(1 - S11)

... where S11 is some complex value S + C:

Zin = (1 + (S + C))/(1 - (S + C)) = ((1+S) + C)/((1-S) - C)

For next steps, accept that: This is known as squared magnitude.
Applying complex conjugate to calculate impedance from S11
and substituting sin = (1-S) and cos = C:

Zin = ((1+S) + C)*((1-S) + C) / ((1-S)*(1-S) + C*C)

Calculate denominator D magnitude:

D = ((1-S)*(1-S) + C*C) = 1 - 2*S + S*S + C*C

Collect numerator terms with single C factors separately from those without:

Zin = (((1+S)*(1-S) - C*C) + C*((1-S) + (1+S)))/D
     = (1 - S*S - C*C)/D + 2*C/D

gnuplot is very mature plotting software that interprets algebra,
for which I have nearly always used it instead of Excel.
Touchstone files turn out to be compatible with gnuplot data format..
In gnuplot:
set xlabel "frequency"
set ylabel "impedance"
# denominator magnitude
D(S,C) = 1 - 2*S + S*S + C*C
# real and imaginary impedances, assuming 50 Ohm calibration
Zr(S,C) = 50*(1 - S*S - C*C)/D(S,C)
Zi(S,C) = 100*C/D(S,C)

# Using second and third column values for S and C,
# plot impedance components as Y vs frequency as X with lines
set title '30pF_1__1M_150MHz_505point.s1p'
plot '30pF_1__1M_150MHz_505point.s1p' u 1:(S=$2, C=$3, Zr(S,C)) w l title "resistance"
replot '30pF_1__1M_150MHz_505point.s1p' u 1:(S=$2, C=$3, Zi(S,C)) w l title "reactance"
S-Parameters and Smith Charts - Nick Gamroth, Oct 2004