DSP Lab 3
DSP Lab 3
AIM:To write a program in MATLAB to perform linear Convolution between two discrete time sequences
PROGRAM:
clc;
clear all;
close all;
m=length(x);
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
xlabel('---->n');
ylabel('---->h(n)');grid;
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
subplot(2,2,[3,4]),stem(y);
xlabel('---->n');
ylabel('---->y(n)');grid;
OUTPUT :
RESULT : The linear convolution of two sequences is verified by using MATLAB program.
b)Auto Correlation
PROGRAM :
clc;
clear all;
close all;
%% Inputs
% You can specify the inputs or can take them through command window
h=[1 1 2 3 4];
x=[1 3 5 7 9 2 4 6 8];
pp=h;qq=x;
%%
x= [x zeros(1,l)];
h= [h zeros(1,l)];
end
end
end
y=y';
OUPUT:
RESULT:
c)Cross Correlation
PROGRAM :
close all;
clear all;
clc;
x=input('enter the value of 1st sequence');
j=input('enter the value of 2nd sequence');
h=fliplr(j);
disp('the 1st sequence is-');
disp(x);
disp('the 2nd sequence is-');
disp(j);
lx=length(x);
lh=length(h);
n=lx+lh-1;
subplot(3,1,1);
stem(x);
title('1st sequence');
subplot(3,1,2);
stem(j);
title('2nd sequence');
hh=[h zeros(1,n-lh)];
xx=zeros(n);
xx(1:lx,1)=x;
for i=2:n
for j=2:n
xx(j,i)=xx(j-1,i-1);
end;
end;
yy=xx*hh';
subplot(3,1,3);
stem(yy);
disp('cross correlate o/p->');
disp(yy');
title('y=cross correlation of x & j');
OUPUT:
RESULT: