xcorr and time lag

조회 수: 13 (최근 30일)
N
N 2014년 8월 29일
댓글: N 2014년 9월 1일
Hi all,
I have a simple, but yet I can't seem to figure it out, question about crosscorrelation.When I find my maximum crosscorrelation, I want to find the corresponding time lag. What I have in code so far:
x = [0 0 1 5 1 -2 -3 -2 0 0];
y = [0 0 1 5 1 -2 -3 -2 0 0];
X2 = xcorr(x,y,'coeff'); (so we expect a xcorr of 1 because its the same signal)
plot(lags,C)
[val,idx] = max(abs(C))
Now it says that the maximum crosscorrelation (1) is at time lag 10. now I get that because the time series goes from -9 till +9, so step 10 is at zero-lag, but how can I get as answer the zero and not 10. So I want the real value of time lag and not the amount of steps.
Later on I would actually want to make the time lags correspond to real time as well ,so for example a lag of 1 equals to 2 seconds, which is the reason I want the amount and not the steps so I know how many seconds really passed. How can I do this also, so make the time lag correspond to real seconds?

채택된 답변

dpb
dpb 2014년 8월 29일
편집: dpb 2014년 8월 29일
t=-length(x)+dt*idx;
where dt is the sampling time interval.
BTW, this is for full-length. If use the optional MAXLAGS argument, then will want to return and use the LAGS alternate return to get the actual lag instead of just counting from 1.
  댓글 수: 1
N
N 2014년 9월 1일
thank you for your answer, it works !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Honglei Chen
Honglei Chen 2014년 8월 29일
You already have a variable lags, you can simply do lags(idx). BTW I didn't see how you compute the lags, but you could get it from xcorr, e.g.,
[X2,lags] = xcorr(x,y,'coeff')
HTH

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by