Algorithm Search⌘K

Algorithmcore

Range-Doppler algorithm

Also called RDA.

Focus SAR data by range compression, range cell migration correction in the range-Doppler domain and azimuth matched filtering by FFT.

Time
O(M N (log(M N) + K)) worst
Space
O(M N) extra · data
Where
K = the number of taps of the interpolator; M = the number of pulses; N = the number of range samples per pulse
Properties
deterministicnot exactlinear in dataiterative
Origin
C. Wu, 1976

The range-Doppler algorithm (RDA) focuses stripmap synthetic aperture radar data with one-dimensional FFTs and one interpolation. It first compresses each pulse in range with the matched filter of the chirp. Then it takes an FFT along the track for every range bin, into the range-Doppler domain. There, all targets at one closest range follow one curve of range cell migration, so a range-varying interpolation straightens all of them together. Last, it multiplies each Doppler line by the azimuth matched filter of its range and takes the inverse FFT along the track. It is not the range-Doppler processing of pulse-Doppler radar, which estimates the range and the radial velocity of targets from a burst of pulses; the RDA forms an image.

In plain words

The raw data hold, for every pulse, a long smeared echo of every point. The first step sharpens each pulse along the range direction. The echo of one point still runs along the flight direction as a long, faint, slightly curved streak. Changing the flight direction into frequencies makes every point at one distance share the same curve, so one correction straightens them all. After that, a second sharpening along the flight direction, done with a quick transform, turns each streak into one bright spot.

The problem

The input is the raw data s[p][j]s[p][j] of MM pulses on a straight track at the speed VV, with the pulse repetition frequency PRF, and NN range samples per pulse at the rate fsf_s. Sample jj is the slant range rstart+j Δrr_{\text{start}} + j\, \Delta r with Δr=c/(2fs)\Delta r = c/(2 f_s). The pulse is a chirp with the FM rate KrK_r, the carrier is f0f_0 with λ=c/f0\lambda = c/f_0, and the beam has zero squint. A point at the along-track position x0x_0 and the closest range R0R_0 gives a chirp(τ−2R(η)/c) e−i4πf0R(η)/ca\, \text{chirp}(\tau - 2R(\eta)/c)\, e^{-i 4\pi f_0 R(\eta)/c} with R(η)=R02+(Vη−x0)2R(\eta) = \sqrt{R_0^2 + (V\eta - x_0)^2}. The page uses the Fourier sign e−i2πfte^{-i 2\pi f t} of the DFT; radar books often use e+jωte^{+j\omega t} and so write the opposite signs. The output is the complex image on the same M×NM \times N grid, with a peak of each target at the pulse closest to it and at the bin of R0R_0, close to the SAR image formation matched filter value.

The algorithm

  1. RDA(s, chirp, f_0, V, PRF, r_start, Δr) ▷ s[p][j]: pulse p, range bin j; returns the image
  2. 1for every pulse p: s_c[p] ← IDFT(DFT(s[p]) · conj(DFT(chirp))) ▷ range compression
  3. 2for every range bin j: S[·][j] ← DFT over p of s_c[·][j] ▷ to the range-Doppler domain
  4. 3for every Doppler bin k with |f_k| ≤ f_max: f ← f_k ▷ f_k wrapped to [-PRF/2, PRF/2)
  5. 4D ← sqrt(1 - (λ f / (2V))²)
  6. 5for every range bin j: R_0 ← r_start + j Δr; u ← (R_0 / D - r_start) / Δr
  7. 6v ← SINC-INTERP(S[k][·], u) ▷ RCMC
  8. 7K_a ← 2 V² f_0 D³ / (c R_0); H ← (PRF / sqrt(K_a)) e^{+i 4π f_0 R_0 D / c}
  9. 8I[k][j] ← v · H ▷ azimuth matched filter
  10. 9for every range bin j: image[·][j] ← IDFT over k of I[·][j]

Line L1 is pulse compression by fast convolution. It is circular, so the record must hold the whole chirp of every target. Line L2 moves to the range-Doppler domain. By the principle of stationary phase, Doppler frequency ff comes from the slow time at which the target is seen at the squint angle with sine −λf/(2V)-\lambda f/(2V), so its range there is R0/D(f)R_0 / D(f). Lines L4 to L6 read the line of Doppler bin kk at that range, which is a range-varying shift; SINC-INTERP is an 8-tap Hann-weighted sinc interpolation. After L6, the energy of every target at R0R_0 is in bin jj of R0R_0, whatever its along-track position. The azimuth phase there is −4πf0R0D(f)/c−2πfx0/V-4\pi f_0 R_0 D(f)/c - 2\pi f x_0/V plus a constant, so the factor of L7 cancels the first term, and the inverse DFT of L9 turns the linear phase that is left into a peak at x0x_0. The gain PRF/Ka\text{PRF}/\sqrt{K_a} of L7 makes the peak close to the brute-force matched filter value; KaK_a is the azimuth FM rate at ff. The Doppler band fmax⁡=2Vsin⁡θ/λf_{\max} = 2 V \sin\theta / \lambda of a beam with the half angle θ\theta limits the loop of L3.

Example

The tests use f0=300f_0 = 300 MHz (λ=1\lambda = 1 m), a chirp of B=100B = 100 MHz and 0.2 us sampled at fs=120f_s = 120 MHz (Δr=1.25\Delta r = 1.25 m), V=100V = 100 m/s and PRF =80= 80 Hz (a pulse every 1.25 m), M=128M = 128 pulses, N=64N = 64 range bins from 380 m, and a beam with sin⁡θ=0.125\sin\theta = 0.125. A target at R0=400R_0 = 400 m is in view for 81 pulses, and its migration at the edge of the beam is 3.16 m, about 2.5 bins. The Doppler band is ±25\pm 25 Hz.

target (x0,R0)(x_0, R_0), amplitude matched filter value RDA peak / matched filter without RCMC (L5 with u=ju = j)
(0 m, 400 m), 1 1945 0.904 0.468
(10 m, 410 m), 0.7 1394 0.904 0.461

Both peaks are at the predicted pixels (pulse 64 and bin 16 for the first). The ratio of the two peaks, each divided by its own ideal value, is 0.70, the ratio of the amplitudes. Both outputs carry the same constant phase of about −38-38 degrees, close to the −45-45 degrees of the stationary phase factor e−iπ/4e^{-i\pi/4}, which L7 does not remove. Along range, the neighbors of the peak at ±1.25\pm 1.25 m are 0.29 and 0.26 of the peak; along the track they are 0.50 of the peak at ±1.25\pm 1.25 m and 0.17 at ±2.5\pm 2.5 m, as expected for the resolutions c/(2B)=1.5c/(2B) = 1.5 m and V/(50 Hz)=2V/(50\ \text{Hz}) = 2 m. All numbers in this section are measurements on this simulation.

Correctness

Every step is linear in the data, so the image of a scene is the sum of the images of its points. For one point, the stationary phase approximation of the azimuth DFT gives the range-Doppler signal W(f) pc(τ−2R0/(cD(f))) e−i4πf0R0D(f)/c−i2πfx0/VW(f)\, p_c(\tau - 2R_0/(c D(f)))\, e^{-i 4\pi f_0 R_0 D(f)/c - i 2\pi f x_0/V} times a constant, with the compressed pulse pcp_c. This is the key invariant: the migration curve depends on R0R_0 and ff only. With exact interpolation, L5 and L6 put the target in the bin of R0R_0 for every ff; L7 cancels the phase that depends on ff except the linear term; and L9 gives a peak at x0x_0 of about aa times the number of pulses in view times the compressed pulse peak, which is the matched filter value. The result is exact only up to the stationary phase approximation, the interpolation and the coupling of range and azimuth, which this basic form ignores. The proofs are in proofs/correctness.md.

Proof: The range-Doppler algorithm is linear and, under the stationary phase approximation, focuses a point target at its position with the matched filter gainfull

We prove four facts about the RDA as written on the main page (lines L1 to L9) for the stripmap model with zero squint: a straight track at the speed VV, point targets, a constant speed of light cc, and the stop-and-go approximation. Theorem 1 is exact. Theorems 2 to 4 are statements about the continuous model under the principle of stationary phase, which is an asymptotic approximation that is good when the azimuth time-bandwidth product KaTa2K_a T_a^2 is large; they are not exact statements about the sampled data.

Setting. After range compression, a target of amplitude aa at the along-track position x0=Vη0x_0 = V \eta_0 and the closest range R0R_0 gives

sc(τ,η)=a w(η−η0) pc ⁣(τ−2R(η)c)e−i4πf0R(η)/c,R(η)=R02+V2(η−η0)2,s_c(\tau, \eta) = a\, w(\eta - \eta_0)\, p_c\!\left(\tau - \frac{2R(\eta)}{c}\right) e^{-i 4\pi f_0 R(\eta)/c}, \qquad R(\eta) = \sqrt{R_0^2 + V^2 (\eta - \eta_0)^2},

with the compressed pulse pcp_c (peak pc(0)p_c(0) at zero delay), the window ww of the beam, and the Fourier sign e−i2πfte^{-i 2\pi f t}. Write λ=c/f0\lambda = c/f_0, D(f)=1−(λf/(2V))2D(f) = \sqrt{1 - (\lambda f / (2V))^2} and Ka(f)=2V2f0D(f)3/(cR0)K_a(f) = 2 V^2 f_0 D(f)^3 / (c R_0).

Theorem 1 (linearity). The output of lines L1 to L9 is a linear function of the input ss. So the image of a sum of targets is the sum of their images.

Proof. L1, L2 and L9 are DFTs and products with a fixed sequence. L6 is a weighted sum of samples with weights that depend only on jj, kk and the geometry. L8 multiplies by a factor that does not depend on the data. A composition of linear maps is linear. □\square

Theorem 2 (the range-Doppler signal). Under the stationary phase approximation, and treating the envelope pcp_c and the window ww as slowly varying, the azimuth Fourier transform Sc(τ,f)=∫sc(τ,η) e−i2πfη dηS_c(\tau, f) = \int s_c(\tau, \eta)\, e^{-i 2\pi f \eta}\, d\eta is

Sc(τ,f)≈a e−iπ/4Ka(f) W(f) pc ⁣(τ−2R0c D(f))e−i4πf0R0D(f)/c e−i2πfη0,S_c(\tau, f) \approx \frac{a\, e^{-i\pi/4}}{\sqrt{K_a(f)}}\, W(f)\, p_c\!\left(\tau - \frac{2 R_0}{c\, D(f)}\right) e^{-i 4\pi f_0 R_0 D(f)/c}\, e^{-i 2\pi f \eta_0},

where W(f)W(f) is the value of ww at the stationary point.

