Band Stop Filter with an Algebraic Loop
NOTE: You will need to have an installed and functioning version of MATLAB® and Simulink® to run this example.
Section Layout
Import the System
Simulate the System
Initialization
withBlockImporter
BuildDE,Import,PrintSummary,SimplifyModel
This is an example of a band pass filter. This example contains an algebraic loop, and therefore will not execute in Simulink.
We import the model with the following command. We need to specify the name of the model to import, as well as a MATLAB® script that initializes the variable names.
datadir≔BlockImporter:-DataDirectory:
model1 ≔ Importfilterb,path=datadir, init=filterb_init,inplace:
Warning: Block diagram 'temp_filterb' contains 1 algebraic loop(s). To see more details about the loops use the command line Simulink debugger by typing "sldebug temp_filterb" in the MATLAB command window. To eliminate this message, set the Algebraic loop option in the Diagnostics page of the Simulation Parameters Dialog to "None". > In calsignal at 35 In startrep at 127 Found algebraic loop containing: 'temp_filterb/Gain' 'temp_filterb/Derivative1' 'temp_filterb/Gain2' 'temp_filterb/Sum3' 'temp_filterb/Sum1' (algebraic variable)
Using the PrintSummary command, we can view the model that we have imported.
PrintSummarymodel1
K0,c1=0.00100000000000000002,K0,c2=0.00100000000000000002,K0,r=1000.
We can now simplify the model to reduce the number of equations.
smodel1 ≔ SimplifyModelmodel1:
PrintSummarysmodel1
First we take the system and build a set of differential equations, and assign the result to the variable sys.
sys1 ≔ BuildDEsmodel1:
The following table illustrates the different components of the variable sys1.
Differential Equations
sys1:-equations
x2,1⁡t=K0,c2⁢SinkScope,8,1,1⁡t−SourceStep,9,1⁡t,ⅆⅆt⁢x7,1⁡t=−K0,r⁢ⅆⅆt⁢x2,1⁡t−SourceStep,9,1⁡t+x7,1⁡tK0,r⁢K0,c1,SinkScope,8,1,1⁡t=−K0,r⁢ⅆⅆt⁢x2,1⁡t+x7,1⁡t
Parameter values
sys1:-parameters
Initial conditions
sys1:-initialeqs
x2,1⁡0=0,x7,1⁡0=0
Equations for the sources (inputs)
sys1:-sourceeqs
SourceStep,9,1⁡t={0t<11otherwise
List of sinks (outputs)
sys1:-outputvars
SinkScope,8,1,1⁡t
Using the information in the variable sys, we construct a simulation procedure.
sol1 ≔ dsolveevalevalsys1:-equations, sys1:-sourceeqs,sys1:-parameters, sys1:-initialeqs, numeric,interr=false
procx_rkf45_dae...end proc
Then we plot the simulation results.
plotsodeplotsol1, t, sys1:-outputvars1, 0..20, numpoints=200, title=Step Response,gridlines=true
Download Help Document