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.

Automated Phase Correction

Manual phase correction is often tedious. The .xmr.autophase() method automates this process by utilizing global optimization algorithms to find the ideal zero-order (p0p_0) and first-order (p1p_1) phase angles.

Because Magnetic Resonance Spectra vary wildly in density and Signal-to-Noise Ratio (SNR), xmris provides three distinct scoring methods:

  1. acme: Minimizes spectral entropy. Excellent for dense, high-SNR spectra with multiple overlapping peaks.

  2. positivity: Maximizes positive real signal and heavily penalizes negative signal within a defined Region of Interest (ROI). Excellent for sparse, noisy spectra.

  3. peak_minima: Minimizes the difference between the minima on either side of a target peak. Good for isolated peaks on a rolling baseline.

Imports & plotting function to compare spectra

1. Complex Multi-Peak Spectra (ACME)

The ACME algorithm works best when there is plenty of signal to evaluate across the entire spectrum. Here, we simulate a dense spectrum, intentionally ruin the phase, and compare the automated solvers.

As expected, acme reconstructs the ground truth perfectly, whereas local ROI solvers struggle because they ignore the wider spectral context.

Make a dummy 1H spectrum
<Figure size 1000x1100 with 5 Axes>

2. Sparse, Noisy Spectra (Positivity)

When dealing with sparse spectra (e.g., hyperpolarized 13C{}^{13}\text{C} or isolated 31P{}^{31}\text{P} peaks) hidden in high noise, entropy-based methods like ACME often fail because the noise dominates the objective function.

In these cases, utilizing the positivity or peak_minima methods over a localized peak_width around the highest signal is significantly more robust.

Make a dummy 13C spectrum
<Figure size 1000x1100 with 5 Axes>

3. Ultra-Low SNR & Parameter Locking

In extremely challenging SNR environments, fitting both p0p_0 and p1p_1 simultaneously can lead to the optimizer escaping into local minima by applying massive, unrealistic first-order twists.

You can restrict the solver by locking the first-order phase (p0_only=True) and forcing it to evaluate an explicit coordinate (target_coord) rather than guessing the peak location based on the absolute maximum (which might just be a noise spike).

Make another dummy 13C spectrum (even lower SNR)
<Figure size 1000x1100 with 5 Axes>

4. Multi-Dimensional Datasets (mode)

When processing multi-dimensional data (such as kinetic series, dynamic nuclear polarization buildups, or repeated acquisitions), attempting to autophase every slice individually can be risky—especially for early time points where the signal is buried in noise.

The autophase method handles N-dimensional data natively via the mode parameter:

Make a dummy 2D dataset (e.g., an amplitude buildup)
<Figure size 1000x660 with 3 Axes>
References
  1. Chen, L., Weng, Z., Goh, L., & Garland, M. (2002). An efficient algorithm for automatic phase correction of NMR spectra based on entropy minimization. Journal of Magnetic Resonance, 158(1–2), 164–168. 10.1016/s1090-7807(02)00069-1