Experiment 2 (B) : Aim: To Write A MATLAB Program To Receive An Input Sequence From The User and To
Experiment 2 (B) : Aim: To Write A MATLAB Program To Receive An Input Sequence From The User and To
Aim : To write a MATLAB program to receive an input sequence from the user and to
increase its sampling rate by a user-defined factor and to verify the same using
the MATLAB in-built function.
Theory : In order to increase the sampling rate of a sequence by a factor p, (p-1)
zeros are inserted between samples. This is implemented using iteration loops.
MATLAB also has an in-built function upsample defined as upsample(x,n) which
inserts (n-1) zeros between each sample of x. This is used to verify the program.
Tool used : MATLAB R2010b
Program :
clc;
clear all;
close all;
m=input('Enter the length of the sequence : ');
for i=1:m
x(i)=input('Enter the sequence value : ');
end
p=input('Enter the upsampling factor : ');
j=1;
for i=1:m
y(j)=x(i);
for k=1:p-1
j=j+1;
y(j)=0;
end;
j=j+1;
end;
subplot(2,2,1);
stem(x);
axis([0 10 0 4]);
title('Original signal');
subplot(2,2,2);
stem(y);
axis([0 15 0 4]);
title('Up-sampled signal');
subplot(2,2,4);
z=upsample(x,p);
stem(z);
axis([0 15 0 4]);
title('Up-sampled signal using in-built');
Result :
Enter the length of the sequence : 5
Enter the sequence value : 1
Enter the sequence value : 2
Enter the sequence value : 3
Enter the sequence value : 2
Enter the sequence value : 1
Enter the up-sampling factor : 2
Enter the up-sampling factor : 3
Conclusion : Implemented a MATLAB program to accept input sequence from the
user and increased its sampling rate by 2 and 3 and obtained the results for
the same. Also verified the outputs using the MATLAB in-built function.