A Savitzky-Golay filter smooths data by fitting a polynomial in a moving window using polynomial
least squares fitting and evaluating the fitted polynomial
at the desired location (Savitzky and Golay 1964). A fit of polynomial
degree
requires at least
distinct data points. For equally spaced data, a fixed
window and fixed polynomial degree give reusable
convolution weights. Low-degree fits provide smoothing,
while a fit of degree one less than the window size simply interpolates the data.
Derivatives of the fitted polynomial similarly give
numerical differentiation formulas.
For local distinct real abscissas ,
, ...,
, choose orthogonal
polynomials
of polynomial degree
for the discrete inner product
. For
and
, the
th derivative of the fitted
polynomial at
is
|
(1)
|
with weights
|
(2)
|
where
(Gorry 1990, 1991). Evaluating the first and last windows away from their centers
retains estimates at the endpoints instead of discarding them (Gorry 1990). For unequally
spaced data, the local weights generally depend on the locations of the data points,
so a single translation-invariant convolution stencil
does not in general apply (Gorry 1991).
For example, take five equally spaced samples at offsets
from the window center, where
,
, 0, 1, 2 and
. A quadratic polynomial
fitted to these samples gives
|
(3)
| |||
|
(4)
|