This example shows how to model an RF filter using Circuit Envelope Library. In this example you compare the input and output signal amplitudes to study the signal attenuation.
This example uses an LC bandpass filter designed to have a bandwidth of 200 MHz. The filter uses a three tone input signal to demonstrate the filter attenuation property for in-band and out-band frequencies. The input signal tones are:
700 MHz — Center frequency of the filter passband
600 MHz — Lower edge frequency of the filter passband
900 MHz — Frequency outside the filter passband
Define model variables for blocks that share parameter values
using the InitFcn
:
In Simulink® editor, click Modeling. In the toolstrip, in SETUP> Model Settings, click Model Properties.
In the Model Properties dialog
box, on the Callbacks tab in Model
callbacks pane, select InitFcn
.
In the Model initialization function pane, enter:
amp = ones(1,3) freq = [600 700 900]*1e6 stepsize = 1/500e6
Click OK.
In the Simulink tool bar, change the Simulation stop time to 0.
In Simulink editor, click Simulation In the PREPARE, click Model Settings in
Configuration and Simulation In the
Solver tab, in Solver
options change the Solver
to discrete (no continuous states)
.
The filter system consists of LC Ladder, Inport, Outport and Configuration blocks. The physical part of the model uses bidirectional RF signals.
The blocks used in the system are:
Block | Library Path | Description | Quantity |
---|---|---|---|
Constant | Simulink > Sources | Generates real and complex constant value | 1 |
Inport | RF Blockset > Circuit Envelope > Utilities | Convert Simulink input signal to RF Blockset™ input signal | 1 |
Configuration | RF Blockset > Circuit Envelope > Utilities | Set the system wide parameters for RF Blockset simulation | 1 |
LC Ladder | RF Blockset > Circuit Envelope > Elements | Models the signal attenuation caused by the LC Ban | 1 |
Outport | RF Blockset > Circuit Envelope > Utilities | Convert RF Blockset signals to Simulink Signals | 1 |
db Conversion | DSP System Toolbox > Math Functions > Math Operations | Convert magnitude data to decibels | 2 |
Math Function | Simulink > Math Operations | Performs mathematical function. | 2 |
To workspace | Simulink > Sinks | Write data to a MATLAB® workspace for plotting | 2 |
Terminator | Simulink > Commonly Used Blocks > Terminator | Terminate the angle baseband output of the Outport block | 1 |
Connect the blocks as shown in the figure:
Generate the three-tone input signal using these blocks:
Constant block specifies the amplitude of the signal.
Inport block configures the frequencies of the three tones.
Configuration block specifies the step size.
In the Constant block dialog box set
the Constant value to amp
,
as defined in the InitFcn
.
In the Inport block:
Set Source type to Power
.
Set Carrier frequencies to freq
,
as defined in InitFcn
. The freq
variable
sets the frequency of the three tones to 600 MHz, 700 MHz, and 900
MHz respectively.
Click OK.
In the Configuration block dialog box:
Set Step size to step size
, as defined in
InitFcn
.
Clear Simulate noise.
Click OK.
The fundamental tones and harmonics are updated automatically when you run the model.
In the LC Ladder block dialogue box:
Set Ladder topology to LC
Bandpass Pi
.
Click Apply and then click OK.
In the Outport block :
Set Sensor type to Power
.
Set Output to Magnitude
and Angle Baseband
.
Set Carrier frequencies to freq
,
as defined in InitFcn
.
Click OK.
In the Simulink editor, connect the Ang port of the Outport block to Terminator block to terminate the angle baseband output.
In Math Function and Math
Function 1 block dialog boxes, set Function to magnitude^2
and
click OK. The block squares the magnitude of
the input and output signal.
In dB Conversion and dB
Conversion 1 block dialog boxes, set Input Signal to Power
and
click OK. The block converts the input and
output signals to dB.
In To Workspace, change the Variable
name to In
. In To Workspace
1, change the Variable name to Out
.
In both the block dialog boxes, change the set Save format to Array
and
click OK.
Use Simulation > Run
to
run the model.
Display the input and output signals using semilogx
function,
in dB.
Transfer the input and output dB values to the MATLAB workspace using To Workspace block.
To view the input signal, plot In
array
from the MATLAB workspace :
figure h = semilogx(freq, In,'-gs','LineWidth',1,... ...'MarkerSize',3,'MarkerFaceColor','r'); xlim([5.5e8,9.5e8]) xlabel('Frequency[Hz]') ylabel('Amplitude[dB]') title('Input Signal')
To view the output signal, plot Out
array
from the MATLAB workspace :
figure h = semilogx(freq, Out,'-gs','LineWidth',1,... ...'MarkerSize',3,'MarkerFaceColor','r'); xlim([5.5e8,9.5e8]) ylim([-25,1]) xlabel('Frequency[Hz]') ylabel('Amplitude[dB]') title('Attenuated Output Signal')
Compare the input and output signal plots to verify the attenuation caused by the filter.
Input Signal to RF Filter
The following plot shows the filtered attenuated signal.
Attenuated Output Signal
Notice that the RF filter does not attenuate the signal at the center frequency of 700 MHz.
Plot more points to better understand the response of the LC bandpass filter. Change the defined variables in Model Properties to :
amp = ones(1,201) freq = logspace (8,10,201) stepsize = 1/500e6
Run the model. Notice that the signal is not attenuated within the 200 MHz range of the LC bandpass filter.
Plot the attenuated output:
figure h = semilogx(freq, Out,'-gs','LineWidth',1... .............,'MarkerSize',3,'MarkerFaceColor','r'); xlim([5.5e8,9.5e8]) ylim([-25,1]) xlabel('Frequency[Hz]') ylabel('Amplitude[dB]') title('LC Bandpass Filter Frequency Response')