% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/features_ppick.R
\name{ppick2}
\alias{ppick2}
\title{Peak picking using Savitzky–Golay derivatives}
\usage{
ppick2(
  X,
  ppm = NULL,
  type = c("max", "min", "both"),
  fil_p = 3L,
  fil_n = 11L,
  noise_win = NULL,
  min_snr = 10,
  min_height = NULL,
  min_prominence = NULL,
  prom_half_window_ppm = 0.02,
  min_distance_ppm = 0.005,
  min_curvature = NULL,
  keep_cols = c("height", "snr", "curvature", "prominence")
)
}
\arguments{
\item{X}{Numeric matrix or vector. Spectra in rows.}

\item{ppm}{Numeric vector or NULL. If NULL, inferred from colnames(X).}

\item{type}{Character. "max", "min", or "both".}

\item{fil_p}{Integer. Polynomial order for SG filter.}

\item{fil_n}{Integer. Window length for SG filter (odd).}

\item{noise_win}{Numeric length-2 vector or NULL. Ppm window used to estimate noise per spectrum.
If NULL, a robust noise estimate is computed from the full spectrum (MAD of first differences).}

\item{min_snr}{Numeric. Minimum SNR (peak height / noise). Set NULL to disable.}

\item{min_height}{Numeric. Minimum absolute peak height (in original intensity units). NULL disables.}

\item{min_prominence}{Numeric. Minimum local prominence. NULL disables.}

\item{prom_half_window_ppm}{Numeric. Half-window (ppm) for prominence estimation around each peak.}

\item{min_distance_ppm}{Numeric. Minimum separation between peaks (ppm). NULL disables.}

\item{min_curvature}{Numeric. Minimum absolute curvature at peak (|d2|). NULL disables.}

\item{keep_cols}{Character. Extra columns to keep (default keeps all computed).}
}
\value{
List of data.frames (one per spectrum). Each contains:
idc, ppm, Int, Etype (+1 max, -1 min), height, snr, curvature, prominence.
}
\description{
Finds local extrema in 1D spectra using Savitzky–Golay first and second derivatives.
Candidate peaks are identified at zero-crossings of the first derivative and classified
by the sign of the second derivative. Optional filters control peak height, prominence,
SNR, curvature and minimum separation.
}
\examples{
data(covid)
X <- covid$X
ppm <- covid$ppm

peaklist <- ppick2(X[1,], ppm, min_snr=50)

plot_spec(X[1, ], ppm, shift = c(3, 4.5), backend='base')
points(peaklist[[1]]$ppm, peaklist[[1]]$Int, col = "cyan")
head(peaklist[[1]])
}