Proof. The phase of the integrand is ϕ(η)=−4πf0R(η)/c−2πfη\phi(\eta) = -4\pi f_0 R(\eta)/c - 2\pi f \eta. Put u=η−η0u = \eta - \eta_0. Then ϕ′(η)=−4πf0cV2uR−2πf\phi'(\eta) = -\frac{4\pi f_0}{c} \frac{V^2 u}{R} - 2\pi f, which is zero when VuR=−λf2V\frac{V u}{R} = -\frac{\lambda f}{2V}. Call this number sin⁡ψ\sin\psi; then R0=Rcos⁡ψR_0 = R \cos\psi, so R=R0/D(f)R = R_0 / D(f) at the stationary point, and fu=−2f0V2u2cRf u = -\frac{2 f_0 V^2 u^2}{c R}. The phase there is

ϕ∗=−4πf0Rc+4πf0V2u2cR−2πfη0=−4πf0cR(R2−V2u2)−2πfη0=−4πf0R0D(f)c−2πfη0,\phi^\ast = -\frac{4\pi f_0 R}{c} + \frac{4\pi f_0 V^2 u^2}{c R} - 2\pi f \eta_0 = -\frac{4\pi f_0}{c R}(R^2 - V^2 u^2) - 2\pi f \eta_0 = -\frac{4\pi f_0 R_0 D(f)}{c} - 2\pi f \eta_0,

because R2−V2u2=R02R^2 - V^2 u^2 = R_0^2 and R02/R=R0DR_0^2 / R = R_0 D. The second derivative is ϕ′′(η)=−4πf0cV2R02R3\phi''(\eta) = -\frac{4\pi f_0}{c} \frac{V^2 R_0^2}{R^3}, and at the stationary point its size is 4πf0V2D3cR0=2πKa(f)\frac{4\pi f_0 V^2 D^3}{c R_0} = 2\pi K_a(f). The stationary phase formula ∫g(η)eiϕ(η)dη≈g(η∗)2π/∣ϕ′′(η∗)∣ eiϕ∗−iπ/4\int g(\eta) e^{i\phi(\eta)} d\eta \approx g(\eta^\ast) \sqrt{2\pi / |\phi''(\eta^\ast)|}\, e^{i\phi^\ast - i\pi/4} for ϕ′′<0\phi'' < 0 gives the factor e−iπ/4/Kae^{-i\pi/4}/\sqrt{K_a}, and the envelope is evaluated at the range R0/D(f)R_0/D(f) of the stationary point. □\square

The range R0/D(f)R_0 / D(f) of the envelope depends on R0R_0 and ff only, not on η0\eta_0. This is the invariant that lets one interpolation correct all targets at the same range.

Theorem 3 (migration correction). Assume that L6 interpolates the range-Doppler line exactly (a band-limited signal and an ideal interpolator). Then after L6 the value in the bin jj with rstart+jΔr=R0r_{\text{start}} + j \Delta r = R_0 at Doppler frequency ff is Sc(2R0/(cD(f)),f)S_c(2 R_0 / (c D(f)), f), which by Theorem 2 has the envelope value pc(0)p_c(0), its peak, for every ff.

Proof. L5 sets uu to the fractional bin of the range R0/D(f)R_0 / D(f), and an exact interpolation returns the value of the line at that range. The delay argument of pcp_c in Theorem 2 is then 00. □\square

Without L5, that is with u=ju = j, the envelope is pc(2R0(1−1/D)/c)p_c(2R_0(1 - 1/D)/c), smaller than the peak wherever the migration R0(1/D−1)R_0 (1/D - 1) is a sizable part of the range resolution. This is the loss that the example measures.

Theorem 4 (azimuth compression and the peak). Under the assumptions of Theorems 2 and 3, with the DFT approximating PRF\text{PRF} times the integral and the pulses at ηp=(p−M/2)/PRF\eta_p = (p - M/2)/\text{PRF}, the image of the target is largest at the pulse p0p_0 with ηp0=η0\eta_{p_0} = \eta_0, and its value there is about a e−iπ/4 na pc(0)a\, e^{-i\pi/4}\, n_a\, p_c(0), where nan_a is the number of pulses in the beam. For a chirp of ncn_c samples of modulus 1, pc(0)=ncp_c(0) = n_c, so the value is aa times the energy of the echo, the matched filter value.

Proof. After L6 the value at Doppler bin kk (frequency fkf_k) is PRF a e−iπ/4W(fk)pc(0)e−i4πf0R0D(fk)/ce−i2πfkη0/Ka(fk)\text{PRF}\, a\, e^{-i\pi/4} W(f_k) p_c(0) e^{-i 4\pi f_0 R_0 D(f_k)/c} e^{-i 2\pi f_k \eta_0} / \sqrt{K_a(f_k)}. L7 and L8 multiply by PRF e+i4πf0R0D(fk)/c/Ka(fk)\text{PRF}\, e^{+i 4\pi f_0 R_0 D(f_k)/c} / \sqrt{K_a(f_k)}, which leaves a e−iπ/4pc(0) PRF2W(fk)e−i2πfkη0/Ka(fk)a\, e^{-i\pi/4} p_c(0)\, \text{PRF}^2 W(f_k) e^{-i 2\pi f_k \eta_0} / K_a(f_k). The inverse DFT of L9 at pulse pp is 1M∑k\frac{1}{M}\sum_k of this times ei2πfkηpe^{i 2\pi f_k \eta_p}, a sum of terms of one phase when ηp=η0\eta_p = \eta_0, and of rotating phases otherwise. At ηp=η0\eta_p = \eta_0, with W=1W = 1 on the beam band, KaK_a close to its value at f=0f = 0, and PRFM\frac{\text{PRF}}{M} the spacing of the Doppler bins, the sum is about a e−iπ/4pc(0) PRF Ba/Kaa\, e^{-i\pi/4} p_c(0)\, \text{PRF}\, B_a / K_a, where BaB_a is the Doppler bandwidth of the beam. The target is in view for the time Ta=Ba/KaT_a = B_a / K_a, which is na/PRFn_a / \text{PRF}, so the value is a e−iπ/4pc(0) naa\, e^{-i\pi/4} p_c(0)\, n_a. The matched filter value of the target with itself is a∑p,j∣echo∣2=a nanca \sum_{p, j} |\text{echo}|^2 = a\, n_a n_c. □\square

