NMR and MRI physics · Introductory

Slice selection with gradients

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

In MRI, a magnetic field gradient makes the Larmor frequency vary linearly with position along one axis. A radiofrequency pulse with a limited bandwidth then excites only the slice whose resonance frequencies fall inside that band. Slice position is set by the pulse center frequency, and slice thickness by the bandwidth and gradient strength.

Intuition

Imagine a row of tuning forks, each tuned to a slightly different pitch depending on where it sits along a shelf. If you play a note with a narrow range of pitches, only the forks matching that range ring. A gradient does the tuning: it makes the field, and so the precession frequency of protons, change steadily with position. The RF pulse is the sound you play. A narrow band of frequencies picks out a thin slab of tissue, a wider band picks a thicker slab, and shifting the center frequency slides the slab along the axis. A steeper gradient spreads the frequencies over a shorter distance, so the same pulse excites a thinner slice.

Key equations

ω(z)=γ(B0+Gzz)
(1)

Larmor angular frequency varies linearly with position z when a gradient Gz is applied; γ is the gyromagnetic ratio.

f(z)=γ2π(B0+Gzz)
(2)

Same relation in hertz; for hydrogen γ2π is about 42.58 MHz/T.

z0=fc−f0γ‾Gz
(3)

Slice center position is set by the RF center frequency fc relative to the frequency f0 at isocenter; γ‾=γ2π.

Δz=Δfγ‾Gz
(4)

Slice thickness equals RF bandwidth divided by γ‾ times gradient strength.

Derivation

  1. Start with the Larmor relation: f=γ‾×B.
  2. Apply a gradient along z so B(z)=B0+Gz⋅z.
  3. Substitute: f(z)=γ‾B0+γ‾Gzz. Frequency is a linear function of z.
  4. An RF pulse containing frequencies from f_c − Δf/2 to f_c + Δf/2 excites only spins whose f(z) is in that range.
  5. Solve f(z)=fc±Δf/2 for z. The difference between the two positions gives Δz=Δf/(γ‾Gz).
  6. The midpoint gives z0=(fc−f0)/(γ‾Gz), where f0=γ‾B0.

Worked example

Problem

A slice-select gradient of 10 mT/m is applied for hydrogen (gamma-bar = 42.58 MHz/T). The RF pulse has a bandwidth of 1.704 kHz and is offset 8.516 kHz from the isocenter frequency. Find the slice thickness and position.

  1. Convert gradient to frequency per meter: 42.58 MHz/T × 0.010 T/m = 425.8 kHz/m.
  2. Thickness: Δz = 1704 Hz / 425,800 Hz/m = 0.0040 m = 4.0 mm.
  3. Position: z0 = 8516 Hz / 425,800 Hz/m = 0.0200 m = 20 mm from isocenter.

Answer A 4 mm thick slice centered 20 mm from isocenter along the gradient axis.

Common mistakes

  • Thinking the RF pulse itself is spatially selective; it is the gradient that maps frequency to position.
  • Believing a stronger gradient makes a thicker slice; it makes it thinner for fixed bandwidth.
  • Confusing center frequency (controls position) with bandwidth (controls thickness).
  • Forgetting that the slice-select gradient dephases spins, which requires a rephasing lobe afterward.
  • Using angular frequency in rad/s with γ‾ in Hz/T without converting.

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

BG = "#0e1117"
C_SLICE = "#FFD166"
C_MAG = "#58C4DD"
C_RF = "#FF6B6B"

def slice_geometry():
    """Compute the slice profile geometry for a given gradient and bandwidth."""
    # Parameters
    gamma = 42.58  # MHz/T (simplified)
    Gz = 0.02      # T/m (gradient strength)
    BW = 2000      # Hz (RF bandwidth)
    
    # Slice thickness delta_z = BW / (gamma * Gz)
    # Note: gamma in Hz/T is ~42.58e6, Gz in T/m, BW in Hz
    # delta_z = BW / (gamma * Gz) meters
    # Using MHz/T for gamma: 42.58 MHz/T = 42.58e6 Hz/T
    gamma_hz = 42.58e6
    thickness = BW / (gamma_hz * Gz)
    
    # Center position (arbitrary, say 0.05m = 5cm)
    z_center = 0.05
    
    # Frequency range covered by RF
    f_center = gamma_hz * Gz * z_center
    f_min = f_center - BW / 2
    f_max = f_center + BW / 2
    
    # Corresponding z positions
    z_min = f_min / (gamma_hz * Gz)
    z_max = f_max / (gamma_hz * Gz)
    
    return {
        "thickness": thickness,
        "z_center": z_center,
        "z_min": z_min,
        "z_max": z_max,
        "f_center": f_center,
        "f_min": f_min,
        "f_max": f_max,
        "gamma_hz": gamma_hz
    }

