Crosscorelation

by

 

Used in digital signal processing

crosscorelation.m
clc
clear all
x1=input('Enter the seq - X: ');
px=input('Enter the position of x: ');
y1=input('Enter the seq - Y: ');
py=input('Enter the position of Y: ');
lx=length(x1);
ly=length(y1);
x=[zeros(1, (ly-1)) x1];
y=[y1 zeros(1, (lx-1))];
for k=1:(lx+ly-1)
    d1=shift(y,(k-1));
    d2(k)=sum(x.*d1);
end
d2
t1=[-(px-1):(lx-px)];
t2=[-(py-1):(ly-py)];
t3=[-(px-1+ly-py):(lx+py-px-1)];
subplot(3, 1, 1);
stem(t1, x1,'pm');
title('seq - X');
xlabel('l');
ylabel('r(l)');
subplot(3, 1, 2);
stem(t2, y1,'pg');
title('seq - Y');
xlabel('l');
ylabel('r(l)');
subplot(3, 1, 3);
stem(t3, d2,'pc');
title('Cross Corelation');
xlabel('l');
ylabel('r(l)');

Contact us