# 'xcorr' function in matlab not working for zero signal

I came across an interesting problem when using 'xcorr' in MATLAB. The expected signal and generated signal both are at zero DC. So, I expect correlation coefficient to be 1 or perfectly correlated. To my surprise, It is showing the highest error and time lag !!! Pls help !

Thanks,

• According to the definition of xcorr the output should be zero at all lags for input vectors that are all zeros, and that is what I get when I put X=zeros(1,10);Y=zeros(1,10) and execure [R,LAG]=xcorr(X,Y). Note xcorr is not producing the correlation coefficient unless you specifically ask it to, but then you will be dividing by zero and get NaN as a result.. – Conrad Turner Jun 22 '15 at 12:49

the xcorr function is defined as $$R_{xy}(m)= \left\{ \begin{array}{ll} \sum\limits_{n=0}^{N-m-1}x_{n+m}y^*_n & \mbox{if } m \geq 0 \\ R^*_{yx}(-m)& \mbox{if } m < 0 \end{array} \right.$$ The output is given as $$c(m)=R_{xy}(m-N)$$ where N is the length of the signal by the above definition the output for zero signal is zero