Algorithm Search⌘K

Algorithmcore

Time-domain backprojection for SAR

Also called global backprojection SAR.

Form a SAR image by summing at each pixel the range compressed echoes at the round trip delay of that pixel, for any flight path.

Time
O(P (n^2 + F N log(F N))) worst
Space
O(n^2 + F N) extraO(P N) data
Where
F = the upsampling factor; N = the number of samples per pulse; P = the number of pulses; n = the number of pixels along one side of the image
Properties
deterministicnot exactlinear in dataiterative
Origin
Mita D. Desai, W. Kenneth Jenkins, 1992

Time-domain backprojection forms a synthetic aperture radar image directly from the definition of focusing. For every pixel and every pulse, it computes the range from the antenna at that pulse to the pixel, reads the range compressed echo at the matching round trip delay, removes the carrier phase of that range, and adds the result to the pixel. The echoes of a target at the pixel then add in phase, and the echoes of other targets do not. Nothing in the method assumes a straight flight path, a constant speed or a flat Earth, only that the antenna positions are known. It is the radar form of the back-projection operator of tomography, applied along range spheres instead of straight lines, and it is the same sum as SAFT in ultrasound. Its cost of one operation per pixel and pulse is its weak point; fast factorized backprojection reduces it.

In plain words

Each echo tells you how strongly something reflected at each distance from the antenna, but not in which direction. For one point of the picture, you know how far it was from the antenna at each pulse. Look up each echo at that distance, turn each value so that a real reflector at the point would give the same phase every time, and add them all. A real reflector at the point gives a large total. Anything else gives values that point in different directions and mostly cancel. Do this for every point of the picture.

The problem

The input is PP range compressed pulses dp[j]d_p[j], j=0,…,N−1j = 0, \ldots, N - 1, sampled at the two-way delays t0+j/fst_0 + j/f_s, the antenna positions apa_p at the pulses, the carrier frequency f0f_0 and a list of pixels qq on the ground. A point target of amplitude α\alpha at q0q_0 gives dp(t)=α g(t−2Rp(q0)/c) e−i4πf0Rp(q0)/cd_p(t) = \alpha\, g(t - 2R_p(q_0)/c)\, e^{-i 4\pi f_0 R_p(q_0)/c}, where Rp(q)=∣ap−q∣R_p(q) = |a_p - q| and gg is the compressed pulse, here sinc⁡(Bt)\operatorname{sinc}(B t) for a bandwidth BB. The Fourier sign is e−i2πfte^{-i 2\pi f t}, as for the DFT; radar books often use e+jωte^{+j\omega t} and so the opposite signs. The output is the complex image

I(q)=∑pdp(2Rp(q)/c) e+i4πf0Rp(q)/c,I(q) = \sum_{p} d_p\big(2R_p(q)/c\big)\, e^{+i 4\pi f_0 R_p(q)/c},

the matched filter for a target at qq when the pulse gg has already been compressed.

The algorithm

  1. BACKPROJECT(d, a, pixels, f_0, f_s, t_0, F) ▷ d[p][j]: range compressed pulses; I starts at 0
  2. 1for every pulse p: e ← UPSAMPLE(d[p], F) ▷ zero padding of the DFT; spacing Δr = c / (2 F f_s)
  3. 2for every pixel q: R ← |a_p - q|
  4. 3u ← (R - c t_0 / 2) / Δr ▷ fractional sample index of R
  5. 4v ← (1 - w) e[⌊u⌋] + w e[⌊u⌋ + 1] with w = u - ⌊u⌋ ▷ skip q if u is outside e
  6. 5I[q] ← I[q] + v · e^{+i 4π f_0 R / c}
  7. 6return I

The pseudocode works pulse by pulse, so only one upsampled pulse is in memory at a time. Line L1 interpolates the pulse by the factor FF with zero padding of its DFT, which is exact for a periodic band-limited signal. This lets L4 use cheap linear interpolation on the fine grid with a small error. L2 computes the true range, with the antenna height if there is one. L3 turns the range into a sample index of the fine grid. L5 removes the carrier phase e−i4πf0R/ce^{-i 4\pi f_0 R/c} of a target at the pixel; its sign is the opposite of the sign of the echo phase. Line L6 returns the image.

