how to calculate time lag in two signal using cross correlation

조회 수: 18 (최근 30일)
kavya saxena
kavya saxena 2012년 9월 14일
hi all,i m facing some problem with finding the time lag between two signals. i imported the data and used the cross correlation function.it gives 74 but according to my calculations it should be 32. i don't understand where i m wrong. please chk it out
t=end100(:,1);
>> ux228=start228(:,2);
>> ux100=end100(:,2);
>> Y=xcorr(ux228,ux100);
>> plot(Y);
>> find(Y==max(Y))
ans =
74
>> N=length(t);
>> R=Y(1:N);
>> Rx=fliplr(R);
>> Plot (Rx);

답변 (1개)

Wayne King
Wayne King 2012년 9월 15일
편집: Wayne King 2012년 9월 15일
You have to keep in mind:
1.) xcorr is returning negative lags as well as positive, but for real-valued inputs the cross-correlation sequence is even
2.) you can return the lags argument
Create an example with a lag of 10 between the two vectors.
x = randn(100,1);
y = [zeros(10,1); x];
% xcorr returns 2*length of the longest vector-1 lags by default
% therefore lag 110 is the zero-th lag
[xc,lags] = xcorr(y,x);
xc = xc(110:end);
lags = lags(110:end);
[val,index] = max(abs(xc));
lags(index)
The above gives a lag of 10, which is the correct lag.
Also see the examples and how tos for estimating delay on this page:
< < https://www.mathworks.com/help/signal/convolution-and-correlation.html>

카테고리

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