From: speng on
Hi all,

I have some doubts on finding the time delay between 2 signals.

Ok, i am dealing with a project that requires me to find out the time
delay between 2 analog input signals capturing the same sound source.

I acquired 40000 samples of each input signal( say x(t) and y(t)).

Then i decided to make use of xcorr to find out the max value between
2 signals. My understanding of the working mechanism of xcorr is such
that, while x(t) stays, we try to shift y(t) along some horizontal
axes such that the value of x(t)*y(t) is the maximum i.e similarity
among the signals.

xcorr returns a length 2*N-1 vector( i.e now i have 79999 data
points). So what i did was to locate the max value and subsequently
find the horizontal pt which this max value occurs.

[max_value, nth_pt]=max(xcorr(x,y))

In the context of my question, i got nth_pt as 39997 i.e abt the mid
point of the 79999 data points. What does that translate to in terms
of time delay?

speng
From: Martin Hammer on
Hi Speng,

from $ help xcorr

<SNIP>
The zeroth lag of the output correlation is in the middle of the
sequence, at element or row M.
</SNIP>

The output will obvious be symmetric around this 'middle' point. Thus,
use for example:

$ R_xy = fftshift( xcorr(x, y) );

To move the zero'th lag to index 1.

Regards,
Martin



On Thu, 8 Feb 2007 09:43:13 -0500
speng <speng_Ster(a)yahoo.com> wrote:

> Hi all,
>
> I have some doubts on finding the time delay between 2 signals.
>
> Ok, i am dealing with a project that requires me to find out the time
> delay between 2 analog input signals capturing the same sound source.
>
> I acquired 40000 samples of each input signal( say x(t) and y(t)).
>
> Then i decided to make use of xcorr to find out the max value between
> 2 signals. My understanding of the working mechanism of xcorr is such
> that, while x(t) stays, we try to shift y(t) along some horizontal
> axes such that the value of x(t)*y(t) is the maximum i.e similarity
> among the signals.
>
> xcorr returns a length 2*N-1 vector( i.e now i have 79999 data
> points). So what i did was to locate the max value and subsequently
> find the horizontal pt which this max value occurs.
>
> [max_value, nth_pt]=max(xcorr(x,y))
>
> In the context of my question, i got nth_pt as 39997 i.e abt the mid
> point of the 79999 data points. What does that translate to in terms
> of time delay?
>
> speng


--
Martin Hammer
DK-9000, Aalborg
Denmark

mhje03(a)kom.aau.dk
http://kom.aau.dk/~mhje03
From: Martin Hammer on
Sorry Speng,

This will _not_ be symmetric. I just assumed you just wanted positive
lags. This might not be the case since max is at 39997. Just use the
output and the information, that zero lag is in the middle.

Martin


On Thu, 8 Feb 2007 16:30:16 +0100
Martin Hammer <mhje03(a)kom.aau.dk> wrote:

> Hi Speng,
>
> from $ help xcorr
>
> <SNIP>
> The zeroth lag of the output correlation is in the middle of the
> sequence, at element or row M.
> </SNIP>
>
> The output will obvious be symmetric around this 'middle' point. Thus,
> use for example:
>
> $ R_xy = fftshift( xcorr(x, y) );
>
> To move the zero'th lag to index 1.
>
> Regards,
> Martin
>
>
>
> On Thu, 8 Feb 2007 09:43:13 -0500
> speng <speng_Ster(a)yahoo.com> wrote:
>
> > Hi all,
> >
> > I have some doubts on finding the time delay between 2 signals.
> >
> > Ok, i am dealing with a project that requires me to find out the
> > time delay between 2 analog input signals capturing the same sound
> > source.
> >
> > I acquired 40000 samples of each input signal( say x(t) and y(t)).
> >
> > Then i decided to make use of xcorr to find out the max value
> > between 2 signals. My understanding of the working mechanism of
> > xcorr is such that, while x(t) stays, we try to shift y(t) along
> > some horizontal axes such that the value of x(t)*y(t) is the
> > maximum i.e similarity among the signals.
> >
> > xcorr returns a length 2*N-1 vector( i.e now i have 79999 data
> > points). So what i did was to locate the max value and subsequently
> > find the horizontal pt which this max value occurs.
> >
> > [max_value, nth_pt]=max(xcorr(x,y))
> >
> > In the context of my question, i got nth_pt as 39997 i.e abt the mid
> > point of the 79999 data points. What does that translate to in terms
> > of time delay?
> >
> > speng
>
>


