Spectral smoothing aims at reducing high frequency noise (e.g. removing “spikes” in the spectrum). However, when smoothing a spectrum, one should pay attention at not removing high frequency components that represents useful information. A compromise needs to be found by choosing an appropriate smoothing window size. Two main methods for smoothing spectra are presented below: the moving average window and the Savitzky-Golay algorithm.
Moving average window
A simple smoothing of a spectrum can be done using a moving average window. For example, for a given point (wavelength) i > j in the spectrum, the value of i is replaced by the average value of the points in the window ranging from i-j to i+j. Therefore, the only parameter that needs to be defined is the half window size (j). However, with this method, j points at both ends of the spectrum remain unchanged (i.e. are not smoothed). Plus, it is fairly slow. To increase computational speed, we propose below an algorithm that uses matrix operations to perform the smoothing of the entire spectral data frame at once:
Note that as the PHAZIR spectra are quite short, with only 100 wavelengths. Therefore, the moving average window size has to be small to avoid removing useful information from the signal.
Savitsky-Golay method
The Savitzky-Golay algorithm is based on a moving window that fit a polynomial curve of fixed degree to the spectral data. It is assumed that the fitted values are a better estimate than the measured ones and therefore that some noise is being removed in the process (De Maesschalck et al., 1999). Two parameters need to be defined: the polynomial order (p) and the filter length (n). The Savitzky-Golay algorithm is available in the signal package with the sgolayfilt function. Note however that this function is designed to process vectors. Therefore, we are using the function apply to process each row of our spectral matrix: