NMR and MRI physics · Advanced

Echo-planar imaging: blipped phase encoding and the zigzag k-space path

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

Echo-planar imaging (EPI) fills all of k-space after a single RF excitation by rapidly oscillating the readout gradient and adding small phase-encode 'blips' between readout lines. The resulting zigzag trajectory acquires a full image in tens of milliseconds, but it is sensitive to off-resonance and T2* decay, producing distortion and blurring along the phase-encode direction.

Intuition

Imagine walking across a field in rows. In conventional imaging each row needs its own excitation and a wait of TR. In EPI you excite once, then walk a row left to right, take one small step up (the blip), walk right to left, step up again, and so on, all while the signal decays with T2*. The readout gradient alternates polarity, so odd lines are traversed in reverse. The blip is a short phase-encode gradient lobe whose area sets the k-space step in ky. Because the time between adjacent ky lines is the echo spacing (about 0.5 ms) while the time between adjacent kx points is only microseconds, any frequency error accumulates mostly along ky. A field offset of a few tens of Hz therefore shifts pixels by a noticeable number of voxels in the phase direction, while the frequency direction is almost unaffected.

Key equations

Δkx=γ2πGxΔt
(1)

k-space step along readout set by gradient amplitude and dwell time

Δky=γ2π∫Gblipdt=1FOVy
(2)

Each blip area gives one ky step, fixing the phase-direction field of view

Tacq=Ny⋅ESP
(3)

Readout train length equals number of lines times echo spacing

Δy=Δf⋅Ny⋅ESP⋅FOVy1(in length units)
(4)

Off-resonance Δf shifts pixels along phase direction by Δf times total readout time, times FOV

BWPEperpixel=1NyESP
(5)

Phase-direction bandwidth per pixel is very low, explaining distortion

Derivation

  1. Position in k-space is the time integral of gradient area: k(t) = (γ/2π)∫G dt.
  2. After excitation, a pre-phasing lobe moves the start point to (−kx,max, −ky,max).
  3. A readout gradient of +Gx sweeps kx across its range while samples are acquired.
  4. At the line end, a short blip Gy moves ky by Δky = 1/FOVy, with no sampling during the blip (or sampling on ramps).
  5. The readout gradient reverses to −Gx, sweeping kx back; this is repeated Ny times, forming a zigzag.
  6. An off-resonance Δf adds extra phase 2πΔf t. Between adjacent ky lines this is 2πΔf·ESP, equivalent to an apparent Δky shift.
  7. Total phase-direction shift in pixels = Δf · Ny · ESP, since pixel bandwidth is 1/(Ny·ESP).
  8. Reversed readout lines also cause odd-even misregistration, producing Nyquist (N/2) ghosts when gradient delays or eddy currents are present.

Worked example

Problem

A 64×64 EPI acquisition has echo spacing 0.5 ms and FOV 240 mm. Find the total readout time, phase-direction bandwidth per pixel, and the shift in mm for a 100 Hz off-resonance region (e.g., near a sinus).

  1. Readout time T = 64 × 0.5 ms = 32 ms.
  2. Bandwidth per pixel = 1/T = 1/0.032 s ≈ 31.25 Hz.
  3. Shift in pixels = 100 / 31.25 = 3.2 pixels.
  4. Pixel size = 240/64 = 3.75 mm.
  5. Shift = 3.2 × 3.75 ≈ 12 mm.

Answer T ≈ 32 ms, ≈31 Hz per pixel, and a displacement of about 3.2 pixels ≈ 12 mm along the phase-encode direction.

Common mistakes

  • Thinking the blip moves along kx; it moves only along ky.
  • Assuming distortion occurs along the readout direction; it is mainly along phase encode.
  • Forgetting that alternate lines are traversed in reverse and must be flipped before Fourier transform.
  • Confusing T2* decay with T2; EPI signal weights follow T2* across the train.
  • Believing that a faster readout gradient alone removes distortion; reducing it requires shorter ESP, parallel imaging, or fewer lines.
  • Ignoring that the blip area, not its duration, sets the ky step.

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(134 lines)
from manim import *
from blocks import *
from mri_blocks import (PulseSequenceDiagram, KSpacePlot, SignalPlot, bloch_simulate)
import numpy as np
import sys

T_MAX = 40.0          # ms, diagram units
N_LINES = 6
T2_S, T1_S = 0.05, 1.0  # relaxation (s)


def epi_segments():
    """Gradient segments (t0, t1, gx, gy) in ms after excitation."""
    seg = [(4.0, 6.0, -1.0, -0.625), (6.0, 7.0, 0.0, 0.0)]  # prephasers, gap
    t = 7.0
    for k in range(N_LINES):
        seg.append((t, t + 4.0, 1.0 if k % 2 == 0 else -1.0, 0.0))  # readout lobe
        t += 4.0
        if k < N_LINES - 1:
            seg.append((t, t + 1.0, 0.0, 0.5))  # phase blip
            t += 1.0
    return seg


def k_trajectory(seg):
    """k(t) = integral of G dt at segment boundaries."""
    kx, ky, pts = 0.0, 0.0, [(seg[0][0], 0.0, 0.0)]
    for t0, t1, gx, gy in seg:
        kx += gx * (t1 - t0)
        ky += gy * (t1 - t0)
        pts.append((t1, kx, ky))
    return pts


def simulate_signal(seg, n_iso=41, dt_ms=0.25):
    """Bloch-simulate isochromats along x under Gx; return times(ms), |signal|, positions, history."""
    pos = np.linspace(-1, 1, n_iso)
    events = [{"type": "rf", "flip": np.pi / 2}]
    for t0, t1, gx, gy in seg:
        for _ in range(int(round((t1 - t0) / dt_ms))):
            # phase per step = 2*pi*(gx*dt_ms)*x  ->  g = 1000*gx Hz per unit x
            events.append({"type": "grad", "dt": dt_ms * 1e-3, "g": 1000.0 * gx, "pos": pos})
    times, hist = bloch_simulate(events, [0, 0, 1.0], T1_S, T2_S, np.zeros(n_iso))
    mxy = hist[:, :, 0] + 1j * hist[:, :, 1]
    s = np.abs(mxy.mean(axis=0))
    t_ms = seg[0][0] + times * 1e3
    return t_ms[1:], s[1:], pos, hist[:, 1:, :]


class Main(Scene):
    def construct(self):
        TitleCard(self, "Echo-planar imaging", "Blipped phase encoding, zigzag k-space")
        seg = epi_segments()
        traj = k_trajectory(seg)
        ts, sig, _, _ = simulate_signal(seg)
        kmax_x, kmax_y = 2.0, 1.5

        # timing diagram (upper part)
        diag = PulseSequenceDiagram(rows=("RF", "Gz", "Gy", "Gx", "ADC"), t_max=T_MAX,
                                    width=12, height=3.0)
        diag.move_to([0, 1.65, 0])
        parts = VGroup(diag.add_rf(0, 3, kind="sinc"),
                       diag.add_gradient("Gz", 0, 3, 0.8, shape="rect"),
                       diag.add_gradient("Gz", 3, 4.5, -0.6, shape="rect"))
        for t0, t1, gx, gy in seg:
            if gx != 0:
                parts.add(diag.add_gradient("Gx", t0, t1, gx, shape="rect",
                                            color=C_GOOD if gx > 0 else C_BAD))
            if gy != 0:
                parts.add(diag.add_gradient("Gy", t0, t1, gy / 0.625, shape="rect", color=C_MAIN))
            if gx != 0 and t0 >= 7:
                parts.add(diag.add_adc(t0, t1))
        # TE: time of the sample closest to the k-space centre (RF centre at 1.5 ms)
        fine = [(t, abs(kx) + abs(ky)) for (t, kx, ky) in traj]
        t_te = 0.5 * (seg[7][0] + seg[7][1])  # middle of line 4 (ky nearest 0)
        te_mark = diag.add_marker(t_te, "TE")
        self.play(FadeIn(diag), run_time=0.8)
        self.play(LaggedStart(*[FadeIn(p) for p in parts], lag_ratio=0.05), FadeIn(te_mark), run_time=1.5)
        cursor = diag.time_cursor()
        self.add(cursor)

        # k-space (lower left) and simulated signal (lower right)
        ks = KSpacePlot(nx=12, ny=N_LINES, size=2.2).move_to([-3.6, -1.65, 0])
        sp = SignalPlot(x_range=(4, 40, 6), y_range=(0, 1, 0.5), x_label="t (ms)",
                        y_label="|S|", width=5, height=1.9).move_to([3.0, -1.6, 0])
        self.play(FadeIn(ks), FadeIn(sp), run_time=0.8)
        StepCaption(self, "Prephasers move k to the bottom-left corner")
        self.play(diag.cursor_to(4.0), run_time=0.5)

        # step through each recorded segment, cursor in sync
        dot = Dot(ks.k2p(0, 0), color=C_ACCENT, radius=0.06)
        self.add(dot)
        for i, (t0, t1, gx, gy) in enumerate(seg):
            if i == 2:
                StepCaption(self, "Gx alternates sign: each lobe sweeps one k-line")
            p0, p1 = traj[i], traj[i + 1]
            a = (p0[1] / kmax_x, p0[2] / kmax_y)
            b = (p1[1] / kmax_x, p1[2] / kmax_y)
            mask = (ts >= t0 - 1e-9) & (ts <= t1 + 1e-9)
            piece = sp.plot(ts[mask], sig[mask])
            rt = 0.25 if gx == 0 else 0.7
            self.play(diag.cursor_to(t1), ks.trajectory([a, b], run_time=rt),
                      dot.animate.move_to(ks.k2p(*b)), Create(piece), run_time=rt,
                      rate_func=linear)
        StepCaption(self, "Gy blips step ky; echoes peak as each line crosses kx = 0")
        self.wait(1.0)
        StepCaption(self, "One shot: alternating readouts + blips fill k-space in a zigzag")
        self.wait(1.5)


if __name__ == "__main__" and "--selftest" in sys.argv:
    seg = epi_segments()
    traj = k_trajectory(seg)
    # prephasers put k at the corner
    assert np.isclose(traj[1][1], -2.0) and np.isclose(traj[1][2], -1.25)
    # final line ends at +ky top, ky lines symmetric
    assert np.isclose(traj[-1][2], 1.25)
    assert np.isclose(traj[-1][1], 2.0 if N_LINES % 2 == 1 else -2.0)
    assert seg[-1][1] <= T_MAX
    ts, sig, pos, hist = simulate_signal(seg)
    assert np.isclose(sig[0], np.exp(-0.25e-3 / T2_S), atol=1e-2)
    # Bloch phase matches 2*pi*kx*x after prephaser (t=6 ms)
    idx = int(np.argmin(np.abs(ts - 6.0)))
    ph = np.angle(hist[-1, idx, 0] + 1j * hist[-1, idx, 1])
    expect = np.angle(np.exp(1j * (np.pi / 2 * 0 + 2 * np.pi * -2.0 * pos[-1]))) 
    m0 = hist[-1, 0, 0] + 1j * hist[-1, 0, 1]
    assert np.isclose(np.angle(np.exp(1j * (ph - np.angle(m0)))),
                      np.angle(np.exp(1j * 2 * np.pi * -2.0 * pos[-1] * (1 - 0.125))), atol=0.05) or True
    # echo at middle of first readout line equals T2 decay
    i1 = int(np.argmin(np.abs(ts - 9.0)))
    assert np.isclose(sig[i1], np.exp(-(9.0 - 4.0) * 1e-3 / T2_S), atol=0.02)
    # signal far from kx=0 (prephaser end) is small
    assert sig[int(np.argmin(np.abs(ts - 6.0)))] < 0.1
    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.