Documentation  ›  Documentation Library  ›  Savitzky-Golay Filter
Filtering & Corrections

Savitzky-Golay Filter

Savitzky-Golay smoothing reduces high-frequency spectral noise by fitting a low-order polynomial within a moving spectral window.

Overview

Savitzky-Golay smoothing reduces high-frequency spectral noise by fitting a low-order polynomial within a moving spectral window.

The filter is applied independently to every pixel spectrum along the spectral dimension. Spatial rows and columns are not smoothed.

Compared with a simple moving average, Savitzky-Golay filtering is designed to preserve local spectral shape, peak position, and curvature more effectively while reducing high-frequency noise.

Polynomial order is the degree of the local polynomial fitted inside each moving frame.

Order 2 is a strong general starting value. Order 3 can preserve more local curvature but requires a sufficiently large frame.

Frame size is the number of spectral bands used in each local fit.

The frame must be odd so that there is a unique center band.

Smaller frames perform milder smoothing. Larger frames produce stronger smoothing but can broaden or suppress narrow real spectral features.

If noise remains, increase the frame gradually to 7 or 9 while inspecting representative spectra.

The frame must be greater than the polynomial order.

IDCubePro automatically adjusts invalid combinations when possible.

If an even frame is entered, the tool increases it to the next odd value.

If the requested frame is larger than the number of spectral bands, the tool reduces it to the largest valid odd frame.

Use the lowest polynomial order and smallest frame that provide adequate noise reduction.

Do not select parameters only because they make spectra look visually smooth.

The goal is to suppress noise while preserving scientifically meaningful peaks, minima, shoulders, widths, and spectral edges.

Possible signs include flattened peaks, broadened bands, shifted minima, disappearing shoulders, merged nearby features, or reduced class separation.

Possible signs include dominant point-to-point noise, unstable peak detection, or excessively noisy derivative spectra.

Frame size should be interpreted together with wavelength sampling.

A 9-band frame spans a much wider physical wavelength interval when bands are 10 nm apart than when they are 1 nm apart.

Important Implementation Detail

The current implementation uses MATLAB sgolayfilt along the ordered band dimension.

It does not explicitly account for unequal physical wavelength spacing.

For strongly nonuniform wavelength sampling, use additional caution.

Moving-window filters have special behavior near the first and last spectral bands because a full symmetric neighborhood is not available beyond the data boundaries.

Inspect spectral edges carefully when important features occur near the ends of the wavelength range.

This tool does not blur neighboring image pixels.

Each pixel spectrum is processed independently, so spatial edges are not directly smoothed across x or y.

If the input cube is integer, IDCubePro clips the filtered values to the valid datatype range and casts them back to the original integer class.

For quantitative spectroscopy, floating-point data are generally more appropriate because smoothing naturally produces fractional values.

Click Apply after choosing Polynomial order and Frame size.

The cube is reshaped to pixels x bands, filtered in vectorized form along the spectral dimension, then reshaped back to the original cube.

The smoothed cube replaces the current working myData.Images dataset.

Rows, columns, spectral bands, and wavelength metadata remain unchanged.

IDCubePro records the Polynomial order, Frame size, and output cube dimensions in processing history.

  • High-frequency spectral noise is present.
  • Real features are sampled by enough bands to tolerate local smoothing.
  • Derivatives, peak detection, PCA, clustering, classification, or regression would benefit from reduced noise.
  • Important features are very narrow.
  • Only a few bands sample each feature.
  • Wavelength spacing is strongly irregular.
  • Edge bands contain important features.
  • Signal-to-noise ratio is already high.

Savitzky-Golay smoothing is often useful before spectral derivatives because derivatives amplify high-frequency noise.

The current function performs smoothing only; it does not calculate derivatives.

Smoothing may reduce noise-dominated variance and make PCA more stable.

It can also remove subtle real variance, so compare PCA results with and without smoothing when appropriate.

Smoothing may improve cluster stability when noise obscures spectral structure.

If classes differ by very narrow features, excessive smoothing can reduce separation.

Use validation data to determine whether smoothing helps predictive performance.

If a model is trained on smoothed spectra, the same Savitzky-Golay parameters must be applied consistently to future prediction data.

Choose parameters using predictive validation error and model stability, not visual smoothness alone.

Common Problem - Features Look Flattened

Common Problem - Noise Remains

Increase the frame gradually and compare against the original data.

Common Problem - Parameter Changes Automatically

IDCubePro enforces an odd frame that is greater than the polynomial order and does not exceed the number of bands.

Common Problem - Edge Values Look Strange

Inspect the first and last several bands and consider a smaller frame or removal of unreliable edge bands.

1. Load and inspect the hyperspectral cube.

2. Perform required calibration and remove clearly invalid bands.

3. Inspect representative raw spectra.

4. Start with order 2 and frame 5.

6. Compare raw and smoothed spectra.

7. Verify that important peaks, minima, shoulders, and edges remain.

8. If noise remains, return to the original data and test frame 7.

9. Increase the frame gradually only as needed.

10. Validate the effect on downstream analysis.

Use the least aggressive smoothing that provides adequate noise reduction while preserving the spectral features that matter scientifically.

Savitzky-Golay Spectral Smoothing