Question
Why does the XCORR function in Signal Processing Toolbox 6.0 (R13) produce incorrect results when using sampled data? XCORR appears to produce incorrect results according to autocorrelation. If the data is sampled and has a non-zero mean, then the result of XCORR is significantly slow in its dropoff factor.
Related Questions
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 13, 2026
This is not a bug in Signal Processing Toolbox 6.0 (R13). XCORR calculates the correlation between two vectors. XCORR does not require the input vectors to have a zero mean. The limitation of zero mean sequences would require the autocorrelation and cross-correlation to be identical to the autocovariance and cross-covariance respectively. Recall that:
Cxx(t,u)=Rxx(t,u)+E[x(t)]E[x(u)],
where Cxx is the autocovariance and Rxx is the autocorrelation of the process, X.
However, this is not always the case. As a workaround, you can pre-process your input vector and subtract its mean before passing it as an input of XCORR, as in the following example:
x=rand(1,1000); % Some signal without zero mean x=x-mean(x);% Make 'x' have zero mean [Rx, lags]=xcorr(x,'coeff'); % Calculate autocorrelation of 'x' and normalize zero lag to unity plot(lags,Rx); % Plot the autocorrelation vs. the lag
Have a different question? Ask here