Algorithm Search⌘K

Algorithmresearch

Delay-multiply-and-sum beamforming

Also called DMAS.

A nonlinear beamformer that sums the signed square roots of the products of all pairs of delayed channel samples. It rewards channels that agree, and a square of sums makes it O(M) per pixel.

Time
O(M n^2) worst
Space
O(M) extra
Where
M = the number of array elements; n = the number of pixels along one side of the image
Properties
deterministicexactnot linear in dataiterative
Origin
Giulia Matrone, Alessandro Stuart Savoia, Giosue Caliano, Giovanni Magenes, 2015

Delay-multiply-and-sum (DMAS) is a nonlinear combiner for beamforming. It uses the same delayed channel samples s1,…,sMs_1, \ldots, s_M as delay-and-sum (DAS), but in place of the sum ∑isi\sum_i s_i it adds the products of all pairs, each with a signed square root so that the output keeps the units of the input: y=∑i<jsign⁡(sisj)∣sisj∣y = \sum_{i<j} \operatorname{sign}(s_i s_j) \sqrt{|s_i s_j|}. A pair contributes a positive value when the two channels agree in sign and a negative value when they do not, so the output is large only where many channels agree. DAS is linear and treats a strong echo on a few channels the same as a weak echo on all of them; DMAS favors the second case. With the signed roots rir_i, the pair sum is ((∑ri)2−∑ri2)/2((\sum r_i)^2 - \sum r_i^2)/2, so DMAS costs O(M)O(M) per pixel, not O(M2)O(M^2).

In plain words

After the delays, each element of the array holds one number for the point you want to see. The usual method adds them up. DMAS instead takes every pair of elements and asks whether they agree. Two elements that agree add to the score, two that disagree take away from it. An echo that truly comes from the point is seen the same way by all elements, so all pairs agree and the score is high. Noise and echoes from other places are seen differently by different elements, so the pairs cancel. A square root on each product keeps the result at the same scale as a plain sum.

The problem

The input of the combiner is a real vector s=(s1,…,sM)s = (s_1, \ldots, s_M): the RF samples of the MM channels after the focusing delays of one pixel, as in dynamic receive focusing. The output is the real number y(s)y(s) above. For an image, the combiner is applied at every pixel of an n×nn \times n grid; the RF image is then band-pass filtered, envelope detected and log compressed as in B-mode image formation.

The algorithm

  1. DMAS(s_1 … s_M) ▷ returns the pair sum y
  2. 1r_i ← sign(s_i) √|s_i| for i = 1 … M ▷ signed square roots
  3. 2R ← Σ_i r_i
  4. 3E ← Σ_i |s_i| ▷ equals Σ_i r_i²
  5. 4return (R² - E) / 2

Line L4 is the square of the sum minus the diagonal, which leaves twice the sum over the pairs i<ji < j. In an image, a pixel loop computes the delayed samples (by interpolation of the RF traces at the two-way time) and calls DMAS in place of the plain sum.

Example

For s=(4,1,−1,9)s = (4, 1, -1, 9), line L1 gives r=(2,1,−1,3)r = (2, 1, -1, 3), line L2 gives R=5R = 5, line L3 gives E=15E = 15, and line L4 gives (25−15)/2=5(25 - 15)/2 = 5. The six pairs give 2−2+6−1+3−3=52 - 2 + 6 - 1 + 3 - 3 = 5, the same value. DAS gives 4+1−1+9=134 + 1 - 1 + 9 = 13. The channel with the value −1-1 disagrees with the other three, and in DMAS it takes away from three pairs.

The tests simulate M=16M = 16 elements with pitch 0.3 mm, a plane wave at normal incidence, one scatterer of amplitude 1 at (0,6)(0, 6) mm, f0=5f_0 = 5 MHz, fs=40f_s = 40 MHz and a Gaussian envelope with σt=0.1\sigma_t = 0.1 us. The lateral profile is the largest modulus of the RF output over depths from 5.9 to 6.1 mm, normalized to its peak:

combiner peak value at x = 0.3 mm largest side lobe at abs(x) at least 0.6 mm
DAS 15.11 0.329 0.131
DMAS 113.33 0.095 0.029

At the scatterer the 16 delayed samples are almost equal, so DMAS is close to (162)=120\binom{16}{2} = 120 times one sample, and 120⋅15.11/16=113.3120 \cdot 15.11/16 = 113.3. These are measurements on this simulation without noise and without the band-pass filter; they depend on the array, the pulse and the scene.

