Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Simulating NMR Spectra with xmris

In this tutorial, we will use the xmris.processing.simulation module to generate synthetic Free Induction Decay (FID) signals. Generating synthetic data is a critical step for validating fitting algorithms, building test suites, and understanding the physical parameters that govern magnetic resonance spectroscopy (MRS).

We will generate two distinct datasets with realistic parameters and physical noise:

  1. A 1H (Proton) spectrum showing the dominant water and lipid (fat) resonances.

  2. A 13C (Carbon-13) spectrum showing typical downstream metabolites of hyperpolarized [1-13C]pyruvate, utilizing carrier frequency offsets to prevent spectral aliasing.

FunctionWhat it does here
simulate_fid()generates the complex FID from a peak list
.xmr.to_spectrum()FID → spectrum, for looking at the result
.xmr.to_ppm()relabels the frequency axis in ppm

Theory: The AMARES Simulation Model

The signal generation in xmris is grounded in the AMARES (Advanced Method for Accurate, Robust, and Efficient Spectral fitting) algorithm, originally introduced by Vanhamme, van den Boogaart, and Van Huffel in 1997.

The time-domain magnetic resonance spectroscopy signal is modeled as a sum of exponentially damped sinusoids. The specific forward model used in our simulation function corresponds to Equation 6 of the AMARES paper:

yn=∑k=1Kakejϕke(−dk(1−gk+gktn)tn)ej2πfktny_n=\sum_{k=1}^{K}a_ke^{j\phi_k}e^{(-d_k(1-g_k+g_kt_n)t_n)}e^{j2\pi f_kt_n}

Where the parameters for each peak kk are defined as:

1. Environment Setup

First, let’s import the necessary libraries. We will use numpy for array math, xarray for data structures, matplotlib.pyplot for figure management, and our updated simulate_fid function.

2. Simulating a Noisy 1H (Proton) Spectrum

Proton spectroscopy in tissue is dominated by the massive water peak and the lipid backbone resonances. For this simulation, we assume a 3T clinical scanner (Larmor frequency ~127.7 MHz). We will also inject a realistic noise floor using our target_snr feature.

We will simulate the following resonances:

<Figure size 800x400 with 1 Axes>

To visualize the spectrum, we apply a Fast Fourier Transform (FFT). Because we simulated around a default carrier of 0 ppm, we construct the chemical shift axis directly from the FFT frequencies.

<Figure size 800x400 with 1 Axes>

3. Simulating a 13C (Carbon-13) Spectrum with Carrier Offsets

Carbon-13 MRS spans a much wider chemical shift range. We will simulate the downstream metabolites of [1-13C]pyruvate. If we simulated this relative to 0 ppm, the massive frequency offsets would violate the Nyquist limit at standard sampling rates, causing the peaks to wrap (alias) to the wrong side of the spectrum.

To fix this, we set our carrier_ppm to 171.0 ppm, effectively centering the “listening window” of our digital receiver right over our metabolites.

<Figure size 1000x500 with 1 Axes>