Library / Signal processing and digital filters / DSP-34
Signal processing and digital filters
Five-point quadratic Savitzky–Golay smoothing
Quadratic least-squares smoothed value at the centre of five equally spaced samples, entered in time order as x₋₂ … x₂ (slots 0 to 4).
- Ref
- DSP-34
- Rev
- v1
- Field
- Signal processing and digital filters
- Result
- ŷ0 [V]
Fitting a quadratic to five equally spaced points by least squares and taking its value at the centre gives the weights (−3, 12, 17, 12, −3)/35. This Savitzky–Golay filter keeps the height and width of peaks that a moving average would flatten. It needs two samples on each side, so a real-time version has a two-sample latency.
Quadratic least-squares smoothed value at the centre of five equally spaced samples, entered in time order as x₋₂ … x₂ (slots 0 to 4). It needs two future samples, or two samples of output latency, and it preserves the shape of peaks better than a plain moving average.
Calculator
- Plain five-point mean2.2 V
- Change from the raw centre sample−0.5143 V
- Noise power gain, Σc²0.4857
What drives the result
Each variable is moved across its typical range while the others stay at the values above. The longest bar is the key driver.
- The smoothed centre value is 0.4857 V, −0.5143 V away from the raw centre sample of 1 V.
- White noise power falls to 0.486 of its input value, while a quadratic trend passes through exactly, so a noiseless parabola is reproduced at its vertex.
Chart data as tables
Ranked variables
| Variable | Typical range | Lowest result | Highest result | Swing (V) | Local step | Change in result |
|---|---|---|---|---|---|---|
| x0 Sample at offset 0 | −10 to 10 V | −4.857 | 4.857 | 9.714 | +0.4 V | +40 % |
| x-1 Sample at offset -1 | −10 to 10 V | −3.286 | 3.571 | 6.857 | +0.4 V | +28.2 % |
| x1 Sample at offset 1 | −10 to 10 V | −3.286 | 3.571 | 6.857 | +0.4 V | +28.2 % |
| x-2 Sample at offset -2 | −10 to 10 V | −0.02857 | 1.686 | 1.714 | +0.4 V | −7.06 % |
| x2 Sample at offset 2 | −10 to 10 V | −0.02857 | 1.686 | 1.714 | +0.4 V | −7.06 % |
Sweep of Sample at offset 0
| Sample at offset 0 (V) | Smoothed centre value (V) |
|---|---|
| −10 | −4.857 |
| −7.5 | −3.643 |
| −5 | −2.429 |
| −2.5 | −1.214 |
| 0 | 0 |
| 2.5 | 1.214 |
| 5 | 2.429 |
| 7.5 | 3.643 |
| 10 | 4.857 |
Sweep one variable
Variables and how each one contributes
Smoothed centre value
What the equation gives you. Everything else feeds it.
Sample at offset -2
The sample at offset -2 from the centre, in V. Is weighted by −3/35 in the smoothed value. Raising it by 10 % (to 4.4) moves the result by −7.06 %, from 0.4857 to 0.4514 V.
Sample at offset -1
The sample at offset -1 from the centre, in V. Is weighted by 12/35 in the smoothed value. Raising it by 10 % (to 1.1) moves the result by +7.06 %, from 0.4857 to 0.52 V.
Sample at offset 0
The sample at offset 0 from the centre, in V. Is weighted by 17/35 in the smoothed value. Raising it by 10 % (to 1.1) moves the result by +10 %, from 0.4857 to 0.5343 V.
Sample at offset 1
The sample at offset 1 from the centre, in V. Is weighted by 12/35 in the smoothed value. Raising it by 10 % (to 1.1) moves the result by +7.06 %, from 0.4857 to 0.52 V.
Sample at offset 2
The sample at offset 2 from the centre, in V. Is weighted by −3/35 in the smoothed value. Raising it by 10 % (to 4.4) moves the result by −7.06 %, from 0.4857 to 0.4514 V.
Worked example with the values above
- Weighted terms: −3 × 4, 12 × 1, 17 × 1, 12 × 1, −3 × 4.
- Sum: 17.
- ŷ = 17 / 35 = 0.48571 V.
Assumptions and limits
- Equally spaced samples, and noise that is uncorrelated from sample to sample.
- A signal that is smooth over the filter span, so a local quadratic fit describes it.
Common mistakes
- Using these filters at the ends of a record, where the window is incomplete.
- Forgetting that centred filters add a delay of half the window length in real-time use.
- Using a moving average where the sinc sidelobes let high frequencies leak through.
Statistics and uncertainty
Smoothing reduces random error and adds bias, which cannot both be small. A Savitzky–Golay fit lowers the noise variance by the factor Σc² (here 0.49) but flattens any curvature of higher order than a quadratic.
Where it is used
- Smoothing sensor signals and estimating velocity from position records.
- Predicting the noise reduction and frequency response of simple FIR smoothers.
Maths you need
- Moving average: the mean of the latest M samples
- Least-squares fit: the polynomial that minimises squared error
- Noise power gain: Σh² for an FIR filter