Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Learn the Savitzky–Golay Algorithm: Local Polynomial Smoothing, Derivatives, Convolution Coefficients and Signal-Preservation Trade-Offs

Three students studying together in an eduKate small-group classroom.

Wait, What?

You can smooth noisy data without simply flattening every peak—by fitting a tiny polynomial over and over again.

The Savitzky–Golay algorithm smooths uniformly sampled data by fitting a low-degree polynomial inside a moving window and evaluating that polynomial, usually at the centre of the window. Because the least-squares problem has the same geometry at each interior position, the fit can be converted into fixed convolution coefficients. The same machinery can estimate derivatives. This makes Savitzky–Golay a beautiful bridge between least squares, FIR filtering, numerical differentiation and experimental data analysis.

Quick Answer

Learn Savitzky–Golay through moving averages → local polynomial least squares → window length → polynomial order → convolution coefficients → derivative estimation → edge handling → frequency response → noise/feature trade-offs → production diagnostics. The professional skill is knowing when local polynomial preservation is useful and when a different filter is more appropriate.

1. Why Not Just Use a Moving Average?

A moving average replaces each point by the average of nearby samples. It reduces high-frequency noise, but it can broaden sharp features, lower peak heights and distort local curvature. Savitzky–Golay asks a more structured question: “What polynomial of degree p best fits these neighbouring samples?”

If the underlying signal is locally well approximated by a low-degree polynomial, that model can preserve shape better than a plain box average.

2. The Local Least-Squares Problem

Choose an odd window length, for example 5 samples, centred on the current point. With offsets −2,−1,0,1,2 and a quadratic model, fit

q(t) = a0 + a1 t + a2 t^2

to the five observed values by least squares. The smoothed output at the centre is q(0)=a₀. If you want the first derivative, use q′(0)=a₁, adjusted for the physical sample spacing.

This is the core algorithm. Everything else—convolution coefficients, efficient implementation and derivative filters—comes from solving this same small least-squares geometry in advance.

3. From Polynomial Fit to FIR Coefficients

For uniformly spaced samples and a fixed window, the design matrix is identical at every interior point. The least-squares solution is linear in the data, so the centre estimate can be written as a dot product

y_smooth[i] = Σ c_j y[i+j]

The coefficients cⱼ can therefore be precomputed. That turns repeated polynomial regression into a finite impulse response convolution.

For a common five-point quadratic smoother, one coefficient set is proportional to

[-3, 12, 17, 12, -3] / 35

Notice the negative edge weights. Savitzky–Golay is not simply averaging positive neighbours; it is reconstructing the centre value implied by a local polynomial fit.

4. Window Length and Polynomial Order

Two parameters control the local model:

  • window length: how many nearby samples participate;
  • polynomial order: how much local curvature the model can reproduce.

The polynomial order must be smaller than the window length. A larger window usually increases smoothing but risks washing out short features. A higher polynomial order can preserve more curvature but may also follow noise more closely and become numerically delicate.

There is no universally correct pair. Parameter choice must be tied to sampling rate, expected feature width and noise spectrum.

5. Polynomial Preservation

One of the method’s defining properties is that, away from boundaries and under exact arithmetic, a Savitzky–Golay smoother of polynomial order p reproduces polynomial data up to degree p. If the input window lies exactly on a quadratic and you use a quadratic fit, the centre estimate is exact.

This explains why peaks and curvature may be preserved better than under simple averaging. It does not mean arbitrary signals are preserved perfectly.

6. Derivative Estimation

The fitted polynomial provides derivatives analytically. Instead of evaluating q(0), evaluate q′(0), q″(0) and so on. These derivative estimates can also be encoded as convolution coefficients.

The sample spacing Δ matters. A derivative coefficient designed in sample-index units must be scaled by the appropriate power of Δ. Current SciPy documentation exposes this explicitly through the deriv and delta parameters of Savitzky–Golay routines.

7. Work a Tiny Example

Take five samples from a quadratic trend with one small noise perturbation:

x = [-2, -1, 0, 1, 2]
y = [4.1, 1.0, 0.2, 1.1, 3.9]

The noiseless quadratic y=x² would be [4,1,0,1,4]. Fit a quadratic across the window and compare the estimated centre with the raw centre 0.2. Then compare with a five-point moving average. The exercise shows two different notions of “smoothing”: averaging suppresses variation indiscriminately, whereas the polynomial fit tries to recover a local geometric shape.

8. Edge Handling Is Part of the Algorithm

At the first and last half-window of a signal, a centred window extends beyond the available data. Implementations must choose a boundary strategy. Common options include padding, mirroring, nearest-value extension, wrapping or fitting one-sided/local edge polynomials.

