Algorithm Search⌘K

Algorithmadvanced

Total focusing method

Also called TFM.

Form an ultrasonic image from full matrix capture data: at every pixel, sum the trace of every transmit and receive pair at its two-way time. Focused everywhere, at a cost of O(M^2 n^2).

Time
O(M^2 n^2) worst
Space
O(M) extraO(M^2 T) data
Where
M = the number of array elements; T = the number of samples per trace; n = the number of pixels along one side of the image
Properties
deterministicnot exactlinear in dataiterative
Origin
Caroline Holmes, Bruce W. Drinkwater, Paul D. Wilcox, 2005

The total focusing method (TFM) forms an image from full matrix capture (FMC) data. In FMC, each of the MM elements of an array fires in turn and all MM elements record, so the data holds one trace for every transmit and receive pair. TFM computes, for every pixel, the two-way travel time of each pair through that pixel, reads each trace at its time and adds the M2M^2 values. The image is focused on transmit and on receive at every pixel, which a physical array with one transmit focus cannot do. TFM is delay-and-sum beamforming applied to the full matrix, and it is the image formation step of synthetic transmit aperture imaging; the name TFM comes from nondestructive testing. The cost is O(M2n2)O(M^2 n^2) for an n×nn \times n image.

In plain words

Imagine a row of 16 loudspeakers that are also microphones. Each one clicks once while all 16 listen, so you get 256 recordings. To decide how bright one point of the image is, work out for every pair how long a click takes to go from the first one to the point and back to the second one. Read each recording at that moment and add the 256 readings. If something reflects at that point, all readings line up and the sum is large. If nothing is there, the readings come from different places and mostly cancel. Do this for every point of the picture.

The problem

The input is FMC data DijD_{ij}, i,j=1,…,Mi, j = 1, \ldots, M: the trace recorded by element jj when element ii fires, as complex baseband (IQ) samples at tk=t0+k/fst_k = t_0 + k/f_s. The analytic radio frequency (RF) signal is rij(t)=bij(t)ei2πf0tr_{ij}(t) = b_{ij}(t) e^{i 2\pi f_0 t}, where bijb_{ij} is the baseband signal and f0f_0 the center frequency (see analytic signal). The array lies on z=0z = 0 with element ii at ei=(xi,0)e_i = (x_i, 0), and the medium has a constant speed of sound cc. The output is an image I(p)I(p) on a grid of n×nn \times n pixels p=(x,z)p = (x, z), z>0z > 0, that is large where a scatterer is. The pulse-echo model gives the data of a point scatterer at p0p_0: an echo in trace (i,j)(i, j) at the time (∣p0−ei∣+∣p0−ej∣)/c(|p_0 - e_i| + |p_0 - e_j|)/c.

The algorithm

  1. TFM(D, e_1 … e_M, pixels, c, f_s, t_0, f_0) ▷ returns the image I
  2. 1for each pixel p do
  3. 2d_i ← |p - e_i| / c for i = 1 … M ▷ one-way times
  4. 3acc ← 0
  5. 4for i ← 1 to M do ▷ transmit element
  6. 5for j ← 1 to M do ▷ receive element
  7. 6acc ← acc + SAMPLE(D_ij, d_i + d_j)
  8. 7I(p) ← |acc|
  9. 8return I
  10. SAMPLE(b, t) ▷ analytic RF value of an IQ trace at time t
  11. 9u ← (t - t_0) f_s; k ← ⌊u⌋; φ ← u - k
  12. 10if k < 0 or k + 1 ≥ T then return 0
  13. 11return ((1 - φ) b[k] + φ b[k+1]) · e^{i 2π f_0 t}

Line L2 computes the travel time from each element to the pixel once, and the pair (i,j)(i, j) then uses di+djd_i + d_j: out from eie_i, back to eje_j. SAMPLE interpolates the baseband trace linearly and restores the carrier phase at the exact time tt. The sum in L6 is coherent: it adds complex values, so echoes that arrive in phase add up and the others cancel. Line L7 takes the modulus, which is the envelope of the focused signal; a B-mode display then applies log compression.

