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');
[rx_signal, fs] = audioread('received_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.