Pure R implementation of the Savitzky-Golay filter using local polynomial fitting. Useful for smoothing noisy signals while preserving features like peak height and width better than simple moving averages.
Details
The Savitzky-Golay filter fits a local polynomial of degree poly_order
to a window of window_length points, using least-squares. The filter
coefficients are computed analytically and applied via convolution.
For differentiation (deriv > 0), the result is the derivative of the
fitted polynomial, which provides a smooth estimate of the derivative.
Edge handling: the first and last floor(window_length/2) points are
computed with truncated windows where possible, or set to NA.
References
Savitzky A, Golay MJE (1964). "Smoothing and Differentiation of Data by Simplified Least Squares Procedures." Analytical Chemistry, 36(8), 1627-1639.
See also
butterworthFilter() for frequency-domain Butterworth filtering,
movingAverage() for simple moving average smoothing,
differentiate() for numerical differentiation.