Cross correlation is to be used to measure distance to an aircraft by transmitting a known wide-band signal and correlating the transmitted signal with incoming signals received via the radar reception dish

The transmitted signal x(n) is of length N=512 while the received signal y(n) is of length N=2048.

y(n)=kx(n-d)+w(n); where 'kx(n-d)' is x(n) delayed by d samples and attenuated by a factor k, and w(n) is reception noise.

i am trying to write a MATLAB program to cross correlate x(n) with the y(n) to determine the value of d, the number of samples delay. And also Determine a suitable sampling frequency if the distance to the aircraft is to be determined within 50 km to an accuracy of 50 m, given that the transmitted and received data is travelling at the speed of light.

4

There are 4 best solutions below

1
On

The easiest way to do this is with the "xcorr" function. This is part of the Signal Processing toolbox for matlab, but should be available for GNU Octave here. I have not checked if the octave script is completely MATLAB compatible.

You can use the xcorr function as:

[correlation,lags] = xcorr(x,y);

The lag value can be found using

delay = lags(find(correlation==max(correlation)))

At the speed of light, the signal will be travelling at 3 x 10^8 m/s, so to have a resolution of 50m, you should be sampling at at least (3e8/50m) = 6MHz. At this sampling rate, each lag will be 1/6000000 second. If you multiply your delay by this value, you get your total time intervel between transmission and reception of the signal. Multiply this time intervel by the speed of light to get your distance.

0
On

You can use generalized Cross correlation -Phase transform GCC PHAT The following is the MATLAB code for it

function time=GCCPHAT_testmode(b1,b2)

b1f=fft(b1);

b2f=fft(b2);

b2fc=conj(b2f);

neuma=(b1f).*(b2fc);

deno=abs((b1f).*(b2fc));

GPHAT=neuma./deno;

GPHATi=ifft(GPHAT);

[maxval ind]= max(GPHATi);

samp=ind

end
1
On

Aj463's comment above is good, indeed GCC-PHAT is better than unweighted correlation for estimating delay of wide-band signals.

I would suggest a small improvement to the code posted above: to add a small value epsilon to the denominator, epsilon -> 0, in order to avoid eventual division by zero.

Thus, I would change the line

deno=abs((b1f).*(b2fc));

to

deno=abs((b1f).*(b2fc)) + epsilon; 
0
On

we can ignore the 'find' function in matlab, the command could be changed to

delay = lags(correlation==max(correlation))

'xcorr' suits for vectors with long length;
'gcc' prefer frame by frame.