Example

The tests use f0=300f_0 = 300 MHz (λ=1\lambda = 1 m), B=100B = 100 MHz, fs=120f_s = 120 MHz, N=64N = 64 samples starting at the range 370 m, and P=64P = 64 pulses from a straight path at 1.25 m spacing, an aperture of L=80L = 80 m. Targets of amplitude 1 at (0,400)(0, 400) m and 0.5 at (5,410)(5, 410) m are imaged on a grid of 0.625 m pixels with F=8F = 8.

  • The largest pixel is at (0,400)(0, 400) with the value 63.78, against the ideal P=64P = 64; the phase is near 0.
  • The image is within 1% of 64 of the brute-force sum that reads each pulse with exact sinc interpolation over all its samples.
  • Along the track through the target, the first null is at 2.5 m, the value λR/(2L)=1⋅400/160\lambda R/(2L) = 1 \cdot 400 / 160 m, and the value there is below 3% of the peak.
  • With a curved and noisy flight path, of up to 2.5 m sideways and 0.3 m in height, the image with the true positions gives both targets within 3% of 64 at their pixels. The image of the same data with the positions of the straight path stays below 0.3⋅640.3 \cdot 64 everywhere on the grid.

All values are measurements on these simulations.

Correctness

The sum is linear in the data. For one target and exact interpolation, the term of pulse pp at the pixel qq is α g(Δp) ei2πf0Δp\alpha\, g(\Delta_p)\, e^{i 2\pi f_0 \Delta_p} with Δp=2(Rp(q)−Rp(q0))/c\Delta_p = 2(R_p(q) - R_p(q_0))/c. At q=q0q = q_0 every Δp\Delta_p is 0, so the pixel gets Pα g(0)P \alpha\, g(0). Elsewhere the triangle inequality gives a value of at most this size, with equality only where every range is the same as at q0q_0; for a straight track and pixels on one side of it, two pulses at different places along the track already fix the point. The proofs are in proofs/correctness.md.

Proof: Backprojection is linear and focuses a point target to a unique maximum equal to the number of pulses times its amplitudefull

We prove three facts about time-domain backprojection as written on the main page (lines L1 to L6), for the stop-and-go model: point targets, known antenna positions apa_p, p=1,…,Pp = 1, \ldots, P, and no antenna pattern or range loss in the data. Theorems 1 and 2 are exact for the sum I(q)I(q) with exact interpolation; the error of the interpolation in L1 and L4 is a measurement, given on the main page.

Setting. Pulse pp is a complex baseband signal dp(t)d_p(t), sampled at t0+j/fst_0 + j/f_s. Lines L1 to L4 return an approximation d~p(t)\tilde d_p(t) of dp(t)d_p(t) at t=2Rp(q)/ct = 2R_p(q)/c with Rp(q)=∣ap−q∣R_p(q) = |a_p - q|, or skip the pulse when tt is outside the record. Let A(q)A(q) be the set of pulses that are not skipped. The algorithm returns I(q)=∑p∈A(q)d~p(2Rp(q)/c) e+i4πf0Rp(q)/cI(q) = \sum_{p \in A(q)} \tilde d_p(2R_p(q)/c)\, e^{+i 4\pi f_0 R_p(q)/c}. The Fourier sign is e−i2πfte^{-i 2\pi f t}.

Theorem 1 (linearity). II is linear in the data.

Proof. The set A(q)A(q), the read time and the phase factor depend only on the geometry. L1 is a DFT, a zero padding and an inverse DFT, which is linear, and L4 is a weighted sum of two samples with weights fixed by the geometry. A sum over pulses of linear maps is linear. □\square