Example

The tests use M=16M = 16 elements with pitch 0.3 mm, centered at x=0x = 0, so the outer elements are at x=±2.25x = \pm 2.25 mm. The speed of sound is c=1.54c = 1.54 mm/us (1540 m/s), f0=5f_0 = 5 MHz (wavelength 0.308 mm), fs=40f_s = 40 MHz, and the pulse has a Gaussian envelope with σt=0.1\sigma_t = 0.1 us. One point scatterer of amplitude 1 sits at (0,6)(0, 6) mm.

For the pixel p=(0,6)p = (0, 6), line L2 gives d1=62+2.252/1.54=4.1610d_1 = \sqrt{6^2 + 2.25^2}/1.54 = 4.1610 us for the outer element and d8=62+0.152/1.54=3.8973d_8 = \sqrt{6^2 + 0.15^2}/1.54 = 3.8973 us for an inner one. The pair (1,1)(1, 1) is read at 8.32218.3221 us and the pair (1,8)(1, 8) at 8.05848.0584 us. These are exactly the times of the simulated echoes, so all 256 terms are close to 11, and the pixel value is 254.67254.67. Theorem 2 of the proof gives M2=256M^2 = 256 for exact samples; the small loss comes from the linear interpolation.

The lateral profile at z=6z = 6 mm, normalized to its peak, at x=−0.3,−0.2,…,0.3x = -0.3, -0.2, \ldots, 0.3 mm:

x (mm) -0.3 -0.2 -0.1 0 0.1 0.2 0.3
TFM 0.179 0.426 0.802 1 0.802 0.426 0.179
one transmit (element 8), dynamic receive 0.313 0.624 0.893 1 0.893 0.625 0.315

The single transmit row focuses on receive only, as a dynamic receive beamformer does after an unfocused transmit. TFM adds the transmit focus and the peak is narrower. With two scatterers at x=±0.4x = \pm 0.4 mm, the TFM profile drops to 0.1760.176 of the peak at x=0x = 0, so the two points are clearly resolved. These numbers are measurements on this simulation, not properties of TFM in general.

Correctness

TFM is a linear map of the data followed by a modulus, and the code checks the linear part against its exact adjoint. For a point scatterer and exact samples, every term at the scatterer equals the amplitude times g(0)g(0), so the pixel value is M2∣a∣ g(0)M^2 |a|\, g(0). By the triangle inequality no pixel is larger, and with at least two elements the maximum is only at the scatterer, because two distinct elements at equal distances from two points in z>0z > 0 force the points to be equal. If the data is reciprocal, Dij=DjiD_{ij} = D_{ji}, the half matrix gives the same image. The proofs are in proofs/correctness.md.

These are theorems about the model: point scatterers, single scattering, a known constant cc, no attenuation, spreading or directivity. In a real specimen, an error in cc moves and blurs the focus, and multiple scattering adds echoes that TFM puts in the wrong place.

Proof: TFM is linear in the data, focuses a point scatterer to a unique maximum of height M^2, and can use half of a reciprocal matrixfull

We prove four facts about TFM as written on the main page (lines L1 to L11). The facts hold for the pulse-echo model of the page: point scatterers, no spreading loss, no directivity and a constant speed of sound cc. They are theorems about that model, not about a real specimen.

Setting. The elements are ei=(xi,0)e_i = (x_i, 0), i=1,…,Mi = 1, \ldots, M, with distinct xix_i. For a pixel p=(x,z)p = (x, z) with z>0z > 0, line L2 computes di(p)=∣p−ei∣/cd_i(p) = |p - e_i|/c. The data DijD_{ij} is a complex baseband trace sampled at tk=t0+k/fst_k = t_0 + k/f_s. SAMPLE (lines L8 to L10) returns r~ij(t)=b~ij(t)ei2πf0t\tilde r_{ij}(t) = \tilde b_{ij}(t) e^{i 2\pi f_0 t}, where b~ij\tilde b_{ij} is the linear interpolation of the samples of DijD_{ij}, and 00 outside the recorded window. TFM returns I(p)=∣S(p)∣I(p) = |S(p)| with S(p)=∑i,jr~ij(di(p)+dj(p))S(p) = \sum_{i,j} \tilde r_{ij}(d_i(p) + d_j(p)).

