Reply by Albert van der Horst April 2, 20092009-04-02
In article <s9KdnUBmQ-eZXVvUnZ2dnUVZ_tjinZ2d@giganews.com>,
staplep <pstapo@gmail.com> wrote:
>Sorry, I should have clarified a lot more, excuse my ignorance! > >The GCC is the generalized cross correlation, used for determining the >time delay of arrival(TDOA). All of the implementation is in MATLAB aswell. >I have two recordings of the same sound, from spaced microphones. Using a >cross correlation, I can work out the time delay (supposedly). I am trying >to implement a sound localization system, to find the angle of arrival from >this time delay. So, different angles should give wholly different results, >because the delay changes. > >OK, so my way of implementing this is to execute the cross correlation, >then find the time delay from the peak of the correlation. When I observe >the peak, it often spans a few samples, which I think is the cause of my >poor results. I could be wrong though. When I use MATLAB to find the >delay, it does return a seemingly accurate result. The thing is, when I >change the angle, it often returns the same result as before! The fact that >the delay doesn't change when I change the angle of the sound source means >that my implementation is wrong, or the correlation isn't specific enough!
What was the frequency with which you measured? How long a burst did you have? Was the distance between the microphones greater than the wavelength? Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Reply by March 29, 20092009-03-29
On Mar 24, 5:24&#4294967295;pm, "staplep" <pst...@gmail.com> wrote:
> I've tried the whole experiment again, using a theodelite to measure the > angles at which the speaker lies to the microphones, just in case the error > was in the angle measurement, but still no luck. > > Here are my results for each angle > > 5 degrees = 4.42 degrees > 10 degrees = 4.42 degrees > 15 degrees = 13.3732 degrees > 20 degrees = 13.3732 degrees > 25 degrees = 22.674 degrees > 30 degrees = 22.674 degrees > 35 degrees = 32.66 degrees > 40 degrees = 90-339i degrees > 45 degrees = 32.66 degrees > 50 degrees = 43.9278 degrees > 55 degrees = 90 - 351i degrees > 60 degrees = 43.9278 degrees > 65 degrees = 43.9278 degrees > 70 degrees = 90 - 328i degrees > 75 degrees = 58.0026 degrees > 80 degrees= 90 - 345i degrees > 85 degrees = 58.0026 degrees > 90 degrees = 58.0026 degrees > > So as you can see, sometimes I get a complex value. It's quite annoying > that my results dont change if i change the angle of arrival, can some one > please help!!
You have lost some resolution in your calculation somewhere along the way. For example, you have an answer of 58.0026 degrees for a test with 85 and 90 degrees (you have many other examples). Could it be that somewhere in your calculation you went from floating point to fixed point then back to floating point. Maybe your precision is being lost in the conversion from a ratio to an angle. Good luck. Crash Magnet
Reply by Rune Allnor March 25, 20092009-03-25
On 23 Mar, 21:16, "staplep" <pst...@gmail.com> wrote:

> WIth regards to my signal, i am just using an ipod playing through a > guitar amp. I am under the impresssion that the signal shouldn't matter, as > long as it is frequency-rich.
Wrong. For time-domain analysis you need transients. Try to use sharp sounds, like gunshots or sounds of rocks hitting each other. Drums or anything like that might work.
> I have done my recordings in an outdoor space > to ensure there are no reverberations,
Ah. You have the reflections from the ground to worry about. If you can, do the measurements in a grassy field (I know, not that time of year). Or over snow - not with icy crust! - if there is any around. Rune
Reply by dbd March 25, 20092009-03-25
On Mar 24, 4:24 pm, "staplep" <pst...@gmail.com> wrote:
> I've tried the whole experiment again, using a theodelite to measure the > angles at which the speaker lies to the microphones, just in case the error > was in the angle measurement, but still no luck. > > Here are my results for each angle > > 5 degrees = 4.42 degrees > 10 degrees = 4.42 degrees > 15 degrees = 13.3732 degrees > 20 degrees = 13.3732 degrees > 25 degrees = 22.674 degrees > 30 degrees = 22.674 degrees > 35 degrees = 32.66 degrees > 40 degrees = 90-339i degrees > 45 degrees = 32.66 degrees > 50 degrees = 43.9278 degrees > 55 degrees = 90 - 351i degrees > 60 degrees = 43.9278 degrees > 65 degrees = 43.9278 degrees > 70 degrees = 90 - 328i degrees > 75 degrees = 58.0026 degrees > 80 degrees= 90 - 345i degrees > 85 degrees = 58.0026 degrees > 90 degrees = 58.0026 degrees > > So as you can see, sometimes I get a complex value. It's quite annoying > that my results dont change if i change the angle of arrival, can some one > please help!!
You still haven't given much useful information. How far apart are your microphones? Figure it out in terms of number of sample times. How do you determine the peak of the cross correlation? The delay sample with greatest value? Unless the microphones are many sample times apart, small changes in bearing will not necessarily change the delay sample with greatest response. You would than need to put your microphones further apart, interpolate the delay response to find the true peak, use a phase based delay estmation algorithm, or some combination. Good luck Dale B. Dalrymple
Reply by staplep March 24, 20092009-03-24
I've tried the whole experiment again, using a theodelite to measure the
angles at which the speaker lies to the microphones, just in case the error
was in the angle measurement, but still no luck.

