MATLAB: Xcorr ‘coef’ is used by correlation coefficients

xcorr

In reviewing questions and material on xcorr, it appears to be that for autocorrelation or cross-corelation coefficients, most responses suggest using the 'coef' option in xcorr. While this does give you a value between -1 and 1, I am not sure why this option is calculated with as xcorr(a,b)/(norm(a)*norm(b)) where a and b are column vectors, in most cases I would think an unbiased correlation should be used?
In my limited understanding, it seems the correlation values should be unbiased, then normalized…
For example autocorrelation, xcorr(a,'unbiased')./var(a),
To illustrate my point, if I autocorrelate a sine function, I would expect the lagged correlation coefficient to vary between 1 and -1 every time the cycle re-alignes itself. But the 'coef' option consistently deceases the correlation coefficient with lag. I realized this is because of how it is calculated, but I don't understand why it is calculated this way? Shouldn't the unbiased approach be used?
A simple example to illustrate this question: t=0:500; n=length(t); ts=5*sin(2*pi*(t./12)); lags=-250:250; test1=xcov(ts,250,'coef'); test2=xcov(ts,250,'unbiased')./var(ts);
figure; plot(t,ts); xlabel('time'); ylabel('amplitude'); figure; plot(lags,test2,'r'); hold on; plot(lags,test1);

Best Answer

Hey Wayne,
Thanks again for you prompt response. I understand what you are saying about how Matlab makes this calculation when the 'coef' option is used. What I am trying to better understand is whether it makes sense to say that the lagged sine function is less correlated as lags increase as the normalized output does('coef' option). As the example showed xcorr(ts,'coef') has a value .76 at lag 120, even though the lagged time series actually perfectly correlated if we compared the two time series in an unbiased way (i.e. lagging one of the two sine curves by 120 would have both shorten times overlaying each other). Shouldn't the process of normalizing the result be done in an unbiased way? Does this clarify what I am trying to get at?
Thanks again!
Brian Dz