Documentation Center

  • Trial Software
  • Product Updates

Contents

Downsample

Resample input at lower rate by deleting samples

Library

Signal Operations

dspsigops

Description

The Downsample block decreases the sampling rate of the input by deleting samples. When the block performs frame-based processing, it resamples the data in each column of the Mi-by-N input matrix independently. When the block performs sample-based processing, it treats each element of the input as a separate channel and resamples each channel of the input array across time. The resample rate is K times lower than the input sample rate, where K is the integer you specify for the Downsample factor parameter. The Downsample block resamples the input by discarding K–1 consecutive samples following each sample that is passed through to the output.

The Sample offset parameter delays the output samples by an integer number of sample periods, D, where 0 ≤ D ≤ (K–1), 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.

Input SequenceSample Offset, DOutput Sequence (K=4)

1,2,3,...

0

1,5,9,13,17,21,25,29,...

1,2,3,...

1

0,2,6,10,14,18,22,26,...

1,2,3,...

2

0,3,7,11,15,19,23,27,...

1,2,3,...

3

0,4,8,12,16,20,24,28,...

The initial zero in each of the latter three output sequences in the table is a result of the default zero Initial conditions parameter setting for this example. See Latency for more information on the Initial conditions parameter.

This block supports triggered subsystems when you set the Rate options parameter to Enforce single-rate processing.

Sample-Based Processing

When you set the Input processing parameter to Elements as channels (sample based), the input can be an N-D array. The Downsample block treats each element of the input as a separate channel, and resamples each channel of the input over time. The block downsamples the input array by discarding K–1 samples following each sample that it passes through to the output. The input and output sizes of the Downsample block are identical.

The Rate options parameter specifies how the block adjusts the rate at the output to accommodate the reduced number of samples. There are two available options:

  • Allow multirate processing

    When you select Allow multirate processing, the sample period of the output is K times longer than the input sample period (Tso = KTsi).

  • Enforce single-rate processing

    When you select Enforce single-rate processing, 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. In this mode, the behavior of the block is similar to the operation of a Sample and Hold block with a repeating trigger event of period KTsi.

Frame-Based Processing

When you set the Input processing parameter to Columns as channels (frame based), the block treats each of the N input columns as an individual channel containing Mi sequential time samples. 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 Rate options parameter specifies how the block adjusts the rate at the output to accommodate the reduced number of samples. There are two available options:

  • Allow multirate processing

    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 ex_downsample_ref1ex_downsample_ref1 model 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.

  • Enforce single rate processing

    The block generates the output at the slower (downsampled) rate 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 ex_downsample_ref2ex_downsample_ref2 model shows a single-channel input with a frame size of 64 being downsampled by a factor of 4 to a frame size of 16. The input and output frame rates are identical.

Latency

The Downsample block has zero-tasking latency in the following cases:

  • The Downsample factor parameter, K, is 1.

  • The Input processing parameter is set to Columns as channels (frame based) and the Rate options parameter is set to Enforce single-rate processing.

  • The Input processing parameter is set to Columns as channels (frame based) and the input frame size is equal to one.

  • The Input processing parameter is set to Elements as channels (sample based), and Sample offset parameter, D, is 0.

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. When there is zero-tasking latency, the block ignores the value of the Initial conditions parameter.

In all other cases, the latency is nonzero:

  • When the Input processing parameter is set to Elements as channels (sample based), the latency is one sample.

  • When the Input processing parameter is set to Columns as channels (frame based) and the input frame size is greater than one, the latency is one frame.

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 conditions parameter can be an array of the same size as the input, 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 conditions value can be an Mi-by-N matrix containing one value for each channel, or a scalar to be repeated across all elements of the Mi-by-N matrix. See the following example for an illustration of this case.

Examples

Open the ex_downsample_ref3ex_downsample_ref3 model.

Run the model and look at the output, yout. The first few samples of each channel are as follows:

yout =
    11   -11
    12   -12
    13   -13
    14   -14
     2    -2
     4    -4
     6    -6
     8    -8
    10   -10
    12   -12
    14   -14

You can see from the two Probe blocks that there are at least two distinct frame rates in this model. Because you ran this model in multirate, 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 (row D+1, where D is the Sample offset) appears in the output as sample 5 (sample Mi+1, where Mi is the input frame size).

Dialog Box

Downsample factor

The integer factor, K, by which to decrease the input sample rate.

Sample offset

The sample offset, D, which must be an integer in the range [0, K–1].

Input processing

Specify how the block should process the input. You can set this parameter to one of the following options:

  • Columns as channels (frame based) — When you select this option, the block treats each column of the input as a separate channel. See Frame-Based Processing for more information

  • Elements as channels (sample based) — When you select this option, the block treats each element of the input as a separate channel. See Sample-Based Processing for more information.

    Note:   The Inherited (this choice will be removed - see release notes) option will be removed in a future release.

Rate options

Specify the method by which the block should downsample the input. You can select one of the following options:

  • Enforce single-rate processing — When you select this option, the block maintains the input sample rate.

  • Allow multirate processing — When you select this option, the block downsamples the signal such that the output sample rate is K times slower than the input sample rate.

Initial conditions

The value with which the block is initialized for cases of nonzero latency. You can specify a scalar, or an array of the same size as the input. This parameter appears only when you set the Rate options parameter to Allow multirate processing.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed and unsigned)

  • Boolean

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Output

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed and unsigned)

  • Boolean

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

See Also

FIR DecimationDSP System Toolbox
FIR Rate ConversionDSP System Toolbox
RepeatDSP System Toolbox
Sample and HoldDSP System Toolbox
UpsampleDSP System Toolbox

Was this topic helpful?