% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preproc_bline.R
\name{correct_baseline}
\alias{correct_baseline}
\alias{bline}
\title{Baseline Correction for Spectral Data}
\usage{
correct_baseline(X, method = c("asls", "linear"), ...)

bline(X, ...)
}
\arguments{
\item{X}{Numeric matrix or metabom8 \code{dat} object containing spectra
in rows and spectral variables in columns.}

\item{method}{Character specifying the baseline correction algorithm.
One of:
\describe{
\item{\code{"asls"}}{Asymmetric least squares baseline estimation.}
\item{\code{"linear"}}{Linear baseline estimated from edge regions.}
}}

\item{...}{Additional parameters passed to the selected method.

\strong{Arguments for \code{method = "asls"}}
\describe{
\item{lambda}{Numeric smoothing parameter controlling baseline stiffness.
Larger values produce smoother baselines. Default \code{1e7}.}
\item{iter_max}{Maximum number of iterations used in the baseline
estimation procedure. Default \code{30}.}
}

\strong{Arguments for \code{method = "linear"}}
\describe{
\item{ppm}{Numeric vector describing the spectral axis (e.g. chemical shift).
Must have length equal to \code{ncol(X)}.}
\item{edge_frac}{Fraction of points at each spectrum edge used to
estimate the baseline. Default \code{0.1}.}
}}
}
\value{
Numeric matrix containing baseline-corrected spectra with the
same dimensions as \code{X}. If \code{X} is a metabom8 \code{dat} object, the corrected
matrix replaces the \code{X} component while preserving associated metadata.
}
\description{
Applies baseline correction to each spectrum (row) of a spectral matrix.
Multiple correction algorithms are available and selected via the
\code{method} argument.
}
\details{
Baseline correction is performed independently for each spectrum.

The \code{"asls"} method estimates a smooth baseline using asymmetric least
squares smoothing, which is well suited for spectra with positive peaks
such as NMR metabolomics data.

The \code{"linear"} method estimates a straight baseline from the edges of
each spectrum and subtracts the fitted trend.

The returned object includes a \code{.stamp} attribute recording the
baseline correction method and parameters used.
}
\examples{
data(hiit_raw)

plot_spec(hiit_raw$X[1,], hiit_raw$ppm, shift=c(3.1,4), backend='base')
hiit_proc <-
  hiit_raw |>
  excise() |>
  correct_baseline()

plot_spec(hiit_proc$X[1,], hiit_proc$ppm, shift=c(3.1,4), backend='base', add=TRUE, col='red')

}
\references{
Eilers PHC, Boelens HFM (2005).
Baseline correction with asymmetric least squares smoothing.
}
\seealso{
Other preprocessing: 
\code{\link{align_segment}()},
\code{\link{align_spectra}()},
\code{\link{binning}()},
\code{\link{calibrate}()},
\code{\link{correct_lw}()},
\code{\link{pqn}()},
\code{\link{print_preprocessing}()}
}
\concept{preprocessing}
