Main Content

downsample

R2026b

Decrease sample rate by integer factor

Description

y = downsample(x,n) decreases the sample rate of x by keeping the first sample and then every nth sample after the first. If x is a matrix, the function treats each column as a separate sequence.

example

y = downsample(x,n,phase) specifies the number of samples by which to offset the downsampled sequence.

example

Examples

collapse all

Decrease the sample rate of a sequence by a factor of 3.

x = [1 2 3 4 5 6 7 8 9 10];
y = downsample(x,3)
y = 1×4

     1     4     7    10

Decrease the sample rate of the sequence by a factor of 3 and add a phase offset of 2.

y = downsample(x,3,2)
y = 1×3

     3     6     9

Decrease the sample rate of a matrix by a factor of 3.

x = [1  2  3;
     4  5  6;
     7  8  9;
    10 11 12];
y = downsample(x,3)
y = 2×3

     1     2     3
    10    11    12

Since R2026b

Generate a 100-second sine waveform with a fundamental frequency of 0.01 Hz.

t = (1:100)';
x = sin(2*pi*0.01*t);

Downsample the signal using a downsampling factor of 5. Compare the original and downsampled signals.

out = downsample([t x],5);
plot(t,x,".",out(:,1),out(:,2),"*")
legend(["Original" "Downsampled"])

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original, Downsampled.

Downsample the signal using a downsampling factor of 5 and a phase offset of 3. Compare the original and downsampled signals. Because of the specified phase offset, the first sample of the downsampled signal starts at the fourth sample on the original signal.

out3 = downsample([t x],5,3);
plot(t,x,".",out3(:,1),out3(:,2),"*")
legend(["Original" "Downsampled"])

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original, Downsampled.

Input Arguments

collapse all

Input array, specified as a vector or matrix. If x is a matrix, the function treats the columns as independent channels.

Tip

To avoid aliasing in the downsampled output, apply a lowpass filter with a normalized cutoff frequency pi/n rad/sample to x before passing it to the function. Alternatively, use the decimate function.

Example: cos(pi/4*(0:159)) + randn(1,160) specifies a sinusoid embedded in white Gaussian noise.

Example: cos(pi./[4;2]*(0:159))' + randn(160,2) specifies a two-channel noisy sinusoid.

Downsampling factor, specified as a positive integer.

Data Types: single | double

Offset, specified as a positive integer from 0 to n – 1.

Data Types: single | double

Output Arguments

collapse all

Downsampled array, returned as a vector or matrix.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced before R2006a

expand all