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

Related simulators

Continue with similar topics in this category — or all 85 in Math Visualization.

View category →
NewSchool

Least Squares Fit

Launch Simulator

Noisy linear data; fitted slope and intercept with residuals.

NewSchool

Linear Regression: OLS, Ridge, Lasso & R²

Launch Simulator

Click/drag scatter points; fit y = β₀ + β₁x with OLS, Ridge (L2 on slope), or Lasso (L1 on slope). Spike Δy on the largest |x| point to see outlier sensitivity; compare SSE and R².

NewUniversity / research

Kalman Filter 2D Tracking

Launch Simulator

4-state constant-velocity tracker: noisy (x,y) measurements, process acceleration noise Q, measurement variance R, and a live ≈2σ covariance ellipse.

NewUniversity / research

Kalman Filter (1-D)

Launch Simulator

Recursive optimal estimation: noisy measurements, hidden truth, predict + update with Q and R; random-walk or constant-velocity model with ±2σ band and innovations.

FeaturedSchool

Trigonometry Circle

Launch Simulator

Unit circle with live sin, cos, tan values as you drag.

NewUniversity / research

LMS / NLMS Adaptive Noise Cancellation

Launch Simulator

Primary p = s + v with v a fixed unknown FIR of Gaussian reference x[n]. Watch an L-tap FIR adapt by LMS or NLMS so error e = p − wᵀx → s; running MSE and ‖w − h‖.

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

Noisy cosine vs SG(7,2) convolution — preserves peaks better than a wide boxcar.

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

About this model

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

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.