Maths & numbers

Savitzky–Golay smoothing calculator with window and polynomial order

Smooth equally spaced data with local polynomial fits, explicit endpoint treatment, selectable window length and degree.

Your numbers

Use 3–512 finite values separated by commas or spaces, each within ±10¹².

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Savitzky–Golay smoothing replaces each sample by a value from a nearby polynomial least-squares fit. The window controls how many observations enter a fit, while the degree controls the local shape it can reproduce. This page assumes equally spaced indices and uses an odd window. At endpoints it fits the nearest complete window and evaluates that polynomial at the actual edge index, avoiding an unstated reflected or periodic extension.

THE FORMULAFit a degree-d polynomial by least squares in each complete window, then evaluate it at the selected sample index.

A worked example

For [2,2,5,2,2], a five-sample window and quadratic degree give smoothed values [61/35,106/35,121/35,106/35,61/35] in exact arithmetic. The reported middle-index value is 121/35, approximately 3.457143. The central spike is reduced, but neighboring samples change too because they share the same fitted quadratic.

Good to know

Use 3–512 finite real samples. The odd window is 3–101, no longer than the data; degree is 0–6 and strictly below the window. Nonuniform sampling, automatic parameter selection, derivative filtering and uncertainty estimation are excluded. Numerical least squares is approximate. RMS change measures how much smoothing altered the input, not how accurately it recovered an unknown noise-free signal.

Window length and polynomial degree have different roles

A longer window combines a wider neighborhood and can reduce short-scale variation more strongly, but it can also blur a genuine narrow feature. Raising the polynomial degree allows more local bending, which can preserve some structure while reducing the amount of smoothing. Degree equal to window length minus one interpolates every sample in a full window, leaving little smoothing in exact arithmetic.

The implementation scales the local index coordinates and uses reorthogonalized QR least squares rather than directly inverting normal equations. This reduces avoidable numerical conditioning problems. The input and output plot is a comparison of the supplied data and the filtered sequence; the algorithm does not infer which visible feature was signal and which was noise.

A quadratic five-point fit reduces the central spike while changing neighboring valuesQuadratic fit, window = 5Middle output = 121/35
The dashed raw values are 2,2,5,2,2. The solid smoothed values are 61/35,106/35,121/35,106/35,61/35; the middle output is about 3.457143.

The Polynomial interpolation calculator from points passes through every supplied value, while local smoothing deliberately permits residuals.

Endpoint rules can change the first and last values

An interior odd window is centered around its output index. At the first few positions that centered window would extend beyond the data. This page shifts to the first complete window, fits it once and evaluates the polynomial at those edge indices. The corresponding final window handles the other end. It does not wrap values from the opposite end or reflect missing samples.

A polynomial sequence of degree no greater than the chosen fit degree is reproduced in real arithmetic, including the endpoints under this rule. That gives a strong test case, but it does not establish the best parameters for arbitrary measured data. For irregular x locations use an appropriate regression or interpolation model rather than treating unequal gaps as equal indices. The general polynomial interpolation calculator matches all supplied values exactly and therefore answers a different question from smoothing noisy observations.

A few questions, answered

Why must the window be odd on this page?

An odd window has one central sample and gives a straightforward symmetric interior convention. Even-window alternatives are not implemented here.

Can the smoothed output overshoot the input range?

Yes. Local polynomial fits are not constrained averages with only positive weights, so overshoot can occur near sharp changes.

Find your calculator

Start typing to explore the library.