DSPRelated.com
Forums

GCC Clarity.

Started by staplep March 20, 2009
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. 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. i think there is a mathematical minimum > to the 2nd derivative of a normalized autocorrelation. 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? i know, at least how i would > define cross-correlation in a sorta practical manner: > > 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. this can be turned into a > discrete-time version as so: > > R_xy(tau,n) = sum{ x[n+i+floor(tau/2)]*y[n+i+floor(tau/2)-tau]*w[i] } > i > > where now the lag, tau, is an integer. > > i s'pose you might wanna normalize it by dividing by > > sqrt(R_xx(0,n)*R_yy(0,n)} > > so my question is, specifically, what other kind of cross-correlation > are people using? > > r b-j
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. Dale B. Dalrymple
>On Mar 22, 7:40=A0pm, 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. 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. i think there is a mathematical minimum >to the 2nd derivative of a normalized autocorrelation. 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? i know, at least how i would >define cross-correlation in a sorta practical manner: > > > R_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) has >to be complex conjugated in the integral. this can be turned into a >discrete-time version as so: > > > R_xy(tau,n) =3D sum{ x[n+i+floor(tau/2)]*y[n+i+floor(tau/2)-tau]*w[i] } > i > >where now the lag, tau, is an integer. > >i s'pose you might wanna normalize it by dividing by > > sqrt(R_xx(0,n)*R_yy(0,n)} > > > > >so my question is, specifically, what other kind of cross-correlation >are people using? > >r b-j >
There are two general methods for estimating the TDOA of a signal. The first method requires subtracting the time-of-arrival (TOA) estimates from two receivers to produce a relative measurement, i.e., the TDOA. The second method requires a cross correlation between the signal collected at one receiver with the signal collected at another receiver. The first method is only useful if there is an accurate timing reference between the transmitter and the receiver. The second method is more generally applicable and is the foundation of many of the most useful methods for estimating TDOA. One of these methods is called the generalized cross correlation (GCC) method of time delay estimation. The GCC method was originally introduced as a method for estimating TDOA for a signal of interest (SOI) in the absence of relative motion between receivers and the emitter. However, the GCC method can be used to produce a TDOA vs. time representation when the change in TDOA is small compared to the receiver sample rate. The GCC can be understood as the cross-correlation function with various non unity weighting functions. For example, using a weighting function of 1 reduces reduces the GCC function to a simple cross correlation estimate. Given prior knowledge of the noise characteristics of the received signals it is possible to choose a weighting function that can help in reducing specific noise problems. Several common weighting functions are called the ROTH, SCOTT, PHAT, etc. The respective advantages and disadvantages of the various weighting functions have been thoroughly presented in the literature. I would guess (given the limited info so far) that original problem is that your sample rate is not high enough to support the microphone spacing (and/or your microphone spacing is not correct to support the frequencies you are targeting), and therefore small changes in angle-of-arrival that you are testing. The GCC and the typical cross correlation should give similar results unless you are exploiting difficult noise environments effects and/or SNR limitations. Just guessing until you provide more info. The following are the best papers I know about to understand the GCC mehod better. The other best method is to collect some real data and experiment. Probably the best DSPers to understand the GCC tradeoffs will be from the sonar community. [1] G. C. Carter, \Coherence and Time Delay Estimation," Proceedings of the IEEE, vol. 75, pp. 236{255, February 1987. [2] C. H. Knapp and G. C. Carter, \The Generalized Correlation Method for Esti- mation of Time Delay," IEEE Trans. on Acoustics, Speech, and Signal Processing, vol. ASSP-24, No. 4, August 1976. [3] M. Azaria and D. Hertz, \Time-Delay Estimation by Generalized Cross-Correlation Methods," IEEE Trans. on Acoustics, Speech, and Signal Processing, vol. ASSP-32, No. 2, April 1984. Hope this helps. Take care Dave
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
>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
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
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
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!


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!!
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
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