The constant e−iπ/4e^{-i\pi/4} is common to all targets, so ratios of complex amplitudes are kept. The example measures a common phase of about −38-38 degrees and a peak of 0.90 of the matched filter value, the difference coming from the approximations above, the finite interpolator, and the coupling of range and azimuth that the basic RDA ignores.

Cost. L1 costs O(MNlog⁡N)O(M N \log N) with an FFT, L2 and L9 cost O(MNlog⁡M)O(M N \log M), and L3 to L8 cost O(K)O(K) per Doppler bin and range bin, O(MNK)O(M N K). The total is O(MN(log⁡(MN)+K))O(M N (\log(M N) + K)) in the real-RAM model, with O(MN)O(M N) extra space for the range-Doppler array.

Complexity

Line L1 does MM DFTs of length NN, O(MNlog⁡N)O(M N \log N). Lines L2 and L9 do NN DFTs of length MM each, O(MNlog⁡M)O(M N \log M). Lines L3 to L8 run once per Doppler bin and range bin, with KK taps of interpolation and O(1)O(1) other work, O(MNK)O(M N K). The total is O(MN(log⁡(MN)+K))O(M N (\log(M N) + K)) in the real-RAM model with an FFT, and the extra space holds the M×NM \times N range-Doppler array. With K=8K = 8 fixed, the cost is O(MNlog⁡(MN))O(M N \log(M N)).

Properties

  • Linear in the data, and shift-invariant along the track: a target moved by one pulse spacing moves its image by one pixel.
  • Range-varying: L5 and L7 depend on the range bin, which is why the correction is done in the range-Doppler domain and not in the 2D frequency domain.
  • The only interpolation is along range, in L6; it is the main cost besides the FFTs and the main source of error.
  • The image keeps the phase of the targets up to one constant, so it can feed SAR interferometry.

Variants and improvements

  • Secondary range compression (SRC). In the range-Doppler domain the range chirp has the FM rate KmK_m of the range cell migration page, not KrK_r. A second range filter for the difference, applied in the 2D frequency domain at one reference range or in the range-Doppler domain, restores the range focus at wide beams and high squint.
  • Squint. With a nonzero Doppler centroid, the loop of L3 is centered on the centroid, and the centroid must be estimated from the data.
  • Approximate RCMC. For small migrations, nearest neighbor or shorter interpolators in L6 save time with some loss.
  • Doppler aliasing. When the PRF is close to the Doppler bandwidth, the frequencies of L3 must be unwrapped around the centroid.
  • Autofocus. Errors of the motion leave a phase error along the track; phase gradient autofocus or map drift estimates it after L9.

When to use it

Use the RDA for stripmap data from a straight, steady track with a narrow beam and low squint, the usual case for satellites. It is simple, fast and easy to adapt to a range-varying Doppler centroid. For wide beams or high squint, the chirp scaling algorithm avoids the interpolation and includes SRC, and the omega-k algorithm is exact for the straight track. For curved tracks or very wide apertures, use backprojection. In the wide-beam test of the omega-k page (sine of the half beam angle 0.35, R0=96R_0 = 96 m), this basic RDA reaches 0.855 of the ideal peak, against 0.957 for omega-k (measurements).

Pitfalls

  • Wrong RCMC sign or factor. L5 must read at R0/DR_0 / D, a range larger than R0R_0. Reading at R0DR_0 D doubles the migration error instead of removing it.
  • Unwrapped Doppler bins. DFT bin k≥M/2k \ge M/2 is the negative frequency (k−M) PRF/M(k - M)\, \text{PRF}/M. Using k PRF/Mk\, \text{PRF}/M for all bins in L3 gives wrong DD and wrong filters for half of the band.
  • Phase sign. With the echo phase e−i4πf0R/ce^{-i 4\pi f_0 R/c}, L7 must use e+i4πf0R0D/ce^{+i 4\pi f_0 R_0 D/c}. The wrong sign doubles the phase and leaves the target unfocused.
  • Nearest neighbor in L6. Rounding uu to an integer leaves an error of up to half a bin, which lowers the peak and raises the side lobes; use a sinc interpolator with several taps.
  • Targets near the end of the range window. The fast convolution of L1 is circular, so a chirp that runs past the last sample wraps around. Pad the range record by the length of the chirp, or keep targets inside the window.
  • Wide beams without SRC. The basic form loses focus as the beam widens, as in the measurement above.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

imgkit.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small images and signals for the imaging and inverse problems pages.

Conventions:
- A signal is a list of numbers. An image is a list of rows, img[i][j], with
  row i from the top and column j from the left.
- An n x n image covers the square [-1, 1]^2. The center of pixel (i, j) is
  x_j = -1 + (2 j + 1) / n and y_i = 1 - (2 i + 1) / n, so y goes up.
- DFT: X_k = sum_j x_j exp(-2 pi i j k / n), unnormalized; the inverse has
  the factor 1 / n. Index k stands for frequency k for k < n / 2 and k - n
  otherwise. fftshift moves the zero frequency to position n // 2.
