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
- 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.
- 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
| Variable | Typical range | Lowest result | Highest result | Swing (V/s) | Local step | Change in result |
|---|---|---|---|---|---|---|
| Δt Sample interval | 1e-6 to 10 s | 0.01 | 100,000 | 100,000 | +10% | −9.09 % |
| x-2 Sample at offset -2 | −10 to 10 V | −190 | 210 | 400 | +0.4 V | −80 % |
| x2 Sample at offset 2 | −10 to 10 V | −198 | 202 | 400 | +0.4 V | +80 % |
| x-1 Sample at offset -1 | −10 to 10 V | −89 | 111 | 200 | +0.4 V | −40 % |
| x1 Sample at offset 1 | −10 to 10 V | −93 | 107 | 200 | +0.4 V | +40 % |
| x0 Sample at offset 0 | −10 to 10 V | 10 | 10 | 0 | +0.4 V | 0 % |
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 |
| 0 | 2 |
| 2.5 | 52 |
| 5 | 102 |
| 7.5 | 152 |
| 10 | 202 |
Sweep one variable
Variables and how each one contributes
Slope at the centre
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 −2/10 in the slope. Raising it by 10 % (to 0) moves the result by +0 %, from 10 to 10 V/s.
Sample at offset -1
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.
Sample at offset 0
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.
Sample at offset 1
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.
Sample at offset 2
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.
Sample interval
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
- Numerator: −2 × 0 − 0.1 + 0.3 + 2 × 0.4 = 1.
- Denominator: 10Δt = 10 × 0.01 = 0.1 s.
- 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