Savitzky-Golay Filter
Table of contents
Introduction
Savitzky-Golay Filter smooths spectra by fitting a local polynomial in a moving window and evaluating the fitted center point.
How to use
To apply Savitzky-Golay smoothing to your data:
- Upload data and select the spectra you want to process.
- Navigate to the sidebar and turn on the Smoothing toggle.
- In Select smoothing function, choose Savitzky-Golay filter.
- Configure parameters:
- Window length (defaults to
15) - Polynomial order (defaults to
2) - Should be less than window length.
- Window length (defaults to
Behavior
If Savitzky-Golay filter is selected, SpectraGuru’s smoothing feature applies SciPy’s implementation signal.savgol_filter to each spectrum, which works as follows:
- For each Ramanshift value $x$, consider the values between $x-\frac{w}{2}$ and $x+\frac{w}{2}$, where $w$ is the window length.
-
Try to find the polynomial with order $d$ that best fits with the data centered around $x$. Mathematically speaking, this can be thought of as a minimization of the following expression as the coefficients $a_i$ vary:
\[\sum_{j=-w/2}^{w/2} \left(I(x+j)-\sum_{i=0}^d \left(a_i (x+j)^i\right)\right)^2\]where $I(x)$ is the actual intensity at Ramanshift $x$.
- Minimize the above expression using least squares optimization on the coefficients $a_i$. Then use the polynomial fit to find the filtered intensity at Ramanshift $x$.
- Repeat this process for all $x$.
Method
The filter fits a local polynomial in each moving window and uses the fitted center value:
\[\hat{y}_i = \sum_{j=-m}^{m} c_j y_{i+j}\]| Parameter | Tunable or fixed | Implementation |
|---|---|---|
| Savitzky-Golay window length | Tunable | Default 15, UI range 1-100 |
| Savitzky-Golay polynomial order | Tunable | Default 2, UI range 1-15; must be less than window length |
| Filtering function | Fixed | scipy.signal.savgol_filter |
References
SpectraGuru uses SciPy’s signal.savgol_filter function for Savitzky-Golay smoothing.
- Virtanen, P., Gommers, R., Oliphant, T. E., Haberland, M., Reddy, T., Cournapeau, D., … SciPy 1.0 Contributors. (2020). SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nature Methods, 17(3), 261–272. https://doi.org/10.1038/s41592-019-0686-2