Correctness

Line L4 equals the pair sum because each signed product is rirjr_i r_j and ri2=∣si∣r_i^2 = |s_i|. With E=∑∣si∣E = \sum |s_i|, the output lies between −E/2-E/2 and M−12E\frac{M-1}{2} E, and the upper bound holds only when all delayed samples are equal: by the Cauchy-Schwarz inequality, DMAS measures how well the channels agree. The output is homogeneous of degree one in the magnitude, y(as)=∣a∣ y(s)y(a s) = |a|\, y(s), so it loses the sign: for equal channels it is a rectified copy of the signal, with its spectrum at 00 and 2f02 f_0. This is a theorem, and it explains the band-pass filter at 2f02 f_0 of filtered DMAS. The proofs are in proofs/correctness.md.

Proof: The O(M) form of delay-multiply-and-sum equals the pair sum, is bounded by the channel energy, and rectifies the signalfull

We prove five facts about the combiner on the main page (lines L1 to L4). The input is a real vector s=(s1,…,sM)s = (s_1, \ldots, s_M) of delayed RF samples at one pixel. Let ri=sign⁡(si)∣si∣r_i = \operatorname{sign}(s_i) \sqrt{|s_i|} (line L1), R=∑iriR = \sum_i r_i (line L2) and E=∑i∣si∣E = \sum_i |s_i| (line L3). The definition of DMAS is

y(s)=∑1≤i<j≤Msign⁡(sisj)∣sisj∣.y(s) = \sum_{1 \le i < j \le M} \operatorname{sign}(s_i s_j) \sqrt{|s_i s_j|}.

Theorem 1 (the O(M) form). y(s)=(R2−E)/2y(s) = (R^2 - E)/2, which is line L4.

Proof. For every pair, sign⁡(sisj)=sign⁡(si)sign⁡(sj)\operatorname{sign}(s_i s_j) = \operatorname{sign}(s_i) \operatorname{sign}(s_j) and ∣sisj∣=∣si∣∣sj∣\sqrt{|s_i s_j|} = \sqrt{|s_i|} \sqrt{|s_j|}, so each term is rirjr_i r_j. This also holds when si=0s_i = 0 or sj=0s_j = 0, because both sides are then 00. Expand the square: R2=∑iri2+2∑i<jrirjR^2 = \sum_i r_i^2 + 2 \sum_{i < j} r_i r_j, and ri2=∣si∣r_i^2 = |s_i|, so ∑iri2=E\sum_i r_i^2 = E. Solve for the pair sum. □\square

The test compares the two forms on 300 random vectors with some zero entries.

Theorem 2 (bounds). −E/2≤y(s)≤M−12E-E/2 \le y(s) \le \frac{M - 1}{2} E. The lower bound holds with equality if and only if R=0R = 0. The upper bound holds with equality if and only if all rir_i are equal, that is, all sis_i are equal.

Proof. R2≥0R^2 \ge 0 gives the lower bound, with equality exactly when R=0R = 0. By the Cauchy-Schwarz inequality, R2=(∑i1⋅ri)2≤M∑iri2=MER^2 = (\sum_i 1 \cdot r_i)^2 \le M \sum_i r_i^2 = M E, with equality if and only if rr is a multiple of (1,…,1)(1, \ldots, 1). Then y≤(ME−E)/2y \le (M E - E)/2. The map v↦sign⁡(v)∣v∣v \mapsto \operatorname{sign}(v)\sqrt{|v|} is one-to-one, so equal rir_i means equal sis_i. □\square

So, for a fixed channel energy EE, DMAS is largest when all delayed channels agree exactly in value and sign, and for MM equal samples vv it returns M(M−1)2∣v∣\frac{M(M-1)}{2} |v|. The test checks this value for v=±2.25v = \pm 2.25 and v=0v = 0. For the same equal samples, delay-and-sum gives MvM v, which grows like MM and keeps the sign. DMAS grows like M2/2M^2/2 for agreeing channels, and it can be negative (down to −E/2-E/2) when the signed roots cancel, which happens at a pixel where the channels disagree in sign.

Theorem 3 (homogeneity). For every real aa, y(as)=∣a∣ y(s)y(a s) = |a|\, y(s).

Proof. sign⁡(asi)∣asi∣=sign⁡(a)∣a∣ ri\operatorname{sign}(a s_i) \sqrt{|a s_i|} = \operatorname{sign}(a) \sqrt{|a|}\, r_i. Each product rirjr_i r_j is multiplied by sign⁡(a)2∣a∣=∣a∣\operatorname{sign}(a)^2 |a| = |a|. □\square

So the output keeps the dimension of the input (the square root undoes the product), which is the purpose of the signed square root, but it does not keep the sign: y(−s)=y(s)y(-s) = y(s).

Theorem 4 (rectification). Let all channels carry the same delayed signal, si(t)=A(t)cos⁡(2πf0t+φ)s_i(t) = A(t) \cos(2\pi f_0 t + \varphi) for all ii. Then y(s(t))=M(M−1)2∣A(t)∣ ∣cos⁡(2πf0t+φ)∣y(s(t)) = \frac{M(M-1)}{2} |A(t)|\, |\cos(2\pi f_0 t + \varphi)|. For a constant AA this is periodic with period 1/(2f0)1/(2 f_0), so its spectrum lies at 00 and at the multiples of 2f02 f_0, and has nothing at f0f_0.

Proof. Theorem 2 with equal entries gives the first formula. The function ∣cos⁡∣|\cos| has period π\pi, so t↦∣cos⁡(2πf0t+φ)∣t \mapsto |\cos(2\pi f_0 t + \varphi)| has period 1/(2f0)1/(2 f_0), and a periodic function has a Fourier series on the multiples of its base frequency. □\square

This is why the filtered DMAS of Matrone et al. (2015) applies a band-pass filter around 2f02 f_0 to the output before envelope detection: the DC part is removed and the second harmonic band is kept. For channels that differ, the output is no longer a pure rectified signal; the statement about the band at 2f02 f_0 is then a heuristic for narrow-band data, not a theorem.

Theorem 5 (cost). Lines L1 to L4 cost O(M)O(M) per pixel, against O(M2)O(M^2) for the pair sum. An n×nn \times n image costs O(Mn2)O(M n^2), the same order as delay-and-sum.

Proof. Lines L1 and L3 touch each entry once, line L2 is one sum and line L4 is O(1)O(1). □\square

Complexity

In the real-RAM model, lines L1 to L4 cost O(M)O(M) per pixel, so an n×nn \times n image costs O(Mn2)O(M n^2), the same order as DAS, with O(M)O(M) extra space for the delayed samples. The defining pair sum costs O(M2)O(M^2) per pixel. The square root in L1 is one more operation per channel; on hardware the products and the filter cost more than the sum of DAS.

Properties

  • Nonlinear: the output of a sum of two scenes is not the sum of the outputs, so cross terms between scatterers appear.
  • Homogeneous of degree one in the magnitude, even in the sign: y(−s)=y(s)y(-s) = y(s).
  • Gain M(M−1)/2M(M-1)/2 for perfectly aligned channels, against MM for DAS, and a negative output where the channels cancel.
  • The signed square root is a design choice that keeps the units; other exponents give other trade-offs between contrast and speckle. Treat it as tuned, not as derived.
  • Matrone et al. (2015) explain the narrower main lobe by the pairwise products, which act like the autocorrelation of the receive aperture and so like a wider virtual aperture. This is a heuristic argument; the side-lobe and resolution gains are measurements.

Variants and improvements

  • Filtered DMAS (F-DMAS). A band-pass filter around 2f02 f_0 on the RF image removes the DC part of the rectified output before envelope detection (Matrone et al. 2015).
  • Short-lag DMAS. Only the pairs with ∣i−j∣|i - j| up to a lag LL enter the sum, which trades resolution for less speckle variance.
  • Synthetic aperture and plane waves. DMAS can combine the channels of TFM or plane-wave compounding data, over elements, angles or both.
  • Other adaptive weights. The coherence factor also rewards agreement, but as a weight on the DAS output; the Capon beamformer solves for data-dependent linear weights.

When to use it

Use DMAS when contrast and lateral resolution matter more than a linear, well-understood speckle pattern, and the channel data are available after the delays. It is a research method: its nonlinearity changes the speckle statistics and the relation between echo strength and pixel value, so quantitative methods that assume a linear beamformer, such as Doppler and backscatter estimation, should use DAS.

Pitfalls

  • Using the defining double loop. It costs O(M2)O(M^2) per pixel; use the square of sums of L4.
  • No band-pass filter. The raw output has a strong DC part; envelope detection at f0f_0 on it gives a wrong image. Filter around 2f02 f_0 first.
  • Sampling. The output has energy at 2f02 f_0, so the RF sampling must keep that band, or it aliases.
  • IQ data. The signed square root is defined for real samples. For complex baseband data the sign must be replaced, for example by the phase, and the result is a different method.
  • Linear expectations. Two equal scatterers do not give twice the output of one, and weak targets near strong ones are suppressed more than with DAS.

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.

delay_multiply_and_sum.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/delay-multiply-and-sum/. The authors are listed in prov/SF6EBZ.jsonl.
"""Delay-multiply-and-sum (DMAS) beamforming (Matrone et al. 2015).

The input of the combiner is the vector s_1, ..., s_M of real RF channel
samples after the focusing delays of one pixel. DMAS returns

    y = sum over pairs i < j of sign(s_i s_j) sqrt(|s_i s_j|).

With the signed square roots r_i = sign(s_i) sqrt(|s_i|), each term is r_i r_j,
so y = ((sum r_i)^2 - sum r_i^2) / 2, which costs O(M) in place of O(M^2).

The image part uses a plane wave at normal incidence and a linear array on
z = 0, in millimetres, microseconds and megahertz (1540 m/s is 1.54 mm/us).
"""

import math

SOUND_SPEED = 1.54  # mm per microsecond


def signed_sqrt(v):
    """sign(v) sqrt(|v|), with the value 0 at 0."""
    return math.copysign(math.sqrt(abs(v)), v) if v != 0 else 0.0


def dmas(samples):
    """DMAS of one delayed channel vector in O(M), by the square of the sum."""
    r = [signed_sqrt(s) for s in samples]  # @line L1
    total = sum(r)  # @line L2
    energy = sum(abs(s) for s in samples)  # @line L3
    return (total * total - energy) / 2  # @line L4


def dmas_pairs(samples):
    """DMAS by the defining double sum over the pairs i < j, in O(M^2)."""
    m = len(samples)
    y = 0.0
    for i in range(m):
        for j in range(i + 1, m):
            p = samples[i] * samples[j]
            y += math.copysign(math.sqrt(abs(p)), p) if p != 0 else 0.0
    return y


def das(samples):
    """Delay-and-sum of the same delayed samples, for comparison."""
    return sum(samples)


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


def simulate_rf(elements, scatterers, f0, sigma_t, fs, t0, ns, c=SOUND_SPEED):
    """Real RF traces for a plane wave at normal incidence and point scatterers (x, z, amp).

    The pulse is g(t) cos(2 pi f0 t) with a Gaussian envelope g of standard
    deviation sigma_t, delayed by z / c + |p - e_j| / c.
    """
    data = []
    for xj in elements:
        tr = [0.0] * ns
        for (sx, sz, amp) in scatterers:
            tau = sz / c + math.hypot(sx - xj, sz) / c
            lo = max(0, math.ceil((tau - 5 * sigma_t - t0) * fs))
            hi = min(ns - 1, math.floor((tau + 5 * sigma_t - t0) * fs))
            for q in range(lo, hi + 1):
                dt = t0 + q / fs - tau
                tr[q] += amp * math.exp(-dt * dt / (2 * sigma_t * sigma_t)) * math.cos(2 * math.pi * f0 * dt)
        data.append(tr)
    return data


def delayed_samples(data, elements, px, pz, t0, fs, c=SOUND_SPEED):
    """The RF sample of each channel at the two-way time of the pixel, by linear interpolation."""
    out = []
    for xj, tr in zip(elements, data):
        t = pz / c + math.hypot(px - xj, pz) / c
        u = (t - t0) * fs
        q = math.floor(u)
        if q < 0 or q + 1 >= len(tr):
            out.append(0.0)
            continue
        phi = u - q
        out.append((1 - phi) * tr[q] + phi * tr[q + 1])
    return out


def beamform(data, elements, xs, zs, t0, fs, combiner, c=SOUND_SPEED):
    """The RF image combiner(delayed samples) on the grid; rows follow zs."""
    return [[combiner(delayed_samples(data, elements, px, pz, t0, fs, c)) for px in xs] for pz in zs]
test_delay_multiply_and_sum.py 67 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/delay-multiply-and-sum/. The authors are listed in prov/SF6EBZ.jsonl.

import random

