# Audio - TDOA and $\tt xcorr$, find the 'best' peak

I try to locate a mobile device using multilateration. The mobile device acts as the receiver and in the room I have three speakers. To calculate the position I need the time difference of arrival (TDOA) values for each speaker signal. I am using MATLAB and xcorr for this. The (simplified) code looks like this:

[signal1, fs] = audioread('speaker1_signal.wav');
[R, lags] = xcorr(signal1, rx_signal);
[v, i] = max(R);
lag = lags(i);
% for each speaker signal


Calculating the time difference is not difficult. I calculate the lag value for each speaker, set one as 'fixed' and substract the other values from the fixed one. So far, so good.

My problem: it seems that the maximum value of the xcorr is not always the best value. Looking at the following plot (real data) we can see the problem:

The max values for Signal1 and Signal2 are placed around 18k; However, the value for Signal3 (yellow) is placed around 15k. This results in huge time differences (that results to wrong positions). I would like to know if there are any solutions for detecting the ''best'' peak value or how I can solve my problem?

HINT:

My signal is linear frequency modulated (each speaker has a bandwith of $1\textrm{ kHz}$) and I am using FDMA and the ultrasonic range (17-21k) due to hardware limitations. The receiver is a Smartphone; on a measurement microphone this problem doesn't occur very often. But the final product should run on a smartphone as well.

• Do the speakers emit a linear sweep at different frequency ranges? Please note that the room will modulate the speaker signal until it hits the mic, so, you might need to do a bit of equalisation before cross-correlation, or somehow take the envelope into account. Can you please try reducing the amplitude of the speakers and give it another try? (I.e. try to minimise the impact of reflections on the signal. I am implying walls here but If you are in the supersonic range, other objects will give strong reflections too) – A_A Jul 18 '16 at 10:14
• @A_A Yes they emit at different ranges. Speaker1 from 17k to 18k; speaker2 from 18k to 19k and speaker3 from 19k to 20k. I will try what you've suggested but it will take some time 'cause I don't have access to the room each day. But I think I can recreate the problem in another room. (Both ''normal offices'') Since the room modulates the signal I assume the signal length could have an impact as well? The results above were achieved with a length of 100ms. – Philipp Jul 18 '16 at 10:49
• Thanks for letting me know. You cannot do much with the signal length in this scenario. Sound does a km in ~3 sec. To avoid reflections in a room you would have to create very short bursts and use higher sampling frequencies which might quickly become a problem for your processing on the smartphone. – A_A Jul 18 '16 at 11:17
• Try to do the processing in baseband. – ThP Jul 18 '16 at 20:13
• @ThP could you please explain this a little bit. I am pretty new to DSP. – Philipp Jul 23 '16 at 11:37