def plot_three_load(): # dummy 2-port network from Frequency and s-parameters freq = Frequency(1, 10, 1, 'ghz') # Frequency([start, stop, npoints, unit, …]) print(freq) s = [0 + 1j, 0 - 1j, 0.23 - 0.43j] # random complex numbers print(s) # if not passed, will assume z0=50. name is optional but it's a good practice. ntwk = Network(frequency=freq, z0=50, s=s, name='random values 1-port') print(ntwk) plt.figure() ntwk.plot_s_smith(marker='o', linestyle='dotted') plt.legend(loc=7) plt.text(0, 0.85, "0+1j", fontsize=12, bbox=dict(facecolor='red', alpha=0.5)) plt.text(0, -0.85, "0-1j", fontsize=12, bbox=dict(facecolor='red', alpha=0.5)) plt.text(0.28, -0.43, "0.23-0.43j", fontsize=12, bbox=dict(facecolor='red', alpha=0.5)) plt.title("S-Parameters") data_log("plot some predefined loads in the smith char using skrf") plt.show()
def plot_smith(freq, s11, s11_phase, location): plt.figure() f = Frequency(np.min(freq), np.max(freq), len(freq), 'mhz') n = Network(freq=f, s=10**(s11 / 20) * np.exp(1j * s11_phase * np.pi / 180), z0=50) n.plot_s_smith(draw_labels=True) plt.savefig(location)
def plot_demo_rf(): ring_slot = Network('ring slot.s2p') plt.figure() ring_slot.plot_s_smith() plt.figure() ring_slot.plot_s_db() plt.title("S-Parameters") data_log("plot demo data") plt.show()
def s4p_to_tf(s4p, zs=50, zl=50): # read S-parameter file ntwk = Network(s4p) # extract characteristic impedance # assumed to be the same for all 16 measurements z0 = ntwk.z0[0, 0] # extract frequency list freq = ntwk.frequency.f # extract transfer function tf = np.array([s2tf(s2sdd(s), 2 * z0, 2 * zs, 2 * zl) for s in ntwk.s]) return freq, tf
def S_D(P1, P3, P2, P4, Type, Folder_1, Title_1, Legend_1): SP = Network(Folder_1) F = SP.f[:] P1 -= 1 P2 -= 1 P3 -= 1 P4 -= 1 if int(Type) == 11: SDD = 0.5 * (SP.s[:, P1, P1] - SP.s[:, P1, P3] - SP.s[:, P3, P1] + SP.s[:, P3, P3]) elif int(Type) == 21: SDD = 0.5 * (SP.s[:, P2, P1] - SP.s[:, P4, P1] - SP.s[:, P2, P3] + SP.s[:, P4, P3]) plt.title(Title_1) plt.plot(F, 20 * np.log10(SDD), label=Legend_1, linewidth='3') plt.xlabel('F, Гц') plt.ylabel(f'S{Type}, дБ')
# -*- coding: utf-8 -*- """ Created on Fri Dec 7 14:55:26 2018 @author: justRandom """ import time import numpy as np from skrf import Network import visa a = [] for i in range(0, 4): real = i / 10 imag = i / 100 a.append(complex(real, imag)) #SKRF smith chart plotting myNet = Network(f=[0, 1, 2, 3], s=a, z0=[50]) myNet.plot_s_smith()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_FF = Network('SP/PEX_RF12_FF.s2p') SP_SS = Network('SP/PEX_RF12_SS.s2p') SP_TT = Network('SP/PEX_RF12_TT.s2p') SP_Ideal =Network('SP/SP_Bad_Load.s2p') #print(SP_TT.s[:, 0, 0]) S21_TT_db = 20*np.log10(SP_TT.s[:, 1, 0]) S21_FF_db = 20*np.log10(SP_FF.s[:, 1, 0]) S21_SS_db = 20*np.log10(SP_SS.s[:, 1, 0]) S21_Ideal_db = 20*np.log10(SP_Ideal.s[:, 1, 0]) F = SP_TT.f[:] Error_FF = S21_Ideal_db-S21_FF_db Error_SS = S21_Ideal_db-S21_SS_db Error_TT = S21_Ideal_db-S21_TT_db plt.figure() plt.title("PEX") plt.plot(F, -Error_SS, label='SS', linewidth ='3') plt.plot(F, Error_TT, label='TT', linewidth ='3') plt.plot(F, -Error_FF, label='FF', linewidth ='3') plt.legend() plt.xlabel('F, Гц')
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_GL102 = Network('SP/Four_line_GL102.s16p') SP_GX13 = Network("SP/Four_line_GX13.s16p") F = SP_GL102.f[:] #S11 GL102 plt.figure() plt.title("GL102") for x in 0, 1, 2, 3: S11_GL102 = SP_GL102.s[:, (4 * x) + 1 - 1, (4 * x) + 1 - 1] S33_GL102 = SP_GL102.s[:, (4 * x) + 3 - 1, (4 * x) + 3 - 1] S13_GL102 = SP_GL102.s[:, (4 * x) + 1 - 1, (4 * x) + 3 - 1] S31_GL102 = SP_GL102.s[:, (4 * x) + 3 - 1, (4 * x) + 1 - 1] Sdd11 = 20 * np.log10( (S11_GL102 - S13_GL102 - S31_GL102 + S33_GL102) * 0.5) if x == 0: Legend = "1mm" elif x == 1: Legend = "2mm" elif x == 2: Legend = "4mm" else:
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np import math, cmath plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_single = Network("SP/Test_diff/SD_line.s4p") SP_diff = Network("C:/Users/SH/Desktop/one_diff/diff.s2p") SP_one_port = Network("C:/Users/SH/Desktop/Test_1/Results_Final.s2p") S11_one_db = 20 * np.log10(SP_one_port.s[:, 1 - 1, 1 - 1]) S21_one_db = 20 * np.log10(SP_one_port.s[:, 2 - 1, 1 - 1]) F2 = SP_one_port.f[:] S11_db = 20 * np.log10(SP_diff.s[:, 1 - 1, 1 - 1]) S21_db = 20 * np.log10(SP_diff.s[:, 2 - 1, 1 - 1]) F1 = SP_diff.f[:] Sdd11_single = 0.5 * ( SP_single.s[:, 1 - 1, 1 - 1] - SP_single.s[:, 1 - 1, 3 - 1] - SP_single.s[:, 3 - 1, 1 - 1] + SP_single.s[:, 3 - 1, 3 - 1]) Sdd21_single = 0.5 * ( SP_single.s[:, 2 - 1, 1 - 1] - SP_single.s[:, 4 - 1, 1 - 1] - SP_single.s[:, 2 - 1, 3 - 1] + SP_single.s[:, 4 - 1, 3 - 1]) Sdd11_single_db = 20 * np.log10(Sdd11_single) Sdd21_single_db = 20 * np.log10(Sdd21_single)
print("start: " + start) stop = argv[2] print("stop: " + stop) step = argv[3] print("step: " + step) try: device = sark_open() if not device: print("device not connected") else: print("device connected") prot, ver = sark_version(device) print(prot, ver) sark_buzzer(device, 1000, 800) y = [] x = [] for freq in range(int(start), int(stop), int(step)): # setup loop over number of points rs, xs = sark_measure(device, freq) x.append(freq) y.append(z2gamma(rs[0], xs[0])) ring_slot = Network(frequency=x, s=y, z0=50) ring_slot.plot_s_smith() print("done") finally: sark_close(device) exit(1)
for i in vna.file.files(): src = str(temp_dir / i) dest = str(dest_dir / i) vna.file.download_file(src, dest) # Read data. # Data file naming convention: open_filename = 'CalibrationUnit Open (P{0}).s1p' short_filename = 'CalibrationUnit Short (P{0}).s1p' match_filename = 'CalibrationUnit Match (P{0}).s1p' thru_filename = 'CalibrationUnit Through (P{0}P{1}).s2p' # Read port 1 # open, short, match # format is complex (re + j*im) freq_Hz = Network(str(dest_dir / open_filename.format(1))).f p1_open = [s[0][0] for s in Network(str(dest_dir / open_filename.format(1))).s] p1_short = [ s[0][0] for s in Network(str(dest_dir / short_filename.format(1))).s ] p1_match = [ s[0][0] for s in Network(str(dest_dir / match_filename.format(1))).s ] # Read port 1, 2 through, # if it exists # format is complex (re + j*im) p12_thru_path = dest_dir / thru_filename.format(1, 2) if p12_thru_path.exists(): p12_thru = [s[1][0] for s in Network(str(p12_thru_path)).s]
import skrf as rf from pylab import * # from skrf.data import wr2p2_short as short # from skrf.data import wr2p2_delayshort as delayshort from skrf import Network, Frequency induct = Network('Inductor_0p6nH.s2p') # induct = Network('2.s2p') probe = Network('E_PROBE_THROUGH.S2P') probe.frequency.unit = 'ghz' print(probe.frequency_nb) # round_sig(probe.frequency, 6) = 'ghz' # probe = Network('1.S2P') # Interpolate induct frequency form probe Frequency # probe.interpolate_from_f(induct.frequency) # induct.interpolate_from_f(probe.frequency) # if probe.frequency == induct.frequency : # print("good!") # else : # print("bad!") # probe.write_touchstone('probe.freq') # induct.write_touchstone('induct.freq') # whatwewant = induct.inv ** probe # short_2 = line.inv ** delayshort # if short_2 == short : # print("good!")
import matplotlib.pyplot as plt import skrf as rf from skrf import Network plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_GL102 = Network('SP/Three_via_GL102.s6p') SP_FR4 = Network('SP/Three_via_FR4.s6p') plt.figure() plt.title("GL102") SP_GL102.plot_s_db(m=6-1, n=5-1, label='S65', linewidth ='3') SP_GL102.plot_s_db(m=4-1, n=3-1, label='S43', linewidth ='3') SP_GL102.plot_s_db(m=2-1, n=1-1, label='S21', linewidth ='3') plt.xlabel('F, Гц') plt.ylabel('S , дБ') plt.grid() plt.figure() plt.title("GL102") SP_GL102.plot_s_smith(5-1,5-1, label='S55', linewidth ='3',draw_labels=True) SP_GL102.plot_s_smith(3-1,3-1, label='S33', linewidth ='3',draw_labels=True) SP_GL102.plot_s_smith(1-1,1-1, label='S11', linewidth ='3',draw_labels=True) plt.figure() plt.title("FR4") SP_FR4.plot_s_db(m=6-1, n=5-1, label='S65', linewidth ='3') SP_FR4.plot_s_db(m=4-1, n=3-1, label='S43', linewidth ='3') SP_FR4.plot_s_db(m=2-1, n=1-1, label='S21', linewidth ='3') plt.xlabel('F, Гц') plt.ylabel('S , дБ')
files = [ 'thru_0201_10pf_accup.s2p', 'thru_0402_10pf_accup.s2p', 'thru_barrel.s2p', 'thru_tee_BLM15GG471_10pf_220nf.s2p', 'thru_thru.s2p' ] from pylab import * from skrf import Network for f in files: net = Network(f) net.plot_s_db() plt.show()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_ADS = Network('SP/Spiral/Spiral_std_ads.s2p') SP_CAD = Network('SP/Spiral/Spiral_std_cadence.s2p') plt.figure() SP_CAD.plot_s_db(m=1 - 1, n=1 - 1, label='S11 Cadence', linewidth='3') SP_ADS.plot_s_db(m=1 - 1, n=1 - 1, label='S11 ADS', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.grid() plt.figure() SP_CAD.plot_s_smith(0, 0, label='S11 Cadence', linewidth='3', draw_labels=True) SP_ADS.plot_s_smith(0, 0, label='S11 ADS', linewidth='3', draw_labels=True) plt.figure() SP_CAD.plot_s_db(m=2 - 1, n=1 - 1, label='S21 Cadence', linewidth='3') SP_ADS.plot_s_db(m=2 - 1, n=1 - 1, label='S21 ADS', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S21, дБ') plt.grid() plt.show()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP = Network( 'C:/Users/SH/Desktop/homework_V2/Рабочий стол/Утюг/Микрополосковая линия/S2P/Four_line_Solaris.s8p' ) plt.figure() SP.plot_s_db(m=2 - 1, n=1 - 1, label='S21', linewidth='3') SP.plot_s_db(m=4 - 1, n=3 - 1, label='S43', linewidth='3') SP.plot_s_db(m=6 - 1, n=5 - 1, label='S65', linewidth='3') SP.plot_s_db(m=8 - 1, n=7 - 1, label='S87', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('SP, дБ') plt.grid() plt.figure() SP.plot_s_db(m=1 - 1, n=1 - 1, label='S11', linewidth='3') SP.plot_s_db(m=3 - 1, n=3 - 1, label='S33', linewidth='3') SP.plot_s_db(m=5 - 1, n=5 - 1, label='S55', linewidth='3') SP.plot_s_db(m=7 - 1, n=7 - 1, label='S77', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('SP, дБ') plt.grid()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" Folder_1 = f"SP/Chip_Via_Line/Via_Line_Chip.s4p" Title = "L= 100 мкм" SP = Network(Folder_1) SP.se2gmm(2) plt.figure() plt.title(Title) SP.plot_s_db(m=1 - 1, n=1 - 1, label='VIA+Line', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.grid() plt.figure() plt.title(Title) SP.plot_s_db(m=2 - 1, n=1 - 1, label='VIA+Line', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S21, дБ') plt.grid() plt.show()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" Title = "1.5 мкм" Folder_1 = f"SP/Chip_Line/Chip_Line_Accuracy/Three_lines_15um.s12p" Legend_1 = "50 мкм" Legend_2 = "100 мкм" Legend_3 = "200 мкм" SP = Network(Folder_1) SP.se2gmm(6) plt.figure() plt.title(Title) SP.plot_s_db(m=1 - 1, n=1 - 1, label=Legend_1, linewidth='3') SP.plot_s_db(m=3 - 1, n=3 - 1, label=Legend_2, linewidth='3') SP.plot_s_db(m=5 - 1, n=5 - 1, label=Legend_3, linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.legend() plt.grid() plt.figure() plt.title(Title) SP.plot_s_smith(m=1 - 1, n=1 - 1,
import matplotlib.pyplot as plt import skrf as rf from skrf import Network plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_Ideal = Network('SP/SP_Bad_Load.s2p') SP_FF = Network('SP/Load_RF12_FF.s2p') SP_SS = Network('SP/Load_RF12_SS.s2p') SP_TT = Network('SP/Load_RF12_TT.s2p') plt.figure() SP_TT.plot_s_db(m=0, n=0, label='S11(TT)', linewidth='3') SP_FF.plot_s_db(m=0, n=0, label='S11(FF)', linewidth='3') SP_SS.plot_s_db(m=0, n=0, label='S11(SS)', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.grid() plt.figure() SP_TT.plot_s_db(m=1, n=0, label='S21(TT)', linewidth='3') SP_FF.plot_s_db(m=1, n=0, label='S21(FF)', linewidth='3') SP_SS.plot_s_db(m=1, n=0, label='S21(SS)', linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S21, дБ') plt.grid() plt.show()
import matplotlib.pyplot as plt import skrf as rf from skrf import Network plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP = Network('SP/FR4_1UM.s2p') plt.figure() SP.plot_s_db(m=2-1, n=1-1, label='S21', linewidth ='3') plt.xlabel('F, Гц') plt.ylabel('S21, дБ') plt.grid() plt.figure() SP.plot_s_db(m=1-1, n=1-1, label='S11', linewidth ='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.grid() plt.figure() SP.plot_s_smith(0,0, label='S11', linewidth ='3',draw_labels=True) plt.show()
def VNA_Error(SP): for i in range(len(SP)): if abs(SP.s[i, 1, 0]) >= 1: SP.s[i, 1, 0] = SP.s[i - 1, 1, 0] if abs(SP.s[i, 0, 0]) >= 1: SP.s[i, 0, 0] = SP.s[i - 1, 0, 0] if abs(SP.s[i, 1, 1]) >= 1: SP.s[i, 1, 1] = SP.s[i - 1, 1, 1] if abs(SP.s[i, 0, 1]) >= 1: SP.s[i, 0, 1] = SP.s[i - 1, 0, 1] SP_W = Network('SP/De_embedding/W_DUT.s2p') SP_WO = Network('SP/De_embedding/WO_DUT.s2p') VNA_Error(SP_W) VNA_Error(SP_WO) plt.figure() SP_WO.plot_s_db(m=0, n=0, label='With', linewidth='3') SP_WO.plot_s_db(m=1, n=0, label='With', linewidth='3') SP_WO.plot_s_db(m=1, n=1, label='With', linewidth='3') SP_WO.plot_s_db(m=0, n=1, label='With', linewidth='3') plt.grid() DUT = rf.de_embed(SP_WO, SP_W) plt.figure()
from scipy import linalg plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" #Интересные функции numpy #https://pythonworld.ru/numpy/4.html #example #https://github.com/scikit-rf/scikit-rf/issues/235 #---------------------------------------------------------- #Input Data #---------------------------------------------------------- S_75 = Network("C:/Users/SH/PycharmProjects/Course_Python_Django/SP/Two_ports/Reference_75_DUT.s2p") Cascade = Network("C:/Users/SH/PycharmProjects/Course_Python_Django/SP/Two_ports/Cascade_D_A_D.s2p") Attenuator = Network("C:/Users/SH/PycharmProjects/Course_Python_Django/SP/Two_ports/Attenuator_9db.s2p") F = S_75.f[:] #---------------------------------------------------------- #Conversion and calculations #---------------------------------------------------------- Cascade_t = rf.s2t(Cascade.s) Attenuator_t = rf.s2t(Attenuator.s)
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np import math, cmath plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" #------------------------------------------------------------------ S_75 = Network("C:/Users/SH/Desktop/Test_1/75Ohm/75_Ohm_line.s2p") S_75_calc = Network("C:/Users/SH/Desktop/Test_1/75Ohm_calc.s2p") Attenuator_6db = Network( "C:/Users/SH/Desktop/Test_1/Attenuator_6db/Attenuator.s2p") Attenuator_6db_calc = Network( "C:/Users/SH/Desktop/Test_1/Attenuator_6db_calc.s2p") Attenuator_9db = Network( "C:/Users/SH/Desktop/Test_1/Attenuator_9db/Attenuator_9db.s2p") Attenuator_9db_calc = Network( "C:/Users/SH/Desktop/Test_1/Attenuator_9db_calc.s2p") #------------------------------------------------------------------ S11_75_db = 20 * np.log10(S_75.s[:, 1 - 1, 1 - 1]) S11_75_calc_db = 20 * np.log10(S_75_calc.s[:, 1 - 1, 1 - 1]) S21_75_db = 20 * np.log10(S_75.s[:, 2 - 1, 1 - 1]) S21_75_calc_db = 20 * np.log10(S_75_calc.s[:, 2 - 1, 1 - 1]) S11_AT_6db = 20 * np.log10(Attenuator_6db.s[:, 1 - 1, 1 - 1]) S11_AT_6db_calc = 20 * np.log10(Attenuator_6db_calc.s[:, 1 - 1, 1 - 1]) S21_AT_6db = 20 * np.log10(Attenuator_6db.s[:, 2 - 1, 1 - 1]) S21_AT_6db_calc = 20 * np.log10(Attenuator_6db_calc.s[:, 2 - 1, 1 - 1])
@author: Yevgeniy Simonov """ import numpy as np import matplotlib.pyplot as plt from skrf import Network #used for reading .snp files from numpy.fft import ifft if __name__ == "__main__": #paths to S-parameter data file_300 = 'BBHA9120D_300.s1p' file_1201 = 'BBHA9120D_1201.s1p' #frequencies in Hz S11_freq = np.squeeze(Network(file_300).frequency.f) #S11 parameters of Serial 300 S11_300 = np.squeeze(Network(file_300).s) #S11 parameters of Serial 1201 S11_1201 = np.squeeze(Network(file_1201).s) #defermine sampling frequency, assuming Nyquist Rate fs = 2.0 * np.amax(S11_freq) #determine the number of points in IFFT N = fs / (S11_freq[1] - S11_freq[0]) #2 ** 20 #find the closest location, so that 2^x1 < N < 2^x2 for i in range(1, 20):
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np import math, cmath plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" SP_input_50 = Network("SP/Test_diff/S11_input_50.s2p") SP_input_100 = Network("SP/Test_diff/S11_input_100.s2p") SP_input_200 = Network("SP/Test_diff/S11_input_200.s2p") SP_input_400 = Network("SP/Test_diff/S11_input_400.s2p") SP_load_50 = Network("SP/Test_diff/S11_load_50.s2p") SP_load_100 = Network("SP/Test_diff/S11_load_100.s2p") SP_load_200 = Network("SP/Test_diff/S11_load_200.s2p") SP_load_400 = Network("SP/Test_diff/S11_load_400.s2p") Sdd11_load_50 = 0.5 * (SP_load_50.s[:, 1 - 1, 1 - 1] + SP_load_50.s[:, 2 - 1, 2 - 1]) Sdd11_load_100 = 0.5 * (SP_load_100.s[:, 1 - 1, 1 - 1] + SP_load_100.s[:, 2 - 1, 2 - 1]) Sdd11_load_200 = 0.5 * (SP_load_200.s[:, 1 - 1, 1 - 1] + SP_load_200.s[:, 2 - 1, 2 - 1]) Sdd11_load_400 = 0.5 * (SP_load_400.s[:, 1 - 1, 1 - 1] + SP_load_400.s[:, 2 - 1, 2 - 1]) Sdd11_input_50 = 0.5 * ( SP_input_50.s[:, 1 - 1, 1 - 1] - SP_input_50.s[:, 1 - 1, 2 - 1] - SP_input_50.s[:, 2 - 1, 1 - 1] + SP_input_50.s[:, 2 - 1, 2 - 1])
def noise_matrices(): ''' Returns ------- mnm : complex128 (array) outbound noise correlation matrix due to internal noise. msesm : complex128 (array) outbound noise correlation matrix due to external noise. mem : complex128 (array) inbound noise correlation matrix due to external noise. z_load : complex128 (array) load impedance (impedance of identical LNAs). ''' #Specify data foulders sds_dut = Network(CONST.SDS_DUT_DIR).s s_array_pol = Network(CONST.S_ARRAY_DIR).s shape = (CONST.F_NUM, CONST.N_DIM, CONST.N_DIM) #matrix that holds scattering parameters of LNA s_lna = np.zeros(shape, dtype=np.complex128) s_array = np.zeros(shape, dtype=np.complex128) e_mat = np.zeros(shape, dtype=np.complex128) m_mat = np.zeros(shape, dtype=np.complex128) mp_mat = np.zeros(shape, dtype=np.complex128) msesm = np.zeros(shape, dtype=np.complex128) mem = np.zeros(shape, dtype=np.complex128) mnm = np.zeros(shape, dtype=np.complex128) imat = np.identity(CONST.N_DIM, dtype=np.float64) #Scattering parameters of DUT (LNA) s11_lna = sds_dut[:, 0, 0] s12_lna = sds_dut[:, 0, 1] s21_lna = sds_dut[:, 1, 0] s22_lna = sds_dut[:, 1, 1] z_load = 100.0 * (1.0 + s11_lna) / (1.0 - s11_lna ) #100 is the characteristic impedance #Create noise correlation matrix n_mat = noise_waves(s11_lna, s21_lna) for i in range(0, CONST.N_DIM, 2): j = i + 1 s_lna[:, i, i] = s11_lna[:] s_lna[:, j, j] = s22_lna[:] s_lna[:, i, j] = s12_lna[:] s_lna[:, j, i] = s21_lna[:] s_array[:, 0::2, 0::2] = s_array_pol[:, :, :] for i in range(0, CONST.F_NUM): e_mat[i, :, :] = imat[:, :] - mat_prod(s_array[i, :, :], conjt(s_array[i, :, :])) m_mat[i, :, :] = inv(imat[:, :] - mat_prod(s_lna[i, :, :], s_array[i, :, :])) mp_mat[i, :, :] = inv(imat[:, :] - mat_prod(s_array[i, :, :], s_lna[i, :, :])) msesm[i, :, :] = multi_dot([m_mat[i, :, :], s_lna[i, :, :], e_mat[i, :, :], \ conjt(s_lna[i, :, :]), conjt(m_mat[i, :, :])]) mem[i, :, :] = multi_dot( [mp_mat[i, :, :], e_mat[i, :, :], conjt(mp_mat[i, :, :])]) mnm[i, :, :] = multi_dot( [m_mat[i, :, :], n_mat[i, :, :], conjt(m_mat[i, :, :])]) return mnm, msesm, mem, z_load
import matplotlib.pyplot as plt import skrf as rf from skrf import Network import numpy as np plt.rcParams["font.family"] = "Century Gothic" plt.rcParams["font.size"] = "14" Folder_1 = f"SP/Calibration/Calibration_10mm.s2p" Legend_1 = "L=10мм" Folder_2 = f"SP/Calibration/Calibration_50mm.s2p" Legend_2 = "L=50мм" SP_10 = Network(Folder_1) SP_50 = Network(Folder_2) plt.figure() SP_10.plot_s_db(m=1 - 1, n=1 - 1, label = Legend_1, linewidth='3') SP_50.plot_s_db(m=1 - 1, n=1 - 1, label = Legend_2, linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S11, дБ') plt.grid() plt.figure() SP_10.plot_s_db(m=2 - 1, n=1 - 1, label = Legend_1, linewidth='3') SP_50.plot_s_db(m=2 - 1, n=1 - 1, label = Legend_2, linewidth='3') plt.xlabel('F, Гц') plt.ylabel('S21, дБ') plt.grid()
def open_file(file_dialog, file_dialog_result, mpl_plot, **kwargs): file_dialog_result.value = file_dialog.open() private.network = Network(file_dialog_result.value) update_plot(mpl_plot)
def AnalyzeTouchstoneFile(): root = tk.Tk() root.withdraw() root.filename = askopenfilename(initialdir="./Touchstone_Files", title="Select Touchstone file", filetypes=(("Touchstone files", "*.s1p *.s2p *.s*p"), ("all files", "*.*"))) TSFilePath = root.filename Sm = 1 Sn = 1 def setSParam(mm, nn): global Sm, Sn Sm = mm Sn = nn Close_start_menu.config(state=tk.NORMAL) Close_start_menu.config(bg='lime') def getSParam(): global Sm, Sn return Sm, Sn def close_start_window(): start_window.quit() start_window.destroy() start_window = tk.Tk() start_window.title('Select S-Parameter') start_window.config(bg='white') S11_button = tk.Button(start_window, text="S11", bg='white', command=lambda: setSParam(1, 1), height=1, width=20) S21_button = tk.Button(start_window, text="S21", bg='white', command=lambda: setSParam(2, 1), height=1, width=20) S12_button = tk.Button(start_window, text="S12", bg='white', command=lambda: setSParam(1, 2), height=1, width=20) S22_button = tk.Button(start_window, text="S22", bg='white', command=lambda: setSParam(2, 2), height=1, width=20) blank_space = tk.Label(start_window, text=" ", bg='white') Close_start_menu = tk.Button(start_window, text="GO!", bg='white', command=close_start_window) Close_start_menu.config(state=tk.DISABLED) S11_button.grid(sticky='we', row=0, column=0) S21_button.grid(sticky='we', row=1, column=0) S12_button.grid(sticky='we', row=0, column=1) S22_button.grid(sticky='we', row=1, column=1) blank_space.grid(sticky='we', row=2, column=0) Close_start_menu.grid(sticky='we', row=3, column=0, columnspan=2) start_window.mainloop() Sm, Sn = getSParam() #fig, axarr = plt.subplots(1,2, sharex=True) #plot1 = axarr[0] #plot2 = axarr[1] plt.figure() #plt.title('Scattering Parameter Results') s_plot = Network(TSFilePath) s_plot.frequency.unit = 'mhz' s_plot.plot_s_db(m=Sm - 1, n=Sn - 1) #, label = "Tuned and Matched") #s_plot.plot_s_smith(m=Sm-1,n=Sn-1, ax=plot2, draw_labels=True) #plot1.set_title('Magnetude') plt.legend(loc='best') plt.grid(color='lightgray', linestyle='-', linewidth=1) #plot2.set_title('Smith Chart') #plot2.legend(loc='lower center', ncol=2) #plot2.grid(color='lightgray', linestyle='-', linewidth=2) plt.tight_layout() plt.show()