Your Equation

Library / Signal processing and digital filters / DSP-35

Signal processing and digital filters

Five-point least-squares first derivative

Slope at the centre of a local quadratic least-squares fit to five equally spaced samples in time order (slots 0 to 4), with sample interval Δt in seconds.

Ref
DSP-35
Rev
v1
Field
Signal processing and digital filters
Result
x'0 [V/s]

The slope of the quadratic least-squares fit to five equally spaced samples, taken at the centre, is x′ = (−2x₋₂ − x₋₁ + x₁ + 2x₂)/(10Δt). It uses all five points, so it suppresses high-frequency noise much more than a two-point difference, at the cost of smoothing the derivative.

Slope at the centre of a local quadratic least-squares fit to five equally spaced samples in time order (slots 0 to 4), with sample interval Δt in seconds. It suppresses high-frequency noise differently from a two-point difference.

Calculator

Solve for
V/s
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
s
1e-610
  • Two-point central difference, (x₁ − x₋₁)/(2Δt)10 V/s
  • Slope per sample, x′Δt0.1 V
  • Quadratic-fit second derivative, (2x₋₂ − x₋₁ − 2x₀ − x₁ + 2x₂)/(7Δt²)0 V/s²

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.

Slope at the centre (V/s) current value 10 V/s
ΔtSample intervalKey driver
0.01100,000
x-2Sample at offset -2
−190210
x2Sample at offset 2
−198202
x-1Sample at offset -1
−89111
x1Sample at offset 1
−93107
x0Sample at offset 0
  • The local slope is 10 V/s, against 10 V/s from the two-point central difference.
  • For these evenly rising samples both agree; with noise, the five-point estimate varies much less, since the noise gain of its weights is lower than that of a simple difference.
Chart data as tables

Ranked variables

VariableTypical rangeLowest resultHighest resultSwing (V/s)Local stepChange in result
Δt Sample interval1e-6 to 10 s0.01100,000100,000+10%−9.09 %
x-2 Sample at offset -2−10 to 10 V−190210400+0.4 V−80 %
x2 Sample at offset 2−10 to 10 V−198202400+0.4 V+80 %
x-1 Sample at offset -1−10 to 10 V−89111200+0.4 V−40 %
x1 Sample at offset 1−10 to 10 V−93107200+0.4 V+40 %
x0 Sample at offset 0−10 to 10 V10100+0.4 V0 %

Sweep of Sample at offset 2

Sample at offset 2 (V)Slope at the centre (V/s)
−10−198
−7.5−148
−5−98
−2.5−48
02
2.552
5102
7.5152
10202

Sweep one variable

Slope at the centre (V/s)Hover, touch, or use the arrow keys on the chart
−200−1000100200 −10−50510 Sample at offset 2 (V) now 10

Variables and how each one contributes

x'0

Slope at the centre

Result · V/s

What the equation gives you. Everything else feeds it.

x-2

Sample at offset -2

V · typical −10 to 10

The sample at offset -2 from the centre, in V. Is weighted by −2/10 in the slope. Raising it by 10 % (to 0) moves the result by +0 %, from 10 to 10 V/s.

x-1

Sample at offset -1

V · typical −10 to 10

The sample at offset -1 from the centre, in V. Is weighted by −1/10 in the slope. Raising it by 10 % (to 0.11) moves the result by −1 %, from 10 to 9.9 V/s.

x0

Sample at offset 0

V · typical −10 to 10

The sample at offset 0 from the centre, in V. Is weighted by 0/10 in the slope. Raising it by 10 % (to 0.22) moves the result by +0 %, from 10 to 10 V/s.

x1

Sample at offset 1

V · typical −10 to 10

The sample at offset 1 from the centre, in V. Is weighted by +1/10 in the slope. Raising it by 10 % (to 0.33) moves the result by +3 %, from 10 to 10.3 V/s.

x2

Sample at offset 2

V · typical −10 to 10

The sample at offset 2 from the centre, in V. Is weighted by +2/10 in the slope. Raising it by 10 % (to 0.44) moves the result by +8 %, from 10 to 10.8 V/s.

Δt

Sample interval

s · typical 1e-6 to 10

The sample interval, in s. A smaller interval raises the slope in inverse proportion. Raising it by 10 % (to 0.011) moves the result by −9.09 %, from 10 to 9.091 V/s.

Worked example with the values above

  1. Numerator: −2 × 0 − 0.1 + 0.3 + 2 × 0.4 = 1.
  2. Denominator: 10Δt = 10 × 0.01 = 0.1 s.
  3. x′ = 1 / 0.1 = 10 V/s.

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

Related formulas

Practise this formula