I have two signals like following:
They are the same length (200),
But d = finddelay(x,y) shows
d=0;
It cannot find the correct delay between them. Which function can be used here to get the right solution?

 Akzeptierte Antwort

Jonas
Jonas am 13 Mai 2022

1 Stimme

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 Kommentare

Yunyu Hu
Yunyu Hu am 16 Mai 2022
Thanks for the answer, but xcorr is also not working in my case. I think finddelay also uses xcorr, so they are the same.
Another example:
x=[10,11,12,13,14,15,16,15,14,12];
y=[10,10,10,10,11,12,13,14,15,16,15,14,12];
[~,I]=max(xcorr(x,y))
I =
10
I-length(x)
ans =
0
The problem of using xcorr and finddelay maybe that the signal should be long enough (multiple cycles), so that these two functions will work.
But my originial data is not that long enough.
Jonas
Jonas am 16 Mai 2022
Bearbeitet: Jonas am 16 Mai 2022
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');
Yunyu Hu
Yunyu Hu am 16 Mai 2022
Hi, Thanks a lot for the explaination! It is quite reasonable.
And I found the reason, why both xcorr and finddelay cannot give me the correct answer for my original signals. Because the peak is downwards.
If I change the the x and y like this:
x=20-[10,11,12,13,14,15,16,15,14,12];
y=20-[10,10,10,10,11,12,13,14,15,16,15,14,12];
and run your codes, it can also not find the correct answer.
I think this is the limitation of cross correlation. But I can do conversion on signals. :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 13 Mai 2022

Kommentiert:

am 16 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by