% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preproc_alignSegment.R
\name{align_spectra}
\alias{align_spectra}
\title{Cohort-Guided Interval Alignment for 1D NMR Spectra}
\usage{
align_spectra(x, ppm = NULL, half_win_ppm = 0.007, lag.max = 200)
}
\arguments{
\item{x}{A numeric matrix/vector of spectra or a named list with elements
\code{X}, \code{ppm}, and optionally \code{meta}.}

\item{ppm}{Numeric vector of chemical shift values (ppm). Ignored if \code{x} is
a \code{dat} list.}

\item{half_win_ppm}{Numeric scalar controlling alignment interval width.}

\item{lag.max}{Integer. Maximum allowed lag for cross-correlation alignment.}
}
\value{
If input is \code{dat}, returns updated \code{dat}. Otherwise returns aligned matrix.
}
\description{
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 \code{dat} list or plain matrix/vector with \code{ppm}.
}
\details{
Alignment intervals are derived from peaks in the cohort median spectrum.

The \code{half_win_ppm} parameter controls interval granularity:

\itemize{
\item Smaller values (e.g. 0.005–0.007 ppm) generate more, narrower
intervals (RSPA-like behaviour).
\item Larger values (e.g. 0.008–0.015 ppm) merge nearby multiplets into
broader regions (icoshift-like behaviour).
}

Typical 600–800 MHz \eqn{^1}H NMR data:
\itemize{
\item 0.006–0.008 ppm: stable multiplet-level alignment
\item <0.005 ppm: may split J-coupled systems
\item >0.015 ppm: may merge unrelated resonances
}

Alignment parameters and interval definitions are recorded in
\code{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
}
\seealso{
\code{\link{align_segment}}

Other preprocessing: 
\code{\link{align_segment}()},
\code{\link{binning}()},
\code{\link{calibrate}()},
\code{\link{correct_baseline}()},
\code{\link{correct_lw}()},
\code{\link{pqn}()},
\code{\link{print_preprocessing}()}
}
\concept{preprocessing}