Here are my results for each angle 

5 degrees = 4.42 degrees
10 degrees = 4.42 degrees
15 degrees = 13.3732 degrees
20 degrees = 13.3732 degrees
25 degrees = 22.674 degrees
30 degrees = 22.674 degrees
35 degrees = 32.66 degrees
40 degrees = 90-339i degrees
45 degrees = 32.66 degrees
50 degrees = 43.9278 degrees
55 degrees = 90 - 351i degrees
60 degrees = 43.9278 degrees
65 degrees = 43.9278 degrees
70 degrees = 90 - 328i degrees
75 degrees = 58.0026 degrees
80 degrees= 90 - 345i degrees
85 degrees = 58.0026 degrees
90 degrees = 58.0026 degrees

So as you can see, sometimes I get a complex value. It's quite annoying
that my results dont change if i change the angle of arrival, can some one
please help!!
Reply by staplep March 23, 20092009-03-23
The aim of my project is to design a low-cost sound intensity probe, so I
decided to use two mics and matlab for analysis. It is part of my degree
project, which is due in next week, so I am under a lot of pressure! Really
appreciate the replys so far, as it is worth 20% of my degree!

WIth regards to my signal, i am just using an ipod playing through a
guitar amp. I am under the impresssion that the signal shouldn't matter, as
long as it is frequency-rich. I have done my recordings in an outdoor space
to ensure there are no reverberations, but as I live in Ireland, it was
probably windy on the day that I did the recordings. There was also
background traffic. 

From this, my understanding of it is that the signal to noise ratio might
be big.

Here is some of my code so far:

