Smoothing and curve fitting¶
Note that smoothing and curve fitting should be done with care. Makes things look nicer, but can miss actual observables. Check residuals and the like.
Smoothing of spectra¶
Illustrate different smoothing schemes, plotting:
0F spectra: raw, smooth, residual
0F - 2F: raw, smooth, residual
Can print the integral of the residual, as an illustration of the approximate error (note that this is a rough measure). Can also use the standard deviation of the residual vector(?)
Binning¶
Just bin to lower resolution.
Spline¶
Spline raw can introduce articifial oscillations, and is not that suitable for illustrations. Binning and then splining can produce better results.
Rectangular / box / unweighted sliding-average smooth¶
Example: 3-point
Weighted triangular smooth¶
Example: 5-point
For example, the 5-point triangular smooth above is equivalent to two passes of a 3-point rectangular smooth.
In all these smooths, the width of the smooth m is chosen to be an odd integer, so that the smooth coefficients are symmetrically balanced around the central point, which is important because it preserves the x-axis position of peaks and other features in the smoothed signal.
Note that we are assuming here that the x-axis intervals of the signal is uniform, that is, that the difference between the x-axis values of adjacent points is the same throughout the signal. This is technically not the case here, but the variation within a small number of pixels is small enough for the present purpose.
Savitzky-Golay¶
The Savitzky-Golay smooth is based on the least-squares fitting of polynomials to segments of the data. Compared to the sliding-average smooths of the same width, the Savitzky-Golay smooth is less effective at reducing noise, but more effective at retaining the shape of the original signal.
Illustrate different smoothing widths