Skip to contents

Normalises 1D NMR spectra using an ERETIC reference signal. By default the ERETIC position is discovered in a search window and the spectra are normalised by the integral in a narrow window around the detected position. Power users can supply pos to enforce a fixed ERETIC position.

Usage

norm_eretic(
  X,
  integr = FALSE,
  ppm = NULL,
  pos = NULL,
  search = c(10, 16),
  width = 0.2,
  warn_absent = TRUE,
  noise_win = c(9.8, 10.2),
  snr_factor = 10
)

Arguments

X

Numeric matrix or vector. NMR spectra with spectra in rows. If ppm is not provided, it is inferred from colnames(X).

integr

Logical. If TRUE, returns the ERETIC integral per spectrum. If FALSE, returns the normalised spectra.

ppm

Numeric vector of chemical shift positions. If NULL, inferred from colnames(X).

pos

Numeric scalar or NULL. If NULL (default), ERETIC position is discovered within search. If provided, the ERETIC window is centered on pos.

Numeric vector of length 2. Ppm window used to discover ERETIC when pos = NULL.

width

Numeric scalar. Full integration window width in ppm (default 0.2 gives pos ± 0.1).

warn_absent

Logical. If TRUE, warn when ERETIC integral is zero/invalid for individual spectra.

noise_win

Numeric vector of length 2. Ppm window for estimating noise intensity.

snr_factor

Numeric scaler. Minimum Signal-to-Noise Ratio required for detecting the ERETIC peak.

Value

If integr = TRUE, numeric vector of ERETIC integrals. If integr = FALSE, numeric matrix of normalised spectra.

Details

Binning/normalisation history is recorded in attr(X, "m8_prep") if present. Ppm axis values are stored in attr(X, "m8_axis")$ppm.

Examples

set.seed(123)

n <- 1000
ppm <- seq(0, 14, length.out = n)

gauss <- function(x, c, h, w = 0.05) {
  h * exp(-((x - c)^2) / (2 * w^2))
}

heights <- c(100, 80, 60, 40, 20)

spectra <- sapply(heights, function(h)
  rnorm(n, 0, 0.01) + gauss(ppm, 12, h)
)

spectra <- t(spectra)   # 5 spectra × 1000 variables

plot_spec(spectra, ppm, shift = c(11, 13))
X_norm <- norm_eretic(spectra, ppm=ppm) plot_spec(X_norm, ppm, shift=c(11, 13))