Skip to content

Instantly share code, notes, and snippets.

@shabaz123
Created March 9, 2024 00:10
Show Gist options
  • Save shabaz123/0f9ad5392812d55db9dcefe48f5782bb to your computer and use it in GitHub Desktop.
Save shabaz123/0f9ad5392812d55db9dcefe48f5782bb to your computer and use it in GitHub Desktop.
Python program to plot a Smith Chart with two traces; one for uncorrected S11, and the other for corrected with electrical length compensation
# elec_comp.py - Electrical length compensation
# rev 1 - shabaz - January 2024
# based on code by Keisuke Kawahara
# This code reads two .s1p files, (for S11 Open and DUT).
# Then, the electrical length is calculated from the Open file,
# and applied to the DUT file. The corrected DUT file is saved to a new file,
# and is also displayed on a Smith chart.
import skrf as rf
import matplotlib.pyplot as plt
import sys
# set the filenames
open_fname = 'test-ci-open.s1p'
dut_fname = 'test-ci-195ohm.s1p'
# output filename for the corrected results
corrected_dut_fname = 'corrected-ci-195ohm.s1p'
# read the two files
dut_ntwk = rf.Network(dut_fname)
open_ntwk = rf.Network(open_fname)
# electrical length compensation
lossless_tline = rf.media.DefinedGammaZ0(frequency=dut_ntwk.frequency, z0_port=None, z0=50, Z0=None, gamma=1j)
electrical_length = open_ntwk.s_deg[:,0,0] / 2
corrected_dut_ntwk = lossless_tline.line(electrical_length, unit='deg') ** dut_ntwk
# save the corrected DUT network
corrected_dut_ntwk.write_touchstone(corrected_dut_fname)
# plot the results on a Smith chart
dut_ntwk.plot_s_smith(lw=2, label='Uncorrected')
corrected_dut_ntwk.plot_s_smith(lw=2, label='Corrected')
plt.title('VNA Raw and Corrected Measurements')
plt.legend() # re-generate legend
plt.show()
print('Done, exiting..')
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment