| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Signal Processing Blockset |
| Contents | Index |
| Learn more about Signal Processing Blockset |
| On this page… |
|---|
Rate Conversion by Frame-Rate Adjustment Rate Conversion by Frame-Size Adjustment Avoiding Unintended Rate Conversion |
There are two common types of operations that impact the frame and sample rates of a signal: direct rate conversion and frame rebuffering. Direct rate conversions, such as upsampling and downsampling, can be implemented by altering either the frame rate or the frame size of a signal. Frame rebuffering, which is used alter the frame size of a signal in order to improve simulation throughput, usually changes either the sample rate or frame rate of the signal as well.
The following table lists the principal rate conversion blocks in Signal Processing Blockset software. Blocks marked with an asterisk (*) offer the option of changing the rate by either adjusting the frame size or frame rate.
| Block | Library |
|---|---|
Downsample * | Signal Operations |
Dyadic Analysis Filter Bank | Filtering / Multirate Filters |
Dyadic Synthesis Filter Bank | Filtering / Multirate Filters |
FIR Decimation * | Filtering / Multirate Filters |
FIR Interpolation * | Filtering / Multirate Filters |
FIR Rate Conversion | Filtering / Multirate Filters |
Repeat * | Signal Operations |
Upsample * | Signal Operations |
Rate conversion blocks accept an input signal at one sample rate, and propagate the same signal at a new sample rate. Several of these blocks contain a Frame-based mode parameter offering two options for adjusting the sample rate of the signal:
Maintain input frame rate: Change the sample rate by changing the frame size (that is, Mo ≠ Mi), but keep the frame rate constant (Tfo = Tfi).
Maintain input frame size: Change the sample rate by changing the output frame rate (that is Tfo ≠ Tfi), but keep the frame size constant (Mo = Mi).
The setting of this parameter does not affect sample-based inputs.
Note When a Simulink model contains signals with various frame rates, the model is called multirate. You can find a discussion of multirate models in Excess Algorithmic Delay (Tasking Latency). Also see Scheduling Considerations in the Real-Time Workshop® documentation. |
One way to change the sample rate of a signal, 1/Tso, is to change the output frame rate (Tfo ≠ Tfi), while keeping the frame size constant (Mo = Mi). Note that the sample rate of a signal is defined as 1/Tso = Mo/Tfo:
At the MATLAB command prompt, type doc_downsample_tut1.
The Downsample Example T1 model opens.

From the Format menu, point to Port/Signal Displays, and select Signal Dimensions.
When you run the model, the dimensions the signals appear next to the lines connecting the blocks.
Double-click the Signal From Workspace block. The Block Parameters: Signal From Workspace dialog box opens.
Set the block parameters as follows:
Sample time = 0.125
Samples per frame = 8
Based on these parameters, the Signal From Workspace block outputs a frame-based signal with a sample period of 0.125 second and a frame size of 8.
Save these parameters and close the dialog box by clicking OK.
Double-click the Downsample block. The Block Parameters: Downsample dialog box opens.
Set the Frame-based mode parameter to Maintain input frame size, and then click OK.
The Downsample block is configured to downsample the signal by changing the frame rate rather than the frame size.
After the simulation, the model should look similar to the following figure.

Because
,
the input frame period,
,
is
second. This value
is displayed by the first Probe block. Therefore the input frame rate,
, is also 1 second.
The second Probe block in the model verifies that the output
from the Downsample block has a frame period,
, of 2
seconds, twice the frame period of the input. However, because the
frame rate of the output,
, is 0.5 second, the Downsample block actually downsampled
the original signal to half its original rate. As a result, the output
sample period,
,
is doubled to 0.25 second without any change to the
frame size. The signal dimensions in the model confirm that the frame
size did not change.
One way to change the sample rate of a signal is by changing the frame size (that is Mo ≠ Mi), but keep the frame rate constant (Tfo = Tfi). Note that the sample rate of a signal is defined as 1/Tso = Mo/Tfo:
At the MATLAB command prompt, type doc_downsample_tut2.
The Downsample Example T2 model opens.

From the Format menu, point to Port/Signal Displays, and select Signal Dimensions.
When you run the model, the dimensions the signals appear next to the lines connecting the blocks.
Double-click the Signal From Workspace block. The Block Parameters: Signal From Workspace dialog box opens.
Set the block parameters as follows:
Sample time = 0.125
Samples per frame = 8
Based on these parameters, the Signal From Workspace block outputs a frame-based signal with a sample period of 0.125 second and a frame size of 8.
Save these parameters and close the dialog box by clicking OK.
Double-click the Downsample block. The Block Parameters: Downsample dialog box opens.
Set the Frame-based mode parameter to Maintain input frame rate, and then click OK.
The Downsample block is configured to downsample the signal by changing the frame size rather than the frame rate.
After the simulation, the model should look similar to the following figure.

