Savitzky-Golay Filter
Table of contents
How to Use
To apply Savitzky-Golay smoothening to your data:
- Upload data and select the spectra you want to process.
- Navigate to the sidebar and turn on the “Smoothening” toggle.
- Select “Savitzky-Golay filter” from the drop-down menu.
- Configure parameters:
- Window length (defaults to
15) - Polynomial order (defaults to
2) - Should be less than window length.
- Window length (defaults to
Behavior
If “Savitky-Golay filter” is selected, SpectraGuru’s smoothening 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$.
References
SpectraGuru uses SciPy’s signal.savgol_filter function for Savitzky-Golay smoothening.
- 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