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:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8581&objectType=file
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
google for "Generalized Cross Correlation".
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
>presence of additional noise sources?
>
>See, I still can't tell what you have tried, and what you have found
>from your trials and experiments.
>
>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?
>
>