Because
,
the input frame period,
,
is
second. This value
is displayed by the first Probe block. Therefore the input frame rate,
, is also 1 second.
The Downsample block downsampled the input signal to half its
original frame size. The signal dimensions of the output of the Downsample
block confirm that the downsampled output has a frame size of 4,
half the frame size of the input. As a result, the sample period of
the output,
, now has a sample
period of 0.25 second. This process occurred without any change to
the frame rate (
).
It is important to be aware of where rate conversions occur in a model. In a few cases, unintentional rate conversions can produce misleading results:
At the MATLAB command prompt, type doc_vectorscope_tut1.
The Vector Scope Example model opens.
Double-click the upper Sine Wave block. The Block Parameters: Sine Wave dialog box opens.
Set the block parameters as follows:
Frequency (Hz) = 1
Sample time = 0.1
Samples per frame = 128
Based on the Sample time and the Samples per frame parameters, the Sine Wave outputs a sinusoid with a frame period of 128*0.1 or 12.8 seconds.
Save these parameters and close the dialog box by clicking OK.
Set the block parameters as follows, and then click OK:
Frequency (Hz) = 2
Sample time = 0.1
Samples per frame = 128
Based on the Sample time and the Samples per frame parameters, the Sine Wave outputs a sinusoid with a frame period of 128*0.1 or 12.8 seconds.
Double-click the Magnitude FFT block. The Block Parameters: Magnitude FFT dialog box opens.
Select the Inherit FFT length from input dimensions check box, and then click OK.
This setting instructs the block to use the input frame size (128) as the FFT length (which is also the output size).
Set the block parameters as follows, and then click OK:
Click the Scope Properties tab.
Input domain = Frequency
Click the Axis Properties tab.
Minimum Y-limit = -10
Maximum Y-limit = 40
The model should now look similar to the following figure. Note that the signal leaving the Magnitude FFT block is 128-by-1.

The Vector Scope window displays the magnitude FFT of a signal composed of two sine waves, with frequencies of 1 Hz and 2 Hz.

The Vector Scope block uses the input frame size (128) and period (12.8) to deduce the original signal's sample period (0.1), which allows it to correctly display the peaks at 1 Hz and 2 Hz.
Double-click the Magnitude FFT block. The Block Parameters: Magnitude FFT dialog box opens.
Set the block parameters as follows:
Based on these parameters, the Magnitude FFT block zero-pads the length-128 input frame to a length of 256 before performing the FFT.
The model should now look similar to the following figure. Note that the signal leaving the Magnitude FFT block is 256-by-1.

The Vector Scope window displays the magnitude FFT of a signal composed of two sine waves, with frequencies of 2 Hz and 4 Hz.

In this case, based on the input frame size (256) and frame period (12.8), the Vector Scope block incorrectly calculates the original signal's sample period to be (12.8/256) or 0.05 second. As a result, the spectral peaks appear incorrectly at 2 Hz and 4 Hz rather than 1 Hz and 2 Hz.
The source of the error described above is unintended rate conversion. The zero-pad operation performed by the Magnitude FFT block halves the sample period of the sequence by appending 128 zeros to each frame. To calculate the spectral peaks correctly, the Vector Scope block needs to know the sample period of the original signal.
To correct for the unintended rate conversion, double-click the Vector Scope block.
The Vector Scope block now accurately plots the spectral peaks at 1 Hz and 2 Hz.
In general, when you zero-pad or overlap buffers, you are changing the sample period of the signal. If you keep this in mind, you can anticipate and correct problems such as unintended rate conversion.
There are two common types of operations that impact the frame and sample rates of a signal: direct rate conversion and frame rebuffering. Direct rate conversions, such as upsampling and downsampling, can be implemented by altering either the frame rate or the frame size of a signal. Frame rebuffering, which is used alter the frame size of a signal in order to improve simulation throughput, usually changes either the sample rate or frame rate of the signal as well.
Sometimes you might need to rebuffer a signal to a new frame size at some point in a model. For example, your data acquisition hardware may internally buffer the sampled signal to a frame size that is not optimal for the signal processing algorithm in the model. In this case, you would want to rebuffer the signal to a frame size more appropriate for the intended operations without introducing any change to the data or sample rate.
The following table lists the principal Signal Processing Blockset buffering blocks.
| Block | Library |
|---|---|
Signal Management/ Buffers | |
Signal Management/ Buffers | |
Signal Management/ Buffers | |
Signal Management/ Indexing |
Buffering operations provide another mechanism for rate changes in signal processing models. The purpose of many buffering operations is to adjust the frame size of the signal, M, without altering the signal's sample rate Ts. This usually results in a change to the signal's frame rate, Tf, according to the following equation:
![]()
However, the equation above is only true if no samples are added or deleted from the original signal. Therefore, the equation above does not apply to buffering operations that generate overlapping frames, that only partially unbuffer frames, or that alter the data sequence by adding or deleting samples.
There are two blocks in the Buffers library that can be used to change a signal's frame size without altering the signal itself:
Buffer — redistributes signal samples to a larger or smaller frame size
Unbuffer — unbuffers a frame-based signal to a sample-based signal (frame size = 1)
The Buffer block preserves the signal's data and sample period only when its Buffer overlap parameter is set to 0. The output frame period, Tfo, is