Theorem 1 (linearity and the adjoint). SS is a linear map from the data to the complex image. The map S∗S^* that adds ei2πf0t‾ v\overline{e^{i 2\pi f_0 t}}\, v with the weights 1−φ1 - \varphi and φ\varphi to the two samples that SAMPLE read for the pixel value vv is its adjoint: ⟨SD,V⟩=⟨D,S∗V⟩\langle S D, V \rangle = \langle D, S^* V \rangle for all data DD and images VV.

Proof. For a fixed pixel and pair, SAMPLE at time tt returns ((1−φ)Dij[k]+φDij[k+1])ei2πf0t((1 - \varphi) D_{ij}[k] + \varphi D_{ij}[k+1]) e^{i 2\pi f_0 t}, or 00, where kk and φ\varphi depend only on tt. This is a linear form ℓ(D)=∑qwqDij[q]\ell(D) = \sum_q w_q D_{ij}[q] with fixed complex weights wqw_q. A sum of linear forms is linear. For one form, ℓ(D)‾ v=∑qDij[q]‾ wq‾ v\overline{\ell(D)}\, v = \sum_q \overline{D_{ij}[q]}\, \overline{w_q}\, v, so the adjoint puts wq‾ v\overline{w_q}\, v on sample qq, which is what tfm_adjoint does. Summing over pairs and pixels gives the identity. □\square

Theorem 2 (a point scatterer). Let the data be exact samples of one point scatterer aa at p0=(x0,z0)p_0 = (x_0, z_0), z0>0z_0 > 0: bij(t)=a g(t−τij)e−i2πf0τijb_{ij}(t) = a\, g(t - \tau_{ij}) e^{-i 2\pi f_0 \tau_{ij}} with τij=di(p0)+dj(p0)\tau_{ij} = d_i(p_0) + d_j(p_0), a real envelope gg with ∣g(s)∣<g(0)|g(s)| < g(0) for s≠0s \ne 0, and assume SAMPLE reads bijb_{ij} without interpolation error inside the window. Then:

  1. S(p)=a∑i,jg(Δij)ei2πf0ΔijS(p) = a \sum_{i,j} g(\Delta_{ij}) e^{i 2\pi f_0 \Delta_{ij}} with Δij=di(p)+dj(p)−τij\Delta_{ij} = d_i(p) + d_j(p) - \tau_{ij};
  2. I(p0)=∣a∣ g(0) M2I(p_0) = |a|\, g(0)\, M^2;
  3. I(p)≤∣a∣ g(0) M2I(p) \le |a|\, g(0)\, M^2 for every pixel pp, and for M≥2M \ge 2 equality holds only at p=p0p = p_0.

