> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Automatic phase correction of NMR spectra
- URL: https://mfitzp.ghost.io/automatic-phase-correction-of-nmr-spectra/
- Published: 2014-06-01T00:00:00.000Z
- Updated: 2024-04-02T21:10:47.000Z
- Author: Martin Fitzpatrick
- Tags: Python, Data Science, #Import 2026-08-24 14:26

This notebook demonstrates automatic phase correction algorithms implemented for nmrglue. Two standard algorithms are implemented:

- ACME algorithm by Chen Li et al. Journal of Magnetic Resonance 158 (2002) 164-168
- Naive peak minima minimisation

The outputs for the two algorithms are shown below. Automatic phase correction can be used through the addition of an `autops` function to the `proc_base` set alongside the algorithm name to employ for scoring of phase. Custom algorithms can be provided via the same parameter.

```Python
import nmrglue as ng

dic, data = ng.bruker.read("/Users/mxf793/Data/THPNH/Extract/1d/103/")
data = ng.bruker.remove_digital_filter(dic, data)

```

```Python
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4))
plt.plot(data)

```

```
/usr/local/lib/python2.7/site-packages/numpy/core/numeric.py:462: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)

[<matplotlib.lines.Line2D at 0x10cc7d090>]

```

![png](https://blog.martinfitzpatrick.com/static/tutorials/legacy/automatic-phase-correction-nmr-spectra/automatic-phase-correction-nmr-spectra_3_2.png)

```Python
data_fft = ng.proc_base.fft(data)
plt.figure(figsize=(10,4))
plt.plot(data_fft)

```

```
[<matplotlib.lines.Line2D at 0x10d0588d0>]

```

![png](https://blog.martinfitzpatrick.com/static/tutorials/legacy/automatic-phase-correction-nmr-spectra/automatic-phase-correction-nmr-spectra_4_1.png)

```Python
data_pc_pm = ng.proc_base.autops(data_fft,'peak_minima')

```

```
Optimization terminated successfully.
         Current function value: 0.000037
         Iterations: 90
         Function evaluations: 165

```

```Python
plt.figure(figsize=(10,4))
plt.plot(data_pc_pm)

```

```
[<matplotlib.lines.Line2D at 0x10d2e6710>]

```

![png](https://blog.martinfitzpatrick.com/static/tutorials/legacy/automatic-phase-correction-nmr-spectra/automatic-phase-correction-nmr-spectra_6_1.png)

```Python
data_pc_acme = ng.proc_base.autops(data_fft,'acme')

```

```
Warning: Maximum number of function evaluations has been exceeded.

```

```Python
plt.figure(figsize=(10,4))
plt.plot(data_pc_acme)

```

```
[<matplotlib.lines.Line2D at 0x10d4db850>]

```

![png](https://blog.martinfitzpatrick.com/static/tutorials/legacy/automatic-phase-correction-nmr-spectra/automatic-phase-correction-nmr-spectra_8_1.png)