baseline: baseline

View source: R/baseline.R

baselineR Documentation

baseline

Description

Maturing lifecycle

Fits a baseline to each spectrum in a matrix and removes it from the corresponding input spectrum. A vector can also be passed to this function.

Usage

baseline(X, wav)

Arguments

X

a numeric matrix or vector to process (optionally a data frame that can be coerced to a numerical matrix).

wav

optional. A numeric vector of band positions.

Details

The baseline function find points lying on the convex hull of a spectrum, connects the points by linear interpolation and subtracts the interpolated line (baseline) from the corresponding spectrum.

Value

a matrix or vector with the baselined spectra. The resulting matrix is output with an attribute called baselines which contain the spectra of the fitted baselines.

This function is similar to continuumRemoval and it might replace some of its functionality in the future.

Author(s)

Leonardo Ramirez-Lopez with contributions from Mervin Manalili

See Also

savitzkyGolay, movav, gapDer, binning, continuumRemoval

Examples

data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))
# plot of the 5 first absorbance spectra
matplot(wav,
  t(NIRsoil$spc[1:5, ]),
  type = "l",
  ylim = c(0, .6),
  xlab = "Wavelength /nm",
  ylab = "Absorbance"
)

bs <- baseline(NIRsoil$spc, wav)
matlines(wav, t(bs[1:5, ]))

fitted_baselines <- attr(bs, "baselines")
matlines(wav, t(fitted_baselines[1:5, ]))
title("Original spectra, baselines and baselined spectra")

prospectr documentation built on June 22, 2024, 11:08 a.m.