Skip to contents

This function normalizes 1D NMR spectra using the ERETIC reference signal. If integr = TRUE, it returns the ERETIC integral only. The reference region is inferred automatically based on the observed ERETIC peak (around 12 ppm for urine or 15 ppm for plasma).

Usage

normErectic(X, integr = FALSE)

Arguments

X

Numeric matrix. NMR data with spectra in rows and chemical shift positions as column names.

integr

Logical. If TRUE, the function returns the ERETIC integral for each spectrum. If FALSE, returns the normalized spectra.

Value

  • If integr = TRUE: numeric vector of ERETIC integrals per spectrum.

  • If integr = FALSE: numeric matrix of spectra normalized by ERETIC integral.

Details

The function identifies the dominant ERETIC peak within the range 10–16 ppm and then uses a narrow window around 12 ppm (urine) or 15 ppm (plasma) to compute the normalization factor.

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 x 1000 points
colnames(spectra) = ppm
matspec(spectra, ppm, shift=c(11, 13))
X_norm = normErectic(spectra) matspec(X_norm, ppm, shift=c(11, 13))