Learn R Programming

EMSC (version 0.9.4)

SavitzkyGolay: 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")
)

Value

A matrix of filtered spectra (possibly with derivatives)

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).

Examples

Run this code
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)

Run the code above in your browser using DataLab