Theorem 2 (a point target). Let the data be one target of amplitude α\alpha at q0q_0, dp(t)=α g(t−2Rp(q0)/c) e−i4πf0Rp(q0)/cd_p(t) = \alpha\, g(t - 2R_p(q_0)/c)\, e^{-i 4\pi f_0 R_p(q_0)/c}, with a real pulse gg such that ∣g(s)∣<g(0)|g(s)| < g(0) for s≠0s \ne 0, and assume exact interpolation, d~p=dp\tilde d_p = d_p. With Δp(q)=2(Rp(q)−Rp(q0))/c\Delta_p(q) = 2(R_p(q) - R_p(q_0))/c:

  1. I(q)=α∑p∈A(q)g(Δp(q)) ei2πf0Δp(q)I(q) = \alpha \sum_{p \in A(q)} g(\Delta_p(q))\, e^{i 2\pi f_0 \Delta_p(q)};
  2. I(q0)=∣A(q0)∣ α g(0)I(q_0) = |A(q_0)|\, \alpha\, g(0), which is Pα g(0)P \alpha\, g(0) when no pulse is skipped;
  3. ∣I(q)∣≤∣A(q)∣ ∣α∣ g(0)|I(q)| \le |A(q)|\, |\alpha|\, g(0) for every qq, and equality needs Rp(q)=Rp(q0)R_p(q) = R_p(q_0) for every p∈A(q)p \in A(q).

Proof. At t=2Rp(q)/ct = 2R_p(q)/c, dp(t)=α g(Δp) e−i4πf0Rp(q0)/cd_p(t) = \alpha\, g(\Delta_p)\, e^{-i 4\pi f_0 R_p(q_0)/c}, and the factor e+i4πf0Rp(q)/ce^{+i 4\pi f_0 R_p(q)/c} turns the phase into 2πf0⋅2(Rp(q)−Rp(q0))/c=2πf0Δp2\pi f_0 \cdot 2(R_p(q) - R_p(q_0))/c = 2\pi f_0 \Delta_p. This is part 1. At q0q_0 every Δp\Delta_p is 0, which gives part 2. By the triangle inequality ∣I(q)∣≤∣α∣∑p∈A(q)∣g(Δp)∣≤∣A(q)∣ ∣α∣ g(0)|I(q)| \le |\alpha| \sum_{p \in A(q)} |g(\Delta_p)| \le |A(q)|\, |\alpha|\, g(0), and the second step is an equality only if Δp=0\Delta_p = 0 for every p∈A(q)p \in A(q). □\square

Theorem 3 (uniqueness for a straight track). Let the antenna move on the line {(s,0,h)}\{(s, 0, h)\} and let the pixels lie in the ground plane z=0z = 0 on one side of the track, y>0y > 0. If A(q)A(q) contains two pulses at different ss, then Rp(q)=Rp(q0)R_p(q) = R_p(q_0) for those two pulses implies q=q0q = q_0. So by Theorem 2 the maximum of ∣I∣|I| over such pixels with A(q)=A(q0)A(q) = A(q_0) is reached only at q0q_0.

Proof. Write q=(x,y,0)q = (x, y, 0) and q0=(x0,y0,0)q_0 = (x_0, y_0, 0). The equations (sk−x)2+y2+h2=(sk−x0)2+y02+h2(s_k - x)^2 + y^2 + h^2 = (s_k - x_0)^2 + y_0^2 + h^2 for k=1,2k = 1, 2 subtract to 2(s2−s1)(x−x0)=02(s_2 - s_1)(x - x_0) = 0, so x=x0x = x_0 because s1≠s2s_1 \ne s_2. Then y2=y02y^2 = y_0^2, and y=y0y = y_0 because both are positive. □\square

For a target at a pixel and P=64P = 64 pulses the test measures 63.78; the loss of 0.3% comes from the linear interpolation in L4 on the pulse upsampled by 8. For a general flight path, part 3 of Theorem 2 still holds, and the maximum is unique wherever the ranges from the positions in A(q)A(q) fix the ground point.

Cost. L1 costs O(FNlog⁡(FN))O(F N \log(F N)) per pulse with an FFT, and L2 to L5 cost O(1)O(1) per pixel and pulse. An n×nn \times n image costs O(P(n2+FNlog⁡(FN)))O(P (n^2 + F N \log(F N))) in the real-RAM model, with O(n2+FN)O(n^2 + F N) extra space.

Complexity

Line L1 costs O(FNlog⁡(FN))O(F N \log(F N)) per pulse with an FFT. Lines L2 to L5 cost O(1)O(1) per pixel and pulse, so an n×nn \times n image costs O(Pn2)O(P n^2). The total is O(P(n2+FNlog⁡(FN)))O(P (n^2 + F N \log(F N))) in the real-RAM model, with O(n2)O(n^2) space for the image and O(FN)O(F N) for one upsampled pulse. For P≈nP \approx n, the usual case, the cost is O(n3)O(n^3), against O(n2log⁡n)O(n^2 \log n) for the frequency-domain algorithms.

Properties

  • Linear in the data.
  • Works for any known flight path, with no approximation of the range.
  • Exact up to the interpolation of L4 and the stop-and-go approximation.
  • Each pixel and each pulse can be processed independently, so the method is easy to run in parallel, and pulses can be added as they arrive.
  • The image can be formed on any surface, for example a digital elevation model.

Variants and improvements

  • Fast factorized backprojection. FFBP forms images of short subapertures on coarse polar grids and merges them, for O(n2log⁡n)O(n^2 \log n).
  • Convolution backprojection. For spotlight data that are dechirped, each pulse is a slice of the 2D Fourier transform of the scene, and backprojection after a ramp filter is the filtered back-projection of tomography (Desai and Jenkins, 1992).
  • Interpolation. Nearest neighbor on a highly upsampled pulse, linear interpolation as here, or a short sinc kernel without upsampling trade memory against accuracy.
  • Weights. A window over the pulses lowers the azimuth side lobes, and weights for the antenna pattern and the range loss can be included in the sum.

When to use it

Use backprojection when the flight path is not straight, when the aperture is wide or the range short, as in airborne systems at low frequency or in ground-based radar, or when the image must be formed on a given surface. It is also the reference to test faster algorithms against. When the path is straight and the scene is large, the omega-k algorithm or the range-Doppler algorithm is much faster.

Pitfalls

  • The sign of the phase correction. The echo has e−i4πf0R/ce^{-i 4\pi f_0 R/c}, so the correction is e+i4πf0R/ce^{+i 4\pi f_0 R/c}. With the opposite sign the terms do not add in phase and the target does not focus.
  • Too coarse an interpolation. Linear interpolation of the pulse at its own sample rate leaves an amplitude and phase error that varies with the pixel. Upsample first, or use a better kernel.
  • Wrong positions. The method needs the antenna positions to a small part of the wavelength. A path error of a few wavelengths defocuses the image, as the test with the wrong path shows; the cure is better navigation data or autofocus.
  • Delay reference. The delay of a sample must be counted from the same instant as the range, including the start time t0t_0 of the record and any fixed delays of the system.
  • Pixel spacing. The pixels must be smaller than the resolution, about c/(2B)c/(2B) in range and λR/(2L)\lambda R/(2L) in azimuth, or targets between pixels lose much of their peak value.

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
sar_backprojection.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sar-backprojection/. The authors are listed in prov/KA63T0.jsonl.
"""Time-domain backprojection for SAR, for any flight path.

Geometry: the scene is a plane with points (x, y). Pulse p is sent from the
antenna position pos[p] = (x, y, z), so a point at (x, y) has the range
R_p = |pos[p] - (x, y, 0)|. Nothing assumes a straight path or a constant
speed.

Signals: complex baseband, range-compressed. Sample j of pulse p is the
two-way delay t0 + j / fs. A point target of amplitude a gives
a sinc(B (t - 2 R_p / c)) exp(-i 4 pi f0 R_p / c), the ideal compressed
pulse of bandwidth B. The Fourier sign is exp(-i 2 pi f t), the sign of the
DFT. Backprojection undoes the carrier phase with exp(+i 4 pi f0 R / c).
"""

import cmath
import math

from imgkit import dft, idft

C = 3.0e8


def sinc(x):
    return 1.0 if x == 0 else math.sin(math.pi * x) / (math.pi * x)


def simulate_compressed(pos, targets, f0, bandwidth, fs, t0, n):
    """Range-compressed pulses data[p][j] of point targets (x, y, amplitude)."""
    data = []
    for px, py, pz in pos:
        row = [0j] * n
        for x, y, amp in targets:
            r = math.sqrt((px - x) ** 2 + (py - y) ** 2 + pz ** 2)
            ph = amp * cmath.exp(-4j * math.pi * f0 * r / C)
            for j in range(n):
                row[j] += ph * sinc(bandwidth * (t0 + j / fs - 2.0 * r / C))
        data.append(row)
    return data


def upsample(row, factor):
    """Band-limited interpolation by zero padding the DFT: factor times more samples."""
    n = len(row)
    spec = dft(row)
    half = n // 2
    padded = spec[:half] + [0j] * (n * factor - n) + spec[half:]
    return [v * factor for v in idft(padded)]


def backproject(data, pos, pixels, f0, fs, t0, factor=8):
    """The complex image value at each pixel (x, y): sum over pulses of d_p(R_p) exp(+i 4 pi f0 R_p / c)."""
    out = [0j] * len(pixels)
    step = C / (2.0 * fs * factor)  # range spacing of the upsampled samples
    r0 = C * t0 / 2.0
    for row, (px, py, pz) in zip(data, pos):
        fine = upsample(row, factor)  # @line L1
        last = len(fine) - 1
        for i, (x, y) in enumerate(pixels):
            r = math.sqrt((px - x) ** 2 + (py - y) ** 2 + pz ** 2)  # @line L2
            u = (r - r0) / step  # @line L3
            k = math.floor(u)
            if k < 0 or k >= last:
                continue
            w = u - k
            val = (1.0 - w) * fine[k] + w * fine[k + 1]  # @line L4
            out[i] += val * cmath.exp(4j * math.pi * f0 * r / C)  # @line L5
    return out  # @line L6


def backproject_exact(data, pos, pixels, f0, bandwidth, fs, t0):
    """Brute force: the same sum with the exact sinc interpolation over all samples.

    The data rows were sampled from sinc(B t) pulses, so the sum over all
    samples of d_j sinc(fs (t - t_j)) recovers the pulse at any delay t when
    fs >= B. This costs O(n) per pixel and pulse instead of O(1).
    """
    out = [0j] * len(pixels)
    for row, (px, py, pz) in zip(data, pos):
        for i, (x, y) in enumerate(pixels):
            r = math.sqrt((px - x) ** 2 + (py - y) ** 2 + pz ** 2)
            t = 2.0 * r / C
            val = sum(d * sinc(fs * (t - t0 - j / fs)) for j, d in enumerate(row) if d != 0)
            out[i] += val * cmath.exp(4j * math.pi * f0 * r / C)
    return out


def image_grid(xs, ys):
    """The pixel list of a grid: row-major, y outer."""
    return [(x, y) for y in ys for x in xs]
test_sar_backprojection.py 70 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sar-backprojection/. The authors are listed in prov/KA63T0.jsonl.

import math
import random

from sar_backprojection import backproject, backproject_exact, image_grid, simulate_compressed, upsample

F0, B, FS, T0, N = 300e6, 100e6, 120e6, 2 * 370 / 3.0e8, 64
STRAIGHT = [(-40.0 + 1.25 * p, 0.0, 0.0) for p in range(64)]
TARGETS = [(0.0, 400.0, 1.0), (5.0, 410.0, 0.5)]
XS = [-2.5 + 0.625 * i for i in range(9)]
YS = [397.5 + 0.625 * i for i in range(9)]
PIX = image_grid(XS, YS)


def curved_path(seed):
    rng = random.Random(seed)
    return [(x, 2.0 * math.sin(x / 15.0) + rng.uniform(-0.5, 0.5), rng.uniform(-0.3, 0.3)) for x, _, _ in STRAIGHT]


def test_point_target_focuses_with_gain_equal_to_the_pulse_count() -> None:
    data = simulate_compressed(STRAIGHT, TARGETS, F0, B, FS, T0, N)
    img = backproject(data, STRAIGHT, PIX, F0, FS, T0)
    best = max(range(len(PIX)), key=lambda i: abs(img[i]))
    assert PIX[best] == (0.0, 400.0)
    assert abs(img[best] - 64) < 0.02 * 64  # phase near 0 too


