Method
A nonrecursive filter is defined by the convolution formula:
The 's are the coefficients of the filter, the
's are the input data, and the
's are the
outputs. The set of points
to
define the moving window of the filter, of width
, where
and
. The
Savitzky-Golay smoothing method finds filter coefficients
that preserve the zeroth, the first, the second, and higher moments. The idea is to approximate the
underlying function within a moving filter window by a polynomial of order
2
, or
of order 4
. For each data point, ,
least-squares fit a polynomial to all
points
within the filter window, and then set
to be the
value of that polynomial at position
.
No use is made of the value of that polynomial at any other point. For the next point,
, a whole new least-squares fit is done using the
shifted window.
Since the process of least-squares fitting involves only a linear matrix inversion, the
coefficients of a fitted polynomial are themselves linear in the values of the data. All the
least-squares fitting can be done in advance, for fictitious data consisting of all zeros except
for a single 1
, and then the fits on the real data are done by taking linear
combinations. Thus, there are particular sets of filter coefficients,
, for which the
convolution formula automatically accomplishes the process of polynomial least-squares fitting
inside a moving window.
The Savitzky-Golay filters provide smoothing without loss of resolution when the underlying function can be locally well fitted by a polynomial. This is true for smooth line profiles not too much narrower than the filter width. When this is not true, these filters have no advantage over other smoothing methods.
If the data is irregularly sampled, that is, the
values are not equally spaced, one can
pretend that the data points are equally spaced. This amounts to virtually shifting, within
each moving window, the data points to equally spaced positions. Such a shift introduces
the equivalent of an additional source of noise into the function values. In those cases where
smoothing is useful, this noise will often be much smaller than the noise already present.
Specifically, if the location of the points is approximately random within the window, then
a rough criterion is this: If the change in
across the full width of the window,
, is less
than
times the measurement noise on a single
point, then this implementation of the Savitzky-Golay filter can be used.