Proof. Part 1: the analytic value at t=di(p)+dj(p)t = d_i(p) + d_j(p) is a g(t−τij)e−i2πf0τijei2πf0t=a g(Δij)ei2πf0Δija\, g(t - \tau_{ij}) e^{-i 2\pi f_0 \tau_{ij}} e^{i 2\pi f_0 t} = a\, g(\Delta_{ij}) e^{i 2\pi f_0 \Delta_{ij}}. Part 2: at p=p0p = p_0 every Δij\Delta_{ij} is 00, so the M2M^2 terms all equal a g(0)a\, g(0). Part 3: by the triangle inequality ∣S(p)∣≤∣a∣∑i,j∣g(Δij)∣≤∣a∣ g(0) M2|S(p)| \le |a| \sum_{i,j} |g(\Delta_{ij})| \le |a|\, g(0)\, M^2. Equality needs ∣g(Δij)∣=g(0)|g(\Delta_{ij})| = g(0) for every pair, so Δij=0\Delta_{ij} = 0 for all i,ji, j. The diagonal pairs give di(p)=di(p0)d_i(p) = d_i(p_0), that is ∣p−ei∣=∣p0−ei∣|p - e_i| = |p_0 - e_i| for every ii. Take two elements with x1≠x2x_1 \ne x_2. Subtracting the squared equations (x−xi)2+z2=(x0−xi)2+z02(x - x_i)^2 + z^2 = (x_0 - x_i)^2 + z_0^2 for i=1,2i = 1, 2 gives 2(x2−x1)(x−x0)=02(x_2 - x_1)(x - x_0) = 0, so x=x0x = x_0, and then z2=z02z^2 = z_0^2 with z,z0>0z, z_0 > 0 gives z=z0z = z_0. □\square

The Gaussian envelope of the code satisfies the hypothesis on gg. In the tests the interpolation error is not zero, so the measured peak is 254.67254.67 for M2=256M^2 = 256; the test allows 1 percent.

Theorem 3 (reciprocity). If Dij=DjiD_{ij} = D_{ji} for all i,ji, j, then S(p)=∑ir~ii(2di(p))+2∑i<jr~ij(di(p)+dj(p))S(p) = \sum_i \tilde r_{ii}(2 d_i(p)) + 2 \sum_{i < j} \tilde r_{ij}(d_i(p) + d_j(p)), which is what tfm_half computes with M(M+1)/2M(M+1)/2 reads in place of M2M^2.

Proof. The time di(p)+dj(p)d_i(p) + d_j(p) is symmetric in ii and jj, and so is the trace by hypothesis. The terms of the pairs (i,j)(i, j) and (j,i)(j, i) are therefore equal, and the full sum splits into the diagonal and twice the strict upper triangle. □\square

Linear acoustics with a reciprocal medium gives Dij=DjiD_{ij} = D_{ji} up to noise; the simulator of the code has it exactly.

Theorem 4 (cost). TFM reads M2M^2 samples per pixel, so an n×nn \times n grid costs Θ(M2n2)\Theta(M^2 n^2) calls of SAMPLE, each O(1)O(1), plus O(Mn2)O(M n^2) for the times of line L2. The extra space is O(M)O(M) per pixel, besides the data of size M2TM^2 T and the image.

Proof. Lines L4 to L6 run M2M^2 times per pixel, and SAMPLE does a fixed number of operations. Line L2 computes MM square roots per pixel. □\square

Remark on the interpolation. Linear interpolation of the baseband envelope has error at most h2max⁡∣b′′∣/8h^2 \max |b''| / 8 with h=1/fsh = 1/f_s, and the phase factor is exact. Interpolating the RF signal itself would need fsf_s several times f0f_0 for the same error, because the RF signal oscillates at f0f_0. This is why the code works on IQ data.

Complexity

In the real-RAM model, lines L4 to L6 run M2M^2 times per pixel, and SAMPLE costs O(1)O(1). An n×nn \times n image therefore costs Θ(M2n2)\Theta(M^2 n^2) operations, plus O(Mn2)O(M n^2) square roots in L2. The extra space is O(M)O(M) for the times, besides the data of size M2TM^2 T and the image of size n2n^2. With M=64M = 64 and a 256×256256 \times 256 grid this is about 2.7×1082.7 \times 10^8 samples per frame. Reciprocity halves the reads (Theorem 3 of the proof).

The data acquisition costs MM firings, one per element, and each firing needs the full round trip to the deepest point. This limits the frame rate, not the computation.

Properties

  • Linear in the data before the modulus of L7, with an exact adjoint (the code checks the adjoint test to 10−1010^{-10}).
  • Focused on transmit and receive at every pixel. The focus does not depend on a transmit focal depth chosen before the scan.
  • Gain M2M^2 for a point scatterer under exact sampling, against MM for receive-only focusing of one transmit.
  • Uses all of the data. The data needs M2TM^2 T samples, which is MM times more than one focused line set.
  • Each firing uses one element, so the transmitted energy and the signal-to-noise ratio per firing are low.

