MR Physics: From Protons to Brain Images

Written by Luke Chang & Ben Graul How do MRI scanners work? And what signal are we actually measuring? Understanding the physics underlying MRI is essential for interpreting neuroimaging results, yet many people who use MRI don't fully grasp how it works -- largely because MR physics can be unintuitive. This course primarily focuses on Blood Oxygenated Level Dependent (BOLD) fMRI signals. Gaining a deep understanding of the MR physics and physiological basis for the BOLD fMRI signal is beyond the scope of this course and we refer the interested reader to the excellent Huettel, Song, & McCarthy (2004) Functional magnetic resonance imaging textbook for a more in depth conceptual and quantitative overview. The goal of this tutorial is to build your intuition from the ground up, starting with things you already know (magnets and compasses) and working toward functional brain imaging. Along the way, you'll interact with simulations that let you see and feel how changing physical parameters affects the signal.
Note on simplifications: We'll use classical physics explanations throughout, following the approach advocated by Lars G. Hanson. While not quantum-mechanically complete, this classical picture provides strong intuitions that will serve you well. Where the full story differs, we'll flag it in optional "Deep Dive" sections.
This notebook covers three major topics:
  1. Magnetism & Resonance — magnetic fields, proton alignment, precession, RF excitation, and the FID signal
  2. Signal & Contrast — T₁/T₂ relaxation, the Bloch equations, tissue contrast, and pulse sequences
  3. Imaging & fMRI — gradients, spatial encoding, k-space, the BOLD signal, and EPI
Let's first start with a short video on the basics of MR physics by Martin Lindquist.

Part 1: Magnetism & Resonance


1. What is a Magnetic Field?

You've used a compass before -- a tiny magnetized needle that aligns with the Earth's magnetic field to point north. This simple device illustrates the core idea behind MRI: magnetic objects tend to align with an applied magnetic field. The Earth's magnetic field is weak -- only about 25-65 microTeslas (µT). An MRI scanner produces a field that is roughly 100,000 times stronger: typically 1.5 or 3 Tesla (T), with research scanners going up to 7T or beyond. Let's start with a simulation inspired by the DRCMR Compass MR Simulator. Use the slider below to change the strength of the external magnetic field (||(B_0||)) and watch how a compass needle responds.
Key observations:
  • With no field (||(B_0 = 0||)), the needle just sits wherever it is -- no preferred direction.
  • As you increase ||(B_0||), the needle oscillates back toward alignment faster.
  • The frequency of oscillation increases with field strength.
  • The oscillation is detected by a nearby coil as a signal that decays over time.
These same principles apply inside an MRI scanner, except instead of compass needles, we're working with hydrogen nuclei -- tiny magnets inside your body.

2. From Compass to Proton

We don't have compass needles inside the body, but do have a large number of hydrogen nuclei (protons). Hydrogen is the most abundant element in the body (it's in every water molecule), and each hydrogen nucleus acts like a tiny magnet because of a quantum property called spin. In the absence of an external magnetic field, these tiny magnets point in random directions, and their effects cancel out -- there's no net magnetization. But when we place them in a strong ||(B_0||) field, a slight majority align with the field rather than against it. This tiny surplus creates a measurable net magnetization vector, called ||(M_0||), that points along ||(B_0||). Use the sliders below to see how random spins create a net magnetization when a field is applied.

3. Precession & the Larmor Frequency

When a spinning top is tilted, it doesn't just fall over -- it precesses, tracing a circle as it wobbles around the vertical axis. Protons in a magnetic field do the same thing: their spin axes precess around the direction of ||(B_0||). The rate of precession is governed by the Larmor equation: ||[\omega_0 = \gamma \cdot B_0||]where:
  • ||(\omega_0||) is the Larmor (precession) frequency
  • ||(\gamma||) is the gyromagnetic ratio -- a constant unique to each nucleus
  • ||(B_0||) is the magnetic field strength
For hydrogen protons, ||(\gamma = 42.576||) MHz/T. This means at 3T, protons precess at about 127.7 MHz -- in the radiofrequency (RF) range! Adjust the field strength below and see how the precession frequency changes.
Larmor frequencies of different nuclei at this field strength:
Nucleus γ (MHz/T) Larmor freq at 3.0T
1H 42.576 127.73 MHz
13C 10.708 32.12 MHz
23Na 11.262 33.79 MHz
31P 17.235 51.70 MHz

4. RF Excitation & Resonance

In an MRI machine, ||(B_0||) is the strong, static magnetic field that runs along the bore of the scanner (the longitudinal plane or z-axis). It aligns hydrogen protons in your body roughly parallel to the field, creating a net magnetization ||(M_0||).
Unfortunately, we can't directly measure magnetization along z -- our receiver coils are only sensitive to magnetization in the transverse (xy) plane. To get a signal, we need to tip the magnetization away from z. We do this by applying a second, much weaker magnetic field called ||(B_1||), oriented perpendicular to ||(B_0||), and oscillating at the Larmor frequency. This is the radiofrequency (RF) pulse. Think of pushing a child on a swing: if you push at the swing's natural frequency, each push adds energy and the swing goes higher. Push at the wrong frequency, and nothing much happens. This is resonance -- and it's the "R" in MRI. The angle by which the magnetization is tipped is called the flip angle (||(\alpha||)). A 90° pulse tips ||(M||) entirely into the xy-plane. A 180° pulse inverts it. Try adjusting the flip angle and the B1 frequency below.
Transverse magnetization |Mxy| = 1.00 (this is our detectable signal strength) Longitudinal magnetization Mz = 0.00

5. The Signal We Measure: Free Induction Decay

After the RF pulse tips the magnetization into the transverse plane, the precessing ||(M_{xy}||) component induces a voltage in the receiver coil -- just like the oscillating compass needle produced a signal in Section 1. This signal is called the Free Induction Decay (FID). The FID has two key features:
  1. It oscillates at the Larmor frequency (the precessing magnetization)
  2. It decays over time as the transverse magnetization dephases (characterized by the time constant ||(T_2^*||))
We can extract the frequency content of the FID using a Fourier Transform (FFT) -- the same mathematical tool introduced in the Dartbrains Signal Processing chapter. The FFT reveals a peak at the Larmor frequency, confirming that the signal came from precessing protons.

Part 2: Signal & Contrast

We've learned how an RF pulse tips the net magnetization into the transverse plane, producing a Free Induction Decay signal. But why does the signal decay? And how do MRI scanners produce images where gray matter, white matter, and CSF all look different? The answers lie in relaxation -- the processes by which the magnetization returns to equilibrium after excitation. Different tissues relax at different rates, and MRI pulse sequences exploit these differences to create contrast.

6. T1 Relaxation

After a 90° RF pulse tips all the magnetization into the xy-plane, the longitudinal component ||(M_z||) is zero. Over time, ||(M_z||) recovers back to its equilibrium value ||(M_0||) through a process called T1 relaxation (also known as spin-lattice relaxation). This recovery follows an exponential curve: ||[M_z(t) = M_0 \left(1 - e^{-t/T_1}\right)||]The T1 time constant is the time it takes for ||(M_z||) to recover to about 63% of ||(M_0||). Crucially, different tissues have different T1 values:
  • Fat has a short T1 (fast recovery) because fat molecules are large and tumble slowly, efficiently transferring energy to the lattice
  • CSF has a long T1 (slow recovery) because water molecules are small and tumble quickly, making energy transfer less efficient
  • Gray and white matter fall in between
T₁ relaxation describes the return of longitudinal magnetization to equilibrium. The recovery follows the Bloch equation for ||(M_z||): ||[\frac{dM_z}{dt} = \frac{M_0 - M_z}{T_1}||]with the solution (after a 90° excitation): ||[M_z(t) = M_0 \left(1 - e^{-t/T_1}\right)||]The physical mechanism involves energy exchange between the excited spin system and the surrounding molecular lattice (hence "spin-lattice" relaxation). The efficiency depends on molecular tumbling rates:
  • Optimal T₁ relaxation occurs when the molecular tumbling frequency matches the Larmor frequency
  • Small, fast-tumbling molecules (like free water) are inefficient → long T₁
  • Large, slow-tumbling molecules (like fat) are more efficient → short T₁
  • T₁ increases with field strength because the Larmor frequency moves further from typical tumbling frequencies

