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).
- Solves
- Beamforming
- 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
- Model
- Real RAM
- Properties
- deterministicnot exactlinear in dataiterative
- Evidence
- Proof sketchCode in 1 languages
- 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 elements of an array fires in turn and all 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 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 for an 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 , : the trace recorded by element when element fires, as complex baseband (IQ) samples at . The analytic radio frequency (RF) signal is , where is the baseband signal and the center frequency (see analytic signal). The array lies on with element at , and the medium has a constant speed of sound . The output is an image on a grid of pixels , , that is large where a scatterer is. The pulse-echo model gives the data of a point scatterer at : an echo in trace at the time .
The algorithm
TFM(D, e_1 … e_M, pixels, c, f_s, t_0, f_0) ▷ returns the image I- 1
for each pixel p do - 2
d_i ← |p - e_i| / c for i = 1 … M ▷ one-way times - 3
acc ← 0 - 4
for i ← 1 to M do ▷ transmit element - 5
for j ← 1 to M do ▷ receive element - 6
acc ← acc + SAMPLE(D_ij, d_i + d_j) - 7
I(p) ← |acc| - 8
return I SAMPLE(b, t) ▷ analytic RF value of an IQ trace at time t- 9
u ← (t - t_0) f_s; k ← ⌊u⌋; φ ← u - k - 10
if k < 0 or k + 1 ≥ T then return 0 - 11
return ((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 then uses : out from , back to . SAMPLE interpolates the baseband trace linearly and restores the carrier phase at the exact time . 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 elements with pitch 0.3 mm, centered at , so the outer elements are at mm. The speed of sound is mm/us (1540 m/s), MHz (wavelength 0.308 mm), MHz, and the pulse has a Gaussian envelope with us. One point scatterer of amplitude 1 sits at mm.
For the pixel , line L2 gives us for the outer element and us for an inner one. The pair is read at us and the pair at us. These are exactly the times of the simulated echoes, so all 256 terms are close to , and the pixel value is . Theorem 2 of the proof gives for exact samples; the small loss comes from the linear interpolation.
The lateral profile at mm, normalized to its peak, at 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 mm, the TFM profile drops to of the peak at , 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 , so the pixel value is . 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 force the points to be equal. If the data is reciprocal, , 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 , no attenuation, spreading or directivity. In a real specimen, an error in 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 . They are theorems about that model, not about a real specimen.
Setting. The elements are , , with distinct . For a pixel with , line L2 computes . The data is a complex baseband trace sampled at . SAMPLE (lines L8 to L10) returns , where is the linear interpolation of the samples of , and outside the recorded window. TFM returns with .
Theorem 1 (linearity and the adjoint). is a linear map from the data to the complex image. The map that adds with the weights and to the two samples that SAMPLE read for the pixel value is its adjoint: for all data and images .
Proof. For a fixed pixel and pair, SAMPLE at time returns , or , where and depend only on . This is a linear form with fixed complex weights . A sum of linear forms is linear. For one form, , so the adjoint puts on sample , which is what tfm_adjoint does. Summing over pairs and pixels gives the identity.
Theorem 2 (a point scatterer). Let the data be exact samples of one point scatterer at , : with , a real envelope with for , and assume SAMPLE reads without interpolation error inside the window. Then:
- with ;
- ;
- for every pixel , and for equality holds only at .
Proof. Part 1: the analytic value at is . Part 2: at every is , so the terms all equal . Part 3: by the triangle inequality . Equality needs for every pair, so for all . The diagonal pairs give , that is for every . Take two elements with . Subtracting the squared equations for gives , so , and then with gives .
The Gaussian envelope of the code satisfies the hypothesis on . In the tests the interpolation error is not zero, so the measured peak is for ; the test allows 1 percent.
Theorem 3 (reciprocity). If for all , then , which is what tfm_half computes with reads in place of .
Proof. The time is symmetric in and , and so is the trace by hypothesis. The terms of the pairs and are therefore equal, and the full sum splits into the diagonal and twice the strict upper triangle.
Linear acoustics with a reciprocal medium gives up to noise; the simulator of the code has it exactly.
Theorem 4 (cost). TFM reads samples per pixel, so an grid costs calls of SAMPLE, each , plus for the times of line L2. The extra space is per pixel, besides the data of size and the image.
Proof. Lines L4 to L6 run times per pixel, and SAMPLE does a fixed number of operations. Line L2 computes square roots per pixel.
Remark on the interpolation. Linear interpolation of the baseband envelope has error at most with , and the phase factor is exact. Interpolating the RF signal itself would need several times for the same error, because the RF signal oscillates at . This is why the code works on IQ data.
Complexity
In the real-RAM model, lines L4 to L6 run times per pixel, and SAMPLE costs . An image therefore costs operations, plus square roots in L2. The extra space is for the times, besides the data of size and the image of size . With and a grid this is about samples per frame. Reciprocity halves the reads (Theorem 3 of the proof).
The data acquisition costs 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 ).
- Focused on transmit and receive at every pixel. The focus does not depend on a transmit focal depth chosen before the scan.
- Gain for a point scatterer under exact sampling, against for receive-only focusing of one transmit.
- Uses all of the data. The data needs samples, which is 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 and count the pairs 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 terms to suppress clutter.
- Other transmissions. Plane-wave compounding fires all elements with tilts and needs fewer firings; SAFT uses only the diagonal .
- Layered media. In nondestructive testing through a wedge or an immersion layer, the times 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 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 . A wrong 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 (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.
# 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
- 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)
- 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)
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 91YVZD Edit this page History Report an error Markdown