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+
1313import 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
1815import 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
3031def 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" )
6057format_plot ()
6158plt .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" )
7472format_plot ()
7573plt .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 ()
8383print ("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