DSPRelated.com
Forums

Re: finding time delay using xcorr!

Started by spor...@gmail.com August 17, 2009
Dear Henry,
Your code doesn't work for time delays other than 500. For example, if you change the code to :

fs00;
fo 0
t=0:1/fs:1-1/fs;
x=sin(2*pi*fo*t).*exp(-20*t);
y=[zeros(1,400) x(1:length(x)-400)]; %changed 500 to 400 delay
xc=xcorr(x,y);
[a,delay]=max(xc)
subplot(311),plot(x)
subplot(312),plot(y)
subplot(313),plot(xc(1:1000))
Then the code says the delay is 600 rather than 400. Am I doing something wrong?

> I am trying to find the time delay between two signals. Suppose to
>straight forward. But I am not getting it right.
>This is what I did;
>>>fs00;
>>>fo 0
>>>t=0:1/fs:1;
>>>x=sin(2*pi*fo*t);
>>>y=sin(2*pi*fo*(t-0.01)); %time delay 0.01s
>>>[a,delay]=max(xcorr(x,y))
>expect to see, delay=0.01
>But, I am getting 1001. Where did I go wrong?
>I will appreciate any help. Any pointers towards a robust m-file to
>determine the time delay between two signals.
>Thanks,
>Thavendra
>
>
>
>
>
>
>
>
>