Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sgolayfilt

Apply a Savitzky-Golay smoothing filter


Description

Smooth data with a Savitzky-Golay smoothing filter.

Usage

sgolayfilt(x, p = 3, n = p + 3 - p%%2, m = 0, ts = 1)

## S3 method for class 'sgolayFilter'
filter(filt, x, ...)

Arguments

x

signal to be filtered.

p

filter order.

n

filter length (must be odd).

m

return the m-th derivative of the filter coefficients.

ts

time scaling factor.

filt

filter characteristics (normally generated by sgolay).

...

additional arguments (ignored).

Details

These filters are particularly good at preserving lineshape while removing high frequency squiggles.

Value

The filtered signal, of length(x).

Author(s)

Original Octave version by Paul Kienzle pkienzle@users.sf.net. Modified by Pascal Dupuis. Conversion to R by Tom Short.

References

Octave Forge http://octave.sf.net

See Also

Examples

# Compare a 5 sample averager, an order-5 butterworth lowpass
# filter (cutoff 1/3) and sgolayfilt(x, 3, 5), the best cubic
# estimated from 5 points.
bf <- butter(5,1/3)
x <- c(rep(0,15), rep(10, 10), rep(0, 15))
sg <- sgolayfilt(x)
plot(sg, type="l")
lines(filtfilt(rep(1, 5)/5,1,x), col = "red") # averaging filter
lines(filtfilt(bf,x), col = "blue")           # butterworth
points(x, pch = "x")                          # original data

signal

Signal Processing

v0.7-6
GPL-2
Authors
Uwe Ligges [aut, cre] (new maintainer), Tom Short [aut] (port to R), Paul Kienzle [aut] (majority of the original sources), Sarah Schnackenberg [ctb] (various test cases and bug fixes), David Billinghurst [ctb], Hans-Werner Borchers [ctb], Andre Carezia [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], E. Farhi [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Sebastian Krey [ctb], Bill Lash [ctb], Friedrich Leisch [ctb], Olaf Mersmann [ctb], Paulo Neis [ctb], Jaakko Ruohio [ctb], Julius O. Smith III [ctb], Doug Stewart [ctb], Andreas Weingessel [ctb]
Initial release
2015-07-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.