1
$\begingroup$

I have two cosine signals in MATLAB both having a frequency of 100 Hz and the second signal has been delayed in time by 0.003 seconds. Both signals have been sampled at 1 Khz. When I use the cross correlation function and plot it to verify the delay between the signals, I expect to see a single point in time at which the signals are aligned but the plot looks symmetrical about the y axis. Why is that?

Also I am not sure about the sign convention here. Does a negative x axis value at the cross correlation peak denote time lag or does a positive x axis value denote time lag?

st=1/1000;
t=[0:999]*st;

s1=cos(2*pi*100*t);
t1=t-(3*st);
s2=cos(2*pi*100*t1);

[c,lags]=xcorr(s1,s2);
plot(lags,c/max(c))
$\endgroup$
1
  • $\begingroup$ I provided an answer below, but this question might have been more on topic on StackOverflow. $\endgroup$
    – amoeba
    Aug 13, 2014 at 16:44

1 Answer 1

1
$\begingroup$

It is not exactly symmetrical. Look where the autocorrelation has a maximal absolute value:

lags(abs(c)==max(abs(c)))

This returns -3, which corresponds to your delay of 0.003 s. The negative sign simply means that your second signal is delayed, not the first. If you swap them when calling xcorr, like that:

[c,lags] = xcorr(s2,s1);
lags(abs(c)==max(abs(c)))

then the answer will be 3. Now it's positive.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.