← Back to Blogs & Publications Spectroscopy Software Preprocessing Interfaces

Understanding Savitzky-Golay Filtering in Preprocessing

What the Savitzky-Golay filter actually does to a spectrum, why derivatives help with baselines and overlapping bands, and how window length and polynomial order should be chosen — with the original and follow-up literature.

Why spectra are pre-processed

Near-infrared spectra of process samples carry, on top of the chemical absorption signal, physical effects that vary from sample to sample: light scatter that depends on particle size and packing, additive baseline offsets and multiplicative changes in effective path length [1]. In diffuse-reflectance measurements these effects can account for a large part of the spectral variation [2], so before a quantitative model such as PLS regression is fitted, pre-processing is used to remove them while preserving the chemical information. Rinnan et al. divide the common NIR pre-processing methods into two families, scatter corrections (MSC, SNV, normalisation) and spectral derivatives, and note that the Savitzky-Golay derivative is one of the most widely used of the latter [1].

What the Savitzky-Golay filter does

Savitzky and Golay showed in 1964 that fitting a low-degree polynomial by least squares to the points inside a moving window, and taking the value of that polynomial at the window centre, is equivalent to convolving the data with a fixed set of integer weights; they tabulated those weights for windows of 5 to 25 points and for quadratic/cubic and quartic/quintic polynomials, both for smoothing and for derivatives [3]. Errors in some of the original tables were corrected in later papers [4][5], and Gorry gave a general method for computing the weights at every position in the window, which also resolves the loss of the first and last points at the ends of a spectrum [6].

Two consequences follow. First, because the weights depend only on the window length and the polynomial degree, the filter is a fixed finite-impulse-response operation and is cheap to apply [3][7]. Second, compared with a moving average of the same length, a Savitzky-Golay filter preserves peak height and width better, at the cost of somewhat less noise suppression [7]. In the classic formulation the window has an odd number of points, 2m + 1, so that it is centred on the point being estimated, and the data must be equally spaced [3].

Derivatives, baselines and overlapping bands

The same least-squares fit yields derivatives of the spectrum: the first and second derivatives of the fitted polynomial at the window centre are again convolutions with fixed weights [3]. Derivatives are used because of what they remove and what they reveal [1]:

  • The first derivative removes a constant (additive) baseline offset and shows the local slope of the spectrum.
  • The second derivative removes both the constant offset and a linear baseline slope; absorption maxima appear as negative bands, which helps to separate overlapping features [1][8].

Differentiation amplifies high-frequency noise, which is why the derivative is computed together with smoothing in a single step and why the window length matters. Luo et al. show that the contrast and resolution obtainable from a Savitzky-Golay differentiator depend on the ratio of the feature width to the filter length, and that small derivative details are not preserved well by long filters [9].

Choosing window length and polynomial order

There is no universal setting. Zimmermann and Kohler, working with PLS models on simulated and measured infrared data, found that the optimal window depends on the component being quantified, that the spectral noise level gives a rough guide to the window length, and that both the window and the polynomial order should be optimised for each application rather than copied from a default [8]. A practical procedure is therefore to treat window length, polynomial degree and derivative order as model hyper-parameters, to compare candidate settings by cross-validation error, and to check that the chosen derivative does not erase the narrow bands the model relies on [8][9]. Note that for smoothing and for even-order derivatives a quadratic and a cubic polynomial give identical Savitzky-Golay weights, so a “cubic” setting adds nothing over “quadratic” for a second derivative [3].

Savitzky-Golay in caliX

In the caliX suite the Savitzky-Golay smoothing and derivative filters are configured in the pre-processing step of model development, where window length, polynomial degree and derivative order are set and candidate settings are compared by cross-validation error, following the approach described by Zimmermann and Kohler [8].

References

  • [1] Rinnan, Å., van den Berg, F., Engelsen, S.B. (2009). Review of the most common pre-processing techniques for near-infrared spectra. TrAC Trends in Analytical Chemistry, 28(10), 1201–1222. doi:10.1016/j.trac.2009.07.007
  • [2] Barnes, R.J., Dhanoa, M.S., Lister, S.J. (1989). Standard Normal Variate Transformation and De-trending of Near-Infrared Diffuse Reflectance Spectra. Applied Spectroscopy, 43(5), 772–777. doi:10.1366/0003702894202201
  • [3] Savitzky, A., Golay, M.J.E. (1964). Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 36(8), 1627–1639. doi:10.1021/ac60214a047
  • [4] Steinier, J., Termonia, Y., Deltour, J. (1972). Smoothing and differentiation of data by simplified least square procedure. Analytical Chemistry, 44(11), 1906–1909. doi:10.1021/ac60319a045
  • [5] Madden, H.H. (1978). Comments on the Savitzky-Golay convolution method for least-squares-fit smoothing and differentiation of digital data. Analytical Chemistry, 50(9), 1383–1386. doi:10.1021/ac50031a048
  • [6] Gorry, P.A. (1990). General least-squares smoothing and differentiation by the convolution (Savitzky-Golay) method. Analytical Chemistry, 62(6), 570–573. doi:10.1021/ac00205a007
  • [7] Schafer, R.W. (2011). What Is a Savitzky-Golay Filter? [Lecture Notes]. IEEE Signal Processing Magazine, 28(4), 111–117. doi:10.1109/MSP.2011.941097
  • [8] Zimmermann, B., Kohler, A. (2013). Optimizing Savitzky-Golay Parameters for Improving Spectral Resolution and Quantification in Infrared Spectroscopy. Applied Spectroscopy, 67(8), 892–902. doi:10.1366/12-06723
  • [9] Luo, J., Ying, K., He, P., Bai, J. (2005). Properties of Savitzky–Golay digital differentiators. Digital Signal Processing, 15(2), 122–136. doi:10.1016/j.dsp.2004.09.008
USTECH Innovations Logo

Discuss this application for your process

Our application team can walk through the method, share the supporting literature and discuss how it applies to your process.

Contact Us

Read Next

Blend Uniformity Verification in Active Pharmaceutical Blending
ARTICLE

Blend Uniformity Verification in Active Pharmaceutical Blending

Why blend uniformity is a regulated in-process attribute, what thief sampling can and cannot tell you, and what the literature shows about in-line NIR monitoring of powder blending as a PAT tool.

Read Article
MEMS Comb-Drive Mechanical Durability in Industrial Environments
ARTICLE

MEMS Comb-Drive Mechanical Durability in Industrial Environments

What the reliability literature says about silicon springs and comb drives under shock, vibration, temperature cycling and fatigue, and what the military and IEC environmental test methods actually specify.

Read Article