Why does the XCORR function in Signal Processing Toolbox 6.0

Illustration
khalilabby - 2021-03-19T14:47:04+00:00
Question: Why does the XCORR function in Signal Processing Toolbox 6.0

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.    

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!