Guy and Seth on Simulink

September 7th, 2008

Continuous Time Integrator

One of the ways I think of Simulink is as a graphical interface to the solvers.  Moreover, when I think of the solvers, I usually think of the continuous time solvers and the integrator block.  In this post, I will show you some of the capabilities of the continuous time integrator that you might not know about.  I will also demonstrate how I keep track of the ports on the integrator block.

The Continuous State

The continuous time Integrator block is the building block for ODEs/continuous time systems.  Labeing the input and output of the Integrator block keeps my signals organized when drawing ODEs.

The Integrator block

Labeling the signals is also beneficial when adding reset, initial condition, saturation, and state ports to the block.

External Reset

The External reset signal (second inport) triggers the integrator state to reset to the initial condition value.  External reset can be set to rising, falling, either edge, level or level hold.

Integrator block with rising edge reset

The internal initial condition is not always the right value at the time the state resets.  Often, the new state value comes from a calculation in the model via the IC port.

External Initial Condition

Set the Initial condition source as external to provide the IC value via signal.

Integrator block with external initial condition

This state (x) is set to this signal value when the reset signal triggers.  To provide an initial condition at time Tstart, add an IC block (from the Signal Attributes library) inline with the signal that calculates the IC.

Limit Output (state saturation)

The Limit output check box enables the Upper saturation limit and Lower saturation limit parameters.  This also adds the saturation icon to the block.  Note, it is easy to mistake this as an integral signal, however, this actually indicates that the state has an upper and/or lower limit.

Integrator block with limited output

Saturation Port

Check the Show saturation port parameter to add a second output, the saturation port.  The signal from this port is 0 when the value of the state is within the limits, and 1 when the value of the state is at the limit.  This transition from 0 to 1 and 1 to 0 can be used as rising and falling edges triggers.

Integrator block with staturation port

State port

Clicking Show state port adds a special port on the top of the block.  The state port provides a way to model self-resetting integrators and performing state hand off between enabled subsystems without creating algebraic loops.

Integrator with state port

Bouncing Ball Demo

The bouncing ball demo combines some of these integrator block capabilities.

Simulink bouncing ball model

Click on this image for a web view of the sldemo_bounce model.

Note the use of the IC block to provide an Initial Velocity and Initial Position for the bouncing ball.  The IC block feeds through its input when T≠Tstart.  This allows the ball to reset the velocity state (V) to -0.8 * V when the position of the ball hits zero.  This use of the state port prevents the algebraic loop connecting the velocity state to the initial state value and reset signals.  Here are the simulation results.

Bouncing ball demo scope

Now it’s your turn

I got into the habit of labeling the ports on the integrator while I was a trainer teaching Simulink.  It was always helpful in keeping the model organized.  Have you used these features of the Integrator block?  What did your model do?  Leave me a comment here.

8 Responses to “Continuous Time Integrator”

  1. Amin replied on :

    Hi Seth!
    Is it necessary to rest the position integral in the bouncing ball demo?
    I get same result without reset the integral and set the internal initial condition to 10.

  2. KMR replied on :

    The initial condition block may not be the best thing to use if you need to generate code from your diagram and have the initial condition be specifiable external to the generated code (e.g., your continuous model is the truth model for a hardware-in-the-loop simulation), or if your diagram is in a referenced model. I typically use parameters with scope ExternGlobal for this. The drawback is that, with lots of integrators, the workspace gets cluttered up. Maybe eventually the Mathworks will support Matlab structure elements as fully tunable parameters in generated code and model references without resorting to the C-API.

  3. dziki replied on :

    Hi

    How can I made blocks “initial volocity” and “initial position” in matlab simulink R14?
    I can not find such block in simulink liblary!

    Teanks You
    Dziki

  4. Seth replied on :

    @Dziki – Those initial conditions are “IC” blocks from the Signal Attributes library. Good luck.

  5. Marcelo Tomim replied on :

    Hello Seth,

    Thank you very much for the very informative article.
    However, I have another question I faced myself with when programming a simulink block. How can I place a port (input or output) at the bottom or at the top of the simulink block, or even nudge them a bit up or down?

    I look forward to hearing from you.

    Cheers,
    Marcelo

  6. Guy replied on :

    @Marcelo, it is only possible to place ports either left-right or up-down by rotating the block. It is not possible to have ports on the four sides of a block simultaneously. Similarly it is not possible to nudge them a bit up or down.

    If your license is under maintenance, I suggest contacting The Mathworks technical support, ask for this capability and explain why this is important for you.

  7. Abdunnoer Kaldine replied on :

    Thanks Seth .. IC port was confuzing me

  8. Seth replied on :

    @Abdunnoer Kaldine – I’m glad it was helpful!

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks
Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.