DSPRelated.com

Finite Differences

The discrete derivative

The last lesson was about smooth curves. But real DSP signals are not smooth, they're lists of numbers measured at regular intervals.

So how do you take the derivative of a list? The answer is embarrassingly simple: just subtract each sample from the next one.

The Discrete Derivative

Below is a sine wave (faint, in the background) and its samples (dots on top). Each pair of adjacent samples has a small arrow drawn between them, showing the difference x[n+1] − x[n]. The lower panel plots those differences. Drag the Δt slider to change how often we sample.

What you see in the lower panel are the finite differences, the discrete cousin of the derivative.

Key Insight: The finite difference x[n+1] − x[n] estimates the derivative at each sample. Divide by Δt for the actual slope; skip the divide and you still get the shape of the derivative. As Δt shrinks, the estimate becomes exact.

Look at where the difference dots fall: they trace out a cosine-like curve, exactly like the derivative of sine should. The fit isn't perfect, there's a small approximation error that depends on Δt, but for reasonable sample rates, it's good enough for almost every real DSP task.

Try it: Crank Δt all the way up. The samples become far apart, the difference arrows zigzag wildly, and the dots in the lower panel only roughly resemble cosine. Now crank Δt all the way down. The dots sit perfectly on the true cosine curve. This is why high sample rates matter for derivative-based DSP.

Why This Matters for DSP

Finite differences are everywhere in DSP. Edge detection in image processing, that sudden jump where pixel values change rapidly, is a finite difference. Velocity from position samples. The "D" term in a PID controller. Discrete differentiation of phase to get instantaneous frequency.

The finite difference is also the simplest possible digital filter. It takes the current sample minus the previous sample, that's a 2-tap FIR filter with coefficients [+1, −1]. The fact that you can compute a derivative by filtering is a foreshadowing of the next chapter.

We've now seen the derivative from both sides: continuous (smooth, ideal) and discrete (sampled, practical). Next we go the other direction. Instead of computing rates of change, we'll accumulate. That's the integral, and once again it'll come in continuous and discrete forms.

Frequently Asked Questions

Why divide by Δt?

Because slope is rise/run. The "rise" is x[n+1] − x[n], and the "run" is Δt. If you only care about the *shape* of the derivative (peaks, zero crossings), the divide is optional. If you need actual physical units (e.g. volts per second), you must divide. Many DSP operations omit the divide because it absorbs into a normalization constant.

Are there more accurate methods?

Yes. Central differences ((x[n+1] − x[n−1]) / 2Δt) cancel out one layer of approximation error and are usually a better choice for derivative estimation when you have samples on both sides. Higher-order formulas using 4 or more samples reduce the error further. For most everyday DSP, the simple forward difference is plenty.

Is the finite difference always exact?

Only in the limit Δt → 0. For real samples, it's an approximation. The error grows for fast-changing signals undersampled (signals with content near the Nyquist limit), which connects directly to aliasing — both are symptoms of insufficient sampling.

Quick Check

Test your understanding of the key concepts from this lesson.