Skip to content
ExtendedSource checked

Savitzky-Golay Filter

Smooths data by fitting a low-degree polynomial inside a moving window.

Quick Facts

Compact metadata for implementation and discovery.

Category
Signal Processing
Difficulty
Intermediate
Family
Polynomial Smoothing
Tier
Extended
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
1
Code example
Ready
Visualization
Ready

Overview

The Savitzky-Golay Filter preserves local shape better than a simple moving average by replacing each point with a polynomial fit estimate.

Core Concepts

local polynomialmoving windowleast squaresshape preservation

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n * window)

Worst

O(n * window)

Space

O(window)

When to Use

  • Use when smoothing should preserve peak height or local curvature.
  • Use when smoothing spectra is a central requirement.

When Not to Use

  • Avoid when impulse noise dominates and a median filter is more robust.
  • Avoid when the sampling rate, window size, or stationarity assumptions do not hold.

What It Does

  • Slides a local window
  • Fits a polynomial to nearby samples
  • Outputs the fitted center value

Use Cases

  • Smoothing spectra
  • Preserving peaks
  • Derivative estimation

Inputs

  • Signal samples
  • Window size
  • Polynomial degree

Outputs

  • Smoothed signal

Key Formulas (1)

Local polynomial

y(t) ≈ a0 + a1·t + a2·t2 + … + ad·td
y(t) ~= a0 + a1*t + a2*t^2 + ... + ad*t^d

Fits nearby samples with a low-degree polynomial.

Pseudocode

  1. 1.Choose an odd window size and polynomial degree
  2. 2.For each sample, collect neighboring samples
  3. 3.Fit or apply precomputed polynomial coefficients
  4. 4.Write the center estimate

Canonical Example

Input
samples = [1, 2, 10, 2, 1], window = 5
Output
center estimate is smoothed but peak-aware
Explanation
The local polynomial fit reduces noise while preserving shape better than plain averaging.

Implementation Notes

  • Precompute convolution coefficients for fixed window and degree settings.
  • Plot or inspect both the original and processed signal for small test cases.
  • Keep a tiny example with expected output beside the implementation.

Common Pitfalls

  • A window that is too wide can smooth away meaningful narrow features.
  • Boundary handling and phase response can change the result in visible or audible ways.
  • Not defining boundary, empty, or degenerate inputs before implementation.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show a small polynomial curve fitted through each moving window.

Savitzky-Golay Filter mechanism walkthrough step 1 of 4x₀x₁x₂x*
Step 1 of 4: Choose an odd window size and polynomial degree
signal-transform

Notes

The polynomial degree must be lower than the window size.

Sources (1)

What each reference supports for this entry.

Savitzky and Golay 1964

Paper

Original paper on smoothing and differentiation by local least-squares polynomial fitting.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toMoving Average

Savitzky-Golay smoothing preserves local polynomial shape better than a plain average.

Related Algorithms

Tags

Signal ProcessingFilteringSmoothingInterpolation