def BPF_synthesis(n, f0, df, fstart, fstop, points, z0=50.0, first_element="series", type = "Chebyshev", ripple = 0.1):
"""
BPFを合成し、scikit-rfのCircuitとして返す関数
n : フィルタの次数(チェビシェフの場合、偶数だと負荷のインピーダンスが50Ωになりません)
f0 : 中心周波数[GHz]
df : 帯域幅[GHz]
fstart : 開始周波数[GHz]
fstop : 終了周波数[GHz]
points : 周波数点数
z0 : 信号源の特性インピーダンス
first_element : 最初にシリーズのLが来る場合"series", 最初にシャントのCが来る場合"shunt"
type : チェビシェフの場合"Chebyshev", バタワースの場合 "Butterworth"
ripple : チェビシェフの場合のリップルの大きさをdBで表したもの
"""
freq = rf.Frequency(start=fstart, stop=fstop, unit='GHz', npoints=points)
LC_elements = LC_BPF(n, f0, df, z0, first_element, type, ripple)
tl_media = rf.DefinedGammaZ0(freq, z0=LC_elements[0, 0], gamma=1j*freq.w/rf.c)
gnd = rf.Circuit.Ground(freq, name='gnd')
port1 = rf.Circuit.Port(freq, name='port1', z0=z0)
port2 = rf.Circuit.Port(freq, name='port2', z0=LC_elements[-1, 0])
if first_element == "series":
Ls = [0]
Cs = [0]
Lp = [0]
Cp = [0]
countL = 1
countC = 1
for k in range(1, n + 1):
if k % 2 != 0:
Ls.append(tl_media.inductor(LC_elements[k,0], name = f"Ls{countL}"))
Cs.append(tl_media.capacitor(LC_elements[k,1], name = f"Cs{countL}"))
countL +=1
else:
Lp.append(tl_media.inductor(LC_elements[k,0], name = f"Lp{countC}"))
Cp.append(tl_media.capacitor(LC_elements[k,1], name = f"Cp{countC}"))
countC += 1
cnx = [[(port1, 0), (Ls[1], 0)]]
if n % 2 != 0:
for k in range(1, n//2 + 1):
cnx.append([(Ls[k], 1), (Cs[k], 0)])
cnx.append([(Cs[k], 1), (Lp[k], 0), (Cp[k], 0), (Ls[k+1], 0)])
cnx.append([(Ls[n//2 + 1], 1),(Cs[n//2 + 1], 0)])
cnx.append([(Cs[n//2 + 1], 1), (port2, 0)])
else:
for k in range(1, n//2):
cnx.append([(Ls[k], 1), (Cs[k], 0)])
cnx.append([(Cs[k], 1), (Lp[k], 0), (Cp[k], 0), (Ls[k+1], 0)])
cnx.append([(Ls[n//2], 1), (Cs[n//2], 0)])
cnx.append([ (Cs[n//2], 1), (Lp[n//2], 0), (Cp[n//2], 0), (port2, 0)])
gnd_cnx = [(gnd, 0)]
for k in range(1, n//2 + 1):
gnd_cnx.append((Lp[k], 1))
gnd_cnx.append((Cp[k], 1))
cnx.append(gnd_cnx)
elif first_element == "shunt":
Ls = [0]
Cs = [0]
Lp = [0]
Cp = [0]
countL = 1
countC = 1
for k in range(1, n + 1):
if k % 2 != 0:
Lp.append(tl_media.inductor(LC_elements[k,0], name = f"Lp{countC}"))
Cp.append(tl_media.capacitor(LC_elements[k,1], name = f"Cp{countC}"))
countC += 1
else:
Ls.append(tl_media.inductor(LC_elements[k,0], name = f"Ls{countL}"))
Cs.append(tl_media.capacitor(LC_elements[k,1], name = f"Cs{countL}"))
countL +=1
cnx = [[(port1, 0), (Lp[1], 0), (Cp[1], 0), (Ls[1], 0)]]
gnd_cnx = [(gnd, 0)]
if n % 2 != 0:
for k in range(1, n//2):
cnx.append([(Ls[k], 1), (Cs[k], 0)])
cnx.append([(Cs[k], 1), (Lp[k+1], 0), (Cp[k+1], 0), (Ls[k+1], 0)])
cnx.append([(Ls[n//2], 1),(Cs[n//2],0)])
cnx.append([(Cs[n//2], 1), (Lp[n//2 + 1], 0), (Cp[n//2 + 1], 0), (port2, 0)])
for k in range(1, n//2 + 2):
gnd_cnx.append((Lp[k], 1))
gnd_cnx.append((Cp[k], 1))
else:
for k in range(1, n//2):
cnx.append([(Ls[k], 1), (Cs[k], 0)])
cnx.append([(Cs[k], 1), (Lp[k+1], 0), (Cp[k+1], 0), (Ls[k+1], 0)])
cnx.append([(Ls[n//2], 1), (Cs[n//2], 0)])
cnx.append([(Cs[n//2], 1), (port2, 0)])
for k in range(1, n//2 + 1):
gnd_cnx.append((Lp[k], 1))
gnd_cnx.append((Cp[k], 1))
cnx.append(gnd_cnx)
return rf.Circuit(cnx)
最近のコメント