Decimation/Downsampling MATLAB Source Code
Advertisement
This section presents MATLAB source code for decimation, also known as downsampling. It covers the fundamental concepts of decimation. Decimation involves removing samples from an existing vector of values. This process reduces the sample rate of the signal or vector, hence the term “downsampling.”
Setting up an Exponential Vector for Downsampling
The following code sets up an exponential vector to be downsampled:
clc;
clear all;
N=input('Enter length of the output sequence:');
M=input('Enter down sampling factor:');
a=input('Enter the value of base of exponent function:');
n=0:N-1;
m=0:N*M-1;
x=a.^m;
Downsampling the Exponential Vector
This code snippet demonstrates downsampling the exponential vector:
% Generate the downsampled signal
y=x([1:M:length(x)]);
figure,stem(n,x(1:N));
xlabel({'Samples in time';'(a)'});
ylabel('magnitude');
title('Decimator input');
figure,stem(n,y);
xlabel({'Samples in time';'(b)'});
ylabel('magnitude');
title('down sampled output');
Here’s the input image generated by the above code:

And the exponential input image:

Finally, here’s the downsampled output image:

Downsampling Using the decimate MATLAB Function
This example uses the built-in decimate function in MATLAB for downsampling:
% Generate the downsampled signal using decimate function
y=decimate(x,M,'fir');
m=0:N/M-1;
figure,stem(m,y(1:N/M));
title('MATLAB decimate function output');
xlabel('Time');
ylabel('magnitude');
Here’s the output image generated by the decimate function:

Explore MATLAB Signal Processing & Filtering
- Analog Filter Implementation in MATLAB
- FIR Digital Filter (MATLAB Source Code)
- Low Pass FIR Filter Implementation in MATLAB
- FIR Digital Filter Design: Kaiser Window in MATLAB
- FIR Digital Filter: Rectangular Window in MATLAB
- FIR Digital Filter: Triangular Window in MATLAB
- Low Pass IIR Butterworth Digital Filter (MATLAB Code)
- Butterworth Filter Design in MATLAB
- Convolution (MATLAB Source Code)
- Auto/Cross-Correlation in MATLAB
- 16-point FFT/DFT MATLAB Code using Decimation in Frequency
- IFFT MATLAB: Inverse Fast Fourier Transform
- Decimation/Downsampling (MATLAB Source Code)
- MATLAB Code for Interpolation and Up-Sampling
- Plotting 2D/3D Curves in MATLAB
