I have two sensors separated by some distance that receive a signal from the source. The signal in its pure form is a sine wave with a frequency of 17 kHz. I want to evaluate TDOA between two sensors. I use crosscorrelation and below - my code
x1; % signal as recieved by sensor1
x2; % signal as recieved by sensor2
len = length(x1);
nfft = 2^nextpow2(2*len-1);
X1 = fft(x1);
X2 = fft(x2);
X = X1.*conj(X2);
m = ifft(X);
r = [m(end-len+1) m(1:len)];
[a,i] = max(r);
td = i - length(r)/2;
I filter my x1 and x2 signals, removing all frequencies below 17 kHz. I have two problems with the above code: 1. With the sensors and the source in the same place, I get different "td" values at every moment in time. I'm not sure what is wrong. Is it because of the noise? If so, can anyone suggest a solution? I read a lot of articles and looked at other questions about stackoverflow, so please answer with the code along with the theory, and not just state the theory. 2. The value of "td" sometimes does not match the delay calculated using xcorr. What am I doing wrong? Below is my code for td using xcorr
[xc,lags] = xcorr(x1,x2);
[m,i] = max(xc);
td = lags(i);
source
share