Using Simulink    

Modeling and Simulating Discrete Systems

Simulink has the ability to simulate discrete (sampled data) systems, including systems whose components operate at different rates (multirate systems) and systems that mix discrete and continuous components (hybrid systems). This capability stems from two key Simulink features:

The ability to specify sample times on a block-by-block basis, either directly through the SampleTime parameter or indirectly through inheritance, enables you to model systems containing discrete components operating at different rates and hybrid systems containing discrete and continuous components.

Specifying Sample Time

Simulink allows you to specify the sample time of any block that has a SampleTime parameter. You can use the block's parameter dialog box to set this parameter. You do this by entering the sample time in the Sample time field on the dialog box. You can enter either the sample time alone or a vector whose first element is the sample time and whose second element is an offset: [Ts, To]. Various values of the sample time and offset have special meanings.

The following table summarizes valid values for this parameter and how Simulink interprets them to determine a block's sample time.

Sample Time
Usage
[Ts, To]
0 > T
s < Tsim
|T
o| < Tp
Specifies that updates occur at simulation times
  • tn = n * Ts + |To| 
    
where n is an integer in the range 1..Tsim/Ts and Tsim is the length of the simulation. Blocks that have a sample time greater than 0 are said to have a discrete sample time.
The offset allows you to specify that Simulink update the block later in the sample interval than other blocks operating at the same rate.
[0, 0], 0
Specifies that updates occur at every major and minor time step. A block that has a sample time of 0 is said to have a continuous sample time.
[0, 1]
Specifies that updates occur only at major time steps, skipping minor time steps (see Minor Time Steps). This setting avoids unnecessary computations for blocks whose sample time cannot change between major time steps. The sample time of a block that executes only at major time steps is said to be fixed in minor time step.
[-1, 0], -1
If the block is not in a triggered subsystem, this setting specifies that the block inherits its sample time from the block connected to its input (inheritance) or, in some cases, from the block connected to its output (back inheritance). If the block is in a triggered subsystem, you must set the SampleTime parameter to this setting.
Note that specifying sample-time inheritance for a source block can cause Simulink to assign an inappropriate sample time to the block if the source drives more than one block. For this reason, you should avoid specifying sample-time inheritance for source blocks. If you do, Simulink displays a warning message when you update or simulate the model.

Changing a Block's Sample Time

You cannot change the SampleTime parameter of a block while a simulation is running. If you want to change a block's sample time, you must stop and restart the simulation for the change to take effect.

Compiled Sample Time

During the compilation phase of a simulation, Simulink determines the sample time of the block from its SampleTime parameter (if it has a SampleTime parameter), sample-time inheritance, or block type (Continuous blocks always have a continuous sample time). It is this compiled sample time that determines the sample rate of a block during simulation. You can determine the compiled sample time of any block in a model by first updating the model and then getting the block's CompiledSampleTime parameter, using the get_param command.


  Algebraic Loops Purely Discrete Systems