--
Martin Hammer
DK-9000, Aalborg
Denmark

mhje03(a)kom.aau.dk
http://kom.aau.dk/~mhje03
From: speng on
Hi Martin,

Just to clarify things. Sorry if i dont see your implications
straightaway....

so lets say i am sampling at rate of 8kHz(i.e 8000 samples per sec).
So each data pt on horizontal axes will correspond to 1/8000 of a
second. Am i right to conclude that since zeroth lag is indicated in
the middle of the sequence, then the time difference between my x and
y signal is approx 2 * 1/8000?

Thanks for previous reply.

Speng

Martin Hammer wrote:
>
>
> Sorry Speng,
>
> This will _not_ be symmetric. I just assumed you just wanted
> positive
> lags. This might not be the case since max is at 39997. Just use
> the
> output and the information, that zero lag is in the middle.
>
> Martin
>
>
> On Thu, 8 Feb 2007 16:30:16 +0100
> Martin Hammer <mhje03(a)kom.aau.dk> wrote:
>
>> Hi Speng,
>>
>> from $ help xcorr
>>
>> <SNIP>
>> The zeroth lag of the output correlation is in the middle of
the
>> sequence, at element or row M.
>> </SNIP>
>>
>> The output will obvious be symmetric around this 'middle'
point.
> Thus,
>> use for example:
>>
>> $ R_xy = fftshift( xcorr(x, y) );
>>
>> To move the zero'th lag to index 1.
>>
>> Regards,
>> Martin
>>
>>
>>
>> On Thu, 8 Feb 2007 09:43:13 -0500
>> speng <speng_Ster(a)yahoo.com> wrote:
>>
>> > Hi all,
>> >
>> > I have some doubts on finding the time delay between 2
signals.
>> >
>> > Ok, i am dealing with a project that requires me to find
out
> the
>> > time delay between 2 analog input signals capturing the
same
> sound
>> > source.
>> >
>> > I acquired 40000 samples of each input signal( say x(t)
and
> y(t)).
>> >
>> > Then i decided to make use of xcorr to find out the max
value
>> > between 2 signals. My understanding of the working
mechanism of
>> > xcorr is such that, while x(t) stays, we try to shift y(t)
> along
>> > some horizontal axes such that the value of x(t)*y(t) is
the
>> > maximum i.e similarity among the signals.
>> >
>> > xcorr returns a length 2*N-1 vector( i.e now i have 79999
data
>> > points). So what i did was to locate the max value and
> subsequently
>> > find the horizontal pt which this max value occurs.
>> >
>> > [max_value, nth_pt]=max(xcorr(x,y))
>> >
>> > In the context of my question, i got nth_pt as 39997 i.e
abt
> the mid
>> > point of the 79999 data points. What does that translate
to in
> terms
>> > of time delay?
>> >
>> > speng
>>
>>
>
>
> --
> Martin Hammer
> DK-9000, Aalborg
> Denmark
>
> mhje03(a)kom.aau.dk
> <http://kom.aau.dk/~mhje03>
>
From: Martin Hammer on
On Thu, 8 Feb 2007 11:19:40 -0500
speng <speng_ster(a)yahoo.com> wrote:

> Hi Martin,
>
> Just to clarify things. Sorry if i dont see your implications
> straightaway....
>
> so lets say i am sampling at rate of 8kHz(i.e 8000 samples per sec).
> So each data pt on horizontal axes will correspond to 1/8000 of a
> second. Am i right to conclude that since zeroth lag is indicated in
> the middle of the sequence, then the time difference between my x and
> y signal is approx 2 * 1/8000?
>
> Thanks for previous reply.
>
> Speng
>

Well, with 40000 input samples, 40000 will be the zero'th lag, as
previously stated. 40000-39997 = ???

It is correct that this number multiplied by the sampling period equals
the time delay.

Martin
 |  Next  |  Last
Pages: 1 2
Prev: Adaptive median filter
Next: Error