This is a pretty general question about how to compute derivatives of a digital signal $x[n]$.

I would like to know what are the different approaches (from naive to complex) and how are they compared to one another? Is it possible with FIR/IIR filters? What are the pro's and contra's. Which are better for real-time applications?


The estimation of derivative is straightforward:



or if you have a signal sampled at $t_i=i\Delta t$, it is

$$x'(t_{i})~=\frac{x(t_{i+1})-x(t_{i-1})}{2*\Delta t}$$

$$x''(t_{i})~=\frac{x(t_{i+1})-2*x(t_{i})+x(t_{i-1})}{(\Delta t)^2}$$

What you are interested in may be how to smooth the estimation. And yes you can use some recursive filters such as $y(n) = a \cdot x(n) + (1-a) \cdot y(n-1)$, or just implement your estimation with some simple windows (Hann window for example).

To achieve the high SNR without distorting the signal very much, Savitzky–Golay filter also smooths your data by fitting successive sub-sets of adjacent data points with a low-degree polynomial with linear least squares.


Matlab code for an N-th derivative of signal row vector x

dx = x; %'Zeroth' derivative

for n = 1:N % Apply iteratively

    dif = diff(dx,1); % First derivative
    first = [dif(1) dif];
    last = [dif dif(end)];

    dx = (first+last)/2;
  • $\begingroup$ What is the n-th derivative then in the straightforward approach? $\endgroup$ – JustGoscha Feb 9 '14 at 1:13
  • $\begingroup$ you can implement the 1st derivative iteratively. I'm not sure which programming language you are using, I added a simple implementation of N-th with Matlab for your reference. Thanks $\endgroup$ – lennon310 Feb 9 '14 at 1:21

There is a good article in Wikipedia: Numerical Differentiation

Since you'd expect differentiation to be (Anti?)symmetric, using IIR filters might not be the wisest of ideas.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.