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: