NMR and MRI physics · Advanced

Echo-planar k-space trajectory

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 while a small blipped phase-encode gradient steps through ky. The result is a zigzag (blipped) trajectory that acquires a whole slice in tens of milliseconds, at the cost of sensitivity to off-resonance and T2* effects.

Intuition

Think of k-space as a sheet of graph paper, and the gradients as steering a pen. The pen position is the time integral of gradient area. A strong readout gradient Gx moves the pen horizontally along a line, collecting one row of data. Reversing Gx sends the pen back the other way, so every line is traversed in opposite direction to its neighbour. Between lines, a short phase-encode blip Gy nudges the pen up by one step in ky. Repeating this builds a serpentine path covering the whole sheet. Because everything happens during one T2* decay, later lines have less signal and accumulate phase errors from field inhomogeneity. Phase accumulates slowly along ky (long time between lines) so off-resonance appears mainly as distortion and shift along the phase-encode direction.

Key equations

kx(t)=γ2π∫0tGx(τ)dτ
(1)

Position along kx is the accumulated readout gradient area.

ky(t)=γ2π∫0tGy(τ)dτ
(2)

Position along ky is the accumulated blip area; each blip moves ky by Δky.

Δky=1FOVy
(3)

Blip area sets the phase-encode step and thus the field of view in y.

Δyshift=ΔB0γ/2πBWPE with BWPE=1Δtesp
(4)

Off-resonance shift in the phase direction is frequency offset times the echo spacing, expressed in pixels, so it is large because the effective PE bandwidth is low.

Tacq=NyΔtesp
(5)

Total readout duration is number of lines times echo spacing.

Derivation

  1. Start with the signal S(t)=∫ρ(x,y) exp(-i2π(kx x+ky y)) dx dy, where k is the gradient integral.
  2. After excitation, apply a pre-phasing lobe so the pen starts at (-kxmax, -kymax).
  3. Apply Gx of constant amplitude: kx increases linearly at rate γGx/2π, sampling one line at the ADC dwell time.
  4. At the line end, reverse Gx so kx decreases; at each reversal apply a Gy blip of area A giving Δky = γA/2π = 1/FOVy.
  5. Repeat Ny times, giving a serpentine path covering Ny lines.
  6. Because lines alternate direction, odd lines are time-reversed; reverse them before Fourier transform and correct phase mismatch between odd and even echoes (Nyquist ghost correction).
  7. Off-resonance Δf adds phase 2πΔf t; between neighbouring ky lines t differs by echo spacing, so the effective PE bandwidth per pixel is 1/(Ny·Δt_esp), giving a pixel shift of Δf·Ny·Δt_esp.

Worked example

Problem

A 64×64 single-shot EPI has echo spacing 0.5 ms. At 3 T, a region near an air cavity is off-resonance by 100 Hz. Find the acquisition time and the pixel shift in the phase direction.

  1. Acquisition time = 64 × 0.5 ms = 32 ms.
  2. Phase-encode bandwidth per pixel = 1/(Ny·Δt_esp) = 1/0.032 s = 31.25 Hz per pixel.
  3. Shift = 100 Hz / 31.25 Hz per pixel = 3.2 pixels.
  4. The readout direction bandwidth is much higher (tens of kHz), so the shift there is negligible.

Answer 32 ms acquisition; about 3.2 pixel displacement along the phase-encode direction.

Common mistakes

  • Thinking each line needs a new excitation; in single-shot EPI there is only one RF pulse.
  • Forgetting that alternate lines run in opposite directions and must be reversed before reconstruction.
  • Assuming distortion occurs along the readout direction; it is mainly along phase encoding.
  • Confusing blip area with amplitude: Δky depends on gradient area, not peak strength.
  • Ignoring T2* decay across the echo train, which blurs the image along y.

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(196 lines)
import sys
import numpy as np
from manim import *
from blocks import *

BG = "#0e1117"

def epi_trajectory(n_lines=10, phase_step=0.2):
    """
    Compute the k-space trajectory for a single-shot EPI sequence.
    Returns a list of (kx, ky) points.
    """
    # Readout duration per line
    t_readout = 1.0
    # Number of points per line (simplified)
    n_points = 20
    
    # Time step
    dt = t_readout / n_points
    
    # Total time includes phase encoding blips
    # We simulate the trajectory point by point
    trajectory = []
    
    # Current k-space position
    kx = 0.0
    ky = 0.0
    
    # Number of phase encoding lines
    n_lines_actual = n_lines
    
    for line_idx in range(n_lines_actual):
        # Determine ky for this line
        ky = (line_idx - n_lines_actual / 2) * phase_step
        
        # Readout: sweep kx from -kmax to +kmax (or vice versa)
        # Direction alternates
        direction = 1 if line_idx % 2 == 0 else -1
        
        for pt_idx in range(n_points):
            # Interpolate kx across the readout window
            # Start at -kmax, end at +kmax (or vice versa)
            t_frac = pt_idx / (n_points - 1)
            kx_start = -1.0 * direction
            kx_end = 1.0 * direction
            kx = kx_start + (kx_end - kx_start) * t_frac
            
            trajectory.append((kx, ky))
            
            # Add a small blip to ky at the end of readout (except last line)
            if pt_idx == n_points - 1 and line_idx < n_lines_actual - 1:
                # The blip happens after the readout, moving to next ky
                # We'll handle this as a separate segment or just jump
                # For simplicity, we'll just add the next line's ky at the end
                pass
                
    # Handle the blips explicitly by inserting intermediate points
    # Re-build with blips
    trajectory_with_blips = []
    for line_idx in range(n_lines_actual):
        ky_current = (line_idx - n_lines_actual / 2) * phase_step
        direction = 1 if line_idx % 2 == 0 else -1
        
        # If not first line, add blip from previous ky to current ky
        if line_idx > 0:
            ky_prev = ((line_idx - 1) - n_lines_actual / 2) * phase_step
            # Blip is vertical movement at kx=0 (or edge)
            # Usually blip is at end of readout
            trajectory_with_blips.append((trajectory_with_blips[-1][0], ky_prev))
            trajectory_with_blips.append((trajectory_with_blips[-1][0], ky_current))
            
        # Readout line
        for pt_idx in range(n_points):
            t_frac = pt_idx / (n_points - 1)
            kx_start = -1.0 * direction
            kx_end = 1.0 * direction
            kx = kx_start + (kx_end - kx_start) * t_frac
            trajectory_with_blips.append((kx, ky_current))
            
    return trajectory_with_blips


class Main(Scene):
    def construct(self):
        self.camera.background_color = BG
        
        TitleCard(self, "EPI Trajectory", "Zigzag through k-space")
        
        # Compute trajectory
        n_lines = 12
        phase_step = 0.3
        traj = epi_trajectory(n_lines, phase_step)
        
        # Create axes
        axes = Axes(
            x_range=[-1.2, 1.2, 0.5],
            y_range=[-2.0, 2.0, 0.5],
            x_length=6.0,
            y_length=5.0,
            axis_config={"color": C_DIM, "include_tip": False}
        )
        axes.to_edge(LEFT, buff=0.5)
        axes.to_edge(DOWN, buff=0.5)
        
        x_label = Text("kx", font_size=24, color=WHITE).next_to(axes.x_axis.get_end(), RIGHT, buff=0.2)
        y_label = Text("ky", font_size=24, color=WHITE).next_to(axes.y_axis.get_end(), UP, buff=0.2)
        
        self.play(Create(axes), FadeIn(x_label), FadeIn(y_label))
        
        # Plot trajectory
        # Convert trajectory points to graph coordinates
        def to_graph_coords(pt):
            return axes.c2p(pt[0], pt[1])
        
        # Create a line for the trajectory
        # We'll build it in segments to animate progressively
        segments = []
        current_points = [to_graph_coords(traj[0])]
        
        # Animate the trajectory line drawing
        # To make it look like a continuous sweep, we'll add points one by one
        # But Manim's Line needs fixed vertices. We'll use a VGroup of small lines or a PolyLine
        
        # Better approach: Use a single Line and update its points? No, that's hard.
        # Use a series of small Line segments that FadeIn
        
        traj_mobs = VGroup()
        
        # Pre-compute all small segments
        all_segments = []
        for i in range(len(traj) - 1):
            p1 = to_graph_coords(traj[i])
            p2 = to_graph_coords(traj[i+1])
            seg = Line(p1, p2, color=C_ACCENT, stroke_width=2)
            all_segments.append(seg)
        
        # Animate them in batches to keep it smooth and fast
        batch_size = 50
        for i in range(0, len(all_segments), batch_size):
            batch = all_segments[i:i+batch_size]
            self.play(*[FadeIn(s) for s in batch], run_time=0.5)
            
        # Add a dot at the end to show current position
        last_pt = to_graph_coords(traj[-1])
        end_dot = Dot(last_pt, color=C_GOOD, radius=0.1)
        self.play(FadeIn(end_dot))
        
        StepCaption(self, "Alternating readout directions with phase blips")
        self.wait(1)
        
        # Highlight a few key features
        # 1. The zigzag pattern
        # 2. The blips
        
        # Let's highlight the first line
        first_line_indices = [i for i, pt in enumerate(traj) if abs(pt[1] - ((0 - n_lines/2) * phase_step)) < 0.01]
        # This is tricky because of floating point. Let's use the structure.
        # Actually, let's just highlight the blips
        
        # Blips occur at the end of each readout line
        # We can highlight the vertical segments
        blip_indices = []
        for i in range(len(traj) - 1):
            p1 = traj[i]
            p2 = traj[i+1]
            # If kx is roughly same and ky changes, it's a blip
            if abs(p1[0] - p2[0]) < 0.1 and abs(p1[1] - p2[1]) > 0.1:
                blip_indices.append(i)
                
        blip_segments = [all_segments[i] for i in blip_indices if i < len(all_segments)]
        
        # Fade out the blip segments to emphasize them? Or color them differently?
        # Let's just add a caption about it.
        
        StepCaption(self, "Blips shift ky between readout lines")
        self.wait(1)
        
        StepCaption(self, "Efficient coverage of k-space")
        self.wait(1)


if __name__ == "__main__" and "--selftest" in sys.argv:
    traj = epi_trajectory(10, 0.2)
    assert len(traj) > 0
    # Check that we have multiple lines
    # The trajectory should start near kx=-1 and end near kx=1 (or vice versa)
    # Check that ky values are discrete steps
    ky_values = [pt[1] for pt in traj]
    unique_ky = sorted(list(set([round(ky, 5) for ky in ky_values])))
    # Should have approximately n_lines unique ky values
    assert len(unique_ky) == 10
    # Check that kx sweeps between -1 and 1
    kx_values = [pt[0] for pt in traj]
    assert min(kx_values) < -0.9
    assert max(kx_values) > 0.9
    print("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.