<jupyter_start><jupyter_text>Insertion Loss Fitted (Fit) 和 ILD<jupyter_code>import skrf
from pylab import *

sp = skrf.Network('/Users/xdong/project/Autotester/temp/Autotest/parameters/test/40g.s4p')
print(sp)
sp.renumber([0, 1, 2, 3], [0, 2, 1, 3])
sp.se2gmm(p=2)
sp_mm = sp
print(sp_mm)
sp_mm.s21.s_db[:,0,0]

sp_mm.plot_s_db()
sp_mm.s_db[:101,1,0]  # get first 100 values of S21, also meas sdd21 in mixedmode
print(sp_mm.s_db[:,1,0].shape)
sp_mm.s_db[:,1,0].reshape(-1, 1)
print(sp_mm.s_db[:,1,0].reshape(-1, 1).shape)<jupyter_output>(2001,)
(2001, 1)<jupyter_text>plot s21<jupyter_code>%matplotlib inline
skrf.stylely()

from matplotlib import pyplot as plt

plt.title('Ring Slot $S_{dd21}$')

sp_mm.s21.plot_s_db(label='Full Band Response')
sp_mm.s21['10-26ghz'].plot_s_db(lw=3,label='Band of Interest')<jupyter_output><empty_output><jupyter_text>构造FIT算法<jupyter_code>from math import sqrt
import numpy
from numpy.linalg import inv

def calc(a1, a2, a4, freq):
    il_fitted = a1*sqrt(freq) + a2*freq + a4*(freq**2)
    return il_fitted
il_fitted = calc(6, 1, 0.08, 5.15625)
print(il_fitted)

# 构造F矩阵
def matrix_f(sp):
    a1 = numpy.sqrt(sp_mm.f)
    a2 = sp_mm.f
    a3 = numpy.square(sp_mm.f)
    return numpy.array((a1, a2, a3)).swapaxes(1, 0) 
# 计算多项式系数矩阵mat_a    
f = matrix_f(sp_mm)
print('f.shape:', f.shape)
f_denominator = inv(f.transpose().dot(f))
print('f_denominator:', f_denominator.shape, f_denominator)
# a = f.transpose().dot(sp_mm.s_db[:,1,0].reshape(-1, 1)).dot(f_denominator)
mat_a = f_denominator.dot(f.transpose()).dot(sp_mm.s_db[:,1,0].reshape(-1, 1))
print(a.shape, a)

# 计算IL_fitted
list_a = mat_a.flatten().tolist()
a1 = list_a[0]; a2 = list_a[1]; a4 = list_a[2]
_il_fitted = [calc(a1, a2, a4, freq) for freq in sp_mm.f]

# plot
%matplotlib inline
skrf.stylely()

from matplotlib import pyplot as plt
# plt.title('IL fitted')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude (dB)')

plt.plot(sp_mm.f, _il_fitted, linewidth=2, label='IL fitted')
plt.plot(sp_mm.f, sp_mm.s21.s_db[:,0,0], color='r', label='IL sdd21')
plt.plot(sp_mm.f, sp_mm.s21.s_db[:,0,0] - _il_fitted, color='c', label='ILD')

plt.legend(loc='best')<jupyter_output>20.907629718438713
f.shape: (2001, 3)
f_denominator: (3, 3) [[ 3.40021910e-12 -3.49693151e-17  4.85563639e-28]
 [-3.49693151e-17  3.74624488e-22 -5.46191002e-33]
 [ 4.85563639e-28 -5.46191002e-33  8.49418464e-44]]
(3, 1) [[-4.80853585e-05]
 [-2.66798920e-10]
 [-8.22153189e-21]]
{'fraction_non_alphanumeric': 0.18788374948833403, 'fraction_numerical': 0.11174785100286533, 'mean_word_length': 5.381201044386423, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '475285', 'license': 'Apache-2.0', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1209, 'n_words': 192, 'path': 'ILfitted and ILD.ipynb', 'repo_name': 'madmadcat/MyNotebook', 'size': '2443'}