# TDOA and localisation (inexperienced Matlab user)

Started by August 4, 2007
```Hi,
I've been thrown into a project that involves determining the location of
a sound source and tracking its movements. I have very little matlab
experience but have been trying to cope. This site has been very useful.

The general idea for the project is implementing a finger mouse where you
have an array of microphones that detects the sound emitted by a finger
sliding across a surface and emulate that as a mouse on a computer. To
start my research, I have used 2 microphones positioned apart and recorded
stereo wave files of a finger moving around single points on the plane.

In terms of Matlab, what I have achieved is loading the wave files and
splitting it into individual vectors of the left and right channel. What
I'm stuck with is how do I clearly analyze both channels to find the TDOA
and possibly find the frequency component of the sound of the sliding
finger? My project supervisor has mentioned about looking at the
covariance of the signals (xcov command) and thus plotting the delay of
the two waves. Can anyone help me on this?

Any help would be great. Thanks

```
```On Aug 4, 7:58 am, "nickch" <nic...@slingshot.co.nz> wrote:
> Hi,
> I've been thrown into a project that involves determining the location of
> a sound source and tracking its movements. I have very little matlab
> experience but have been trying to cope. This site has been very useful.
>
> The general idea for the project is implementing a finger mouse where you
> have an array of microphones that detects the sound emitted by a finger
> sliding across a surface and emulate that as a mouse on a computer. To
> start my research, I have used 2 microphones positioned apart and recorded
> stereo wave files of a finger moving around single points on the plane.
>
> In terms of Matlab, what I have achieved is loading the wave files and
> splitting it into individual vectors of the left and right channel. What
> I'm stuck with is how do I clearly analyze both channels to find the TDOA
> and possibly find the frequency component of the sound of the sliding
> finger? My project supervisor has mentioned about looking at the
> covariance of the signals (xcov command) and thus plotting the delay of
> the two waves. Can anyone help me on this?
>
> Any help would be great. Thanks

Will the environment be very clean, as in the only sound you hear
is only the mouse click?

Did you try using xcov or xcorr in Matlab yet?

I'm having a hard time figuring out what you have tried, what you
don't
know how to try, and what you do not know how to try.

Julius

```
```>Will the environment be very clean, as in the only sound you hear
>is only the mouse click?

No, I assume that the environment will be pretty noisy and have taken
steps to identify the frequency of interest (sliding finger) and filter
out the rest.

>Did you try using xcov or xcorr in Matlab yet?

I have not tried xcorr yet, but I am using xcov to get the covariances and
lag values and plotting that to find the peak which should give me the
delay in the signal (assuming what my supervisor says is correct).

>I'm having a hard time figuring out what you have tried, what you
>don't
>know how to try, and what you do not know how to try.

What I would like to know is: with a stereo wave file loaded into matlab
(wavread), how would I accurately determine and possibly plot the time
difference of arrival between the two channels?

Thanks

```
```On 4 Aug, 14:58, "nickch" <nic...@slingshot.co.nz> wrote:
> Hi,
> I've been thrown into a project that involves determining the location of
> a sound source and tracking its movements. I have very little matlab
> experience but have been trying to cope. This site has been very useful.

Your courage is impressive. As I write this, my radio is playing
by my PC, playing loud so I can hear it over the noise from the
neighbour's kids who are playing soocer just outside the open
window by my desk. If you want to track the sounds of a mouse
(BTW, I use a mouse mat with mine) in such an environment,
you certainly have your work cut out for you.

This reminds me of a project proposal I once saw, for a
seismic sonar for land mine detection in agricultural
areas. The person who hatched the idea had never worked
with farming or gardening, as he did not know that soil
contains stones, lumps of clay, roots and so on which
would destroy any attempts to single out land mine
targets.

> The general idea for the project is implementing a finger mouse where you
> have an array of microphones that detects the sound emitted by a finger
> sliding across a surface and emulate that as a mouse on a computer.

A *finger* sliding across a surface? How do you model the
sound source representation of greasy soft tissue sliding
across a hard surface? How loud is it? What are its
characteristics? How robust is this source with respect
to skin humidity? Air humidity? Surface roughness?
Surface hardness?

Rune

```
```On Aug 6, 6:27 pm, "nickch" <nic...@slingshot.co.nz> wrote:
> >Will the environment be very clean, as in the only sound you hear
> >is only the mouse click?
>
> No, I assume that the environment will be pretty noisy and have taken
> steps to identify the frequency of interest (sliding finger) and filter
> out the rest.
>
> >Did you try using xcov or xcorr in Matlab yet?
>
> I have not tried xcorr yet, but I am using xcov to get the covariances and
> lag values and plotting that to find the peak which should give me the
> delay in the signal (assuming what my supervisor says is correct).
>
> >I'm having a hard time figuring out what you have tried, what you
> >don't
> >know how to try, and what you do not know how to try.
>
> What I would like to know is: with a stereo wave file loaded into matlab
> (wavread), how would I accurately determine and possibly plot the time
> difference of arrival between the two channels?
>
> Thanks

Have you actually tried using xcov/xcorr to see if you can possibly
get a good estimate?  What did you find?  Have you tried it in the

See, I still can't tell what you have tried, and what you have found

At this point I tend to agree with Rune, I doubt that this approach
will work in anything but a very synthetic environment.  Have you
at least tried looking at what kind of noise you pick up at the
sensors?

Can you separate the sound of a mouse click from {everything else
that sensors pick up}?

Do you understand how finding the peak in the xcov/xcorr gives
you the time delay of arrival?

```
```The xcorr method to obtain TDoA is all good if the signals do not contain
too much noise. If the signals are corrupted by noise you better use one
of the Generalized Cross Correlation (GCC) methods like PHAT, SCOT, HT,
etc.

Fortunately there is a pretty good, and easy to use, implementations of
GCC in the Matlab file exchange page:

Here is a little example of how I used it. I am not expert so don't expect
much of this code. Replace xnoisy and ynoisy with your data obtained from
the sensors and set Nfft and Fs to your needs. You can read the help files
for pwelch and cpsd for details. For more information on GCC methods simply

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Estimate the spectra.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Sxx, Fxx] = pwelch(xnoisy,[],[],Nfft, Fs);
[Syy, Fyy] = pwelch(ynoisy,[],[],Nfft, Fs);
[Sxy, Fxy] = cpsd(xnoisy,ynoisy,[],[], Nfft, Fs);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Obtain the Generalized Correlation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[corr1, t1] = GCC('unfiltered',Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);
[corr2, t2] = GCC('scot', Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);
[corr3, t3] = GCC('roth', Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);
[corr4, t4] = GCC('phat', Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);
[corr5, t5] = GCC('cps-m', Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);
[corr6, t6] = GCC('ht', Sxx, Syy, Sxy, Fs, length(xnoisy), Nfft);

figure(1);
subplot(321);
plot(t1,corr1);
%axis([-1 1 -1 1]);
[m,k] = max(corr1);
k = t1(k);
title('Unfiltered GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

subplot(322);
plot(t2,corr2);
%axis([-30e-6 30e-6 -1.5 1.5]);
[m,k] = max(corr2);
k = t2(k);
title('SCOT GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

subplot(323);
plot(t3,corr3);
%axis([-1 1 -1 1]);
[m,k] = max(corr3);
k = t3(k);
title('ROTH GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

subplot(324);
plot(t4,corr4);
%axis([-1 1 -1 1]);
[m,k] = max(corr4);
k = t4(k);
title('PHAT GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

subplot(325);
plot(t5,corr5);
%axis([-1 1 -1 1]);
[m,k] = max(corr5);
k = t5(k);
title('cps-m GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

subplot(326);
plot(t6,corr6);
%axis([-1 1 -1 1]);
[m,k] = max(corr6);
k = t6(k);
title('HT GCC');
text(1e-4,0.5,strcat(num2str(k),'sec'));

cheers,
Horacio

>On Aug 6, 6:27 pm, "nickch" <nic...@slingshot.co.nz> wrote:
>> >Will the environment be very clean, as in the only sound you hear
>> >is only the mouse click?
>>
>> No, I assume that the environment will be pretty noisy and have taken
>> steps to identify the frequency of interest (sliding finger) and
filter
>> out the rest.
>>
>> >Did you try using xcov or xcorr in Matlab yet?
>>
>> I have not tried xcorr yet, but I am using xcov to get the covariances
and
>> lag values and plotting that to find the peak which should give me the
>> delay in the signal (assuming what my supervisor says is correct).
>>
>> >I'm having a hard time figuring out what you have tried, what you
>> >don't
>> >know how to try, and what you do not know how to try.
>>
>> What I would like to know is: with a stereo wave file loaded into
matlab
>> (wavread), how would I accurately determine and possibly plot the time
>> difference of arrival between the two channels?
>>
>> Thanks
>
>Have you actually tried using xcov/xcorr to see if you can possibly
>get a good estimate?  What did you find?  Have you tried it in the
>
>See, I still can't tell what you have tried, and what you have found
>
>At this point I tend to agree with Rune, I doubt that this approach
>will work in anything but a very synthetic environment.  Have you
>at least tried looking at what kind of noise you pick up at the
>sensors?
>
>Can you separate the sound of a mouse click from {everything else
>that sensors pick up}?
>
>Do you understand how finding the peak in the xcov/xcorr gives
>you the time delay of arrival?
>
>
```
```Thanks for all the replies...

What I have rigged up so far, is an MDF surface (representing the
'mouse/touch' pad) and using two condensor microphones placed on two
corners of the pad to record a finger moving across the MDF surface which
essentially is passive audio location.

I know humidity etc will affect how it will sound. Seeing as I'm leading
towards trying to do a 'proof of concept' type research, I've gotten rid
of humidity issues by using talc on the surface, so (if you can imagine) a
slight hissing noise as the finger slides across it.

In terms of how loud it is, you can distinctively hear it on the recorded
wave files. There is a significant amount of noise in the signal however,
mainly at 50Hz and some other random frequencies due to my computer being
rather loud. I have taken my board to different locations and computer
labs (less noisy environments) and recorded a few samples there as well.

I have found the frequency band of interest and filtered out all other
frequencies as best I can and have done this (simply put):

[cov, lags] = xcov (wav_L, wav_R, 'coeff');
delays = lags / fs;
plot (delays, cov);

With recordings of localised sound (ie finger sliding around a single spot
on the MDF board), I took the peak values in the plot and recorded them.
There is a noticable trend with a graph of the delays are plotted (ie from
Left most point to Right most point) but the amount of error that I was
getting made me think twice about using the results as the delay could end
up positive instead of being negative in certain cases. I feel this might
be my recording method and I'm worried that this might make it even more
complicated to implement.

Even after filtering most of the noise out, assuming white noise is
equally present in both channels, and considering my computer CPU is
sitting to the right of the pad when recording, could it affect my delay
plots enough to cause this error? (I'm pretty sure my CPU induces noise at
50 and 22 kHz only (pwm fan controller))

The amount of challenges involved in this project has gotten me over the
top and i'm afraid that i might not be able to complete it at all...

Thanks ryujin_ssdt, I will give that code a try..

```
```Hi,

some quick shooting-from-the-hip concept:
I assume for simplicity that there is a single scratch sound, and the
recorded time window is much longer (silence before and after, means I can
use cyclic FFT without most of the worries)

- Calculate IFFT(FFT(sig1) .* conj(FFT(sig2)))
Explanation in "numerical recipes in C", FFT section (cyclic
convolution).
Search for the peak in the (complex) result. Its location is related to
the time difference between sig1 and sig2.

You'll need to oversample, otherwise the accuracy is too bad, given the
velocity of sound (one sample at 44.1ksps corresponds to 7 mm)
Easily done inside the FFT by zero-padding - split FFT(sig1) in the middle
and insert for example zeros with 3 x the length for oversampling of four.

If noise is too high (the peak isn't clear enough), use a filter that
matches the expected amplitude spectrum of your sound (after the FFTs on
sig1 and sig2, multiply with H(f)).

BTW, are two mics sufficient? Without absolute time reference, wouldn't I
need a third mic? Anyway, it doesn't matter, the same code that gives me
the time difference between mic 1 and 2 will also work for mic 1 and 3.

The FFT processing approach is overkill on a cosmic scale for a product
implementation, but it should do for a concept demo.

Hope that's useful.

-Markus
```
```mnentwig wrote:

...

> You'll need to oversample, otherwise the accuracy is too bad, given the
> velocity of sound (one sample at 44.1ksps corresponds to 7 mm)
> Easily done inside the FFT by zero-padding - split FFT(sig1) in the middle
> and insert for example zeros with 3 x the length for oversampling of four.

Do I understand correctly that you propose to add information by zero

...

Jerry
--
Engineering is the art of making what you want from things you can get.
&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
```
```"Jerry Avins" <jya@ieee.org> wrote in message
news:QYidnayPv_apCibbnZ2dnUVZ_tjinZ2d@rcn.net...
> mnentwig wrote:
>
>   ...
>
>> You'll need to oversample, otherwise the accuracy is too
>> velocity of sound (one sample at 44.1ksps corresponds to
>> 7 mm)
>> Easily done inside the FFT by zero-padding - split
>> FFT(sig1) in the middle
>> and insert for example zeros with 3 x the length for
>> oversampling of four.
>
> Do I understand correctly that you propose to add