Variants and improvements

  • Half matrix. For reciprocal data, use the pairs i≤ji \le j and count the pairs i<ji < j twice. This halves the reads and the storage.
  • Apodization and aperture. Weight each pair, or skip pairs outside a receive f-number, to trade the side lobes against the main lobe width, as in dynamic receive focusing.
  • Coherence weighting. Multiply each pixel by the coherence factor of its M2M^2 terms to suppress clutter.
  • Other transmissions. Plane-wave compounding fires all elements with tilts and needs fewer firings; SAFT uses only the diagonal i=ji = j.
  • Layered media. In nondestructive testing through a wedge or an immersion layer, the times did_i follow refracted ray paths by Fermat's principle in place of straight lines.
  • Frequency domain. Wavenumber (migration) methods compute the same focusing faster on regular grids; Kirchhoff migration is the seismic analogue of the time-domain sum.

When to use it

Use TFM when the array is small enough that MM firings are fast, and when focus everywhere matters more than frame rate: defect sizing in welds and castings is the main case. For large arrays in medical imaging, where the frame rate and the signal-to-noise ratio of single-element firings are a problem, plane-wave compounding or focused transmits are more common.

Pitfalls

  • Wrong speed of sound. The times scale with 1/c1/c. A wrong cc moves the image and smears the focus, worst at large angles.
  • Element directivity. Real elements radiate weakly at large angles. Pairs that see the pixel at a steep angle add noise and little signal; an aperture limit helps.
  • Interpolation. Linear interpolation of RF data at a few samples per period loses gain. Interpolate the baseband signal and restore the phase, as in L11, or sample faster.
  • The recorded window. A two-way time outside the window must give 00 (L10), not an index error or a wrapped sample.
  • Dead zone. The firing itself saturates the receivers for a short time, so the shallowest pixels are not reliable.

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.

total_focusing_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/total-focusing-method/. The authors are listed in prov/91YVZD.jsonl.
"""Total focusing method (TFM) on full matrix capture data.

Units: millimetres, microseconds and megahertz, so the speed of sound in soft
tissue, 1540 m/s, is 1.54 mm/us. The array lies on the line z = 0, with
element i at (x_i, 0). Depth z is positive down.

The data D[i][j] is the complex baseband (IQ) trace for transmit element i and
receive element j, sampled at t_k = t0 + k / fs. The analytic RF signal is
r(t) = b(t) exp(i 2 pi f0 t), where b is the baseband signal.

TFM forms, at every pixel p, the coherent sum over all transmit and receive
pairs of r_ij at the two-way time (|p - e_i| + |p - e_j|) / c, and returns its
modulus. The complex sum is a linear map of the data; tfm_adjoint is its exact
adjoint (a discrete pulse-echo model with the same interpolation).
"""

import cmath
import math

SOUND_SPEED = 1.54  # mm per microsecond, the soft tissue convention of 1540 m/s


def element_positions(m_count, pitch):
    """x positions of a linear array of m_count elements, centered at x = 0."""
    return [(i - (m_count - 1) / 2) * pitch for i in range(m_count)]


def one_way_times(px, pz, elements, c=SOUND_SPEED):
    """Travel times from each element (x_i, 0) to the point (px, pz)."""
    return [math.hypot(px - xe, pz) / c for xe in elements]


def simulate_fmc(elements, scatterers, f0, sigma_t, fs, t0, ns, c=SOUND_SPEED):
    """Full matrix capture of point scatterers: D[i][j][k] in complex baseband.

    Each scatterer (x, z, a) adds a * g(t - tau) * exp(-i 2 pi f0 tau) to the
    trace (i, j), with g a Gaussian envelope of standard deviation sigma_t and
    tau the two-way time. Geometric spreading and directivity are left out.
    """
    m_count = len(elements)
    data = [[[0j] * ns for _ in range(m_count)] for _ in range(m_count)]
    for (sx, sz, amp) in scatterers:
        d = one_way_times(sx, sz, elements, c)
        for i in range(m_count):
            for j in range(m_count):
                tau = d[i] + d[j]
                rot = amp * cmath.exp(-2j * math.pi * f0 * tau)
                lo = max(0, math.ceil((tau - 5 * sigma_t - t0) * fs))
                hi = min(ns - 1, math.floor((tau + 5 * sigma_t - t0) * fs))
                trace = data[i][j]
                for k in range(lo, hi + 1):
                    dt = t0 + k / fs - tau
                    trace[k] += rot * math.exp(-dt * dt / (2 * sigma_t * sigma_t))
    return data


def sample(trace, t, t0, fs, f0):
    """The analytic RF value r(t) from a baseband trace, by linear interpolation."""
    u = (t - t0) * fs  # @line L9
    k = math.floor(u)
    phi = u - k
    if k < 0 or k + 1 >= len(trace):  # @line L10
        return 0j
    return ((1 - phi) * trace[k] + phi * trace[k + 1]) * cmath.exp(2j * math.pi * f0 * t)  # @line L11


def tfm_complex(data, elements, xs, zs, t0, fs, f0, c=SOUND_SPEED):
    """The complex TFM image before the modulus: rows follow zs, columns follow xs."""
    m_count = len(elements)
    image = []
    for pz in zs:  # @line L1
        row = []
        for px in xs:
            d = one_way_times(px, pz, elements, c)  # @line L2
            acc = 0j  # @line L3
            for i in range(m_count):  # @line L4
                for j in range(m_count):  # @line L5
                    acc += sample(data[i][j], d[i] + d[j], t0, fs, f0)  # @line L6
            row.append(acc)
        image.append(row)
    return image


def tfm(data, elements, xs, zs, t0, fs, f0, c=SOUND_SPEED):
    """The TFM image |sum_ij r_ij(d_i + d_j)| on the grid xs by zs."""
    image = [[abs(v) for v in row] for row in tfm_complex(data, elements, xs, zs, t0, fs, f0, c)]  # @line L7
    return image  # @line L8


def tfm_half(data, elements, xs, zs, t0, fs, f0, c=SOUND_SPEED):
    """TFM that uses reciprocity: only pairs i <= j, the pairs i < j counted twice.

    It equals tfm when D[i][j] = D[j][i], and does about half the work.
    """
    m_count = len(elements)
    image = []
    for pz in zs:
        row = []
        for px in xs:
            d = one_way_times(px, pz, elements, c)
            acc = 0j
            for i in range(m_count):
                acc += sample(data[i][i], 2 * d[i], t0, fs, f0)
                for j in range(i + 1, m_count):
                    acc += 2 * sample(data[i][j], d[i] + d[j], t0, fs, f0)
            row.append(abs(acc))
        image.append(row)
    return image


def tfm_adjoint(image, elements, xs, zs, t0, fs, f0, ns, c=SOUND_SPEED):
    """The exact adjoint of tfm_complex: spread each pixel value into the data.

    For each pixel and pair, the interpolation weights and the conjugate phase
    put the value back on the two samples that SAMPLE read.
    """
    m_count = len(elements)
    data = [[[0j] * ns for _ in range(m_count)] for _ in range(m_count)]
    for iz, pz in enumerate(zs):
        for ix, px in enumerate(xs):
            v = image[iz][ix]
            d = one_way_times(px, pz, elements, c)
            for i in range(m_count):
                for j in range(m_count):
                    t = d[i] + d[j]
                    u = (t - t0) * fs
                    k = math.floor(u)
                    if k < 0 or k + 1 >= ns:
                        continue
                    phi = u - k
                    w = v * cmath.exp(-2j * math.pi * f0 * t)
                    data[i][j][k] += (1 - phi) * w
                    data[i][j][k + 1] += phi * w
    return data