- Periodic convolution kernels are stored with their center at index 0
  (wrapped around), so a delta kernel gives the identity and no shift.
"""

import cmath
import math

# ------------------------------------------------------------------ images


def new_image(n1, n2, value=0.0):
    """An n1 x n2 image (n1 rows, n2 columns) filled with value."""
    return [[value] * n2 for _ in range(n1)]


def img_add(a, b):
    """The pixelwise sum a + b."""
    return [[x + y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]


def img_scale(a, c):
    """The image c a."""
    return [[c * x for x in row] for row in a]


def img_dot(a, b):
    """<a, b> = sum conj(a_ij) b_ij."""
    return sum(x.conjugate() * y for ra, rb in zip(a, b) for x, y in zip(ra, rb))


def img_norm(a):
    """The Euclidean (Frobenius) norm of an image."""
    return math.sqrt(sum(abs(x) ** 2 for row in a for x in row))


def flatten(img):
    """Row-major vector of an image."""
    return [x for row in img for x in row]


def unflatten(v, n1, n2):
    """The n1 x n2 image of a row-major vector."""
    return [list(v[i * n2:(i + 1) * n2]) for i in range(n1)]


# ------------------------------------------------------------------ DFT


def _is_pow2(n):
    return n > 0 and n & (n - 1) == 0


def _fft_pow2(x):
    """Iterative radix-2 FFT, unnormalized forward transform."""
    n = len(x)
    a = [complex(v) for v in x]
    j = 0
    for i in range(1, n):
        bit = n >> 1
        while j & bit:
            j ^= bit
            bit >>= 1
        j |= bit
        if i < j:
            a[i], a[j] = a[j], a[i]
    size = 2
    while size <= n:
        half = size // 2
        tw = [cmath.exp(-2j * math.pi * k / size) for k in range(half)]
        for start in range(0, n, size):
            for k in range(half):
                u = a[start + k]
                v = a[start + k + half] * tw[k]
                a[start + k] = u + v
                a[start + k + half] = u - v
        size *= 2
    return a


def dft(x):
    """X_k = sum_j x_j exp(-2 pi i j k / n). Radix-2 FFT when n is a power of 2."""
    n = len(x)
    if n == 0:
        return []
    if _is_pow2(n):
        return _fft_pow2(x)
    w = [cmath.exp(-2j * math.pi * t / n) for t in range(n)]
    return [sum(x[j] * w[(j * k) % n] for j in range(n)) for k in range(n)]


def idft(xf):
    """x_j = (1/n) sum_k X_k exp(2 pi i j k / n)."""
    n = len(xf)
    if n == 0:
        return []
    y = dft([complex(v).conjugate() for v in xf])
    return [v.conjugate() / n for v in y]


def _rows_then_cols(img, f):
    rows = [f(row) for row in img]
    cols = [f(list(col)) for col in zip(*rows)]
    return [list(r) for r in zip(*cols)]


def dft2(img):
    """2D DFT: X_kl = sum_jq x_jq exp(-2 pi i (j k / n1 + q l / n2))."""
    return _rows_then_cols(img, dft)


def idft2(img):
    """Inverse 2D DFT, with the factor 1 / (n1 n2)."""
    return _rows_then_cols(img, idft)


def _shift1(x, s):
    return list(x[s:]) + list(x[:s])


def fftshift(x):
    """Move the zero frequency to position n // 2 (1D, or both axes of an image)."""
    if x and isinstance(x[0], (list, tuple)):
        rows = [fftshift(r) for r in x]
        return _shift1(rows, (len(rows) + 1) // 2)
    return _shift1(x, (len(x) + 1) // 2)


def ifftshift(x):
    """The inverse of fftshift (1D, or both axes of an image)."""
    if x and isinstance(x[0], (list, tuple)):
        rows = [ifftshift(r) for r in x]
        return _shift1(rows, len(rows) // 2)
    return _shift1(x, len(x) // 2)


def circ_conv(x, h):
    """Periodic convolution y_i = sum_j h_j x_{(i - j) mod n}, kernel centered at index 0."""
    n = len(x)
    nz = [(j, hj) for j, hj in enumerate(h) if hj != 0]
    return [sum(hj * x[(i - j) % n] for j, hj in nz) for i in range(n)]


def circ_conv2(img, h):
    """Periodic 2D convolution with the kernel h centered at index (0, 0)."""
    n1, n2 = len(img), len(img[0])
    nz = [(p, q, h[p][q]) for p in range(len(h)) for q in range(len(h[0])) if h[p][q] != 0]
    out = new_image(n1, n2)
    for i in range(n1):
        for j in range(n2):
            out[i][j] = sum(v * img[(i - p) % n1][(j - q) % n2] for p, q, v in nz)
    return out


# ------------------------------------------------------------------ phantoms


def pixel_centers(n):
    """(xs, ys): xs[j] = -1 + (2 j + 1) / n and ys[i] = 1 - (2 i + 1) / n."""
    xs = [-1.0 + (2 * j + 1) / n for j in range(n)]
    ys = [1.0 - (2 * i + 1) / n for i in range(n)]
    return xs, ys


# Rows: rho, A, B, x0, y0, phi (degrees). A is the semi-axis along the
# direction phi (counterclockwise from the x axis), B the other semi-axis.
# Geometry and densities of Shepp and Logan (1974), as reproduced in Kak and
# Slaney, Principles of Computerized Tomographic Imaging, Table 3.1. The value
# at the center (0, 0) is 2 - 0.98 = 1.02.
SHEPP_LOGAN = [
    (2.0, 0.92, 0.69, 0.0, 0.0, 90.0),
    (-0.98, 0.874, 0.6624, 0.0, -0.0184, 90.0),
    (-0.02, 0.31, 0.11, 0.22, 0.0, 72.0),
    (-0.02, 0.41, 0.16, -0.22, 0.0, 108.0),
    (0.01, 0.25, 0.21, 0.0, 0.35, 90.0),
    (0.01, 0.046, 0.046, 0.0, 0.1, 0.0),
    (0.01, 0.046, 0.046, 0.0, -0.1, 0.0),
    (0.01, 0.046, 0.023, -0.08, -0.605, 0.0),
    (0.01, 0.023, 0.023, 0.0, -0.605, 0.0),
    (0.01, 0.046, 0.023, 0.06, -0.605, 90.0),
]

# The same ellipses with the gray levels of Toft (1996), which give more
# contrast. The value at the center is 1 - 0.8 = 0.2.
MODIFIED_SHEPP_LOGAN = [
    (rho, a, b, x0, y0, phi)
    for rho, (_, a, b, x0, y0, phi) in zip(
        (1.0, -0.8, -0.2, -0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1), SHEPP_LOGAN
    )
]


def ellipse_value(x, y, table):
    """The phantom value at the point (x, y): the sum of rho over the ellipses that hold it."""
    total = 0.0
    for rho, a, b, x0, y0, phi in table:
        c, s = math.cos(math.radians(phi)), math.sin(math.radians(phi))
        dx, dy = x - x0, y - y0
        u = dx * c + dy * s
        v = -dx * s + dy * c
        if (u / a) ** 2 + (v / b) ** 2 <= 1.0:
            total += rho
    return total


def ellipse_phantom(n, table):
    """The n x n image of an ellipse table, sampled at the pixel centers."""
    xs, ys = pixel_centers(n)
    return [[ellipse_value(x, y, table) for x in xs] for y in ys]


def disk_phantom(n, radius):
    """1 at pixel centers with x^2 + y^2 <= radius^2, 0 elsewhere."""
    xs, ys = pixel_centers(n)
    r2 = radius * radius
    return [[1.0 if x * x + y * y <= r2 else 0.0 for x in xs] for y in ys]


def spikes_1d(n, positions, amplitudes):
    """A signal of length n with the given amplitudes at the given positions."""
    out = [0.0] * n
    for p, a in zip(positions, amplitudes):
        out[p] += a
    return out


# ------------------------------------------------------------------ projector


def parallel_beam_matrix(n, angles, nbins):
    """Pixel-driven discrete Radon transform of an n x n image on [-1, 1]^2.

    Each pixel center (x, y) projects to s = x cos(theta) + y sin(theta). Its
    value times the pixel area over the bin width is split linearly between
    the two nearest bin centers. The bins cover [-sqrt(2), sqrt(2)]. Row
    a * nbins + b holds angle a and bin b; column i * n + j holds pixel (i, j).
    Returns the sparse rows, each a list of (column, weight) pairs.
    Pixel-driven projection has a ripple: with a bin width close to the pixel
    size, a disk projection is off by up to about 10 percent in some bins. A
    bin of about twice the pixel size (nbins = 23 for n = 32) keeps it near
    1 percent.
    """
    xs, ys = pixel_centers(n)
    smax = math.sqrt(2.0)
    width = 2.0 * smax / nbins
    scale = (2.0 / n) ** 2 / width
    rows = []
    for theta in angles:
        c, s = math.cos(theta), math.sin(theta)
        acc = [dict() for _ in range(nbins)]
        for i, y in enumerate(ys):
            for j, x in enumerate(xs):
                t = (x * c + y * s + smax) / width - 0.5
                b0 = math.floor(t)
                frac = t - b0
                col = i * n + j
                for b, w in ((b0, 1.0 - frac), (b0 + 1, frac)):
                    if 0 <= b < nbins and w > 0.0:
                        acc[b][col] = acc[b].get(col, 0.0) + w * scale
        rows.extend(sorted(d.items()) for d in acc)
    return rows


def sp_matvec(rows, x):
    """y = A x for sparse rows of (column, weight) pairs."""
    return [sum(w * x[c] for c, w in row) for row in rows]


def sp_rmatvec(rows, y, ncols):
    """x = A^H y for sparse rows of (column, weight) pairs and ncols columns."""
    out = [0.0] * ncols
    for row, yi in zip(rows, y):
        if yi == 0:
            continue
        for c, w in row:
            out[c] += w.conjugate() * yi
    return out


# ------------------------------------------------------------------ noise


def gauss_noise(rng, shape, sigma):
    """Independent N(0, sigma^2) values: a list for an int shape, an image for (n1, n2)."""
    if isinstance(shape, int):
        return [rng.gauss(0.0, sigma) for _ in range(shape)]
    n1, n2 = shape
    return [[rng.gauss(0.0, sigma) for _ in range(n2)] for _ in range(n1)]


def _poisson_small(rng, lam):
    """Knuth's product method, exact for a mean lam <= 30."""
    limit = math.exp(-lam)
    k, p = 0, rng.random()
    while p > limit:
        k += 1
        p *= rng.random()
    return k


def poisson_sample(rng, lam):
    """An exact Poisson(lam) sample: a sum of Knuth samples with means at most 30."""
    if lam < 0:
        raise ValueError("negative mean")
    total = 0
    while lam > 30.0:
        total += _poisson_small(rng, 30.0)
        lam -= 30.0
    if lam > 0.0:
        total += _poisson_small(rng, lam)
    return total
range_doppler_algorithm.py 136 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/range-doppler-algorithm/. The authors are listed in prov/76HEMZ.jsonl.
"""Range-Doppler algorithm (RDA) for stripmap SAR with zero squint.

Geometry: the radar moves along a straight line at the speed V and sends one
pulse at each slow time eta_p = (p - n_az / 2) / PRF, at the position
x_p = V eta_p. A point target at the along-track position x and the closest
range R0 has the range history R(eta) = sqrt(R0^2 + (x_p - x)^2). The radar
sees it only inside the beam: |x_p - x| / R <= beam (the sine of the half
beam angle).

Signals: complex baseband. The pulse is a linear FM chirp
p(t) = exp(i pi Kr (t - T/2)^2) for 0 <= t < T. The echo of a target of
amplitude a is a p(t - 2R/c) exp(-i 4 pi f0 R / c). The Fourier sign is
exp(-i 2 pi f t), the sign of the DFT. Range sample j of a pulse is the
two-way delay t_start + j / fs, that is the slant range r_start + j c / (2 fs).

Data layout: data[p][j], row p is a pulse (slow time), column j a range bin.
"""

import cmath
import math

from imgkit import dft, idft

C = 3.0e8


class Stripmap:
    """The parameters of a stripmap acquisition (SI units)."""

    def __init__(self, f0=300e6, bandwidth=100e6, pulse_len=0.2e-6, fs=120e6,
                 v=100.0, prf=80.0, n_range=64, n_az=128, r_start=380.0, beam=0.125):
        self.f0 = f0
        self.bandwidth = bandwidth
        self.pulse_len = pulse_len
        self.fs = fs
        self.v = v
        self.prf = prf
        self.n_range = n_range
        self.n_az = n_az
        self.r_start = r_start
        self.beam = beam
        self.kr = bandwidth / pulse_len
        self.dr = C / (2.0 * fs)

    def slant_range(self, j):
        """The slant range of range bin j (it may be fractional)."""
        return self.r_start + j * self.dr

    def x_pulse(self, p):
        """The along-track position of pulse p."""
        return self.v * (p - self.n_az // 2) / self.prf

    def doppler(self, k):
        """The Doppler frequency of DFT bin k: k PRF / n_az, wrapped to [-PRF/2, PRF/2)."""
        kk = k if k < self.n_az // 2 else k - self.n_az
        return kk * self.prf / self.n_az

    def chirp(self, t):
        """The baseband pulse p(t)."""
        if 0.0 <= t < self.pulse_len:
            return cmath.exp(1j * math.pi * self.kr * (t - self.pulse_len / 2) ** 2)
        return 0j


def simulate_raw(g, targets):
    """Raw echo data of point targets (x, R0, amplitude), exact hyperbolic range."""
    t_start = 2.0 * g.r_start / C
    data = []
    for p in range(g.n_az):
        xp = g.x_pulse(p)
        row = [0j] * g.n_range
        for (x, r0, amp) in targets:
            r = math.hypot(r0, xp - x)
            if abs(xp - x) > g.beam * r:
                continue
            tau = 2.0 * r / C
            ph = amp * cmath.exp(-4j * math.pi * g.f0 * r / C)
            for j in range(g.n_range):
                row[j] += ph * g.chirp(t_start + j / g.fs - tau)
        data.append(row)
    return data


def range_compress(g, data):
    """Matched filter in range: multiply each pulse spectrum by conj(P) (circular)."""
    ref = [g.chirp(j / g.fs) for j in range(g.n_range)]
    h = [v.conjugate() for v in dft(ref)]
    return [idft([a * b for a, b in zip(dft(row), h)]) for row in data]


def sinc_interp(row, u, taps=8):
    """Value of a sampled band-limited signal at the fractional index u (Hann-windowed sinc)."""
    half = taps // 2
    i0 = math.floor(u)
    acc = 0j
    for m in range(i0 - half + 1, i0 + half + 1):
        if 0 <= m < len(row):
            x = u - m
            w = 1.0 if x == 0 else math.sin(math.pi * x) / (math.pi * x)
            acc += row[m] * w * (0.5 + 0.5 * math.cos(math.pi * x / half))
    return acc


def migration_factor(g, f):
    """D(f) = sqrt(1 - (c f / (2 V f0))^2), the cosine of the squint angle of Doppler f."""
    return math.sqrt(1.0 - (C * f / (2.0 * g.v * g.f0)) ** 2)


def rda(g, data, rcmc=True):
    """Focus raw stripmap data. Returns the complex image img[p][j]."""
    rc = range_compress(g, data)  # @line L1
    cols = [dft([rc[p][j] for p in range(g.n_az)]) for j in range(g.n_range)]  # @line L2
    f_max = 2.0 * g.v * g.beam * g.f0 / C  # the Doppler band of the beam
    out = [[0j] * g.n_az for _ in range(g.n_range)]
    for k in range(g.n_az):
        f = g.doppler(k)  # @line L3
        if abs(f) > f_max:
            continue
        d = migration_factor(g, f)  # @line L4
        line = [cols[j][k] for j in range(g.n_range)]
        for j in range(g.n_range):
            r0 = g.slant_range(j)
            u = (r0 / d - g.r_start) / g.dr if rcmc else j  # @line L5
            val = sinc_interp(line, u)  # @line L6
            ka = 2.0 * g.v ** 2 * g.f0 * d ** 3 / (C * r0)  # azimuth FM rate at f
            h = (g.prf / math.sqrt(ka)) * cmath.exp(4j * math.pi * g.f0 * r0 * d / C)  # @line L7
            out[j][k] = val * h  # @line L8
    cols_img = [idft(col) for col in out]  # @line L9
    return [[cols_img[j][p] for j in range(g.n_range)] for p in range(g.n_az)]


def target_pixel(g, x, r0):
    """The (fractional) image position (p, j) where a target at (x, R0) focuses."""
    return x * g.prf / g.v + g.n_az // 2, (r0 - g.r_start) / g.dr
test_range_doppler_algorithm.py 83 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/range-doppler-algorithm/. The authors are listed in prov/76HEMZ.jsonl.

import math

from range_doppler_algorithm import Stripmap, rda, simulate_raw, target_pixel

G = Stripmap()
TARGETS = [(0.0, 400.0, 1.0), (10.0, 410.0, 0.7)]
RAW = simulate_raw(G, TARGETS)
IMG = rda(G, RAW)
IMG_NO_RCMC = rda(G, RAW, rcmc=False)


def matched_filter(x, r0):
    """Brute force: correlate the raw data with the exact echo of a unit target at (x, r0)."""
    ref = simulate_raw(G, [(x, r0, 1.0)])
    return sum(a.conjugate() * b for ra, rb in zip(ref, RAW) for a, b in zip(ra, rb))


def ideal_gain(x, r0):
    """The matched filter output of a unit target on itself: chirp samples times pulses."""
    ref = simulate_raw(G, [(x, r0, 1.0)])
    return sum(abs(a) ** 2 for row in ref for a in row)


def local_peak(img, p0, j0, w=3):
    return max((abs(img[p][j]), p, j) for p in range(p0 - w, p0 + w + 1) for j in range(j0 - w, j0 + w + 1))


def test_targets_focus_at_their_pixels() -> None:
    for x, r0, _ in TARGETS:
        p0, j0 = (round(v) for v in target_pixel(G, x, r0))
        _, p, j = local_peak(IMG, p0, j0)
        assert (p, j) == (p0, j0)


def test_peak_is_close_to_the_brute_force_matched_filter() -> None:
    for x, r0, amp in TARGETS:
        p0, j0 = (round(v) for v in target_pixel(G, x, r0))
        brute = abs(matched_filter(x, r0))
        assert abs(brute - amp * ideal_gain(x, r0)) < 0.02 * brute
        got = abs(IMG[p0][j0])
        assert 0.85 * brute < got < 1.05 * brute


def test_rcmc_is_needed() -> None:
    p0, j0 = (round(v) for v in target_pixel(G, 0.0, 400.0))
    with_rcmc = abs(IMG[p0][j0])
    without = abs(IMG_NO_RCMC[p0][j0])
    assert without < 0.7 * with_rcmc

    def concentration(img):
        total = sum(abs(v) ** 2 for row in img for v in row)
        return abs(img[p0][j0]) ** 2 / total

    assert concentration(IMG_NO_RCMC) < 0.5 * concentration(IMG)


def test_linear_in_the_data() -> None:
    a = simulate_raw(G, [(0.0, 400.0, 1.0)])
    b = simulate_raw(G, [(10.0, 410.0, 0.7)])
    ia, ib = rda(G, a), rda(G, b)
    for p in (60, 64, 72):
        for j in (14, 16, 20):
            assert abs(ia[p][j] + ib[p][j] - IMG[p][j]) < 1e-6 * abs(IMG[64][16])


def test_amplitude_ratio_is_kept() -> None:
    a = abs(IMG[64][16]) / ideal_gain(0.0, 400.0)
    p1, j1 = (round(v) for v in target_pixel(G, 10.0, 410.0))
    b = abs(IMG[p1][j1]) / ideal_gain(10.0, 410.0)
    assert abs(b / a - 0.7) < 0.05


def test_resolution_matches_c_over_2b() -> None:
    """The range impulse response falls to its first null near c / (2 B) = 1.5 m, 1.2 bins."""
    row = [abs(v) for v in IMG[64]]
    peak = row[16]
    assert row[15] < 0.75 * peak and row[17] < 0.75 * peak
    assert max(row[:13] + row[20:]) < 0.35 * peak
    assert abs(G.dr * 1.2 - 3.0e8 / (2 * G.bandwidth)) < 1e-9
    assert math.isclose(G.dr, 1.25)

History

Wu (1976) described a digital system to produce images from SAR data. The steps of this page, range compression, migration correction in the range-Doppler domain and azimuth compression by fast convolution, became the standard processor for spaceborne stripmap data; Cumming and Wong (2005, Chapter 6) describe it with SRC and its variants. Bamler (1992) compared it with the wavenumber domain algorithm and showed which approximations each makes. The chirp scaling algorithm (Raney et al. 1994) later removed its interpolation.

References

  1. Wu 1976, the digital processor with range compression and azimuth correlation (general locator; full text not seen)
  2. Ian G. Cumming and Frank H. Wong, Digital Processing of Synthetic Aperture Radar Data, Artech House, 2005, Chapter 6, The Range Doppler Algorithm, and Chapter 5, SAR Signal Properties
  3. Richard Bamler, A comparison of range-Doppler and wavenumber domain SAR focusing algorithms, IEEE Transactions on Geoscience and Remote Sensing 30(4), 1992, 706 to 713, the approximations of the range-Doppler algorithm against the wavenumber domain algorithm (general locator)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.data
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example