where Tfi is the input frame period, Mi is the input frame size, and Mo is the output frame size specified by the Output buffer size (per channel) parameter.
The Unbuffer block unbuffers a frame-based signal to its sample-based equivalent, and always preserves the signal's data and sample period
![]()
where Tfi and Mi are the period and size, respectively, of the frame-based input.
Both the Buffer and Unbuffer blocks preserve the sample period of the sequence in the conversion (Tso = Tsi).
Some forms of buffering alter the signal's data or sample period in addition to adjusting the frame size. This type of buffering is desirable when you want to create sliding windows by overlapping consecutive frames of a signal, or select a subset of samples from each input frame for processing.
The blocks that alter a signal while adjusting its frame size are listed below. In this list, Tsi is the input sequence sample period, and Tfi and Tfo are the input and output frame periods, respectively:
The Buffer block adds duplicate samples to a sequence when the Buffer overlap parameter, L, is set to a nonzero value. The output frame period is related to the input sample period by
![]()
where Mo is the output frame size specified by the Output buffer size (per channel) parameter. As a result, the new output sample period is
![]()
The Delay Line block adds duplicate samples to the sequence when the Delay line size parameter, Mo, is greater than 1. The output and input frame periods are the same, Tfo = Tfi = Tsi, and the new output sample period is
![]()
The Variable Selector block can remove, add, and/or rearrange samples in the input frame when Select is set to Rows. The output and input frame periods are the same, Tfo = Tfi, and the new output sample period is
![]()
where Mo is the length of the block's output, determined by the Elements vector.
In all of these cases, the sample period of the output sequence is not equal to the sample period of the input sequence.
In the following example, a signal with a sample period of 0.125 second is rebuffered from a frame size of 8 to a frame size of 16. This rebuffering process doubles the frame period from 1 to 2 seconds, but does not change the sample period of the signal (Tso = Tsi = 0.125). The process also does not add or delete samples from the original signal:
At the MATLAB command prompt, type doc_buffer_tut1.
The Buffer Example T1 model opens.

Double-click the Signal From Workspace block. The Block Parameters: Signal From Workspace dialog box opens.
Set the parameters as follows:
Signal = 1:1000
Sample time = 0.125
Samples per frame = 8
Form output after final data value = Setting to zero
Based on these parameters, the Signal from Workspace block outputs a frame-based signal with a sample period of 0.125 second. Each output frame contains eight samples.
Save these parameters and close the dialog box by clicking OK.
Double-click the Buffer block. The Block Parameters: Buffer dialog box opens.
Set the parameters as follows, and then click OK:
Output buffer size (per channel) = 16
Buffer overlap = 0
Initial conditions = 0
Based on these parameters, the Buffer block rebuffers the signal from a frame size of 8 to a frame size of 16.
The following figure shows the model after the simulation has stopped.

Note that the input to the Buffer block has a frame size of 8 and the output of the block has a frame size of 16. As shown by the Probe blocks, the rebuffering process doubles the frame period from 1 to 2 seconds.
Some forms of buffering alter the signal's data or sample period in addition to adjusting the frame size. In the following example, a signal with a sample period of 0.125 second is rebuffered from a frame size of 8 to a frame size of 16 with a buffer overlap of 4:
At the MATLAB command prompt, type doc_buffer_tut2.
The Buffer Example T2 model opens.

Double-click the Signal From Workspace block. The Block Parameters: Signal From Workspace dialog box opens.
Set the parameters as follows:
Signal = 1:1000
Sample time = 0.125
Samples per frame = 8
Form output after final data value = Setting to zero
Based on these parameters, the Signal from Workspace block outputs a frame-based signal with a sample period of 0.125 second. Each output frame contains eight samples.
Save these parameters and close the dialog box by clicking OK.
Double-click the Buffer block. The Block Parameters: Buffer dialog box opens.
Set the parameters as follows, and then click OK:
Output buffer size (per channel) = 16
Buffer overlap = 4
Initial conditions = 0
Based on these parameters, the Buffer block rebuffers the signal from a frame size of 8 to a frame size of 16. Also, after the initial output, the first four samples of each output frame are made up of the last four samples from the previous output frame.
The following figure shows the model after the simulation has stopped.

Note that the input to the Buffer block has a frame size of 8 and the output of the block has a frame size of 16. The relation for the output frame period for the Buffer block is
![]()
Tfo is (16-4)*0.125,
or 1.5 seconds, as confirmed by the second Probe block.
The sample period of the signal at the output of the Buffer block
is no longer 0.125 second. It is now
second. Thus, both the signal's data and the signal's
sample period have been altered by the buffering operation.
![]() | Inspecting Sample Rates and Frame Rates | Converting Frame Status | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |