Skip to content

Commit aca2940

Browse files
ramin4667Samuelopez-ansysmyoung301
authored
FIX: Filtersolutions lumped element example update (#325)
Co-authored-by: Samuelopez-ansys <[email protected]> Co-authored-by: Matthew Young <[email protected]>
1 parent 8d1e0aa commit aca2940

File tree

9 files changed

+98
-31
lines changed

9 files changed

+98
-31
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ exclude: |
33
doc/source/conf.py
44
)
55
6+
67
repos:
78

89
- repo: https://github.com/psf/black
910
rev: 22.3.0
1011
hooks:
1112
- id: black
13+
args: [--line-length=200]
1214

1315
- repo: https://github.com/adamchainz/blacken-docs
1416
rev: 1.16.0
@@ -20,6 +22,7 @@ repos:
2022
rev: 5.12.0
2123
hooks:
2224
- id: isort
25+
args: ["--profile", "black", "--filter-files"]
2326

2427
- repo: https://github.com/PyCQA/flake8
2528
rev: 5.0.4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The following guidelines help ensure that the examples are consistent, easy to r
4242
be rendered and run in [Jupyter Lab](https://docs.jupyter.org/en/latest/) as Notebook files. Jupyter can be used to ensure correct
4343
rendering of markdown, images, and equations.
4444
```
45-
pip install .[doc]
45+
pip install -r requirements/requirements_doc.txt
4646
jupyter lab
4747
```
4848
- You can use this [template](./examples/template.py) to help you start creating a new example

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def convert_examples_into_notebooks(app):
284284
"template.py",
285285
"gui_manipulation.py",
286286
"electrothermal.py",
287-
# TODO: Remove the following example when 2025.1 is released, currently the latest version is 24.1.
287+
# GitHub CI/CD Pipeline fails to run lumped_element.py but it runs locally.
288288
"lumped_element.py",
289289
# TODO: Remove once EMIT examples are moved into extensions.
290290
"interference_type.py",
174 KB
Loading
41.1 KB
Loading
31.3 KB
Loading
43.2 KB
Loading

examples/high_frequency/radiofrequency_mmwave/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ These examples use PyAEDT to show some radio frequency and millimeter wave appli
7171
:align: center
7272

7373
This example shows how to use PyAEDT to use the FilterSolutions module to design and visualize the frequency
74-
response of a band-pass Butterworth filter.
75-
74+
response of a band-pass Butterworth filter and export the lumped element model to AEDT Circuit.
7675

7776
.. grid-item-card:: Flex cable CPWG
7877
:padding: 2 2 2 2
Lines changed: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# # Lumped element filter design
22
#
33
# This example shows how to use PyAEDT to use the ``FilterSolutions`` module to design and
4-
# visualize the frequency response of a band-pass Butterworth filter.
4+
# visualize the frequency response of a band-pass Butterworth filter and export the lumped element model to AEDT Circuit.
55
#
66
# Keywords: **filter solutions**
77

88
# ## Perform imports and define constants
99
#
1010
# Perform required imports.
1111

12-
# +
12+
1313
import ansys.aedt.core
14-
from ansys.aedt.core.filtersolutions_core.attributes import (
15-
FilterClass, FilterImplementation, FilterType)
16-
from ansys.aedt.core.filtersolutions_core.ideal_response import \
17-
FrequencyResponseColumn
14+
import ansys.aedt.core.filtersolutions
1815
import matplotlib.pyplot as plt
19-
# -
16+
from ansys.aedt.core.filtersolutions_core.attributes import FilterClass, FilterType
17+
from ansys.aedt.core.filtersolutions_core.export_to_aedt import ExportFormat
18+
from ansys.aedt.core.filtersolutions_core.ideal_response import (
19+
SParametersResponseColumn,
20+
)
2021

2122
# Define constants.
2223

@@ -30,7 +31,7 @@
3031
def format_plot():
3132
plt.xlabel("Frequency (Hz)")
3233
plt.ylabel("Magnitude S21 (dB)")
33-
plt.title("Ideal Frequency Response")
34+
plt.title("Frequency Response")
3435
plt.xscale("log")
3536
plt.legend()
3637
plt.grid()
@@ -40,44 +41,108 @@ def format_plot():
4041
#
4142
# Create a lumped element filter design and assign the class, type, frequency, and order.
4243

43-
design = ansys.aedt.core.FilterSolutions(
44-
version=AEDT_VERSION, implementation_type=FilterImplementation.LUMPED
45-
)
46-
design.attributes.filter_class = FilterClass.BAND_PASS
47-
design.attributes.filter_type = FilterType.BUTTERWORTH
48-
design.attributes.pass_band_center_frequency = "1G"
49-
design.attributes.pass_band_width_frequency = "500M"
50-
design.attributes.filter_order = 5
44+
lumped_design = ansys.aedt.core.filtersolutions.LumpedDesign(version=AEDT_VERSION)
45+
lumped_design.attributes.filter_class = FilterClass.BAND_PASS
46+
lumped_design.attributes.filter_type = FilterType.BUTTERWORTH
47+
lumped_design.attributes.pass_band_center_frequency = "1G"
48+
lumped_design.attributes.pass_band_width_frequency = "500M"
49+
lumped_design.attributes.filter_order = 5
5150

5251
# ## Plot frequency response of filter
5352
#
5453
# Plot the frequency response of the filter without any transmission zeros.
5554

56-
freq, mag_db = design.ideal_response.frequency_response(
57-
FrequencyResponseColumn.MAGNITUDE_DB
58-
)
59-
plt.plot(freq, mag_db, linewidth=2.0, label="Without Tx Zero")
55+
freq, s21_db = lumped_design.ideal_response.s_parameters(SParametersResponseColumn.S21_DB)
56+
plt.plot(freq, s21_db, linewidth=2.0, label="Without Tx Zero")
6057
format_plot()
6158
plt.show()
6259

60+
# <img src="_static/ideal_filter_response.png" width="400">
61+
62+
6363
# ## Add a transmission zero to filter design
6464
#
6565
# Add a transmission zero that yields nulls separated by two times the pass band width (1 GHz).
6666
# Plot the frequency response of the filter with the transmission zero.
6767

68-
design.transmission_zeros_ratio.append_row("2.0")
69-
freq_with_zero, mag_db_with_zero = design.ideal_response.frequency_response(
70-
FrequencyResponseColumn.MAGNITUDE_DB
71-
)
72-
plt.plot(freq, mag_db, linewidth=2.0, label="Without Tx Zero")
73-
plt.plot(freq_with_zero, mag_db_with_zero, linewidth=2.0, label="With Tx Zero")
68+
lumped_design.transmission_zeros_ratio.append_row("2.0")
69+
freq_with_zero, s21_db_with_zero = lumped_design.ideal_response.s_parameters(SParametersResponseColumn.S21_DB)
70+
plt.plot(freq, s21_db, linewidth=2.0, label="Without Tx Zero")
71+
plt.plot(freq_with_zero, s21_db_with_zero, linewidth=2.0, label="With Tx Zero")
7472
format_plot()
7573
plt.show()
7674

75+
# <img src="_static/filter_response_added_zeros.png" width="400">
76+
7777
# ## Generate netlist for designed filter
7878
#
7979
# Generate and print the netlist for the designed filter with the added transmission zero to
8080
# the filter.
8181

82-
netlist = design.topology.circuit_response()
82+
netlist = lumped_design.topology.netlist()
8383
print("Netlist: \n", netlist)
84+
85+
# ### Printed output:
86+
# ```
87+
# Netlist:
88+
# *
89+
# V1 1 0 AC 1 PULSE 0 1 0 1.592E-13 0
90+
# R0 1 2 50
91+
# *
92+
# * Dummy Resistors Required For Spice
93+
# * Have Been Added to Net List.
94+
# *
95+
# L1 2 0 6.674E-09
96+
# C2 2 0 3.796E-12
97+
# C3 2 3 1.105E-12
98+
# L4 3 4 2.292E-08
99+
# L5 4 5 8.53E-09
100+
# C5 5 0 7.775E-12
101+
# L6 4 6 3.258E-09
102+
# C6 6 0 2.97E-12
103+
# C7 4 7 1.105E-12
104+
# Rq7 4 7 5E+10
105+
# L8 7 8 2.292E-08
106+
# L9 8 0 6.674E-09
107+
# C10 8 0 3.796E-12
108+
# R11 8 0 50
109+
# *
110+
# .AC DEC 200 2E+08 5E+09
111+
# .PLOT AC VDB(8) -80 0
112+
# .PLOT AC VP(8) -200 200
113+
# .PLOT AC VG(8) 0 5E-09
114+
# .TRAN 5E-11 1E-08 0
115+
# .PLOT TRAN V(8) -0.09 0.1
116+
# .END
117+
# ```
118+
119+
# ## Export lumped element model of the filter to AEDT Circuit
120+
#
121+
# Export the designed filter with the added transmission zero to
122+
# AEDT Circuit with the defined export parameters.
123+
124+
lumped_design.export_to_aedt.schematic_name = "LumpedElementFilter"
125+
lumped_design.export_to_aedt.simulate_after_export_enabled = True
126+
lumped_design.export_to_aedt.smith_plot_enabled = True
127+
lumped_design.export_to_aedt.table_data_enabled = True
128+
circuit = lumped_design.export_to_aedt.export_design(export_format=ExportFormat.DIRECT_TO_AEDT)
129+
130+
# <img src="_static/exported_filter_to_desktop.png" width="400">
131+
132+
# ## Plot the simulated circuit
133+
#
134+
# Get the scattering parameter data from the AEDT Circuit simulation and create a plot.
135+
136+
solutions = circuit.post.get_solution_data(
137+
expressions=circuit.get_traces_for_plot(category="S"),
138+
)
139+
sim_freq = solutions.primary_sweep_values
140+
sim_freq_ghz = [i * 1e9 for i in sim_freq]
141+
sim_s21_db = solutions.data_db20(expression="S(Port2,Port1)")
142+
plt.plot(freq, s21_db, linewidth=2.0, label="Without Tx Zero")
143+
plt.plot(freq_with_zero, s21_db_with_zero, linewidth=2.0, label="With Tx Zero")
144+
plt.plot(sim_freq_ghz, sim_s21_db, linewidth=2.0, linestyle="--", label="Simulated")
145+
format_plot()
146+
plt.show()
147+
148+
# <img src="_static/simulated_filter_response.png" width="400">

0 commit comments

Comments
 (0)