[y, fs, nbits] = wavread('C:\Documents and Settings\Liam
Stapleton\Desktop\Latest190309\LastRecordings\last90');%Recordings\1capleft45fromright'
npts = length (y);
%The number of samples in each column
duration = npts/fs;
%The time duration of the signal.

%Splits the signal into two channels, left and right, to be analysed
%separately.
% access a matrix column (1st row)
x = y(:,1);
z = y(:,2);
time = (1:length(y))/fs;

%%%This is where the correlation is done.
ITD  = xcorr(x,z);

a = (1:length(ITD));%-(length(ITD)/2);

%%Setting up a time lag axis.
for i = 1 : length(a)
    a(i) = a(i) - (length(ITD)/2);
end
a = a .* 1/fs;

plot(a,ITD)
xlabel('Time Lag (Seconds)')
ylabel('Correlation')

This is the code where i compute the delay factor. From the maximum
correlation, I have wrote a little bit of code which gives the
corresponding delay from the max correaltion.

Thanks a million for the help, I hope i'm close to getting the right
answer! Although my code might lack a lot, i am doing an engineering degee,
so have found some of the coding hard!


Reply by Rune Allnor March 23, 20092009-03-23
On 22 Mar, 23:47, "staplep" <pst...@gmail.com> wrote:
> Sorry, I should have clarified a lot more, excuse my ignorance! > > The GCC is the generalized cross correlation, used for determining the > time delay of arrival(TDOA). All of the implementation is in MATLAB aswell. > I have two recordings of the same sound, from spaced microphones.
Only two mics? What are the geometries involved?
> Using a > cross correlation, I can work out the time delay (supposedly). I am trying > to implement a sound localization system, to find the angle of arrival from > this time delay. So, different angles should give wholly different results, > because the delay changes.
Well, not unconditionally. A lot depend on the array geometry vs signal wavelengths etc, but even with a well-designed array there are ambiguities in DoA domain. A linear array is, for instance, cylindrically symmetrical around the array axis.
> OK, so my way of implementing this is to execute the cross correlation, > then find the time delay from the peak of the correlation. When I observe > the peak, it often spans a few samples, which I think is the cause of my > poor results.
Yep. Which means you have a 'blurred' signal (I'd guess narrow-band?). Time-domain techniques work best with broad-band signals with 'favourable' transient behaviour.
>&#4294967295;I could be wrong though. When I use MATLAB to find the > delay, it does return a seemingly accurate result. The thing is, when I > change the angle, it often returns the same result as before! The fact that > the delay doesn't change when I change the angle of the sound source means > that my implementation is wrong, or the correlation isn't specific enough!
It could be just about anything.
> So, after trawling through many internet sites, I found many papers on > what is called the generalized cross correlation. This is supposed to > clarify the results, by decreasing the amount of peaks the max correlation > occurs over. My problem is that both the GCC and the cross correlation > return the exact same results!
Which means that both implementations of the correlations likely are correct (the unlikely alternative is that both implementations are flawed the same way), so you have to look for more funcamental causes for your problems.
> And the results are often wrong! Could > someone please clarify my error,
Nope.
> I feel so stupid because I can't figure it > out!
The only way to work this out is to go through the whole system in extreme detail, checking every single parameter against everything else. It will take time and a lot of work, but you'll learn a lot from it. Rune
Reply by dbd March 23, 20092009-03-23
On Mar 23, 1:27 am, "steveu" <ste...@coppice.org> wrote:
> >On Mar 23, 12:22=A0am, dbd <d...@ieee.org> wrote: > >> On Mar 22, 7:43 pm, robert bristow-johnson <r...@audioimagination.com> > >> wrote: > > >> > On Mar 22, 7:40 pm, dbd <d...@ieee.org> wrote: > > >> > > On Mar 22, 3:47 pm, "staplep" <pst...@gmail.com> wrote: > > >> > > > Sorry, I should have clarified a lot more, excuse my ignorance! > > >> > listen, it's me who is ignorant. =A0there's enough alphabet soup in > my > >> > life and in the news that i just don't allocate real estate in my > >> > brain for more acronyms. > > >> > > What signal did you test with? What SNR? What GCC did you > implement. > >> > > How do you determine delay from the 'flat peak'? > > >> > i just can't imagine it being flatter than what correlating a sine > >> > against itself would get you. =A0i think there is a mathematical > minimu= > >m > >> > to the 2nd derivative of a normalized autocorrelation. =A0they can > be > >> > sharp (like with white noise), but the *peak* cannot be really flat. > >> > i don't get it. > > >> > > At high SNR, CC and GCC should be similar. > > >> > can someone spell out the difference? =A0i know, at least how i > would > >> > define cross-correlation in a sorta practical manner: > > >> > =A0R_xy(tau,t) =3D integral{ x(t+u+tau/2)*y(t+u-tau/2)*w(u) du} > > >> > where w(t) is a window function centered around t=3D0 and maybe y(t) > ha= > >s > >> > to be complex conjugated in the integral. =A0this can be turned into > a > >> > discrete-time version as so: > > >> > =A0R_xy(tau,n) =3D sum{ > > x[n+i+floor(tau/2)]*y[n+i+floor(tau/2)-tau]*w[i= > > > > >] } > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i > > >> > where now the lag, tau, is an integer. > > >> > i s'pose you might wanna normalize it by dividing by > > >> > =A0sqrt(R_xx(0,n)*R_yy(0,n)} > > >> > so my question is, specifically, what other kind of > cross-correlation > >> > are people using? > > >... > > >> Robert > > >> I wasn't really trying to trigger you. I was really hoping to get the > >> OP to explain how he had applied CC and GCC to calculate TDOA, and of > >> what, so we might understand where the difficulty might be. I'm still > >> hoping. > > >it's okay, Dale. i take responsibility for my own actions including > >triggering (whatever that is). it's my own curiosity of what would be > >different methods of doing cross-correlation. if you leave out > >prefiltering (so that the TDOA of some frequency components are > >ignored relative to others) or normalization, i dunno what other way > >there is to do it (or to define it). > > >it's for my own learning experience. > > Aren't most of the variants of GCC that people have listed just ways to > whiten or colour the incoming signals to nudge the correlation towards the > desired conclusion? In other words, leave out pre-filtering and there isn't > a huge amount left to discuss. > > Steve
I would say yes, which is why I asked the OP about SNR. At high SNR his results should be similar. But it isn't always good to leave out the pre-filtering. If the SNR is low and the signal resembles colored noise, pre-filtering may be necessary and how it is performed may be important. YMMV Dale B. Dalrymple Dale B. Dalrymple
Reply by steveu March 23, 20092009-03-23
>On Mar 23, 12:22=A0am, dbd <d...@ieee.org> wrote: >> On Mar 22, 7:43 pm, robert bristow-johnson <r...@audioimagination.com> >> wrote: >> >> >> >> > On Mar 22, 7:40 pm, dbd <d...@ieee.org> wrote: >> >> > > On Mar 22, 3:47 pm, "staplep" <pst...@gmail.com> wrote: >> >> > > > Sorry, I should have clarified a lot more, excuse my ignorance! >> >> > listen, it's me who is ignorant. =A0there's enough alphabet soup in
my
>> > life and in the news that i just don't allocate real estate in my >> > brain for more acronyms. >> >> > > What signal did you test with? What SNR? What GCC did you
implement.
>> > > How do you determine delay from the 'flat peak'? >> >> > i just can't imagine it being flatter than what correlating a sine >> > against itself would get you. =A0i think there is a mathematical
minimu=
>m >> > to the 2nd derivative of a normalized autocorrelation. =A0they can
be
>> > sharp (like with white noise), but the *peak* cannot be really flat. >> > i don't get it. >> >> > > At high SNR, CC and GCC should be similar. >> >> > can someone spell out the difference? =A0i know, at least how i
would
>> > define cross-correlation in a sorta practical manner: >> >> > =A0R_xy(tau,t) =3D integral{ x(t+u+tau/2)*y(t+u-tau/2)*w(u) du} >> >> > where w(t) is a window function centered around t=3D0 and maybe y(t)
ha=
>s >> > to be complex conjugated in the integral. =A0this can be turned into
a
>> > discrete-time version as so: >> >> > =A0R_xy(tau,n) =3D sum{
x[n+i+floor(tau/2)]*y[n+i+floor(tau/2)-tau]*w[i=
>] } >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i >> >> > where now the lag, tau, is an integer. >> >> > i s'pose you might wanna normalize it by dividing by >> >> > =A0sqrt(R_xx(0,n)*R_yy(0,n)} >> >> > so my question is, specifically, what other kind of
cross-correlation
>> > are people using? >> >... >> >> Robert >> >> I wasn't really trying to trigger you. I was really hoping to get the >> OP to explain how he had applied CC and GCC to calculate TDOA, and of >> what, so we might understand where the difficulty might be. I'm still >> hoping. > >it's okay, Dale. i take responsibility for my own actions including >triggering (whatever that is). it's my own curiosity of what would be >different methods of doing cross-correlation. if you leave out >prefiltering (so that the TDOA of some frequency components are >ignored relative to others) or normalization, i dunno what other way >there is to do it (or to define it). > >it's for my own learning experience.
Aren't most of the variants of GCC that people have listed just ways to whiten or colour the incoming signals to nudge the correlation towards the desired conclusion? In other words, leave out pre-filtering and there isn't a huge amount left to discuss. Steve
Reply by robert bristow-johnson March 23, 20092009-03-23
On Mar 23, 12:22&#4294967295;am, dbd <d...@ieee.org> wrote:
> On Mar 22, 7:43 pm, robert bristow-johnson <r...@audioimagination.com> > wrote: > > > > > On Mar 22, 7:40 pm, dbd <d...@ieee.org> wrote: > > > > On Mar 22, 3:47 pm, "staplep" <pst...@gmail.com> wrote: > > > > > Sorry, I should have clarified a lot more, excuse my ignorance! > > > listen, it's me who is ignorant. &#4294967295;there's enough alphabet soup in my > > life and in the news that i just don't allocate real estate in my > > brain for more acronyms. > > > > What signal did you test with? What SNR? What GCC did you implement. > > > How do you determine delay from the 'flat peak'? > > > i just can't imagine it being flatter than what correlating a sine > > against itself would get you. &#4294967295;i think there is a mathematical minimum > > to the 2nd derivative of a normalized autocorrelation. &#4294967295;they can be > > sharp (like with white noise), but the *peak* cannot be really flat. > > i don't get it. > > > > At high SNR, CC and GCC should be similar. > > > can someone spell out the difference? &#4294967295;i know, at least how i would > > define cross-correlation in a sorta practical manner: > > > &#4294967295;R_xy(tau,t) = integral{ x(t+u+tau/2)*y(t+u-tau/2)*w(u) du} > > > where w(t) is a window function centered around t=0 and maybe y(t) has > > to be complex conjugated in the integral. &#4294967295;this can be turned into a > > discrete-time version as so: > > > &#4294967295;R_xy(tau,n) = sum{ x[n+i+floor(tau/2)]*y[n+i+floor(tau/2)-tau]*w[i] } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; i > > > where now the lag, tau, is an integer. > > > i s'pose you might wanna normalize it by dividing by > > > &#4294967295;sqrt(R_xx(0,n)*R_yy(0,n)} > > > so my question is, specifically, what other kind of cross-correlation > > are people using? >
...
> > Robert > > I wasn't really trying to trigger you. I was really hoping to get the > OP to explain how he had applied CC and GCC to calculate TDOA, and of > what, so we might understand where the difficulty might be. I'm still > hoping.
it's okay, Dale. i take responsibility for my own actions including triggering (whatever that is). it's my own curiosity of what would be different methods of doing cross-correlation. if you leave out prefiltering (so that the TDOA of some frequency components are ignored relative to others) or normalization, i dunno what other way there is to do it (or to define it). it's for my own learning experience. r b-j