AWR-Python
Design of a low Pass filter using python using AWR.
Design specification : f0=3GHz
Try the following python code to create schematic and measurements automatically from Visual Studio Code.
import math
import pyawr.mwoffice as mwo
# — — — — — — — — — — — — — — — — — — — — — — — —
# User Specifications
# — — — — — — — — — — — — — — — — — — — — — — — —
schematic_name = “Auto_LPF”
N = 5
fc = 3e9
Z0 = 50
# — — — — — — — — — — — — — — — — — — — — — — — —
# Butterworth prototype g values
# — — — — — — — — — — — — — — — — — — — — — — — —
def butterworth_g(n):
g=[]
for k in range(1,n+1):
gk = 2*math.sin((2*k-1)*math.pi/(2*n))
g.append(gk)
return g
gvals = butterworth_g(N)
# — — — — — — — — — — — — — — — — — — — — — — — —
# Convert to lumped elements
# — — — — — — — — — — — — — — — — — — — — — — — —
components=[]
for k,g in enumerate(gvals,start=1):
if k % 2 == 1:
L = Z0*g/(2*math.pi*fc)
components.append((“IND”,L))
else:
C = g/(Z0*2*math.pi*fc)
components.append((“CAP”,C))
# — — — — — — — — — — — — — — — — — — — — — — — —
# Connect to AWR
# — — — — — — — — — — — — — — — — — — — — — — — —
awrde = mwo.CMWOffice()
# Delete schematic if exists
if awrde.Project.Schematics.Exists(schematic_name):
for i in range(1,awrde.Project.Schematics.Count+1):
if awrde.Project.Schematics(i).Name == schematic_name:
awrde.Project.Schematics.Remove(i)
break
schem = awrde.Project.Schematics.Add(schematic_name)
# — — — — — — — — — — — — — — — — — — — — — — — —
# Input Port
# — — — — — — — — — — — — — — — — — — — — — — — —
p1 = schem.Elements.Add(
“PORT”,
0,
0,
0,
False
)
prev_node = p1.Nodes(1)
x=1000
last_series_node = prev_node
# — — — — — — — — — — — — — — — — — — — — — — — —
# Build ladder filter
# — — — — — — — — — — — — — — — — — — — — — — — —
for ctype,val in components:
if ctype==”IND”:
ind=schem.Elements.Add(
“IND”,
x,
0,
0,
False
)
ind.Parameters(“L”).ValueAsDouble=val
schem.Wires.Add(
x1=prev_node.x,
y1=prev_node.y,
x2=ind.Nodes(1).x,
y2=ind.Nodes(1).y
)
prev_node=ind.Nodes(2)
last_series_node=prev_node
if ctype==”CAP”:
cap=schem.Elements.Add(
“CAP”,
x,
-1000,
Get S Pournamy’s stories in your inbox
Join Medium for free to get updates from this writer.
-90,
False
)
cap.Parameters(“C”).ValueAsDouble=val
gnd=schem.Elements.Add(
“GND”,
x,
-2000,
0,
False
)
# connect line node to capacitor
schem.Wires.Add(
x1=prev_node.x,
y1=prev_node.y,
x2=cap.Nodes(1).x,
y2=cap.Nodes(1).y
)
# capacitor to ground
schem.Wires.Add(
x1=cap.Nodes(2).x,
y1=cap.Nodes(2).y,
x2=gnd.Nodes(1).x,
y2=gnd.Nodes(1).y
)
x +=1000
# — — — — — — — — — — — — — — — — — — — — — — — —
# Output Port
# — — — — — — — — — — — — — — — — — — — — — — — —
p2=schem.Elements.Add(
“PORT”,
x+500,
0,
180,
False
)
schem.Wires.Add(
x1=last_series_node.x,
y1=last_series_node.y,
x2=p2.Nodes(1).x,
y2=p2.Nodes(1).y
)
# — — — — — — — — — — — — — — — — — — — — — — — —
# Frequencies
# — — — — — — — — — — — — — — — — — — — — — — — —
schem.UseProjectFrequencies=False
freqs=schem.Frequencies
freqs.Clear()
freq_list=[
0.5e9,
1e9,
1.5e9,
2e9,
2.5e9,
3e9,
3.5e9,
4e9,
5e9
]
freqs.AddMultiple(freq_list)
# — — — — — — — — — — — — — — — — — — — — — — — —
# Response Graph
# — — — — — — — — — — — — — — — — — — — — — — — —
graphs=awrde.Project.Graphs
if graphs.Exists(“LPF_Response”):
for i in range(1,graphs.Count+1):
if graphs(i).Name==”LPF_Response”:
graphs.Remove(i)
break
g=graphs.Add(
“LPF_Response”,
mwo.mwGraphType.mwGT_Rectangular
)
g.Measurements.Add(
schematic_name,
“DB(|S(2,1)|)”
)
g.Measurements.Add(
schematic_name,
“DB(|S(1,1)|)”
)
# — — — — — — — — — — — — — — — — — — — — — — — —
# Simulate
# — — — — — — — — — — — — — — — — — — — — — — — —
awrde.Project.Simulator.Analyze()
print(“Filter synthesized and simulated.”)








