find the delay between two signals
34 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Jonas
2022-5-13
use xcorr(sig1,sig2), and use the max value of xcorr. the corresponding delay can be found at the corresponding value in the lag output (second output)
3 个评论
Jonas
2022-5-16
编辑:Jonas
2022-5-16
you are using the output not correctly. lag contains the corresponding lag value of the correlation calues of the first input. you need to find the lag value of the maximum correlation
dt=0.8;
x=[10,11,12,13,14,15,16,15,14,12];
t1=0:dt:(numel(x)-1)*dt;
y=[10,10,10,10,11,12,13,14,15,16,15,14,12];
t2=0:dt:(numel(y)-1)*dt;
figure;
original=subplot(3,1,1);
plot(t1,x); hold on; plot(t2,y);
title('original')
xlabel('time');
[corrVal,lag]=xcorr(x,y);
lagplot=subplot(3,1,2);
plot(lag*dt,corrVal,'-+');
xlabel('lag');
ylabel('xcorr value');
[~,maxCorrIdx]=max(corrVal);
lagAtMaxVal=lag(maxCorrIdx);
aligned=subplot(3,1,3);
plot(t1,x,'-*'); hold on; plot(t2+lagAtMaxVal*dt,y,'-s');
title('aligned');
xlabel('time')
linkaxes([original lagplot aligned],'x');
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!