You are on page 1of 5

# 3) Convolution and Correlation (auto and cross correlation) of discrete sequences without using

## (a) Linear Convolution

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);

## h=input('enter i/p h(n):');

n=length(h);

x=[x,zeros(1,n)];

subplot(2,2,1), stem(x);

## title('i/p sequence x(n)is:');

xlabel('---->n');

ylabel('---->x(n)');grid;

h=[h,zeros(1,m)];

subplot(2,2,2), stem(h);

## title('i/p sequence h(n)is:');

xlabel('---->n');

ylabel('---->h(n)');grid;

## disp('convolution of x(n) & h(n) is y(n):');

y=zeros(1,m+n-1);

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);

## title('convolution of x(n) & h(n) is :');

xlabel('---->n');

ylabel('---->y(n)');grid;

OUTPUT :

RESULT : The linear convolution of two sequences is verified by using MATLAB program.
b)Auto Correlation

## APPARATUS REQUIRED : MATLAB Software

PROGRAM :

clc;

clear all;

close all;

%% Inputs

% You can specify the inputs or can take them through command window

## % x= input ('enter the sequence x');

h=[1 1 2 3 4];

x=[1 3 5 7 9 2 4 6 8];

pp=h;qq=x;

%%

## if (l1 > l2)

x= [x zeros(1,l)];

## else if(l2 > l)

h= [h zeros(1,l)];

end
end

end

y=y';

## subplot(3,1,3); stem(y,'r'); title ('cross correlation'); xlabel('time');

OUPUT:

RESULT:

c)Cross Correlation

## APPARATUS REQUIRED : MATLAB Software

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: