Algorithm Search⌘K

Algorithmadvanced

Omega-k algorithm

Also called wavenumber domain algorithm, range migration algorithm.

Focus SAR data exactly in the 2D frequency domain by a reference function multiply and a Stolt change of variables.

Time
O(M N (log(M N) + K)) worst
Space
O(M N) extra · data
Where
K = the number of taps of the Stolt interpolator; M = the number of pulses; N = the number of range samples per pulse
Properties
deterministicnot exactlinear in dataiterative
Origin
Ciro Cafforio, Claudio Prati, Fabio Rocca, 1991

The omega-k algorithm, also called the wavenumber domain algorithm or the range migration algorithm, focuses synthetic aperture radar data from a straight track with a constant speed in the two-dimensional frequency domain. The name "range migration algorithm" means this algorithm; it should not be confused with range cell migration, the effect that every SAR focusing method must correct. After a 2D FFT, the phase of a point target is −R0K2−kx2−kxx0-R_0 \sqrt{K^2 - k_x^2} - k_x x_0, where KK is the range wavenumber and kxk_x the along-track wavenumber. A multiply by a reference function focuses the targets at one reference range exactly. The Stolt change of variables, an interpolation in range frequency, then makes the remaining phase linear for every range, and one 2D inverse FFT focuses the whole scene. It is the radar form of Stolt migration of seismic data, and for its geometry it makes no approximation beyond the stationary phase step.

In plain words

Each point on the ground leaves a curved, smeared trace in the radar data. Instead of tracing those curves one by one, the omega-k method looks at the data as a sum of waves. In that view, the blur of a point has a simple formula that depends only on the distance to the point. A first multiply removes the blur exactly for points at one chosen distance. For the other points, a stretch of the frequency axis, the same for every point, finishes the job. After the stretch, one inverse transform gives a sharp image of every point at once.

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 and the pulse rate PRF, with NN range samples at the rate fsf_s from the two-way time tstartt_{\text{start}}, that is from the range rstartr_{\text{start}} with bins of Δr=c/(2fs)\Delta r = c/(2f_s). The pulse is a chirp pp of bandwidth BB, the carrier is f0f_0, and the squint is zero. A target at (x0,R0)(x_0, R_0) gives a p(τ−2R(η)/c) e−i4πf0R(η)/ca\, p(\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 the opposite signs. For the range frequency frf_r and the Doppler frequency faf_a, write K=4π(f0+fr)/cK = 4\pi (f_0 + f_r)/c and kx=2πfa/Vk_x = 2\pi f_a / V. The output is the complex image on the M×NM \times N grid, as for SAR image formation.

The algorithm

  1. OMEGA-K(s, P, f_0, V, PRF, r_ref) ▷ s[p][j]: raw pulse p, range sample j; P = DFT(chirp)
  2. 1S ← 2D DFT of s ▷ range f_r (index q) and Doppler f_a (index k)
  3. 2S[k][q] ← S[k][q] · conj(P[q]) · e^{-i 2π f_r t_start} ▷ range compression, absolute time
  4. 3S[k][q] ← S[k][q] · G e^{+i r_ref sqrt(K² - k_x²)} ▷ reference function multiply
  5. 4T[k][q'] ← S[k][·] read at f_r = sqrt((f_0 + f_r')² + (c f_a / (2V))²) - f_0 ▷ Stolt mapping
  6. 5T[k][q'] ← T[k][q'] · e^{-i 2π f_r' · 2 (r_ref - r_start) / c} ▷ put r_ref at its bin
  7. 6I ← 2D IDFT of T
  8. 7image[p][j] ← I[p][j] · e^{+i 4π f_0 (r_start + j Δr - r_ref) / c} ▷ restore the carrier phase

Line L1 is a 2D FFT. Line L2 is pulse compression by the matched filter, and the factor e−i2πfrtstarte^{-i 2\pi f_r t_{\text{start}}} refers the range phase to the time of transmission, so the phase of a target becomes −KR(η)-K R(\eta). By stationary phase in η\eta, the 2D spectrum of the target is ∣P∣2e−iR0K2−kx2−ikxx0|P|^2 e^{-i R_0 \sqrt{K^2 - k_x^2} - i k_x x_0} times a slowly varying amplitude. Line L3 multiplies by the conjugate phase of the reference range, with the gain G=PRF/KaG = \text{PRF}/\sqrt{K_a} of the azimuth compression. What is left is e−i(R0−rref)K2−kx2e^{-i (R_0 - r_{\text{ref}}) \sqrt{K^2 - k_x^2}}, which is still not linear in frf_r. Line L4 is the Stolt mapping: it defines a new range frequency fr′f_r' by K2−kx2=4π(f0+fr′)/c\sqrt{K^2 - k_x^2} = 4\pi (f_0 + f_r')/c and reads the old spectrum at the matching frf_r by sinc interpolation, for ∣fr′∣≤B/2|f_r'| \le B/2. Now the phase is −4π(f0+fr′)(R0−rref)/c−kxx0-4\pi (f_0 + f_r')(R_0 - r_{\text{ref}})/c - k_x x_0, linear in both frequencies. Line L5 adds the shift that makes the inverse DFT of L6 put each target at the bin of its R0R_0 and the pulse of its x0x_0. Line L7 removes the constant e−i4πf0(R0−rref)/ce^{-i 4\pi f_0 (R_0 - r_{\text{ref}})/c} that is left at each range.

Example

The tests use the geometry of the range-Doppler algorithm: f0=300f_0 = 300 MHz, B=100B = 100 MHz, T=0.2T = 0.2 us, fs=120f_s = 120 MHz (bins of 1.25 m), V=100V = 100 m/s, PRF =80= 80 Hz, M=128M = 128, N=64N = 64 from 380 m, a beam with the sine of the half angle 0.125, and rrefr_{\text{ref}} in the middle of the window. Three targets with complex amplitudes give, at their predicted pixels:

target (x0,R0)(x_0, R_0), amplitude peak / matched filter phase of peak / amplitude
(0 m, 400 m), 1 0.924 −43.7-43.7 degrees
(10 m, 410 m), 0.6i0.6i 0.911 −43.6-43.6 degrees
(-12.5 m, 425 m), −0.5-0.5 0.906 −44.1-44.1 degrees

The common phase of about −44-44 degrees is the e−iπ/4e^{-i\pi/4} of the azimuth stationary phase, so the ratios of complex amplitudes are kept, within 0.06 in the tests. With a wide beam (sine of the half angle 0.35, PRF =200= 200 Hz, M=256M = 256, window from 80 m) and rref=120r_{\text{ref}} = 120 m, a target at R0=96R_0 = 96 m reaches 0.957 of its ideal peak. With L4 skipped, that is with the reference multiply alone, it reaches only 0.213, while a target at R0=rrefR_0 = r_{\text{ref}} is focused the same with or without L4. In the same wide case the basic range-Doppler algorithm reaches 0.855. These values are measurements on these simulations.

Correctness

The algorithm is linear. In the 2D frequency domain, by stationary phase in the slow time, a target has the phase −R0K2−kx2−kxx0-R_0 \sqrt{K^2 - k_x^2} - k_x x_0; this is the only approximation, and it uses no expansion of the square root in range frequency or Doppler, unlike the range-Doppler algorithm. The reference multiply leaves −(R0−rref)K2−kx2-(R_0 - r_{\text{ref}})\sqrt{K^2 - k_x^2}, and the Stolt mapping makes K2−kx2\sqrt{K^2 - k_x^2} the new range wavenumber, so the phase becomes linear in both new frequencies for every R0R_0 at once. An inverse DFT of a linear phase is a peak at the right place. So the algorithm is exact for a straight track at a constant speed, up to the stationary phase step and the interpolation of L4. The proofs are in proofs/correctness.md.

Proof: After the reference multiply and the Stolt mapping, the phase of every target is linear in both frequencies, so one inverse DFT focuses all rangesfull

We prove three facts about the omega-k algorithm as written on the main page (lines L1 to L7), for a straight track at the constant speed VV, zero squint, point targets and the stop-and-go approximation. Theorem 1 is exact. Theorem 2 rests on the principle of stationary phase in the slow time, an asymptotic approximation; it uses no other approximation. Theorem 3 is exact given Theorem 2 and an exact interpolation in L4.

Setting. A target of amplitude aa at (x0,R0)(x_0, R_0) gives the raw signal a w(η) p(τ−2R(η)/c) e−i4πf0R(η)/ca\, w(\eta)\, p(\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}, where τ\tau is the absolute two-way time and pp the baseband pulse with spectrum PP. The Fourier sign is e−i2πfte^{-i 2\pi f t}. For the range frequency frf_r and the Doppler frequency faf_a put K=4π(f0+fr)/cK = 4\pi (f_0 + f_r)/c and kx=2πfa/Vk_x = 2\pi f_a / V, and assume ∣kx∣<K|k_x| < K on the band.

Theorem 1 (linearity). The output of L1 to L7 is linear in the data.

Proof. L1 and L6 are DFTs; L2, L3, L5 and L7 are products with fixed functions; L4 is a weighted sum of samples with weights fixed by the geometry. □\square

Theorem 2 (the 2D spectrum). After L2, the range Fourier transform of the target at frf_r is a w(η) ∣P(fr)∣2e−iKR(η)a\, w(\eta)\, |P(f_r)|^2 e^{-i K R(\eta)}, and under stationary phase in η\eta its Fourier transform in η\eta is

S(fr,fa)≈a ∣P(fr)∣2 W A(fr,fa) e−iπ/4 e−iR0K2−kx2 e−ikxx0,S(f_r, f_a) \approx a\, |P(f_r)|^2\, W\, A(f_r, f_a)\, e^{-i\pi/4}\, e^{-i R_0 \sqrt{K^2 - k_x^2}}\, e^{-i k_x x_0},

with a positive amplitude AA that varies slowly and does not depend on x0x_0.

Proof. The range Fourier transform of p(τ−τd)p(\tau - \tau_d) is P(fr)e−i2πfrτdP(f_r) e^{-i 2\pi f_r \tau_d}. The DFT of the record measures time from tstartt_{\text{start}}, so it gives P(fr)e−i2πfr(τd−tstart)P(f_r) e^{-i 2\pi f_r (\tau_d - t_{\text{start}})}, and the factor e−i2πfrtstarte^{-i 2\pi f_r t_{\text{start}}} of L2 restores e−i2πfrτde^{-i 2\pi f_r \tau_d}. With τd=2R/c\tau_d = 2R/c and the carrier, the phase is −4π(f0+fr)R/c=−KR-4\pi (f_0 + f_r) R / c = -K R, and conj(P)\text{conj}(P) turns PP into ∣P∣2|P|^2. In η\eta, the phase ϕ(η)=−KR(η)−2πfaη\phi(\eta) = -K R(\eta) - 2\pi f_a \eta is that of the range-Doppler proof with 4πf0/c4\pi f_0/c replaced by KK. With u=Vη−x0u = V\eta - x_0, ϕ′(η)=−KVu/R−2πfa\phi'(\eta) = -K V u / R - 2\pi f_a, so the stationary point has u/R=−kx/Ku / R = -k_x / K: the sine of the squint angle ψ\psi is −kx/K-k_x/K. The value there is −R0K2−kx2−kxx0-R_0 \sqrt{K^2 - k_x^2} - k_x x_0, because ϕ=−KR(R2−u2)−kxx0\phi = -\frac{K}{R}(R^2 - u^2) - k_x x_0 at that point, R2−u2=R02R^2 - u^2 = R_0^2 and KR(R2−u2)=KR0cos⁡ψ=R0K2−kx2\frac{K}{R}(R^2 - u^2) = K R_0 \cos\psi = R_0\sqrt{K^2 - k_x^2}, and the term −2πfax0/V=−kxx0-2\pi f_a x_0/V = -k_x x_0 remains. The second derivative is negative, which gives e−iπ/4e^{-i\pi/4} and an amplitude A=2π/∣ϕ′′∣A = \sqrt{2\pi/|\phi''|} that depends on R0R_0, frf_r, faf_a only. □\square

Theorem 3 (focus of every range). Assume Theorem 2 and an exact interpolation in L4. After L3 to L5, the spectrum of the target, as a function of the new range frequency fr′f_r' with ∣fr′∣≤B/2|f_r'| \le B/2 and of faf_a, is

a A~ e−iπ/4 e−i4πf0(R0−rref)/c e−i2πfr′⋅2(R0−rstart)/c e−ikxx0,a\, \tilde A\, e^{-i\pi/4}\, e^{-i 4\pi f_0 (R_0 - r_{\text{ref}})/c}\, e^{-i 2\pi f_r' \cdot 2 (R_0 - r_{\text{start}})/c}\, e^{-i k_x x_0},

with A~=∣P∣2WAG\tilde A = |P|^2 W A G slowly varying. So the 2D inverse DFT of L6 has its peak at the range bin (R0−rstart)/Δr(R_0 - r_{\text{start}})/\Delta r and at the pulse of x0x_0, and after L7 the phase of the peak is −π/4-\pi/4 plus the phase of aa, the same for every target.

Proof. L3 multiplies by e+irrefK2−kx2e^{+i r_{\text{ref}} \sqrt{K^2 - k_x^2}}, which leaves e−i(R0−rref)K2−kx2e^{-i (R_0 - r_{\text{ref}}) \sqrt{K^2 - k_x^2}}. L4 evaluates the spectrum at the frf_r for which K2−kx2=4π(f0+fr′)/c\sqrt{K^2 - k_x^2} = 4\pi (f_0 + f_r')/c; squaring, (f0+fr)2=(f0+fr′)2+(cfa/(2V))2(f_0 + f_r)^2 = (f_0 + f_r')^2 + (c f_a / (2V))^2, which is the formula of L4. So the phase becomes −4π(f0+fr′)(R0−rref)/c−kxx0=−4πf0(R0−rref)/c−2πfr′⋅2(R0−rref)/c−kxx0-4\pi (f_0 + f_r')(R_0 - r_{\text{ref}})/c - k_x x_0 = -4\pi f_0 (R_0 - r_{\text{ref}})/c - 2\pi f_r' \cdot 2(R_0 - r_{\text{ref}})/c - k_x x_0. L5 adds −2πfr′⋅2(rref−rstart)/c-2\pi f_r' \cdot 2(r_{\text{ref}} - r_{\text{start}})/c, so the linear term becomes −2πfr′⋅2(R0−rstart)/c-2\pi f_r' \cdot 2(R_0 - r_{\text{start}})/c. A linear phase e−i2πfΔe^{-i 2\pi f \Delta} over a band has an inverse DFT that peaks at the delay Δ\Delta; here the delays are 2(R0−rstart)/c2(R_0 - r_{\text{start}})/c, which is bin (R0−rstart)/Δr(R_0 - r_{\text{start}})/\Delta r at the sample rate fsf_s, and x0/Vx_0 / V in slow time. At that bin, L7 multiplies by e+i4πf0(R0−rref)/ce^{+i 4\pi f_0 (R_0 - r_{\text{ref}})/c}, which cancels the constant phase. □\square

No step used an expansion of K2−kx2\sqrt{K^2 - k_x^2}, so the result holds for wide beams and for any R0R_0, which is the sense in which the algorithm is exact for its geometry. The errors that remain are those of the stationary phase step, the band edges where the Stolt mapping reads outside the recorded band, and the interpolation of L4. The example measures a common phase near −44-44 degrees, in line with the factor e−iπ/4e^{-i\pi/4}.

Cost. L1 and L6 cost O(MNlog⁡(MN))O(M N \log(M N)) with an FFT, L2, L3, L5 and L7 cost O(MN)O(M N), and L4 costs O(K)O(K) per output sample, so 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.

Complexity

Lines L1 and L6 are 2D FFTs of M×NM \times N samples, O(MNlog⁡(MN))O(M N \log(M N)). Lines L2, L3, L5 and L7 cost O(1)O(1) per sample. Line L4 costs O(K)O(K) per output sample with a KK-tap interpolator. 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.

Properties

  • Linear in the data.
  • Exact for the hyperbolic range history of a straight track at constant speed, including wide beams, high squint and long apertures, up to stationary phase and interpolation.
  • Range-invariant: every operation is in the 2D frequency domain, so it cannot follow a speed or a geometry that changes with range, such as the curved orbit of a satellite. Variants handle that approximately.
  • The only interpolation is the 1D Stolt mapping along range frequency.

Variants and improvements

  • Approximate Stolt mapping. Replace L4 by a phase multiply that is exact at the reference range and a range-varying correction later, which gives an algorithm close to the chirp scaling algorithm.
  • Spotlight data. For dechirped spotlight data the same mapping applies after the deramp; Carrara, Goodman and Majewski call it the range migration algorithm. The polar format algorithm uses a polar instead of a Stolt resampling.
  • Seismic and ultrasonic imaging. With the exploding reflector model, the same mapping is Stolt migration, and in ultrasound it is the frequency domain form of the synthetic aperture focusing technique.
  • Satellite orbits. An effective speed that changes with range is handled by range blocks or by extra correction terms.

When to use it

Use omega-k for straight-track data with wide beams, high squint or long apertures, where the approximations of the range-Doppler algorithm fail, as in low-frequency and airborne systems with wide beams. It needs an interpolation, which the chirp scaling algorithm avoids, but it makes fewer approximations. For curved tracks or a speed that varies, use backprojection.

Pitfalls

  • Missing time reference. Without the factor e−i2πfrtstarte^{-i 2\pi f_r t_{\text{start}}} in L2, the phase is relative to the start of the record, not to the transmission, and L3 no longer matches.
  • Interpolating in the wrong order. The spectrum must be in increasing frequency order (after an fftshift) before L4 reads it at fractional positions; the wrapped DFT order puts the band edges next to each other.
  • Reading outside the band. For large ∣fa∣|f_a| the Stolt mapping asks for frequencies above the band; L4 must restrict fr′f_r' to ∣fr′∣≤B/2|f_r'| \le B/2 and leave the rest zero.
  • Targets near the ends of the range window. The 2D FFT is circular, so a chirp that runs past the last sample wraps. In the tests a target at 385 m, near the start of the window, measured only 0.75 of its ideal peak.
  • The carrier phase. Without L7, the phase of each target varies with R0−rrefR_0 - r_{\text{ref}}; the modulus is right, but interferometry fails.

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
omega_k_algorithm.py 161 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/omega-k-algorithm/. The authors are listed in prov/R4DMS8.jsonl.
"""Omega-k (wavenumber domain) algorithm 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.

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 is the two-way delay
t_start + j / fs, that is the slant range r_start + j c / (2 fs).

In the two-dimensional frequency domain, with K = 4 pi (f0 + fr) / c and
kx = 2 pi f_eta / V, a target has the phase -R0 sqrt(K^2 - kx^2) - kx x
(stationary phase). The Stolt mapping makes this phase linear in the new
range frequency, so one 2D inverse DFT focuses every range at once.
Data layout: data[p][j], row p a pulse, column j a range bin.
"""

import cmath
import math

from imgkit import dft, fftshift, 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):
        return self.r_start + j * self.dr

    def x_pulse(self, p):
        return self.v * (p - self.n_az // 2) / self.prf

    def doppler(self, k):
        """The Doppler frequency of azimuth DFT bin k, 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 range_freq(self, q):
        """The baseband range frequency of range DFT bin q, wrapped to [-fs/2, fs/2)."""
        qq = q if q < self.n_range // 2 else q - self.n_range
        return qq * self.fs / self.n_range

    def chirp(self, 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 sinc_interp(seq, u, taps=8):
    """Value of a sampled band-limited sequence 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(seq):
            x = u - m
            w = 1.0 if x == 0 else math.sin(math.pi * x) / (math.pi * x)
            acc += seq[m] * w * (0.5 + 0.5 * math.cos(math.pi * x / half))
    return acc


def omega_k(g, data, r_ref=None, stolt=True):
    """Focus raw stripmap data. Returns the complex image img[p][j].

    With stolt=False the Stolt interpolation is skipped, so only the
    reference range r_ref is focused exactly (the bulk compression alone).
    """
    if r_ref is None:
        r_ref = g.slant_range(g.n_range / 2)
    n, m = g.n_range, g.n_az
    t_start = 2.0 * g.r_start / C
    ref = [g.chirp(j / g.fs) for j in range(n)]
    pconj = [v.conjugate() for v in dft(ref)]
    rows = []
    for p in range(m):
        spec = dft(data[p])  # @line L1
        rows.append([spec[q] * pconj[q] * cmath.exp(-2j * math.pi * g.range_freq(q) * t_start)
                     for q in range(n)])  # @line L2
    cols = [dft([rows[p][q] for p in range(m)]) for q in range(n)]  # @line L1
    f_max = 2.0 * g.v * g.beam * g.f0 / C
    half_band = g.bandwidth / 2.0
    out = [[0j] * n for _ in range(m)]
    for k in range(m):
        fa = g.doppler(k)
        if abs(fa) > f_max:
            continue
        kx = 2.0 * math.pi * fa / g.v
        d3 = (1.0 - (C * fa / (2.0 * g.v * g.f0)) ** 2) ** 1.5
        gain = g.prf * math.sqrt(C * r_ref / (2.0 * g.v ** 2 * g.f0 * d3))
        line = []
        for q in range(n):
            kk = 4.0 * math.pi * (g.f0 + g.range_freq(q)) / C
            ky = math.sqrt(max(kk * kk - kx * kx, 0.0))
            line.append(cols[q][k] * gain * cmath.exp(1j * r_ref * ky))  # @line L3
        shifted = fftshift(line)  # increasing frequency, zero at index n // 2
        for q in range(n):
            fr2 = g.range_freq(q)
            if abs(fr2) > half_band:
                continue
            if stolt:
                fr = math.sqrt((g.f0 + fr2) ** 2 + (C * fa / (2.0 * g.v)) ** 2) - g.f0  # @line L4
            else:
                fr = fr2
            val = sinc_interp(shifted, fr * n / g.fs + n // 2)  # @line L4
            delay = 2.0 * (r_ref - g.r_start) / C
            out[k][q] = val * cmath.exp(-2j * math.pi * fr2 * delay)  # @line L5
    rows2 = [idft(out[k]) for k in range(m)]  # @line L6
    cols2 = [idft([rows2[k][j] for k in range(m)]) for j in range(n)]  # @line L6
    img = [[0j] * n for _ in range(m)]
    for j in range(n):
        fix = cmath.exp(4j * math.pi * g.f0 * (g.slant_range(j) - r_ref) / C)  # @line L7
        for p in range(m):
            img[p][j] = cols2[j][p] * fix
    return img


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_omega_k_algorithm.py 80 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/omega-k-algorithm/. The authors are listed in prov/R4DMS8.jsonl.

from omega_k_algorithm import Stripmap, omega_k, simulate_raw, target_pixel

G = Stripmap()
TARGETS = [(0.0, 400.0, 1.0), (10.0, 410.0, 0.6j), (-12.5, 425.0, -0.5)]
RAW = simulate_raw(G, TARGETS)
IMG = omega_k(G, RAW)
WIDE = Stripmap(beam=0.35, prf=200.0, n_az=256, r_start=80.0)


def matched_filter(g, raw, 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(g, x, r0):
    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 pixel(g, x, r0):
    return tuple(round(v) for v in target_pixel(g, x, r0))


def test_targets_focus_at_their_pixels() -> None:
    for x, r0, _ in TARGETS:
        p0, j0 = pixel(G, x, r0)
        assert local_peak(IMG, p0, j0)[1:] == (p0, j0)


def test_peak_is_close_to_the_brute_force_matched_filter() -> None:
    for x, r0, amp in TARGETS:
        p0, j0 = pixel(G, x, r0)
        brute = abs(matched_filter(G, RAW, x, r0))
        assert abs(brute - abs(amp) * ideal_gain(G, x, r0)) < 0.03 * brute
        assert 0.85 * brute < abs(IMG[p0][j0]) < 1.05 * brute


def test_complex_amplitudes_are_kept() -> None:
    """The image keeps the ratio of the complex reflectivities, phase included."""
    ref_val = IMG[64][16] / ideal_gain(G, 0.0, 400.0)
    for x, r0, amp in TARGETS[1:]:
        p0, j0 = pixel(G, x, r0)
        ratio = (IMG[p0][j0] / ideal_gain(G, x, r0)) / ref_val
        assert abs(ratio - amp) < 0.06


def test_stolt_mapping_focuses_far_from_the_reference_range() -> None:
    """Wide beam: bulk compression alone defocuses a target 24 m from r_ref; Stolt fixes it."""
    raw = simulate_raw(WIDE, [(0.0, 96.0, 1.0)])
    ideal = ideal_gain(WIDE, 0.0, 96.0)
    p0, j0 = pixel(WIDE, 0.0, 96.0)
    full = omega_k(WIDE, raw, r_ref=120.0)
    bulk = omega_k(WIDE, raw, r_ref=120.0, stolt=False)
    assert local_peak(full, p0, j0)[1:] == (p0, j0)
    assert abs(full[p0][j0]) > 0.9 * ideal
    assert local_peak(bulk, p0, j0)[0] < 0.4 * ideal


def test_bulk_compression_alone_is_exact_at_the_reference_range() -> None:
    raw = simulate_raw(WIDE, [(0.0, 120.0, 1.0)])
    p0, j0 = pixel(WIDE, 0.0, 120.0)
    full = omega_k(WIDE, raw, r_ref=120.0)
    bulk = omega_k(WIDE, raw, r_ref=120.0, stolt=False)
    assert abs(full[p0][j0] - bulk[p0][j0]) < 0.05 * abs(full[p0][j0])


def test_linear_in_the_data() -> None:
    a = omega_k(G, simulate_raw(G, TARGETS[:1]))
    b = omega_k(G, simulate_raw(G, TARGETS[1:]))
    for p in (58, 64, 72):
        for j in (12, 16, 24):
            assert abs(a[p][j] + b[p][j] - IMG[p][j]) < 1e-6 * abs(IMG[64][16])

History

Stolt (1978) introduced migration by Fourier transform for seismic data, a change of variables from temporal frequency to vertical wavenumber. Cafforio, Prati and Rocca (1991) showed that SAR focusing is a migration problem of the same kind and derived the wavenumber domain algorithm from it. Bamler (1992) compared it with the range-Doppler algorithm and showed that it is free of the approximations of the latter for a straight track. Carrara, Goodman and Majewski (1995) described its spotlight form as the range migration algorithm. Cumming and Wong (2005, Chapter 8) call it the omega-K algorithm.

References

  1. Ciro Cafforio, Claudio Prati and Fabio Rocca, SAR data focusing using seismic migration techniques, IEEE Transactions on Aerospace and Electronic Systems 27(2), 1991, 194 to 207, the SAR record as a zero-offset seismic section and its focusing by the Stolt mapping (general locator)
  2. R. H. Stolt, Migration by Fourier transform, Geophysics 43(1), 1978, 23 to 48, the change of variables from temporal frequency to vertical wavenumber (general locator)
  3. Ian G. Cumming and Frank H. Wong, Digital Processing of Synthetic Aperture Radar Data, Artech House, 2005, Chapter 8, The Omega-K Algorithm
  4. 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 wavenumber domain algorithm as the reference without approximation for a straight track (general locator)
  5. Walter G. Carrara, Ron S. Goodman and Ronald M. Majewski, Spotlight Synthetic Aperture Radar: Signal Processing Algorithms, Artech House, 1995, the range migration algorithm for spotlight data (general locator)

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