NMR and MRI physics · Intermediate

CPMG echo train and T2 measurement

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

The CPMG sequence applies a 90 degree pulse followed by a train of 180 degree refocusing pulses, producing a series of spin echoes whose peak amplitudes decay with the true transverse relaxation time T2. Fitting this decay gives T2 while the repeated refocusing cancels static field inhomogeneity and, with short echo spacing, reduces diffusion effects.

Intuition

After a 90 degree pulse, spins precess in the transverse plane at slightly different frequencies because of field inhomogeneity and chemical shift, so they fan out and the signal vanishes quickly (T2*). A 180 degree pulse flips the fan, so the fast spins that were ahead are now behind and catch up. At time 2tau after the excitation the spins realign and an echo forms. Reversible dephasing is undone, but irreversible dephasing from random molecular fluctuations (true T2 processes) cannot be undone. Each echo is therefore a little smaller than the last. CPMG applies the refocusing pulses with a 90 degree phase shift relative to the excitation pulse, so that pulse flip-angle errors cancel on even echoes instead of accumulating. Plotting echo peak heights against time gives a clean exponential decay.

Key equations

S(tn)=S0e−tn/T2
(1)

Echo amplitude at time t_n decays with the true T2.

tn=nTE=2nτ
(2)

The nth echo occurs at n times the echo spacing TE, which is twice the pulse spacing tau.

ln⁡S(tn)=ln⁡S0−tnT2
(3)

Taking logs gives a straight line with slope -1/T2.

1T2∗=1T2+γΔB0
(4)

Observed decay combines intrinsic relaxation and inhomogeneity; the echo removes the second term.

Derivation

  1. Right after the 90∘ pulse, magnetization lies in the transverse plane with magnitude M0.
  2. During time τ, a spin with offset frequency Δω accumulates phase Δω×τ.
  3. A 180 degree pulse about an axis in the plane inverts this phase to minus Δω times τ.
  4. During the next τ the spin gains the same phase again, so the net phase is zero at 2τ regardless of Δω.
  5. Irreversible random-field processes give phases that differ in each interval, so they do not cancel; they cause amplitude loss at rate 1/T2.
  6. Repeating 180 pulses every 2tau gives echoes at 2tau, 4tau, 6tau, and so on, each multiplied by exp(-TE/T2) relative to the previous one.
  7. Therefore the `nth` echo is S0exp⁡(−nTE/T2), and fitting the peaks yields T2.

Worked example

Problem

A CPMG train with TE = 20 ms gives echo amplitudes 80.0 at echo 1 and 29.4 at echo 5. Estimate T2 and the amplitude at echo 10.

  1. Time of echo 1 is 20 ms; time of echo 5 is 100 ms; the interval is 80 ms.
  2. Ratio of amplitudes: 29.4/80.0 = 0.3675.
  3. ln(0.3675) = -1.001.
  4. So 80 ms / T2 = 1.001, giving T2 = about 80 ms.
  5. Echo 10 is at 200 ms, 100 ms after echo 5: 29.4 × exp(-100/80) = 29.4 × 0.2865 = 8.4.

Answer T2 is about 80 ms, and the echo 10 amplitude is about 8.4 (arbitrary units).

Common mistakes

  • Confusing T2 with T2*: a single free induction decay gives T2*, not T2.
  • Using a TE that is too long, so diffusion in gradients shortens the apparent T2.
  • Forgetting that the first echo is at TE, not at time zero, when fitting.
  • Ignoring pulse imperfections or using the wrong pulse phase, causing odd-even echo amplitude oscillation.
  • Fitting a single exponential to a tissue with several T2 components, such as myelin water and free water.

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

scene.py(102 lines)
from manim import *
import numpy as np
import sys
from blocks import *
from mri_blocks import *

# ---- physics parameters (seconds for simulation, ms for the diagram) ----
T2 = 0.080        # true T2 (s)
T1 = 1.0          # T1 (s), irrelevant for the transverse echo amplitudes
TE = 0.020        # echo spacing (s)
N_ECHO = 4
DT = 0.001        # fixed simulation step (s)
N_ISO = 200
SIGMA_HZ = 20.0   # static off-resonance spread (gives T2* decay)


def run_cpmg():
    """Simulate a CPMG train: 90x, then 180y at TE/2 + n*TE; record M at 1 ms steps."""
    dfs = isochromat_offsets(N_ISO, SIGMA_HZ, dist="gaussian", seed=1)
    half = int(round(TE / 2 / DT))
    events = [{"type": "rf", "flip": np.pi / 2, "phase": 0.0}]
    for _ in range(N_ECHO):
        events += [{"type": "wait", "dt": DT}] * half
        events += [{"type": "rf", "flip": np.pi, "phase": np.pi / 2}]
        events += [{"type": "wait", "dt": DT}] * half
    events += [{"type": "wait", "dt": DT}] * half
    times, hist = bloch_simulate(events, [0.0, 0.0, 1.0], T1, T2, dfs)
    mxy = hist[:, :, 0] + 1j * hist[:, :, 1]
    signal = np.abs(mxy.mean(axis=0))
    return times, hist, signal


def index_at(times, t):
    """Index of the last recorded state at time <= t (after any pulse at t)."""
    return int(np.where(times <= t + 1e-9)[0][-1])


TIMES, HIST, SIGNAL = run_cpmg()
ECHO_T = [(k + 1) * TE for k in range(N_ECHO)]
ECHO_S = [SIGNAL[index_at(TIMES, t)] for t in ECHO_T]


class Main(Scene):
    def construct(self):
        TitleCard(self, "CPMG echo train", "Measuring T2 despite field inhomogeneity")

        # ---- timing diagram (ms) ----
        psd = PulseSequenceDiagram(rows=("RF", "ADC"), t_max=90, width=12, height=2.2)
        psd.shift(UP * 2.0)
        parts = [psd.add_rf(0, 3, kind="hard", amp=0.6, label="90x")]
        for k in range(N_ECHO):
            tp = (TE / 2 + k * TE) * 1000
            parts.append(psd.add_rf(tp - 2, tp + 2, kind="hard", amp=1.0,
                                    label="180y" if k == 0 else None, color=C_BAD))
            te = ECHO_T[k] * 1000
            parts.append(psd.add_adc(te - 4, te + 4, color=C_GOOD))
            parts.append(psd.add_marker(te, ["TE", "2TE", "3TE", "4TE"][k]))
        self.play(FadeIn(psd), *[FadeIn(p) for p in parts], run_time=1.5)

        # ---- signal plot and isochromat fan ----
        sp = SignalPlot(x_range=(0, 90, 20), y_range=(0, 1, 0.5), x_label="t (ms)",
                        y_label="|Mxy|", width=7, height=2.5)
        sp.move_to([-2.6, -1.5, 0])
        fan = IsochromatFan(n=12, radius=1.1).move_to([4.3, -1.5, 0])
        cursor = psd.time_cursor()
        self.play(FadeIn(sp), FadeIn(fan), FadeIn(cursor), run_time=1)
        StepCaption(self, "Spins dephase, each 180y pulse flips them, they rephase into an echo")

        # ---- step through the recorded simulation ----
        prev = 0
        for tms in range(5, 95, 5):
            t = tms / 1000
            i = index_at(TIMES, t)
            seg = sp.plot(TIMES[prev:i + 1] * 1000, SIGNAL[prev:i + 1])
            mxy = HIST[:12, i, 0] + 1j * HIST[:12, i, 1]
            self.play(psd.cursor_to(tms), Create(seg),
                      *fan.set_phases(np.angle(mxy), np.abs(mxy)),
                      run_time=0.4, rate_func=linear)
            prev = i

        # ---- echo peaks follow exp(-t/T2) ----
        dots = VGroup(*[sp.dot_at(t * 1000, s, color=C_ACCENT) for t, s in zip(ECHO_T, ECHO_S)])
        tt = np.linspace(0, 0.09, 60)
        env = DashedVMobject(sp.plot(tt * 1000, np.exp(-tt / T2), color=C_ACCENT))
        eq = MathTex(r"S(n\,TE)=S_0\,e^{-n\,TE/T_2}", font_size=32, color=C_ACCENT)
        eq.move_to(sp.axes.c2p(62, 0.85))
        self.play(FadeIn(dots), Create(env), Write(eq), run_time=1.5)
        StepCaption(self, "Echo peaks decay with true T2, not T2*: fit them to get T2")
        self.wait(1.5)


if __name__ == "__main__" and "--selftest" in sys.argv:
    assert abs(SIGNAL[0] - 0.0) < 1e-9                    # before 90: no transverse M
    assert abs(SIGNAL[1] - 1.0) < 1e-9                    # right after 90x: full signal
    mid = SIGNAL[index_at(TIMES, 0.010) - 1]
    assert mid < 0.5                                       # dephased (T2*) before first 180
    for t, s in zip(ECHO_T, ECHO_S):
        assert abs(s - np.exp(-t / T2)) < 0.02, (t, s)    # echoes follow true T2
    assert all(a > b for a, b in zip(ECHO_S, ECHO_S[1:]))
    est = -np.polyfit(ECHO_T, np.log(ECHO_S), 1)[0]
    assert abs(1 / est - T2) < 0.005                       # fitted T2 recovers truth
    print("selftest ok")

The Manim scene code that draws this lesson's animation in the Signals AI app (Python, Manim Community).

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.