test_total_focusing_method.py 110 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/total-focusing-method/. The authors are listed in prov/91YVZD.jsonl.

import cmath
import math
import random

from total_focusing_method import (element_positions, one_way_times, sample, simulate_fmc, tfm,
                                   tfm_adjoint, tfm_complex, tfm_half)

M = 16
PITCH = 0.3
F0, SIGMA, FS, T0, NS = 5.0, 0.1, 40.0, 7.0, 140
ELEMENTS = element_positions(M, PITCH)
XS = [round(-0.7 + 0.1 * k, 10) for k in range(15)]
ZS = [round(5.7 + 0.05 * k, 10) for k in range(13)]


def _peak(img):
    return max((v, i, j) for i, row in enumerate(img) for j, v in enumerate(row))


def test_peak_at_the_scatterer_with_full_coherent_gain() -> None:
    data = simulate_fmc(ELEMENTS, [(0.0, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    img = tfm(data, ELEMENTS, XS, ZS, T0, FS, F0)
    v, i, j = _peak(img)
    assert abs(XS[j]) < 1e-9 and abs(ZS[i] - 6.0) < 1e-9
    # every one of the M^2 pairs adds the value 1 in phase; linear interpolation loses under 1 percent
    assert abs(v - M * M) < 0.01 * M * M


def test_matches_the_analytic_sum_without_sampling() -> None:
    scat = [(0.0, 6.0, 1.0), (0.4, 6.2, 0.5)]
    data = simulate_fmc(ELEMENTS, scat, F0, SIGMA, FS, T0, NS)
    got = tfm_complex(data, ELEMENTS, XS[::4], ZS[::4], T0, FS, F0)
    for a, pz in enumerate(ZS[::4]):
        for b, px in enumerate(XS[::4]):
            d = one_way_times(px, pz, ELEMENTS)
            want = 0j
            for sx, sz, amp in scat:
                ds = one_way_times(sx, sz, ELEMENTS)
                for i in range(M):
                    for j in range(M):
                        dt = d[i] + d[j] - ds[i] - ds[j]
                        want += amp * math.exp(-dt * dt / (2 * SIGMA ** 2)) * cmath.exp(2j * math.pi * F0 * dt)
            assert abs(got[a][b] - want) < 0.01 * M * M


def test_half_matrix_equals_full_matrix_for_reciprocal_data() -> None:
    data = simulate_fmc(ELEMENTS, [(0.2, 6.1, 1.0), (-0.3, 6.3, 0.7)], F0, SIGMA, FS, T0, NS)
    full = tfm(data, ELEMENTS, XS[::2], ZS[::2], T0, FS, F0)
    half = tfm_half(data, ELEMENTS, XS[::2], ZS[::2], T0, FS, F0)
    for r1, r2 in zip(full, half):
        for v1, v2 in zip(r1, r2):
            assert abs(v1 - v2) < 1e-9 * M * M


def test_adjoint() -> None:
    rng = random.Random(9101)
    m, ns = 5, 60
    el = element_positions(m, 0.4)
    xs, zs = [-0.3, 0.0, 0.25], [4.0, 4.1]
    t0 = 5.0
    data = [[[complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in range(ns)] for _ in range(m)] for _ in range(m)]
    img = [[complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in xs] for _ in zs]
    ad = tfm_complex(data, el, xs, zs, t0, FS, F0)
    back = tfm_adjoint(img, el, xs, zs, t0, FS, F0, ns)
    lhs = sum(ad[i][j].conjugate() * img[i][j] for i in range(len(zs)) for j in range(len(xs)))
    rhs = sum(data[i][j][k].conjugate() * back[i][j][k] for i in range(m) for j in range(m) for k in range(ns))
    na = math.sqrt(sum(abs(v) ** 2 for row in ad for v in row))
    ni = math.sqrt(sum(abs(v) ** 2 for row in img for v in row))
    assert abs(lhs - rhs) <= 1e-10 * na * ni


def test_linear_in_the_data() -> None:
    d1 = simulate_fmc(ELEMENTS, [(0.0, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    d2 = simulate_fmc(ELEMENTS, [(0.3, 6.2, -0.8)], F0, SIGMA, FS, T0, NS)
    d12 = simulate_fmc(ELEMENTS, [(0.0, 6.0, 1.0), (0.3, 6.2, -0.8)], F0, SIGMA, FS, T0, NS)
    a = tfm_complex(d1, ELEMENTS, XS[::3], ZS[::3], T0, FS, F0)
    b = tfm_complex(d2, ELEMENTS, XS[::3], ZS[::3], T0, FS, F0)
    c = tfm_complex(d12, ELEMENTS, XS[::3], ZS[::3], T0, FS, F0)
    for ra, rb, rc in zip(a, b, c):
        for va, vb, vc in zip(ra, rb, rc):
            assert abs(va + vb - vc) < 1e-9


def test_two_close_scatterers_are_resolved() -> None:
    data = simulate_fmc(ELEMENTS, [(-0.4, 6.0, 1.0), (0.4, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    prof = tfm(data, ELEMENTS, XS, [6.0], T0, FS, F0)[0]
    left, mid, right = prof[XS.index(-0.4)], prof[XS.index(0.0)], prof[XS.index(0.4)]
    assert mid < 0.7 * min(left, right)


def test_narrower_than_one_transmit_with_dynamic_receive() -> None:
    data = simulate_fmc(ELEMENTS, [(0.0, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    full = tfm(data, ELEMENTS, XS, [6.0], T0, FS, F0)[0]
    tx = M // 2 - 1
    one = []
    for px in XS:
        d = one_way_times(px, 6.0, ELEMENTS)
        one.append(abs(sum(sample(data[tx][j], d[tx] + d[j], T0, FS, F0) for j in range(M))))
    width_full = sum(1 for v in full if v >= 0.5 * max(full))
    width_one = sum(1 for v in one if v >= 0.5 * max(one))
    assert width_full < width_one


def test_pixel_outside_the_recorded_window_is_zero() -> None:
    data = simulate_fmc(ELEMENTS, [(0.0, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    img = tfm(data, ELEMENTS, [0.0], [2.0, 12.0], T0, FS, F0)
    assert img[0][0] == 0.0 and img[1][0] == 0.0

History

Synthetic aperture methods with one transmitting element at a time come from radar and from the synthetic aperture focusing technique of ultrasonic testing. In medical ultrasound the same sum over all transmit and receive pairs is synthetic transmit aperture imaging (Jensen, Nikolov, Gammelmark and Pedersen 2006 give an overview). Holmes, Drinkwater and Wilcox (2005) named the acquisition full matrix capture and the image formation the total focusing method, and showed better images than conventional array imaging on test specimens. Drinkwater and Wilcox (2006) placed TFM in their review of ultrasonic arrays for nondestructive evaluation. TFM is now a standard mode of phased array flaw detectors.

References

  1. Caroline Holmes, Bruce W. Drinkwater and Paul D. Wilcox, Post-processing of the full matrix of ultrasonic transmit-receive array data for non-destructive evaluation, NDT and E International 38(8), 2005, 701 to 711, the full matrix capture, the total focusing method and its comparison with conventional array imaging (general locator)
  2. Bruce W. Drinkwater and Paul D. Wilcox, Ultrasonic arrays for non-destructive evaluation: A review, NDT and E International 39(7), 2006, 525 to 541, the section on array data acquisition and post-processing, including full matrix capture and TFM (general locator)
  3. Jorgen Arendt Jensen, Svetoslav Ivanov Nikolov, Kim Lokke Gammelmark and Morten Hogholm Pedersen, Synthetic aperture ultrasound imaging, Ultrasonics 44 (supplement), 2006, e5 to e15, synthetic transmit aperture imaging with one element per emission, the same sum in medical ultrasound (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