MATLAB: Corrcoef & xcorr

correlationcross correlationMATLABsignal processing

Hello i've two complex functions ( size 1x1x2501) and i need to do a correlation between these (cross-correlation).
i've tried to use this command:
r=corrcoef(Hmimo_tb(1,:)',Hmimo_tb1(1,:)','coeff');
where Hmimo_tb and Hmimo_tb1 are my two signals in which the only difference is the fact that they have been measured in different positions. The difference betweeen these two signals is max equal to 1.5e-13, so they are only affected by noise.
i obtain as result:
ans =
1.0000 1.0000 + 0.0000i 1.0000 - 0.0000i 1.0000
the function that i'm going to correlate are complex but the 0.0000i leave me some doubts…. Another doubt is the fact that the the signals are not equal in fact as i've told before there is a difference of 1.5e-13 that is not reported on the secondary diagonal why?
what are the difference between corrcoef and xcorr?

Best Answer

Salvatore, corrcoef() is not the cross correlation sequence. It does not shift one vector with respect to the other.
x = cos(pi/4*n);
y = cos(pi/4*n-(3*pi)/4);
[r,p] = corrcoef(x,y);
But
[c,lags] = xcorr(y,x,'coeff');
[maxcorr,I] = max(c);
lags(I)
You see that if you allow for shifts then y and x are perfectly correlated and that happens at lag 3, which makes perfect sense since the frequency of x and y is pi/4 radians/sample and y is shifted (3*pi)/4 radians.
Now, note for
lags(length(x))
c(length(x))
This is exactly equal to r in [r,p] = corrcoef(x,y);