% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preproc_alignSegment.R
\name{.alignSegment}
\alias{.alignSegment}
\title{Align NMR Spectra via Cross-Correlation}
\usage{
.alignSegment(
  seg,
  idx_ref = 1,
  clim = 0.7,
  med = TRUE,
  norm = FALSE,
  lag.max = 20
)
}
\arguments{
\item{seg}{Numeric matrix. Each row is a 1D NMR spectrum segment.}

\item{idx_ref}{Integer. Row index to use as reference spectrum. Ignored if
\code{med = TRUE}.}

\item{clim}{Numeric. Minimum cross-correlation threshold. Segments with lower
similarity are not shifted.}

\item{med}{Logical. If \code{TRUE}, the row-wise median spectrum is used as
the reference.}

\item{norm}{Logical. If \code{TRUE}, rows are z-scaled prior to alignment.}
}
\value{
A numeric matrix of aligned spectra with the same dimensions as
\code{seg}. If \code{med = TRUE}, the output excludes the median row.
}
\description{
Aligns rows of an NMR spectral matrix to a reference spectrum by maximizing
cross-correlation. Optionally uses the row-wise median spectrum as reference.
Useful for minor spectral misalignments.
}
\details{
Each spectrum is aligned to the reference by computing the cross-correlation
and applying a lag-based linear interpolated shift. The shift is applied only
if the cross-correlation exceeds \code{clim}. This function is intended for
fine-tuning alignment across short ppm windows (i.e., segments).
}
\keyword{internal}
