06 December 2007

Cross Correlation

Correlation between Two Finite Signals

Algorithm 1:

Cross correlation is defined as, if x(n) and h(n) are finite signals then cross correlation

In cross correlation folding of h(n) doesn’t occur.

1. Input the first sequence.
2. Input the second sequence

3. Find the cross correlation of these sequences using the MATLAB function "xcorr(x,h)" where x and h are the sequences to be correlated.

1. Plot the result

Program

% Program to find correlation of two signals

x=input ('Enter the first sequences ');

h=input(' Enter the second sequences ');

c= xcorr(x,h);

t=0 : (length(x) +length(h)-2);

stem(t,c);

-------------------------------------------------------------------------------------------------

Algorithm 2:

1. Define x(n)
2. Define y(n)
3. Rotate (that is reverse) the signal h(n) using the MATLAB function fliplr(h) where h is to be flipped (i.e, rotated).
4. Find the convolution between x(n) and flipped version of h(n).
5. Plot the resultant signal

Program

% Program to find correlation of two signals

x=input ('Enter the first sequences x(n) : ');

h=input(' Enter the second sequences h(n) : ');

n1 =length(x)-1;

n2=length(h)-1;

r=conv(x,fliplr(h));

t=(-n1):n2;

stem(t,r);

xlabel(' lag index ');

ylabel(' Amplitude ');

v=axis;

axis([-n1 n2 v(3:end)]);

------------------------------------------------------------------------------------------------