## S3 method for class 'sgolayFilter'filter(filt, x,...)sgolayfilt(x, p =3, n = p +3- p%%2, m =0, ts =1)
Arguments
filt: Filter characteristics, usually the result of a call to sgolay
x: the input signal to be filtered, specified as a vector or as a matrix. If x is a matrix, each column is filtered.
...: Additional arguments (ignored)
p: Polynomial filter order; must be smaller than n.
n: Filter length; must a an odd positive integer.
m: Return the m-th derivative of the filter coefficients. Default: 0
ts: Scaling factor. Default: 1
Returns
The filtered signal, of the same dimensions as the input signal.
Details
Savitzky-Golay smoothing filters are typically used to "smooth out" a noisy signal whose frequency span (without noise) is large. They are also called digital smoothing polynomial filters or least-squares smoothing filters. Savitzky-Golay filters perform better in some applications than standard averaging FIR filters, which tend to filter high-frequency content along with the noise. Savitzky-Golay filters are more effective at preserving high frequency signal components but less successful at rejecting noise.
Savitzky-Golay filters are optimal in the sense that they minimize the least-squares error in fitting a polynomial to frames of noisy data.
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", xlab ="", ylab ="")lines(filtfilt(rep(1,5)/5,1, x), col ="red")# averaging filterlines(filtfilt(bf, x), col ="blue")# butterworthpoints(x, pch ="x")# original datalegend("topleft", c("sgolay (3,5)","5 sample average", "order 5Butterworth", "original data"), lty=c(1,1,1,NA),pch = c(NA,NA,NA,"x"), col = c(1,"red","blue",1))