Are the values of xcorr(x,y)
in MATLAB correlation values or not? I'm asking this because in MATLAB xcorr(x,y,'coeff')
normalizes values. Is it normalizing covariance values to get correlations?
I'm confused if cross correlation values are necessarily between -1 and 1 like Pearson correlation values.
Also, I see from running an example that xcorr(x,y,0,'coeff')
!= corr(x,y)
. Could someone explain this?
Best Answer
The function
xcorr()
is used for calculating the time cross correlation of time series (Or any indexed signal).The
corr()
function is all about calculating the correlation of so supposedly 2 random variables.While the 2 coincide if used correctly and wisely pay attention that they basically normalize differently the operation (Hence you don't get what you expect).
In code:
As you can see from the code above what's you missing is that
corr()
removes the mean of the data whilexcorr()
doesn't.So
corr(vA, vB)
is equivalent ofxcorr(vA - mean(vA), vB - mean(vB), 0, 'coeff')
.