prospectr (version 0.1.3)

savitzkyGolay: Savitzky-Golay transformation

Description

Savitzky-Golay smoothing and derivative of a data matrix, data.frame or vector.

Usage

savitzkyGolay(X,m,p,w,delta.wav)

Arguments

X
a numeric data.frame, matrix or vector to transform
m
differentiation order
p
polynomial order
w
window size (must be odd)
delta.wav
optional sampling interval

Details

The Savitzky-Golay algorithm fits a local polynomial regression on the signal. It requires evenly spaced data points. Mathematically, it operates simply as a weighted sum over a given window: $$x_j\ast = \frac{1}{N}\sum_{h=-k}^{k}{c_hx_{j+h}}$$ where $x_j\ast$ is the new value, $N$ is a normalizing coefficient, $k$ is the gap size on each side of $j$ and $c_h$ are pre-computed coefficients, that depends on the chosen polynomial order and degree. The sampling interval specified with the delta.wav argument is used for scaling and get numerically correct derivatives. The convolution function is written in C++/Rcpp for faster computations.

References

Savitzky, A., and Golay, M.J.E., 1964. Smoothing and differentiation of data by simplified least squares procedures. Anal. Chem. 36, 1627-1639. Wentzell, P.D., and Brown, C.D., 2000. Signal processing in analytical chemistry. Encyclopedia of Analytical Chemistry, 9764-9800.

See Also

sgolayfilt

Examples

Run this code
data(NIRsoil)
spc <- 1/10^NIRsoil$spc # conversion to reflectance
opar <- par(no.readonly = TRUE)
par(mfrow=c(2,1),mar=c(4,4,2,2))
# plot of the 10 first spectra
matplot(as.numeric(colnames(spc)),t(spc[1:10,]),type='l',xlab='',ylab='Reflectance')
mtext('Raw spectra')
sg <- savitzkyGolay(X = spc,1,3,11,delta.wav=2)
matplot(as.numeric(colnames(sg)),t(sg[1:10,]),type='l',xlab='Wavelength /nm',ylab='1st derivative')
mtext('1st derivative spectra')
par(opar)

Run the code above in your browser using DataLab