Cross Correlation between two Digital Signals > Matlab

Cross Correlation between two Digital Signals > Matlab

Digital Signal Processing

%Cross Correlation
clear all
x=input('Enter x :');
y=input('Enter y :');
m=length(x);
n=length(y);



yi=fliplr(y);
X=[x,zeros(1,n)];
YI=[yi,zeros(1,m)];
for i=1:n+m-1
Z(i)=0;
for j=1:m
if(i-j+1>0)
Z(i)=Z(i)+X(j)*YI(i-j+1);
else
end
end
end
x
yi
Z
subplot(3,1,1);
stem(x);
title('First Signal');
subplot(3,1,2);
stem(yi);
title('Second Signal');
subplot(3,1,3);
stem(Z);
title('Cross Correlation of Two Signals');

% OUTPUT :
% Enter x :[0 1 2 3 4]
% Enter y :[1 2 3 4 5]
%
% x =
%
%      0     1     2     3     4
%
%
% yi =
%
%      5     4     3     2     1
%
%
% Z =
%
%      0     5    14    26    40    30    20    11     4
%


Comments

Popular posts from this blog

Intermediate Code Generation > C Program