def test_matches_brute_force_exact_interpolation() -> None:
    data = simulate_compressed(STRAIGHT, TARGETS, F0, B, FS, T0, N)
    fast = backproject(data, STRAIGHT, PIX, F0, FS, T0)
    slow = backproject_exact(data, STRAIGHT, PIX, F0, B, FS, T0)
    assert max(abs(a - b) for a, b in zip(fast, slow)) < 0.01 * 64


def test_any_flight_path_focuses_when_it_is_known() -> None:
    path = curved_path(1)
    data = simulate_compressed(path, TARGETS, F0, B, FS, T0, N)
    right = backproject(data, path, [(0.0, 400.0), (5.0, 410.0)], F0, FS, T0)
    assert abs(right[0] - 64) < 0.03 * 64
    assert abs(right[1] - 32) < 0.03 * 64
    wrong = backproject(data, STRAIGHT, PIX, F0, FS, T0)
    assert max(abs(v) for v in wrong) < 0.3 * 64


def test_azimuth_resolution_is_lambda_r_over_2l() -> None:
    data = simulate_compressed(STRAIGHT, TARGETS[:1], F0, B, FS, T0, N)
    cut = [abs(v) for v in backproject(data, STRAIGHT, [(0.25 * k, 400.0) for k in range(13)], F0, FS, T0)]
    first_null = min(range(13), key=lambda k: cut[k])
    lam, length = 3.0e8 / F0, 64 * 1.25
    assert abs(0.25 * first_null - lam * 400.0 / (2 * length)) <= 0.25
    assert cut[first_null] < 0.03 * cut[0]


def test_linear_in_the_data() -> None:
    d1 = simulate_compressed(STRAIGHT, TARGETS[:1], F0, B, FS, T0, N)
    d2 = simulate_compressed(STRAIGHT, TARGETS[1:], F0, B, FS, T0, N)
    both = [[a + b for a, b in zip(r1, r2)] for r1, r2 in zip(d1, d2)]
    i1 = backproject(d1, STRAIGHT, PIX, F0, FS, T0)
    i2 = backproject(d2, STRAIGHT, PIX, F0, FS, T0)
    i12 = backproject(both, STRAIGHT, PIX, F0, FS, T0)
    assert max(abs(a + b - c) for a, b, c in zip(i1, i2, i12)) < 1e-9


def test_upsample_keeps_the_samples() -> None:
    rng = random.Random(3)
    row = [complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in range(16)]
    fine = upsample(row, 4)
    assert max(abs(fine[4 * j] - row[j]) for j in range(16)) < 1e-9

History

Backprojection comes from computed tomography. Munson, O'Brien and Jenkins (1983) showed that spotlight SAR is a tomography problem, and Desai and Jenkins (1992) formed spotlight SAR images by convolution backprojection with 1D interpolation along each filtered pulse, at the cost O(N3)O(N^3). Because the time-domain sum uses the true range, it was then used for airborne systems with wide apertures and curved paths, and Ulander, Hellsten and Stenstrom (2003) gave a fast factorized version that makes it practical for large images.

References

  1. Mita D. Desai and W. Kenneth Jenkins, Convolution backprojection image reconstruction for spotlight mode synthetic aperture radar, IEEE Transactions on Image Processing 1(4), 1992, 505 to 517, the backprojection sum over the pulses with 1D interpolation along each filtered pulse, and its O(N^3) cost (general locator)
  2. Lars M. H. Ulander, Hans Hellsten and Gunnar Stenstrom, Synthetic-aperture radar processing using fast factorized back-projection, IEEE Transactions on Aerospace and Electronic Systems 39(3), 2003, 760 to 776, the global (direct) backprojection that the fast algorithm approximates, for a general flight path (general locator)
  3. Mehrdad Soumekh, Synthetic Aperture Radar Signal Processing with MATLAB Algorithms, Wiley, 1999, the time-domain reconstruction methods (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