PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabs
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry

More from Math Visualization

Other simulators in this category — or see all 46.

View category →
NewSchool

Markov Chain (Weather)

Sun/Rain two-state chain: P matrix, stationary π, empirical vs theory.

Launch Simulator
NewSchool

Gradient Descent (2D)

Level sets of f(x,y) and path (x,y) ← (x,y) − η∇f; bowl or elliptic well.

Launch Simulator
NewUniversity / research

Minkowski Diagram

Light cone and boosted axes in 1+1D; γ from v.

Launch Simulator
NewSchool

Twin Paradox

Out-and-back worldlines; proper time τ = T/γ vs Earth time T.

Launch Simulator
NewKids

Monte Carlo π

Uniform samples in a square; 4·(in disk)/N estimates π.

Launch Simulator
NewSchool

Random Walk

1D or 2D steps; trail and running mean ⟨r²⟩ vs diffusion intuition.

Launch Simulator
PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Math Visualization/Savitzky–Golay Smoothing

Savitzky–Golay Smoothing

Savitzky–Golay smoothing is a digital filtering technique that reduces noise in a signal while preserving its essential shape, particularly important features like peak heights and widths. Unlike a simple moving average (boxcar filter) which can flatten and distort peaks, the Savitzky–Golay method works by fitting a low-degree polynomial to successive subsets of adjacent data points using the method of least squares. This simulator visualizes a fundamental case: a noisy cosine wave, representing a common oscillatory signal corrupted by random noise. It compares the raw data to the output of a Savitzky–Golay filter with a window size of 7 points and a polynomial order of 2, denoted SG(7,2), and to a 7-point moving average. The core mathematical operation is a discrete convolution, where each smoothed data point y_smooth[i] is calculated as a linear combination of the raw points within the window: y_smooth[i] = Σ c_n * y[i+n], where the convolution coefficients c_n are derived from the polynomial fit. The simulator simplifies the underlying derivation, presenting the filter as a ready-to-use tool. By interacting with it, students learn how convolution works as a local weighting operation, why polynomial fitting within a window is superior to simple averaging for peak preservation, and how the choice of window size and polynomial order creates a trade-off between noise reduction and signal fidelity.

Who it's for: Undergraduate and graduate students in science and engineering courses covering signal processing, data analysis, or experimental methods, as well as researchers needing to understand practical smoothing techniques.

Key terms

  • Convolution
  • Signal Smoothing
  • Moving Average
  • Least Squares Fitting
  • Digital Filter
  • Noise Reduction
  • Polynomial Regression
  • Peak Preservation

Signal

0.15

Convolution with SciPy-standard 7-point order-2 Savitzky–Golay coefficients (preserves low-order moments better than a plain moving average).

Measured values

Window7 pts
Poly order2

How it works

Polynomial local regression used everywhere in experimental spectra and time series — smooth without shifting peaks as harshly as a wide boxcar.

Frequently asked questions

Why does the Savitzky–Golay filter preserve peaks better than a moving average?
A moving average simply replaces each point with the mean of its neighbors, which flattens sharp features. The Savitzky–Golay filter fits a polynomial (e.g., a parabola) to the points in the window. Since many peaks are locally parabolic, this fit approximates the underlying signal's shape more accurately, thus maintaining the peak's height and width while still averaging out noise.
What happens if I choose a polynomial order equal to or greater than the window size?
The filter becomes ill-posed. A polynomial of order p requires at least p+1 points to be uniquely defined. If the window has fewer points than that, or if the order is too high, the least squares fit becomes unstable and can overfit the noise, defeating the purpose of smoothing. Typically, the order is much smaller than the window size.
Is Savitzky–Golay smoothing only for cosine waves or evenly spaced data?
No. While this simulator uses a cosine wave for clarity, the technique is general-purpose for smoothing any noisy dataset. A critical requirement, however, is that the data points must be uniformly spaced along the x-axis (e.g., constant time intervals). The convolution coefficients depend on this uniform spacing.
How do I choose the right window size and polynomial order?
It's a trade-off. A larger window smooths more noise but may oversmooth sharp features. A higher polynomial order can follow sharper curves but may follow noise if set too high. Start with a low order (2 or 3) and adjust the window size to be just wide enough to encompass the narrowest feature you wish to preserve. Trial and error on representative data is common.