Skip to content

Instantly share code, notes, and snippets.

@shabaz123
Created January 29, 2024 04:14
Show Gist options
  • Save shabaz123/72d8caea7d02cb5c95161d0e02a4c6c9 to your computer and use it in GitHub Desktop.
Save shabaz123/72d8caea7d02cb5c95161d0e02a4c6c9 to your computer and use it in GitHub Desktop.
Electrical Length Compensation for VNA Measurements
# 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
# set the filenames
open_fname = 'open-meas.s1p'
dut_fname = '100-meas.s1p'
# output filename for the corrected results
corrected_dut_fname = 'corrected.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