import numpy as np
import matplotlib.pyplot as plt
import skrf as rf
from scipy.optimize import minimize
from matplotlib import style
from skrf import plotting
plt.rcParams['figure.figsize'] = 13,6
# Matching network for Antenna
# |------L1-----C1----|----C3-----L2----|
# | | |
# Z_0 C2 Z_L
# | | |
# GND
# Matching with Lumped Elements
# Let’s assume the load is 200 + 0j for a line Z_0 = 50 ohm at the frequency of 6 MHz.
Z_L = 200 + 0j
Z_0 = 50
f_0_str = '10MHz'
# frequency band centered on the frequency of interest
frequency = rf.Frequency(start=6, stop=16, npoints=401, unit='MHz')
# transmission line Media
line = rf.DefinedGammaZ0(frequency=frequency, z0=Z_0)
# load Network
load = line.load(rf.zl_2_Gamma0(Z_0, Z_L))
def matching_network_LCCCL_1(L1, C1, C2, C3, L2):
'L1, C1, C2, C3 and L2 in uH and pF'
return line.inductor(L1*1e-6)**line.capacitor(C1*1e-12)**line.shunt_capacitor(C2*1e-12)**line.capacitor(C3*1e-12)**line.inductor(L2*1e-6)**load
# Static inductor loads
# initial guess values
L1 = 3.2 # uH - Fixed static inductor load
C1 = 260 # pF
C2 = 260 # pF
C3 = 250 # pF
L2 = 3.2 # uH - Fixed static inductor load
x0 = (L1, C1, C2, C3, L2)
# bounds
L1_minmax = (3.2, 3.2) # uH
C1_minmax = (35, 1000) # pF
C2_minmax = (35, 1000) # pF
C3_minmax = (35, 1000) # pF
L2_minmax = (3.2, 3.2) # uH
# the objective functions minimize the return loss at the target frequency f_0
def optim_fun_1(x, f0=f_0_str):
_ntw = matching_network_LCCCL_1(*x)
print("Running optimization for values (L1, C1, C2, C3, L2) : ", x)
return np.abs(_ntw[f_0_str].s).ravel()
res1 = minimize(optim_fun_1, x0, bounds=(L1_minmax, C1_minmax, C2_minmax, C3_minmax, L2_minmax))
print(f'Optimum found for LCCCL network 1: \n L1={res1.x[0]} uH;\n C1={res1.x[1]} pF ;\n C2={res1.x[2]} pF ;\n C3={res1.x[3]} pF ; and\n L2={res1.x[4]} uH')
# printed Optimum results
# Optimum found for LCCCL network 1:
# L1=3.2 uH;
# C1=176.9325799674975 pF ;
# C2=156.43228266359162 pF ;
# C3=257.3454309200819 pF ; and
# L2=3.2 uH
ntw1 = matching_network_LCCCL_1(*res1.x)
ntw1.plot_s_mag(lw=2, label='LCCCL network 1')
plt.ylim(bottom=0)
plt.grid(True)
ntw1.plot_s_db(lw=2, label='LCCCL network 1')
plt.grid(True)
with style.context('seaborn-ticks'):
ntw1.plot_s_smith()
# plotting.add_markers_to_lines()
plt.xlabel('Real Part')
plt.ylabel('Imaginary Part')
plt.title('Smith Chart')
plt.legend(loc=5)
plt.show()