DSP Blockset | ![]() ![]() |
Resample an input at a lower rate by deleting samples.
Library
Description
The Downsample block resamples each channel of the Mi-by-N input at a rate K times lower than the input sample rate by discarding K-1 consecutive samples following each sample passed through to the output. The integer K is specified by the Downsample factor parameter.
The Sample offset parameter delays the output samples by an integer number of sample periods, D, where 0 D < K, so that any of the K possible output phases can be selected. For example, when you downsample the sequence 1, 2, 3, ... by a factor of 4, you can select from the following four phases.
The initial zero in each output sequence above is a result of the default zero Initial condition parameter setting for this example.
Sample-Based Operation
When the input is sample-based, the block treats each of the M*N matrix elements as an independent channel, and downsamples each channel over time. The input and output sizes are identical.
The Sample-based mode parameter determines how the block represents the new rate at the output. There are two available options:
When Allow multirate is selected, the sample period of the sample-based output is K times longer than the input sample period (Tso = KTsi). The block is therefore multirate.
When Enforce single rate is selected, the block forces the output sample rate to match the input sample rate (Tso = Tsi) by repeating every Kth input sample K times at the output. The block is therefore single-rate. (The block's operation when Enforce single rate is selected is similar to the operation of a Sample and Hold block with a repeating trigger event of period KTsi.)
The setting of the Frame-based mode popup menu does not affect sample-based inputs.
Frame-Based Inputs
When the input is frame-based, the block treats each of the N input columns as a frame containing Mi sequential time samples from an independent channel. The block downsamples each channel independently by discarding K-1 rows of the input matrix following each row that it passes through to the output. The downsample factor must be less than the frame size, K < Mi.
The Frame-based mode parameter determines how the block adjusts the rate at the output to accommodate the reduced number of samples. There are two available options:
The block generates the output at the slower (downsampled) rate by using a proportionally longer frame period at the output port than at the input port. For downsampling by a factor of K, the output frame period is K times longer than the input frame period (Tfo = KTfi), but the input and output frame sizes are equal.
The model below shows a single-channel input with a frame period of 1 second being downsampled by a factor of 4 to a frame period of 4 seconds. The input and output frame sizes are identical.
The block generates the output at the slower (downsampled) rate by using a proportionally smaller frame size than the input. For downsampling by a factor of K, the output frame size is K times smaller than the input frame size (Mo = Mi/K), but the input and output frame rates are equal.
The model below shows a single-channel input of frame size 64 being downsampled by a factor of 4 to a frame size of 16. The input and output frame rates are identical.
The setting of the Sample-based mode popup menu does not affect frame-based inputs.
Latency
Zero Latency. The Downsample block has zero tasking latency for the special combinations of input signal sampling and parameter settings shown in the table below. In all of these cases the block has single-rate operation.
Zero tasking latency means that the block propagates input sample D+1 (received at t=0) as the first output sample, followed by input sample D+1+K, input sample D+1+2K, and so on. The Initial condition parameter value is not used.
Nonzero Latency. The Downsample block is multirate for most settings other than those in the above table. The amount of latency for multirate operation depends on input signal sampling and Simulink's tasking mode, as shown in the table below.
Multirate... |
Sample-Based Latency |
Frame-Based Latency |
Single-tasking |
None, for D=0 One sample, for D>0 |
One frame (Mi samples) |
Multitasking |
One sample |
One frame (Mi samples) |
The only case of nonzero single-rate latency occurs in sample-based mode, when Enforce single rate is selected with D > 0. The latency in this case is one sample.
In all cases of one-sample latency, the initial condition for each channel appears as the first output sample. Input sample D+1 appears as the second output sample for each channel, followed by input sample D+1+K, input sample D+1+2K, and so on. The Initial condition parameter can be an Mi-by-N matrix containing one value for each channel, or a scalar to be applied to all signal channels.
In all cases of one-frame latency, the Mi rows of the initial condition matrix appear in sequence as the first Mi output rows. Input sample D+1 (i.e, row D+1 of the input matrix) appears in the output as sample Mi+1, followed by input sample D+1+K, input sample D+1+2K, and so on. The Initial condition value can be an Mi-by-N matrix, or a scalar to be repeated across all elements of the Mi-by-N matrix. See the example below for an illustration of this case.
See Excess Algorithmic Delay (Tasking Latency) and "The Simulation Parameters Dialog Box" in the Simulink documentation for more information about block rates and Simulink's tasking modes.
Example
Construct the frame-based model shown below.
Adjust the block parameters as follows:
[(1:100)' (-1:-1:-100)']
0.25
4
2
1
[11 -11;12 -12;13 -13;14 -14]
This model is multirate because there are at least two distinct frame rates, as shown by the two Probe blocks. To run this model in Simulink's multitasking mode, select Fixed-step and discrete from the Type controls in the Solver panel of the Simulation Parameters dialog box, and select MultiTasking from the Mode parameter. Additionally, set the Stop time to 30
.
Run the model and look at the output, yout
. The first few samples of each channel are shown below.
yout = 11 -11 12 -12 13 -13 14 -14 2 -2 4 -4 6 -6 8 -8 10 -10 12 -12 14 -14
Since we ran this frame-based multirate model in multitasking mode, the first row of the initial condition matrix appears as the first output sample, followed by the other three initial condition rows. The second row of the first input matrix (i.e., row D+1, where D is the Sample offset) appears in the output as sample 5 (i.e., sample Mi+1, where Mi is the input frame size).
Dialog Box
See Also
FIR Decimation |
DSP Blockset |
FIR Rate Conversion |
DSP Blockset |
Repeat |
DSP Blockset |
Sample and Hold |
DSP Blockset |
Upsample |
DSP Blockset |
![]() | Discrete Impulse | DSP Constant | ![]() |