Skip to contents

Aligns spectra within a specified ppm window using cross-correlation. Only the selected region is aligned; the remainder of the spectra is unchanged.

Usage

align_segment(
  dat,
  shift,
  idx_ref = 1,
  med = TRUE,
  clim = 0.7,
  norm = FALSE,
  lag.max = 20
)

Arguments

dat

Named list with elements:

X

Numeric matrix (spectra in rows)

ppm

Numeric vector of chemical shift values

meta

Optional metadata

shift

Numeric vector of length 2 specifying ppm region to align.

idx_ref

Integer. Row index to use as reference spectrum.

med

Logical. Use row-wise median spectrum as reference?

clim

Numeric. Minimum correlation threshold.

norm

Logical. Z-scale before alignment.

lag.max

Integer. Maximum lag allowed.

Value

Updated dat list with aligned spectra in selected region.

Examples

data(hiit_raw)
plot_spec(hiit_raw, shift=c(1.3,1.4))
hiit_aligned <- align_segment(hiit_raw, c(1.3, 1.35)) plot_spec(hiit_aligned, shift=c(1.3,1.4)) # aligned segment
plot_spec(hiit_aligned, shift=c(3, 3.1)) # segment not aligned