Skip to contents

Aligns 1D NMR spectra using signal-adaptive ppm intervals derived from the cohort median spectrum. Intervals are constructed around median peak systems and aligned locally via cross-correlation. The function accepts either a metabom8-style dat list or plain matrix/vector with ppm.

Usage

align_spectra(x, ppm = NULL, half_win_ppm = 0.007, lag.max = 200)

Arguments

x

A numeric matrix/vector of spectra or a named list with elements X, ppm, and optionally meta.

ppm

Numeric vector of chemical shift values (ppm). Ignored if x is a dat list.

half_win_ppm

Numeric scalar controlling alignment interval width.

lag.max

Integer. Maximum allowed lag for cross-correlation alignment.

Value

If input is dat, returns updated dat. Otherwise returns aligned matrix.

Details

Alignment intervals are derived from peaks in the cohort median spectrum.

The half_win_ppm parameter controls interval granularity:

  • Smaller values (e.g. 0.005–0.007 ppm) generate more, narrower intervals (RSPA-like behaviour).

  • Larger values (e.g. 0.008–0.015 ppm) merge nearby multiplets into broader regions (icoshift-like behaviour).

Typical 600–800 MHz \(^1\)H NMR data:

  • 0.006–0.008 ppm: stable multiplet-level alignment

  • <0.005 ppm: may split J-coupled systems

  • >0.015 ppm: may merge unrelated resonances

Alignment parameters and interval definitions are recorded in attr(X, "m8_prep").

Examples

data(hiit_raw)
plot_spec(hiit_raw, shift=c(1.3,1.4))
hiit_aligns <- align_spectra(hiit_raw) plot_spec(hiit_aligns, shift=c(1.3,1.4)) # aligned segment
plot_spec(hiit_aligns, shift=c(3, 3.1)) # aligned segment