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.
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"])
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.
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.
The downsample function supports code generation for
graphical processing units (GPUs). You must have MATLAB®
Coder™ and GPU Coder™ to generate CUDA® code.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.