from delay_multiply_and_sum import (beamform, das, dmas, dmas_pairs, element_positions, signed_sqrt,
                                    simulate_rf)

F0, SIGMA, FS, T0, NS = 5.0, 0.1, 40.0, 7.0, 120
ELEMENTS = element_positions(16, 0.3)
XS = [round(-1.5 + 0.1 * k, 10) for k in range(31)]
ZS = [round(6.0 + 0.01 * k, 10) for k in range(-10, 11)]


def test_page_example() -> None:
    s = [4.0, 1.0, -1.0, 9.0]
    assert dmas_pairs(s) == 5.0
    assert dmas(s) == 5.0
    assert das(s) == 13.0


def test_fast_form_equals_the_pair_sum() -> None:
    rng = random.Random(3105)
    for _ in range(300):
        m = rng.randint(1, 24)
        s = [rng.uniform(-5, 5) for _ in range(m)]
        if rng.random() < 0.2:
            s[rng.randrange(m)] = 0.0
        assert abs(dmas(s) - dmas_pairs(s)) <= 1e-9 * (1 + sum(abs(v) for v in s) * m)


def test_identical_channels_give_the_rectified_value() -> None:
    for v in (2.25, -2.25, 0.0):
        for m in (1, 2, 5, 16):
            assert abs(dmas([v] * m) - m * (m - 1) / 2 * abs(v)) < 1e-12


def test_homogeneous_of_degree_one_in_the_magnitude() -> None:
    rng = random.Random(3106)
    s = [rng.uniform(-3, 3) for _ in range(10)]
    for a in (4.0, 0.25, -1.0, -9.0):
        assert abs(dmas([a * v for v in s]) - abs(a) * dmas(s)) < 1e-9


def test_signed_sqrt() -> None:
    assert signed_sqrt(9.0) == 3.0 and signed_sqrt(-9.0) == -3.0 and signed_sqrt(0.0) == 0.0


def _profile(combiner):
    data = simulate_rf(ELEMENTS, [(0.0, 6.0, 1.0)], F0, SIGMA, FS, T0, NS)
    img = beamform(data, ELEMENTS, XS, ZS, T0, FS, combiner)
    prof = [max(abs(img[i][j]) for i in range(len(ZS))) for j in range(len(XS))]
    peak = max(prof)
    return [v / peak for v in prof], peak


def test_point_target_peak_and_lower_sidelobes_than_das() -> None:
    p_das, peak_das = _profile(das)
    p_dmas, peak_dmas = _profile(dmas)
    assert p_das.index(1.0) == XS.index(0.0) and p_dmas.index(1.0) == XS.index(0.0)
    # at the peak all 16 aligned samples are close to equal, so DMAS is close to 120 times one of them
    assert abs(peak_dmas - 120 * peak_das / 16) < 0.02 * peak_dmas
    side_das = max(v for x, v in zip(XS, p_das) if abs(x) >= 0.6)
    side_dmas = max(v for x, v in zip(XS, p_dmas) if abs(x) >= 0.6)
    assert side_dmas < 0.5 * side_das
    i3 = XS.index(0.3)
    assert p_dmas[i3] < p_das[i3]

History

Lim, Nhung, Li and Thang (2008) introduced delay-multiply-and-sum to reconstruct images in confocal microwave imaging for the detection of breast cancer. Matrone, Savoia, Caliano and Magenes (2015) brought it to medical ultrasound B-mode imaging with the signed square root and a band-pass filter at the second harmonic, and reported better contrast and resolution than DAS on phantoms and simulations. Many later papers combine it with synthetic aperture and plane-wave imaging.

References

  1. Giulia Matrone, Alessandro Stuart Savoia, Giosue Caliano and Giovanni Magenes, The delay multiply and sum beamforming algorithm in ultrasound B-mode medical imaging, IEEE Transactions on Medical Imaging 34(4), 2015, 940 to 949, the definition with signed square roots, the O(M) computation, the band-pass filtered version at 2 f0, and the comparison with delay-and-sum (general locator)
  2. Hooi Been Lim, Nguyen Thi Tuyet Nhung, Er-Ping Li and Nguyen Duc Thang, Confocal microwave imaging for breast cancer detection: delay-multiply-and-sum image reconstruction algorithm, IEEE Transactions on Biomedical Engineering 55(6), 2008, 1697 to 1704, the original pairwise product algorithm for microwave imaging (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.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
  • at least three sources
  • a scene preset for the example