class Main(Scene):
    def construct(self):
        self.camera.background_color = BG
        info = slice_geometry()
        
        # Layout constants
        SCALE_Z = 100  # 1 meter = 100 units on screen
        Z_OFFSET = 2.0 # Shift body to right
        
        # 1. Title
        TitleCard(self, "Slice Selection", "RF + Gradient = Spatial Encoding")
        
        # 2. Draw Body and Gradient
        body = Rectangle(height=4, width=2, fill_color=C_DIM, fill_opacity=0.3, stroke_color=WHITE)
        body.move_to([Z_OFFSET, 0, 0])
        self.play(Create(body), run_time=1)
        
        # Gradient arrow (Gz)
        grad_arrow = Arrow(ORIGIN, UP * 2, color=C_MAG, buff=0)
        grad_arrow.move_to([Z_OFFSET - 1.5, 0, 0])
        grad_label = Text("Gz", font_size=24, color=C_MAG).next_to(grad_arrow, LEFT)
        self.play(Create(grad_arrow), FadeIn(grad_label), run_time=1)
        
        # 3. RF Pulse (B1)
        rf_box = Rectangle(height=0.5, width=1.5, fill_color=C_RF, fill_opacity=0.5, stroke_color=C_RF)
        rf_box.move_to([Z_OFFSET - 1.5, -2.5, 0])
        rf_label = Text("RF Pulse", font_size=24, color=C_RF).next_to(rf_box, DOWN)
        self.play(Create(rf_box), FadeIn(rf_label), run_time=1)
        
        StepCaption(self, "Simultaneous RF pulse and Gradient")
        
        # 4. Highlight Slice
        # Calculate slice bounds in screen coordinates
        z_min_screen = -info["z_center"] * SCALE_Z + Z_OFFSET * SCALE_Z / 2 # Approx mapping
        # Let's use a simpler mapping: z=0 is center of body.
        # Body height is 4. z range approx -2 to 2.
        # Let's map z (meters) to y (screen units).
        # Body center y=0. Height 4.
        # z=0 -> y=0.
        # z=1m -> y=2 (half height). So scale is 2.
        # Wait, info["thickness"] is in meters.
        # Let's define a mapping function: y_screen = z_meters * 2.0
        
        z_min_m = info["z_min"]
        z_max_m = info["z_max"]
        
        y_min = z_min_m * 2.0
        y_max = z_max_m * 2.0
        
        slice_rect = Rectangle(
            height=y_max - y_min, 
            width=2.0, 
            fill_color=C_SLICE, 
            fill_opacity=0.4, 
            stroke_color=C_SLICE,
            stroke_width=3
        )
        slice_rect.move_to([Z_OFFSET, (y_min + y_max) / 2, 0])
        
        self.play(Create(slice_rect), run_time=1.5)
        StepCaption(self, f"Slice thickness: {info['thickness']*1000:.1f} mm")
        
        # 5. Frequency Correspondence
        # Draw frequency axis
        freq_axes = Axes(
            x_range=[0, 10000, 2000],
            y_range=[0, 1, 0.5],
            x_length=6,
            y_length=1.5,
            axis_config={"color": C_DIM}
        )
        freq_axes.to_edge(LEFT, buff=0.5)
        freq_label = Text("Frequency (Hz)", font_size=24, color=WHITE).next_to(freq_axes, DOWN)
        
        # RF Bandwidth on freq axis
        # Map f_min, f_max to x-axis
        # f_center ~ 42.58e6 * 0.02 * 0.05 = 42580 Hz? No.
        # gamma=42.58 MHz/T. Gz=0.02 T/m. z=0.05m.
        # f = 42.58 * 0.02 * 0.05 * 1e6 = 42580 Hz.
        # BW = 2000 Hz.
        # So range is ~41580 to 43580.
        # Let's scale the axis to show this region.
        
        # Re-calculate for visual clarity
        f_c = info["f_center"]
        f_lo = info["f_min"]
        f_hi = info["f_max"]
        
        # Adjust axes to fit the slice frequency
        freq_axes_new = Axes(
            x_range=[f_lo - 500, f_hi + 500, 500],
            y_range=[0, 1.2, 0.5],
            x_length=5,
            y_length=1.5,
            axis_config={"color": C_DIM}
        )
        freq_axes_new.move_to(freq_axes.get_center()) # Keep position
        
        # Draw RF pulse shape (sinc-like approximation or just box for simplicity)
        # Box from f_lo to f_hi
        bw_width = f_hi - f_lo
        rf_freq_box = Rectangle(
            width=bw_width * (freq_axes_new.x_axis.get_length() / (f_hi - f_lo - 1000)), # Scale to axis
            height=0.8,
            fill_color=C_RF,
            fill_opacity=0.5,
            stroke_color=C_RF
        )
        # Center on f_center
        x_center = freq_axes_new.c2p(f_c)[0]
        rf_freq_box.move_to([x_center, 0.4, 0])
        
        self.play(Create(freq_axes_new), FadeIn(freq_label))
        self.play(Create(rf_freq_box), run_time=1)
        
        # Connect slice to freq band
        # Line from slice center to freq box center?
        # Or just show they are linked.
        conn_line = DashedLine(
            slice_rect.get_right(),
            freq_axes_new.c2p(f_c)[0] * RIGHT + slice_rect.get_right() * 0, # Simplified
            color=C_SLICE,
            dash_length=0.1
        )
        # Better connection: from slice right edge to freq axis center x
        start_pt = slice_rect.get_right()
        end_pt = freq_axes_new.c2p(f_c)
        conn_line = DashedLine(start_pt, end_pt, color=C_SLICE)
        
        self.play(Create(conn_line), run_time=1)
        StepCaption(self, "Resonance condition: $f = \gamma G_z z$")
        
        self.wait(2)

if __name__ == "__main__" and "--selftest" in sys.argv:
    info = slice_geometry()
    # Check thickness calculation
    gamma_hz = 42.58e6
    Gz = 0.02
    BW = 2000
    expected_thickness = BW / (gamma_hz * Gz)
    assert abs(info["thickness"] - expected_thickness) < 1e-9
    
    # Check slice bounds
    z_center = 0.05
    f_center = gamma_hz * Gz * z_center
    assert abs(info["f_center"] - f_center) < 1e-3
    
    # Check symmetry
    assert abs(info["f_max"] - f_center - BW/2) < 1e-3
    assert abs(info["f_min"] - f_center + BW/2) < 1e-3
    
    # Check z bounds
    assert abs(info["z_max"] - (f_center + BW/2)/(gamma_hz*Gz)) < 1e-9
    assert abs(info["z_min"] - (f_center - BW/2)/(gamma_hz*Gz)) < 1e-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.