6

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?

lennon310
  • 3,520
  • 13
  • 20
  • 27
JustGoscha
  • 531
  • 1
  • 4
  • 12

2 Answers2

6

The estimation of derivative is straightforward:

$$x'(n)~=\frac{x(n+1)-x(n-1)}{2}$$

$$x''(n)~={x(n+1)-2*x({n})+x({n-1})}$$

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.

EDIT

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;
end
lennon310
  • 3,520
  • 13
  • 20
  • 27
  • What is the n-th derivative then in the straightforward approach? – JustGoscha Feb 09 '14 at 01:13
  • 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 – lennon310 Feb 09 '14 at 01:21
3

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.

user7358
  • 1,122
  • 6
  • 10