Different edge modes can produce visibly different results. SciPy’s current savgol_filter API includes explicit edge-handling modes and an interpolation-based default strategy. A professional analysis therefore inspects boundary behaviour rather than plotting only the middle of the signal.

9. Frequency Response: Shape Preservation Is Not Magic

Once expressed as convolution coefficients, a Savitzky–Golay smoother is an FIR filter and has a frequency response. It attenuates some frequencies more than others, often retaining low-order polynomial trends well but not behaving like an optimally designed low-pass filter for every spectral objective.

This matters because “preserves peaks” is not a universal guarantee. Narrow peaks, high-frequency oscillations and discontinuities can still be distorted. Window and order should be evaluated against the signal’s actual bandwidth and feature scale.

10. Uniform Sampling Is a Core Assumption

The classic convolution coefficients assume equally spaced sample locations. If samples are irregularly spaced, blindly applying the same coefficients is mathematically wrong. You can still perform local polynomial regression on the true x-coordinates, but the coefficients will depend on the local spacing and generally cannot be reused as one fixed convolution kernel.

11. Complexity and Implementation

With precomputed coefficients and a fixed window of width m, direct filtering costs O(nm) for n samples. When m is small and fixed, this behaves linearly in signal length. Vectorized numerical libraries make the practical constant small. For streaming data, a causal or delayed implementation can maintain a rolling window, but a centred filter necessarily requires future samples or output latency.

12. Current Practice

Current SciPy documentation provides savgol_coeffs for computing 1-D Savitzky–Golay FIR coefficients and savgol_filter for applying the filter. The API exposes window length, polynomial order, derivative order, sample spacing and edge behaviour. The original 1964 Savitzky–Golay paper remains the historical foundation for smoothing and differentiation by simplified least squares.

13. Learn It With Fit-First Reasoning

Do not begin by memorising coefficient tables. First fit a line through three points by least squares. Then fit a quadratic through five noisy points. Ask what the centre value and derivative mean. Only after that should the learner derive or inspect convolution coefficients.

A good programming sequence is Predict–Run–Investigate–Modify–Make: predict whether a peak will rise or fall after smoothing; run a supplied implementation; inspect the contribution of each coefficient; modify the window and polynomial order; then build a filter and derivative estimator independently. Subgoal-labelled worked examples help separate “build design matrix,” “solve local fit,” “extract centre/derivative,” and “handle edges.”

14. Test Against Known Signals

  • A constant signal should remain constant.
  • A polynomial of degree ≤ p should be reproduced in the interior.
  • Derivative filters should match known derivatives of test polynomials.
  • White-noise experiments should quantify variance reduction.
  • Peak signals should be checked for height, width and location distortion.
  • Boundary samples should be tested under every supported edge mode.
  • Nonuniform sample spacing should trigger a different method or explicit local regression.

Common Failure States

  • Choosing polynomial order equal to or greater than window length.
  • Forgetting derivative scaling by sample spacing.
  • Applying fixed coefficients to irregularly sampled data.
  • Judging quality only by visual smoothness.
  • Ignoring boundary artefacts.
  • Using too large a window and erasing narrow real features.
  • Assuming a high polynomial order is always more accurate.
  • Calling Savitzky–Golay a universal low-pass filter without inspecting its frequency response.

Practice Ladder

  • Beginner: compare a moving average with a three-point local linear fit.
  • Foundation: derive a five-point quadratic centre estimate using least squares.
  • Intermediate: implement smoothing and first-derivative convolution with explicit Δ.
  • Advanced: plot frequency responses for several window/order choices and quantify peak distortion.
  • Professional: design a validation study comparing Savitzky–Golay, moving-average, spline and modern low-pass methods on synthetic signals with known ground truth and on real experimental data.

Learning Hall Boundary

This article owns Savitzky–Golay as local-polynomial smoothing and differentiation for sampled signals. It does not replace generic numerical differentiation, Fourier analysis, Goertzel, digital-filter design or spectroscopy application articles, and it remains outside MindOS, Bolt and Student/Studying Interface canonical jobs.

Evidence Boundary

The foundational reference is Abraham Savitzky and Marcel J. E. Golay, “Smoothing and Differentiation of Data by Simplified Least Squares Procedures,” Analytical Chemistry 36(8), 1964. Later literature studies boundary behaviour, convolution anomalies and extensions. Current SciPy documentation provides maintained implementations and explicit parameter contracts. The teaching sequence is informed by PRIMM, subgoal-labelled worked examples and scaffolded programming research.

Professional rule: you understand Savitzky–Golay when you can derive it as local polynomial least squares, explain how that becomes convolution, choose window/order from signal scale rather than habit, and validate both interior and boundary behaviour against known ground truth.