how to calculate time lag in two signal using cross correlation
20 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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>
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!