SavitzkyGolay: Savitzky-Golay filtering and derivatives

View source: R/SavitzkyGolay.R

SavitzkyGolayR Documentation

Savitzky-Golay filtering and derivatives

Description

Savitzky-Golay filtering and derivatives

Usage

SavitzkyGolay(
  X,
  poly = 3,
  width = 11,
  deriv = 2,
  ends = c("cut", "extrapolate", "zeros")
)

Arguments

X

matrix containing spectra as rows.

poly

Polynomial degree of smoother.

width

Window width of smoother, default = 11, must be an odd number.

deriv

Derivative degree, can be 0, default = 2.

ends

Handling of spectrum ends, i.e. first and last (width-1)/2 points. Default is "cut", i.e. remove ends, "extrapolate" copies the first/last estimable point, while "zeros" is included for backward compatilibity (fill with 0).

Value

A matrix of filtered spectra (possibly with derivatives)

Examples

data(fishoil)
Raman    <- fishoil$Raman[, 850:3300]
SavGol   <- SavitzkyGolay(Raman)
old.par  <- par(mfrow = c(2,1), mar = c(4,4,1,1))
matplot(colnames(Raman), t(Raman), type = 'l',
        ylab = 'Relative intensity', xlab = 'Raw spectra')
matplot(colnames(SavGol), t(SavGol), type = 'l',
        ylab = 'Relative intensity', xlab = 'Smoothed 2nd derivative')
par(old.par)

EMSC documentation built on May 29, 2024, 3:07 a.m.