Skip to content

Instantly share code, notes, and snippets.

@shabaz123
Created January 23, 2024 01:32
Show Gist options
  • Save shabaz123/a2abfd6360bb5753ea382b41a16d79fd to your computer and use it in GitHub Desktop.
Save shabaz123/a2abfd6360bb5753ea382b41a16d79fd to your computer and use it in GitHub Desktop.
# de_embed.py - VNA Measurement De-Embedding
# rev 1 - shabaz - January 2024
# This code reads three .s1p files, (for S11 Open, Short, and for the DUT).
# Then, the DUT is de-embedded using the Open and Short files.
# The corrected DUT is saved to a new file, and is also displayed on a Smith chart.
import numpy as np
import matplotlib.pyplot as plt
import skrf as rf
from scipy.optimize import minimize
from skrf.calibration import OpenShort
import sys
# set the plot style
rf.stylely()
# set the filenames
short_fname = 'short-meas.s1p'
open_fname = 'open-meas.s1p'
dut_fname = '100-meas.s1p'
# output filename for corrected results
corrected_dut_fname = 'corrected.s1p'
# read the three files and convert to RF Network objects
short_ntwk = rf.Network(short_fname)
open_ntwk = rf.Network(open_fname)
dut_ntwk = rf.Network(dut_fname)
# perform the de-embedding using the skrf calibration module's OpenShort class
dm = OpenShort(dummy_short=short_ntwk, dummy_open=open_ntwk)
corrected_dut_ntwk = dm.deembed(dut_ntwk)
# save the corrected DUT network as a .s1p file
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