7. T2 Relaxation

While ||(M_z||) is recovering along the z-axis, the transverse magnetization ||(M_{xy}||) is decaying in the xy-plane. This happens because individual proton spins gradually lose phase coherence -- they precess at slightly different frequencies due to interactions with neighboring spins. This is T2 relaxation (spin-spin relaxation): ||[M_{xy}(t) = M_{xy}(0) \cdot e^{-t/T_2}||]In practice, additional dephasing from ||(B_0||) field inhomogeneities makes the signal decay even faster, characterized by ||(T_2^*||): ||[\frac{1}{T_2^*} = \frac{1}{T_2} + \frac{1}{T_2'}||]where ||(T_2'||) represents dephasing from field inhomogeneities. T2 is always shorter than or equal to T1 -- the transverse signal always decays before the longitudinal signal fully recovers.
T₂ = 44 ms* (always shorter than T₂ = 80 ms due to field inhomogeneities)

8. T1 and T2 Together: The Full Picture

After an RF excitation pulse, both relaxation processes happen simultaneously: ||(M_z||) recovers (T1) while ||(M_{xy}||) decays (T2). The combined motion of the magnetization vector traces a spiral path as it precesses, dephases in the transverse plane, and recovers along the longitudinal axis. This is the complete Bloch equation picture. The visualization below shows the 3D trajectory of the magnetization vector after a 90° pulse.
The Bloch equations describe the time evolution of the magnetization vector ||(\vec{M} = (M_x, M_y, M_z)||) in a magnetic field: ||[\frac{dM_x}{dt} = \gamma (\vec{M} \times \vec{B})_x - \frac{M_x}{T_2}||]||[\frac{dM_y}{dt} = \gamma (\vec{M} \times \vec{B})_y - \frac{M_y}{T_2}||]||[\frac{dM_z}{dt} = \gamma (\vec{M} \times \vec{B})_z - \frac{M_z - M_0}{T_1}||]The cross-product term describes precession, while the decay terms describe relaxation. In matrix form, for a single time step ||(\Delta t||) with only ||(B_0||) along z:
  1. Precession: Rotate ||(M||) about z by angle ||(\Delta\phi = \gamma B_0 \Delta t||)
  2. T2 decay: Multiply ||(M_x||) and ||(M_y||) by ||(e^{-\Delta t / T_2}||)
  3. T1 recovery: Update ||(M_z \rightarrow M_z \cdot e^{-\Delta t / T_1} + M_0 (1 - e^{-\Delta t / T_1})||)
This is exactly how our simulation module implements the Bloch equations -- using rotation matrices for precession and exponential factors for relaxation.

9. Tissue Contrast: How TE and TR Create Different Images

This is where MRI gets its remarkable soft-tissue contrast. By choosing when we repeat the excitation pulse (||(TR||) = Repetition Time) and when we read the signal (||(TE||) = Echo Time), we can make the image sensitive to different tissue properties:
Weighting TR TE Sensitive to
T1-weighted Short (~500ms) Short (~10ms) T1 differences (anatomy)
T2-weighted Long (~3000ms) Long (~80ms) T2 differences (pathology)
PD-weighted Long (~3000ms) Short (~10ms) Proton density
The spin echo signal equation combines both relaxation effects: ||[S = PD \cdot (1 - e^{-TR/T_1}) \cdot e^{-TE/T_2}||]The first term (||(1 - e^{-TR/T_1}||)) is T1-weighting: short TR means tissues haven't fully recovered, so T1 differences matter. The second term (||(e^{-TE/T_2}||)) is T2-weighting: long TE means more T2 decay has occurred, so T2 differences matter. This is the most important interactive plot in this notebook. Use the sliders below to explore how TE and TR change the contrast between tissues.

10. Spin Echo & Gradient Echo

We've been talking about the signal at time TE after excitation. But how do we actually collect the signal at a specific echo time? There are two fundamental approaches:

Spin Echo (SE)

A 180° refocusing pulse is applied at time TE/2 after the initial 90° excitation. This reverses the dephasing caused by static field inhomogeneities, causing the spins to rephase and form an echo at time TE. The spin echo signal depends on T2 (not T2*), because the refocusing pulse undoes the T2' dephasing.
The diagram shows one full spin echo cycle. A spin echo pulse sequence begins with a 90° RF pulse that tips the net magnetization from the longitudinal axis into the transverse plane. Immediately after excitation, spins begin to dephase due to local field inhomogeneities, producing a decaying free induction decay (FID). A 180° refocusing pulse applied at time TE/2 reverses this dephasing, causing spins to rephase and form an echo at time TE. The sequence repeats every TR (indicated by the faded 90° pulse at the right edge). Three spatial encoding gradients operate alongside the RF pulses:
  • Gss (slice select) is applied during both RF pulses to restrict excitation to a single imaging slice
  • Gpe (phase encode) applies a brief gradient of varying amplitude on each repetition, stepping through k-space line by line
  • Gro (readout/frequency encode) is switched on during the echo to spatially encode signal along the remaining axis.
Together, these three gradients provide the spatial information needed to reconstruct a 2D image from the acquired signal.

Gradient Echo (GRE)

Instead of a 180° pulse, a gradient reversal is used to form the echo. This is faster but does NOT refocus static field inhomogeneities, so the signal depends on T2 (not T2). Gradient echoes are the basis of most fMRI sequences (because fMRI needs T2 sensitivity!).
A gradient echo pulse sequence begins with a low flip angle (α) RF pulse — typically much less than 90° — that tips a fraction of the longitudinal magnetization into the transverse plane. Unlike the spin echo, there is no 180° refocusing pulse. Instead, the echo is formed entirely by gradient manipulation: a negative dephasing lobe on the readout gradient (Gro) deliberately dephases the spins, and then a positive lobe of opposite polarity rephases them to produce the gradient echo at time TE. Because the 180° pulse is absent, static field inhomogeneities are not corrected, so the signal decays with T2* rather than T2. The slice select gradient (Gss) is applied during the α pulse to restrict excitation to a single slice, and the phase encode gradient (Gpe) steps through different amplitudes on each repetition to fill k-space. The combination of a small flip angle and no refocusing pulse allows very short TR and TE, making gradient echo sequences the basis for fast imaging methods such as FLASH, SPGR, and MPRAGE. Here is an interactive figure showing this process over time for each sequence type.
Spin Echo: 90° → wait TE/2 → 180° (refocus) → wait TE/2 → Echo The 180° pulse reverses all static dephasing. The echo signal reflects true T₂ decay only. Used for anatomical imaging (T₁w, T₂w).

Part 3: Imaging & fMRI

We now know how to generate a signal and how different tissues produce different signals. But there's a critical problem: where did the signal come from? If the entire volume inside the scanner experiences the same ||(B_0||) field, all protons precess at the same frequency, and we can't tell whether the signal is coming from your frontal cortex or your cerebellum. We need spatial encoding -- a way to tag different locations with different frequencies or phases so we can reconstruct an image.

11. The Localization Problem: Why We Need Gradients

In a perfectly uniform ||(B_0||) field, every proton in the body precesses at the same Larmor frequency. Our receiver coil picks up the sum of all these signals, with no way to tell where each contribution came from. The solution: gradient coils. These are additional electromagnetic coils that make the magnetic field vary linearly across space. If we add a gradient along the x-axis: ||[B(x) = B_0 + G_x \cdot x||]then the Larmor frequency also varies with position: ||[f(x) = \gamma \cdot (B_0 + G_x \cdot x)||]Now protons at different x-positions precess at different frequencies -- and we can separate them using the Fourier transform!
Gradient: 0 mT/m → Frequency spread across 30cm FOV: 0.0 kHz (uniform field, no spatial encoding!)

12. Slice Selection

MRI typically images one slice at a time. To select a specific slice, we apply a gradient along the z-axis (head-to-foot) during the RF pulse. The RF pulse has a limited bandwidth -- it only excites protons within a narrow range of frequencies. Since the z-gradient makes frequency vary with position, only protons in one slice are on-resonance and get excited. Slice thickness is controlled by: ||[\Delta z = \frac{\Delta f}{\gamma \cdot G_z}||]where ||(\Delta f||) is the RF pulse bandwidth and ||(G_z||) is the slice-select gradient strength. Stronger gradient = thinner slice. Wider RF bandwidth = thicker slice.
With Gz = 20 mT/m and RF bandwidth = 2000 Hz, the selected slice is 2.3 mm thick. The red segment shows the positions where protons are within the RF bandwidth and will be excited. All other protons are off-resonance and unaffected.

13. Frequency & Phase Encoding

After selecting a slice, we still need to encode position within that 2D slice. MRI uses two clever tricks: Frequency encoding (readout direction, x): During signal readout, a gradient along x makes protons at different x-positions precess at different frequencies. The Fourier transform of the readout signal directly gives us the spatial profile along x. Phase encoding (y-direction): Before readout, a brief gradient pulse along y gives protons at different y-positions different phases. This is repeated many times with different gradient strengths to fill out the y-dimension. Each repetition fills one line of k-space. The combination gives each voxel a unique (frequency, phase) signature that can be decoded by a 2D Fourier transform.
Watch how the spin arrows in each voxel respond to gradients:
  • No gradients: all spins precess at the same rate
  • Frequency encoding (Gx): columns spin at different rates
  • Phase encoding (Gy): rows accumulate different phase offsets
  • Both: each voxel gets a unique (frequency, phase) signature
The 2D Fourier transform decodes these signatures back into an image.
The MRI signal at time ||(t||) during readout, for a given phase-encode step with gradient area ||(A_y||), is: ||[S(t) = \int\int \rho(x, y) \cdot e^{-i 2\pi (\gamma G_x x t + \gamma A_y y)} \, dx \, dy||]where ||(\rho(x, y)||) is the spin density (our image). If we define spatial frequencies:
  • ||(k_x = \gamma G_x t||) (varies during readout)
  • ||(k_y = \gamma A_y||) (set by phase-encode gradient)
then the signal equation becomes: ||[S(k_x, k_y) = \int\int \rho(x, y) \cdot e^{-i 2\pi (k_x x + k_y y)} \, dx \, dy||]This is exactly the 2D Fourier transform of the image! Therefore, the image is simply the inverse Fourier transform of the acquired data: ||[\rho(x, y) = \mathcal{F}^{-1}\{S(k_x, k_y)\}||]The space of ||((k_x, k_y)||) is called k-space.

14. K-Space: Where MRI Data Lives

The raw data from an MRI scan doesn't look like an image -- it lives in k-space, the spatial frequency domain. K-space and the image are related by the 2D Fourier transform: ||[\text{Image} = \text{FFT}^{-1}(\text{K-space})||]Different regions of k-space encode different features:
  • Center of k-space → overall contrast, brightness, low-frequency shapes
  • Edges of k-space → fine details, sharp edges, high spatial frequency
This means you don't need ALL of k-space to get a useful image. Keeping only the center gives you a blurry but recognizable image. Keeping only the edges gives you an edge map with no contrast. Try masking different regions below to build intuition!
Progressive fill shows how an MRI scanner acquires k-space line by line, with the image emerging gradually. Try other modes:
  • Center only: Blurry but recognizable -- contrast lives in the center
  • Periphery only: Only edges visible -- detail lives at the edges
  • Undersampled: Aliasing artifacts from skipping lines

15. BOLD & the Hemodynamic Response

Now we arrive at functional MRI (fMRI) -- using MRI to measure brain activity. But MRI doesn't measure neural activity directly. Instead, it measures a downstream consequence: changes in blood oxygenation. The key insight: deoxyhemoglobin is paramagnetic (slightly magnetic), while oxyhemoglobin is diamagnetic (not magnetic). When a brain region becomes active:
  1. Neurons fire and consume oxygen locally
  2. The vascular system responds by increasing blood flow to that region
  3. Blood flow overshoots metabolic demand -- more oxygen arrives than is consumed
  4. The result: less deoxyhemoglobin locally
  5. Less deoxyhemoglobin → less local field distortion → increased T₂* signal
This is the Blood Oxygen Level Dependent (BOLD) signal. The temporal shape of the BOLD response to a brief neural event is called the Hemodynamic Response Function (HRF).
The canonical HRF has several notable features:
  • Initial dip (small, often not detectable at typical fMRI resolution)
  • Peak at ~6s after stimulus
  • Post-stimulus undershoot at ~16s
  • Returns to baseline after ~25-30s
This sluggish hemodynamic response means fMRI has poor temporal resolution (~seconds) compared to EEG (milliseconds), even though the neural events happen on the millisecond timescale.

Convolution: From Events to Predicted BOLD Signal

In an fMRI experiment, we present multiple stimuli over time. The predicted BOLD signal is the convolution of the stimulus timing with the HRF: ||[\text{Predicted BOLD}(t) = \text{stimulus}(t) * \text{HRF}(t)||]This is the foundation of the General Linear Model (GLM) used in fMRI analysis (covered in detail in later Dartbrains chapters). Try adjusting the stimulus timing below to see how the predicted BOLD signal changes.

16. fMRI Pulse Sequences: Echo Planar Imaging (EPI)

Standard MRI acquires one line of k-space per TR -- far too slow for fMRI, which needs to image the whole brain every 1-2 seconds. The solution is Echo Planar Imaging (EPI): after a single RF excitation, rapidly oscillating gradients traverse all of k-space in about 50-100 milliseconds. This is the workhorse sequence for fMRI. Typical fMRI parameters:
Parameter Structural (T₁w MPRAGE) Functional (GRE-EPI)
Weighting T₁ T₂*
TR ~2000 ms 500-2000 ms
TE ~3 ms ~30 ms
Flip angle ~9° ~70-90°
Resolution ~1 mm³ ~2-3 mm³
Volumes 1 (whole brain) 100s-1000s
Duration ~5 min 5-60 min
Parameter Value
Spatial Resolution 3.4 mm
Temporal Resolution 1.0 s
Slices per TR ~27
BOLD sensitivity Good (TE=30ms)
Readout duration ~32 ms

17. Putting It All Together: From Proton to Activation Map

Let's trace the complete chain from physics to functional brain imaging:
Strong magnetic field (B₀)
    
    
Protons align  net magnetization (M₀)
    
    
RF pulse at Larmor frequency  tips M into transverse plane
    
    
Precessing Mxy induces signal in coil (FID)
    
    
Gradients encode spatial position
    
    
Raw signal fills k-space
    
    
2D Inverse FFT  image for each slice
    
    
Repeat with T₂*-weighted GRE-EPI every ~1s
    
    
BOLD signal changes reflect neural activity (via hemodynamics)
    
    
Statistical analysis (GLM)  activation maps
What we gain:
  • Non-invasive measurement of brain activity
  • Whole-brain coverage
  • Reasonable spatial resolution (~2-3mm)
  • No ionizing radiation (unlike PET/CT)
What we lose / must be aware of:
  • Temporal resolution is limited (~seconds, not milliseconds)
  • BOLD is an indirect measure of neural activity
  • Signal can be affected by head motion, physiological noise, susceptibility artifacts (especially near sinuses and ear canals)
  • The hemodynamic response varies across brain regions and individuals
These limitations -- and how to address them -- are covered in the subsequent Dartbrains chapters on preprocessing, the GLM, and statistical analysis.

Summary

Topic Key Concepts
Magnetism & Resonance B₀ alignment, precession, Larmor equation, RF excitation, FID
Signal & Contrast T₁/T₂ relaxation, Bloch equations, TE/TR contrast, spin echo vs gradient echo
Imaging & fMRI Gradients, spatial encoding, k-space, BOLD signal, HRF, EPI
These concepts form the foundation for everything else in neuroimaging. Understanding why the signal looks the way it does -- and what can go wrong -- is essential for designing good experiments, preprocessing data correctly, and interpreting results with appropriate caution. Continue your learning: The subsequent Dartbrains chapters cover signal processing, preprocessing with fMRIPrep, the General Linear Model, group analysis, and multivariate pattern analysis.