26. Delay and Doppler: the Ambiguity Function¶
TDOA: Delays, Peaks and Positions measured the delay between two sensors with a cross-correlation. That works as long as both sensors see the signal at the same frequency. When the emitter or the sensors move, each sensor sees its own Doppler shift, and the difference between the two, the frequency difference of arrival (FDOA), can be large enough that the two records no longer correlate at all. PySDR’s TDOA chapter ends with the remedy: search over delay and frequency offset by maximizing the complex ambiguity function,
“at correspondingly higher computational cost”. In words: shift one record by a trial delay, undo a trial frequency offset, and correlate. The peak of \(|A|\) gives both differences at once. PySDR shows the formula but no code. This chapter computes the cross-ambiguity function, the CAF, in two ways that cost very different amounts, finds a moving emitter’s delay and Doppler difference with it, and shows what plain cross-correlation makes of the same records.
The code is in code/include/cppsdr/caf.hpp and code/tests/test_caf.cpp.
A Moving Emitter¶
The test scene has two fixed sensors 30 km apart and an emitter at 1 GHz, 23 km from the first sensor, moving at 170 m/s. The geometry gives both differences. The range difference of 3583 m is 11.953 samples at 1 MS/s. The two range rates are −8.6 and 159.8 m/s, and each sensor sees a Doppler shift of \(-f_c\,\dot r_i / c\), so the Doppler difference is −561.7 Hz. The emitter sends 200 kHz of noise-like signal, and each sensor adds noise of equal power (0 dB SNR). The records are \(N = 65\,536\) samples, 65.5 ms long.
Over a record of length \(T\), a frequency difference \(\nu\) turns the product \(x_2 x_1^*\) into a rotating phasor. Summed over the record, it shrinks by \(|\operatorname{sinc}(\nu T)|\). Here \(\nu T = 36.8\), which leaves 0.5 % of the correlation peak. The test confirms it: the plain cross-correlation, the Doppler-0 row of the CAF, has its maximum at lag 27 309, nowhere near the emitter. At the true lag it reaches 0.7 % of the CAF peak. Without the Doppler search, the emitter is not just mislocated, it is invisible.
Two Ways to Fill the Plane¶
For records of \(N\) samples, the discrete CAF is
which peaks at \((\tau, k)\) when the second sensor receives the first one’s signal \(\tau\) samples later and \(k\) bins higher. The formula is one DFT, in two ways.
One FFT per lag. For a fixed \(\tau\) it is the DFT of the lag product \(z_\tau[n] = x_2[n]\,x_1^*[n-\tau]\). So every row of the plane is an FFT of length \(N\). Stein’s classic paper on ambiguity function processing (S. Stein, “Algorithms for ambiguity function processing”, IEEE Transactions on Acoustics, Speech, and Signal Processing, 1981) adds the step that makes this fast. The Doppler differences of interest are small, so \(z_\tau\) can be low-pass filtered and decimated before the FFT. caf_by_lag uses the simplest such filter, a sum over blocks of \(D\) samples:
for (std::size_t mm = 0; mm < m_; ++mm) { // m_ = N / D
cf32 acc = 0;
for (std::size_t j = 0; j < d_; ++j) {
const std::size_t i = mm * d_ + j;
acc += x2[i] * std::conj(x1[(i - lag) mod N]);
}
buf_[mm] = acc;
}
fftwf_execute(plan_.get()); // N/D points, same bin spacing fs/N
One inverse FFT per Doppler bin. For a fixed \(k\), multiplying \(x_2\) by \(e^{-j2\pi kn/N}\) rotates its spectrum by \(k\) bins. So after one FFT of each record, every Doppler row is a product and an inverse FFT, with no mixing in the time domain:
fftwf_execute(fwd1_.get()); // X1, once
fftwf_execute(fwd2_.get()); // X2, once
for (long k = -max_bin_; k <= max_bin_; ++k) {
for (std::size_t f = 0; f < n_; ++f) g_[f] = x2_[(f + k) mod N] * std::conj(x1_[f]);
fftwf_execute(inv_.get()); // all N lags of row k
...
}
Both return the surface as an std::mdspan view of one contiguous array, so either one indexes as A[lag, bin] or B[bin, lag]. On the test records, the two agree to \(1.6 \times 10^{-7}\) of the peak, over all 65 × 129 cells they share.
Which one is cheaper depends on the shape of the search. The per-Doppler form computes all \(N\) lags of every row whether they are needed or not. The per-lag form computes all Doppler bins unless the lag product is decimated first. Here the search covers ±32 lags and ±64 bins. On the M1, 65 full-length FFTs take 106 ms and 129 inverse FFTs 207 ms. With Stein’s decimation by \(D = 32\), the per-lag form needs 65 FFTs of only 2048 points, and the whole plane takes 10 ms.
The decimation costs a little gain. A sum over \(D\) samples is a boxcar filter, which attenuates a frequency \(\nu\) (in cycles per sample) by \(|\sin(\pi\nu D)/(D \sin(\pi\nu))|\). At this Doppler bin that predicts 0.99946. The decimated peak is in the same cell, at 0.99938 of the exact magnitude. Larger \(D\) saves more, but the boxcar’s loss grows toward the edge of the decimated band, where it reaches \(2/\pi\) (−3.9 dB).
Between the Cells¶
The peak cell gives the delay to a sample and the Doppler to a bin (15.3 Hz here). The two directions of the CAF have different shapes, so each gets its own refinement.
Along the lag axis, the CAF has the shape of the signal’s autocorrelation: for 200 kHz at 1 MS/s, a main lobe about 5 samples wide. The parabola through three samples fits that well, as in TDOA: Delays, Peaks and Positions.
Along the Doppler axis, the shape is that of the rectangular record, a sinc one bin wide, and a parabola through three samples of a sinc is biased. On the test records it gives bin −36.980, 0.17 bins off. For a sinc, the peak sample \(a_0\) and its larger neighbour \(a_1\) determine the offset exactly. With the true peak a fraction \(\delta\) of a bin from the peak cell toward that neighbour, \(|\sin \pi\delta| = |\sin \pi(1-\delta)|\), so \(a_1/a_0 = \delta/(1-\delta)\), and
inline double sinc_two_point(double m_1, double m0, double p1)
{
return p1 >= m_1 ? p1 / (m0 + p1) : -m_1 / (m0 + m_1);
}
With both refinements, the CAF gives a delay of 11.965 samples (true 11.953) and a Doppler difference of −561.72 Hz (true −561.67), 0.004 bins off.
Key Takeaways¶
A Doppler difference \(\nu\) over a record of length \(T\) scales the cross-correlation by \(|\operatorname{sinc}(\nu T)|\). At \(\nu T = 37\), plain correlation lost the emitter entirely, and the CAF found it at 0 dB SNR.
The CAF is one DFT in two ways: an FFT per lag of the lag product, or an inverse FFT per Doppler bin of a rotated spectrum. They agree to float rounding. Pick the one whose unneeded outputs are cheaper.
Stein’s decimation of the lag product (here a boxcar over 32 samples) shrinks each FFT 32 times and cut the plane from 106 to 10 ms, at the boxcar’s predicted gain loss (0.9995 here).
Refine each direction with a model of its own shape: a parabola for the band-limited lag axis, the exact two-point formula \(a_1/(a_0+a_1)\) for the sinc along Doppler.