Simulink® allows you to specify a block sample time directly
as a numerical value or symbolically by defining a sample time vector.
In the case of a discrete sample time, the vector is [
, ] where
is the sampling
the initial time offset. For example, consider a discrete model that
produces its outputs every two seconds. If your base time unit is
seconds, you can directly set the discrete sample time by specifying
the numerical value of
2 as the
Because the offset value is zero, you do not need to specify it; however,
you can enter [
2,0] in the Sample time field.
For nondiscrete blocks, the components of the vector are symbolic
values that represent one of the types in Types of Sample Time. The following table summarizes these
types and the corresponding sample time values. The table also defines
the explicit nature of each sample time type and designates the associated
color and annotation. Because
an inherited sample time is explicit, you can
specify it as
[-1, 0] or as
Whereas, a triggered sample time is implicit; only Simulink can
assign the sample time of
[-1, -1]. (For more information
about colors and annotations, see View Sample Time Information.)
Designations of Sample Time Information
|Sample Time Type||Sample Time||Color||Annotation||Explicit|
|Discrete||[Ts, To]||In descending order of speed: red, green, blue, light blue, dark green, orange||D1, D2, D3, D4, D5, D6, D7,... Di||Yes|
|Fixed in minor step||[0, 1]||gray||FiM||Yes|
|Variable||[–2,Tvo]||brown||V1, V2,... Vi||No|
|Triggered||cyan||T1, T2,... Ti||No|
|Asynchronous||[–1, –n]||purple||A1, A2,... Ai||No|
The color that is assigned to each block depends on its sample time relative to other sample times in the model. This means that the same sample time may be assigned different colors in a parent model and in models that it references. (See Model Reference.)
For example, suppose that a model defines three sample times:
3. Further, suppose that it references a model
that defines two sample times:
In this case, blocks operating at the
rate appear as green in the parent model and as red in the referenced
It is important to note that Mux and Demux blocks are simply grouping operators; signals passing through them retain their timing information. For this reason, the lines emanating from a Demux block can have different colors if they are driven by sources having different sample times. In this case, the Mux and Demux blocks are color coded as hybrids (yellow) to indicate that they handle signals with multiple rates.
Similarly, Subsystem blocks that contain blocks with differing sample times are also colored as hybrids, because there is no single rate associated with them. If all the blocks within a subsystem run at a single rate, the Subsystem block is colored according to that rate.
You can use the explicit sample time values in this table to specify sample times interactively or programmatically for either block-based or port-based sample times.
The following model,
serves as a reference for this section.
In this example, set the sample time of the input sine wave
0.1. The goal is to achieve an output
sample time of
0.2. The Rate Transition block
serves as a zero-order hold. The resulting block diagram after setting
the sample times and simulating the model is shown in the following
figure. (The colors and annotations indicate that this is a discrete
ex_specify_sample_time after Setting Sample Times
To set the sample time of a block interactively:
In the Simulink model window, double-click the block. The block parameter dialog box opens.
Enter the sample time in the Sample time field.
Following is a figure of a parameters dialog box for the Sine
Wave block after entering
0.1 in the Sample
The Rate Transition block has port-based sample times. You can set the output port sample time interactively by completing the following steps:
Double-click the Rate Transition block. The parameters dialog box opens.
Leave the drop-down menu choice of the Output
port sample time options as
-1 in the Output
port sample time field with
For more information about the sample time options in the Rate Transition parameters dialog box, see the Rate Transition reference page.
To set a block sample time programmatically, set its
to the desired sample time using the
For example, to set the sample time of the Gain block
in the "Specify_Sample_Time" model to inherited (
enter the following command:
As with interactive specification, you can enter just the first vector component if the second component is zero.
To set the output port sample time of the Rate Transition block
0.2, use the
with the parameter
set_param('Specify_Sample_Time/Rate Transition',... 'OutPortSampleTime', '0.2')
To access all sample times associated with a model, use the
To access the sample time of a single block, use the API
You can design custom blocks so that the input and output ports operate at different sample time rates. For information on specifying block-based and port-based sample times for S-functions, see Sample Times .
Since the execution of a Simulink model is not dependent
on a specific set of units, you must determine the appropriate base
time unit for your application and set the sample time values accordingly.
For example, if your base time unit is second, then you would represent
a sample time of
0.5 second by setting the sample
To change a sample time after simulation begins, you must stop
the simulation, reset the
and then restart execution.