The Physical Foundations of Magnetic Resonance
An interactive computational examination of precession dynamics, gradient spatial encoding, resonant RF nutation, and 2D k-space image reconstruction using MRIjs.
Static Field Strength (B₀) and Nuclear Precession Frequency Dynamics
Atomic nuclei containing an odd number of protons or neutrons exhibit an intrinsic quantum mechanical angular momentum known as nuclear spin (\(\vec{I}\)). Proportional to this angular momentum is the magnetic dipole moment \(\vec{\mu} = \gamma \vec{I}\), where \(\gamma\) is the gyromagnetic ratio unique to each nuclide.
When placed into a powerful static main magnetic field \(\vec{B}_0 = B_0 \hat{z}\), the magnetic moment experiences a mechanical torque \(\vec{\tau} = \vec{\mu} \times \vec{B}_0\). Because angular momentum is conserved, this torque causes the vector to undergo gyroscopic precession around \(\hat{z}\) at the angular frequency given by the Larmor Equation:
In our current live model, with the main field set to B₀ = 1.50 T, hydrogen protons (¹H, γ/2π ≈ 42.576 MHz/T) precess at 63.864 MHz, completing one full revolution every 15.66 ns. Because electron clouds slightly shield nuclei from B₀, protons in different chemical environments precess at shifted frequencies. For example, water and lipid protons exhibit a 3.5 ppm chemical shift separation (Δf = 3.5 × 10⁻⁶ × f₀), resulting in an offset of 223.5 Hz.
const BlochSimulator = window.BlochSimulator || require('./bloch.js');
// Define two isochromats: water (w = 0) and fat (w = 40 Hz offset)
const isochromats = [
{ id: 'water', x: 0, T1: 800, T2: 200, PD: 1.0, w: 0 },
{ id: 'fat', x: 0, T1: 300, T2: 120, PD: 1.0, w: 40 }
];
const sim = new BlochSimulator(isochromats, 80, 0.2, 'rotating', 'FID', { flipAngle: 90 });
const results = sim.run();
Spatial Position Encoding via Linear Magnetic Field Gradients
Because an RF receiver coil detects only the integrated voltage induced across the whole sample, a uniform magnetic field yields zero spatial discrimination. To resolve anatomy, we introduce linear magnetic field gradients:
Consequently, the local Larmor frequency varies with coordinate \(x\): \(\omega(x) = \omega_0 + \gamma G_x x\). Spins at position \(x\) accumulate phase according to \(\phi(x, t) = \int_0^t \gamma G_x(\tau) x d\tau\).
In our live model below, with gradient G_x = 20 mT/m applied for 5.0 ms, edge isochromats diverge in frequency by ±851.5 kHz, causing the collective net transverse signal to dephase down to 18.4%.
// Model spatial isochromats across space under a Gradient Echo sequence
const isochromats = [-1.0, -0.6, -0.2, 0.2, 0.6, 1.0].map((x, i) => ({
id: `spin_${i}`, x: x, T1: 800, T2: 300, PD: 1.0, w: 0
}));
const sim = new BlochSimulator(isochromats, 80, 0.2, 'rotating', 'GRE', { flipAngle: 90, TE: 40, TR: 100 });
const results = sim.run();
Resonant Radiofrequency Excitation and B₁ Nutation Dynamics
To tip the longitudinal net magnetization \(M_z\) into the transverse plane, an alternating RF current is applied perpendicular to \(\vec{B}_0\) at the Larmor frequency, creating a dynamic magnetic field \(\vec{B}_1(t)\).
In the rotating reference frame (moving at \(\omega_{\text{rf}} = \omega_0\)), \(\vec{B}_0\) is eliminated. The net magnetization undergoes steady gyroscopic nutation around \(\vec{B}_1\) through a tip angle \(\alpha\):
Currently, for a flip angle of α = 90° and pulse duration 2.0 ms, the required peak RF amplitude is 2.9 µT. When paired with a slice-selection gradient (G_z), shaped pulses (such as sinc pulses) produce rectangular frequency profiles, yielding an excitation slice thickness of 1.47 mm (Δz = Δf / (γ G_z)).
const spin = [{ id: 'gray_matter', x: 0, T1: 600, T2: 120, PD: 1.0, w: 0 }];
const sim = new BlochSimulator(spin, 60, 0.1, 'rotating', 'FID', { flipAngle: 60 });
const results = sim.run();
Signal Reception, 2D k-Space Formalism, and Image Reconstruction
During signal acquisition, the received voltage S(t) represents the spatial integration of transverse magnetization over the sample. By applying orthogonal gradients, we trace a trajectory through k-space (spatial frequency space):
The coordinates in spatial frequency space (\(\vec{k}(t)\)) are dictated by gradient integrals: \(k_x(t) = \frac{\gamma}{2\pi}\int_0^t G_x(\tau)d\tau\) and \(k_y(t) = \frac{\gamma}{2\pi}\int_0^t G_y(\tau)d\tau\). To form the anatomical picture, the computer computes the 2D Inverse Discrete Fourier Transform (2D IDFT):
In the interactive studio below, notice that under Full k-Space, the central 6 × 6 region contains 96.2% of total signal power. Low-pass filtering preserves bulk contrast while blurring edges; high-pass filtering produces edge detection with zero contrast; undersampling induces wrap-around aliasing ghosts.
// Define a 1D spatial phantom with 3 discrete objects along the x-axis
const phantomSpins = [
{ id: 'obj1', x: -0.6, T1: 1000, T2: 500, PD: 1.0, w: 0 },
{ id: 'obj2', x: 0.0, T1: 1000, T2: 500, PD: 0.5, w: 0 },
{ id: 'obj3', x: 0.5, T1: 1000, T2: 500, PD: 0.8, w: 0 }
];
const sim = new BlochSimulator(phantomSpins, 60, 0.2, 'rotating', 'GRE', { flipAngle: 90, TE: 30, TR: 100 });
const results = sim.run();
const spatialProfile = compute1D_FFT(results.signals.map(s => s.Mxy));