smooth_savitzky {alkahest}R Documentation

Savitzky-Golay Filter

Description

Savitzky-Golay Filter

Usage

smooth_savitzky(x, y, ...)

## S4 method for signature 'numeric,numeric'
smooth_savitzky(x, y, m = 3, p = 2)

## S4 method for signature 'ANY,missing'
smooth_savitzky(x, m, p)

Arguments

x, y

A numeric vector. If y is missing, an attempt is made to interpret x in a suitable way (see grDevices::xy.coords()).

...

Currently not used.

m

An odd integer giving the window size (i.e. the number of adjacent points to be used).

p

An integer giving the degree of the polynomial to be used.

Details

This method is based on the least-squares fitting of polynomials to segments of m adjacent points.

Value

Returns a list with two components x and y.

Note

There will be (m - 1) / 2 points both at the beginning and at the end of the data series for which a complete m-width window cannot be obtained. To prevent data loss, the original (m - 1) / 2 points at both ends of the data series are preserved.

Author(s)

N. Frerebeau

References

Gorry, P. A. (1990). General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method. Analytical Chemistry, 62(6), p. 570-573. doi:10.1021/ac00205a007.

Savitzky, A. & Golay, M. J. E. (1964). Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 36(8), p. 1627-1639. doi:10.1021/ac60214a047.

See Also

Other smoothing methods: smooth_likelihood(), smooth_loess(), smooth_rectangular(), smooth_triangular(), smooth_whittaker()

Examples

## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)

## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")

## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")

## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")

## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")

## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")

## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")

[Package alkahest version 1.2.0 Index]