Band Stop Filter with an Algebraic Loop - BlockImporter Help

Home : Support : Online Help : Toolboxes : BlockImporter : Examples : BlockImporter/Examples/AlgebraicLoop

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

$\mathrm{with}\left(\mathrm{BlockImporter}\right)$

 $\left[{\mathrm{BuildDE}}{,}{\mathrm{Import}}{,}{\mathrm{PrintSummary}}{,}{\mathrm{SimplifyModel}}\right]$ (1.1)



Import the System

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.

$\mathrm{datadir}≔\mathrm{BlockImporter}:-\mathrm{DataDirectory}\left(\right):$

 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.

$\mathrm{PrintSummary}\left(\mathrm{model1}\right)$

 $\left[{{K}}_{{0}{,}{"c1"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"c2"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"r"}}{=}{1000.}\right]$ (2.1)

We can now simplify the model to reduce the number of equations.

$\mathrm{PrintSummary}\left(\mathrm{smodel1}\right)$

 $\left[{{K}}_{{0}{,}{"c1"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"c2"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"r"}}{=}{1000.}\right]$ (2.2)



Simulate the System

First we take the system and build a set of differential equations, and assign the result to the variable sys.





The following table illustrates the different components of the variable sys1.

Differential Equations

$\mathrm{sys1}:-\mathrm{equations}$

 $\left[{{x}}_{{2}{,}{1}}{}\left({t}\right){=}{{K}}_{{0}{,}{"c2"}}{}\left({{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{8}{,}{1}{,}{1}}{}\left({t}\right){-}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{9}{,}{1}}{}\left({t}\right)\right){,}\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{7}{,}{1}}{}\left({t}\right){=}{-}\frac{{{K}}_{{0}{,}{"r"}}{}\left(\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{2}{,}{1}}{}\left({t}\right)\right){-}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{9}{,}{1}}{}\left({t}\right){+}{{x}}_{{7}{,}{1}}{}\left({t}\right)}{{{K}}_{{0}{,}{"r"}}{}{{K}}_{{0}{,}{"c1"}}}{,}{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{8}{,}{1}{,}{1}}{}\left({t}\right){=}{-}{{K}}_{{0}{,}{"r"}}{}\left(\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{2}{,}{1}}{}\left({t}\right)\right){+}{{x}}_{{7}{,}{1}}{}\left({t}\right)\right]$ (3.1)

${}$

Parameter values

$\mathrm{sys1}:-\mathrm{parameters}$

 $\left[{{K}}_{{0}{,}{"c1"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"c2"}}{=}{0.00100000000000000002}{,}{{K}}_{{0}{,}{"r"}}{=}{1000.}\right]$ (3.2)

${}$

Initial conditions

$\mathrm{sys1}:-\mathrm{initialeqs}$

 $\left[{{x}}_{{2}{,}{1}}{}\left({0}\right){=}{0}{,}{{x}}_{{7}{,}{1}}{}\left({0}\right){=}{0}\right]$ (3.3)

${}$

Equations for the sources (inputs)

$\mathrm{sys1}:-\mathrm{sourceeqs}$

 $\left[{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{9}{,}{1}}{}\left({t}\right){=}{{}\begin{array}{cc}{0}& {t}{<}{1}\\ {1}& {\mathrm{otherwise}}\end{array}\right]$ (3.4)

${}$

List of sinks (outputs)

$\mathrm{sys1}:-\mathrm{outputvars}$

 $\left[{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{8}{,}{1}{,}{1}}{}\left({t}\right)\right]$ (3.5)

${}$



Using the information in the variable sys, we construct a simulation procedure.



 ${\mathbf{proc}}\left({\mathrm{x_rkf45_dae}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3.6)



Then we plot the simulation results.