Simulink® enables you to model single-rate and multirate discrete systems. In a single-rate system, all the blocks in the model operate at the same rate. In a multirate system, different blocks operate at different rates. You can control the rate of block execution in a model by specifying the sample time (Simulink) (inverse of sample rate) at the block level. The sample time of a block indicates when the block generates outputs or updates its internal state. For more details on block execution rates, see Sample Time (Simulink). You can access sample time information interactively using tools such as Timing Legend and Model Data Editor (Simulink).
This topic starts by defining basic concepts such as samples and frames, sample time (also known as sample period), sample rate, frame period, and frame rate, all in the context of a Simulink model. The topic then explains how to inspect sample rates and frame rates in a Simulink model using color coding and Timing Legend.
Samples and Frames
Sample is a value or a set of values of a signal at a given time instant. A frame can be a vector or matrix of samples of consecutive times stacked together. For more details on samples and frames, see Sample- and Frame-Based Concepts.
Sample Time (or Sample Period)
Sample time Ts of a block is the parameter that indicates when the block during simulation produces outputs and, if appropriate, updates its internal state. Sample time is the time interval between individual samples in a frame.
The sample rate of a signal is the reciprocal of the sample time (or sample period) Ts. Mathematically, the sample rate can be represented using .
In most cases, when you build a Simulink model, you need to set sample rates for only the source blocks. Simulink automatically computes the appropriate sample rates for the blocks connected to the source blocks.
Frame Period and its Relationship to the Sample Period
The frame period Tf is given by the product of the sample time Ts and the frame size M, and it is represented using the following equation:
The frame rate of a signal is the reciprocal of the frame period Tf and can be represented using .
This diagram shows a single-channel signal with a frame size M of 4 and a frame period Tf of 1 second. The sample period Ts is therefore 1/4 or 0.25 seconds.
In most cases, the sequence sample time Ts is more important, while the frame rate is simply a consequence of the frame size that you choose for the signal. For a sequence with a given sample time, a larger frame size corresponds to a slower frame rate and vice versa.
Input and Output Sample and Frame Period
In Simulink, blocks can have different rates for their inputs and outputs (rate conversion blocks). The frame period and frame rate at the input and output of the block is calculated based on the sample time and the signal frame size. In most cases, when you build a Simulink model, you need to set sample rates for only the source blocks. Simulink automatically computes the appropriate sample rates for the blocks connected to the source blocks.
The input frame period (Tfi) of a signal is the time interval between consecutive frame inputs to a block. Similarly, the output frame period (Tfo) is the time at which the block updates the frame vector or matrix value at the output port.
More specifically, the sample time of inputs (Tsi) and outputs (Tso) are related to their respective frame periods by the following equations:
where Mi and Mo are the input and output frame sizes, respectively.
Mathematically, the input frame rate is given by and the output frame rate is given by .
The block decides whether to process the signal one sample at a time or one
frame at a time depending on the settings in the block dialog box. For example,
a Biquad Filter block with the
Input processing parameter set to
as channels (frame based) treats a
2 input signal as a two-frame
signal with three samples in each frame. If the Input
processing parameter is set to
Elements as channels
(sample based), the
2 input signal is treated as a
six-channel signal with one sample in each channel. For more details, see Sample- and Frame-Based Concepts.
You can inspect the sample rate and frame rate of signals in a Simulink model using color coding. When you enable color coding, each sample time type (Simulink) in your model has one or more colors associated with it. Furthermore, you can annotate these signals based on their sample time and show this data in a Timing Legend. The Timing Legend contains the sample time color, annotation, and value for each sample time in the model. For more details, see View Sample Time Information (Simulink).
The following two models enable you to inspect sample rate and frame rate of signals using the color coding technique.
Open the model
'ex_color_tut1'. In this model, the input signal is upsampled by a factor of 5 using the Upsample block, and the signal downsampled by a factor of 2 using the Downsample block. The overall rate conversion factor is 5/2. The Signal From Workspace block that generates the input signal has the Sample time parameter set to 2 seconds, and the Samples per frame parameter is set to 1. The Input processing parameter in the Upsample and the Downsample blocks is set to
Elements as channels (sample based). This setting enables the blocks to treat each sample they receive as an independent channel.
Enable Sample Time Color Coding
To enable sample time color coding in this model, on the Debug tab, select Information Overlays > Colors. This selection turns on sample time color coding. Simulink now assigns each sample time in the model a different color. In addition, to enable annotation for all sample times, select Information Overlays > Text. Selecting both Colors and Text displays both the colors and the annotations. Run the model. Every signal in this model has a different sample rate. Therefore, each signal is assigned a different color.
Inspect Sample Time Using Timing Legend
You can view the information on the sample time color, annotations, and the value of each sample time in the model using a Timing Legend. To enable this legend, select Information Overlays > Timing Legend. Simulink updates the model diagram and opens the Timing Legend. The Timing Legend shows the values of the frame period of the signal. In this example, because the Upsample and Downsample blocks treat each sample as an independent channel, and the Samples per frame parameter of the source block is set to 1 and the frame period of the signal is the same as the sample period (sample time) of the signal.
As you can see from the frame period values in the timing legend, signal D3 originating from the source block is the slowest with a sample time of 2 seconds. The Upsample block increases the sample rate of the signal by a factor of 5. As a result, the sample time reduces by a factor of 5 and becomes 0.4 seconds. Furthermore, the signal is downsampled by a factor of 2, making the sample time of the output signal D2 0.8 seconds.
The legend provides two highlighting options:
Highlighting the blocks and signals that the sample time originates from.
Highlighting all the blocks and signals that contain the selected sample time.
To enable highlighting the origin of the sample times, click the Origin option from the Highlight menu. Select a specific sample time from the list (D3 in this case) to see the source of this sample time.
You can also click the type of the sample time to highlight all sources of a particular type of sample time.
To enable highlighting of all the blocks that contain a selected sample time, click the All option from the Highlight menu.
None option from the Highlight menu clears current highlighting.
You can also display the sample rate (1/sample period) of the signal by clicking on the 1/p button. The timing legend displays 1/period values.
Open the model
'ex_color_tut2'. The Signal From Workspace block has the Sample time parameter set to 1, and the Samples per frame parameter is set to 16. Each frame in the generated signal contains 16 samples. The Input processing parameter in the Upsample and the Downsample blocks is set to
Columns as channels (frame based) and the Rate options parameter is set to
Allow multirate processing. This setting enables the Upsample and Downsample blocks to operate in the multirate mode and treat data as frames of size 16.
Enable Sample Time Color Coding
On the Debug tab, select Information Overlays > Colors and Text. This selection turns on sample time color coding and annotations. Run the model. Simulink assigns each frame rate a different color.
Inspect Frame Rate Using Timing Legend
Enable the Timing Legend by selecting Information Overlays > Timing Legend. Simulink updates the model and opens the Timing Legend. You can view the value of the frame period for each signal in the model, the color associated with the frame period, and the corresponding annotation. For example, the frame period of the input signal (denoted by D3 in the Timing Legend) is given by or , which equals 16 seconds. The D1 signal is upsampled by a factor of 5. As a result, the frame period of D1 is 16/5 or 3.2 seconds. The signal D2 that follows is downsampled by 2, and the resultant frame period is 3.2 x 2 = 6.4 seconds.
Because the Rate options parameter in the Upsample and Downsample blocks is set to
Allow multirate processing, each of these blocks changes the frame rate. Therefore, each frame signal in the model is assigned a different color.
You can view the frame rate of the signal by clicking the 1/p button in the timing legend.
Double-click on the Upsample block and the Downsample block, and change the Rate options parameter to
Enforce single-rate processing.
Run the model. Every signal now has the same frame period and is therefore coded with the same color.
There are two other techniques that you can use to inspect signals in your model: Model Data Editor and Probe (Simulink) blocks.
Model Data Editor
Data Editor (Simulink) (on the Modeling tab, click
Model Data Editor) shows information about model data
(signals, parameters, and states) in a sortable, searchable table. The
Sample Time column shows the sample time specified for
each signal in a model. After you update the block diagram, the column also
shows the specific sample that each signal uses (for example, for signals where
you specify inherited sample time, the column value is
You can also use this column to specify sample times.
You can connect Probe blocks to the signal that you want to inspect. The Probe blocks show signal parameters such as signal width, sample time, signal complexity, and signal dimensions.