# Digital signal derivative

I'm new to signal processing and I need your help: I have an array of 128 elements (call it Window) filled with 128 samples taken from a sensor. I was wondering how to find the derivative of this digital signal. I found this formula on wikipedia:

m = F[n] - F[n-1]


where, for me, F[n] is Window[n]. I'd like to obtain an array M filled with all the derivatives. But there's something I miss: The first step would be:

M[0] = Window[0] - Window[-1]


and I haven't Window[-1]. How can I manage this issue? Thank you in advance.

https://en.wikibooks.org/wiki/Digital_Signal_Processing/Discrete_Operations#Derivatives

• Take Window[-1]=0 . Commented Jun 18, 2015 at 11:35
• First of all you need to figure out for yourself what you mean by "derivative" of a discrete-time signal, because there is actually no such thing. What you've found are first order differences. If that is what you need, then you could either do what Oliver suggested, or you could simply accept the fact that the number of first order differences will be one less than the number of samples. Commented Jun 18, 2015 at 12:19

In theory, M[0] doesn't exist. Your discrete derivative is only defined on [1,127].

As a practical solution, you can define M[0] as a null element of your signal. For example if you expect values between -1 and 1, take M[0] = 0.

In the case of real-time, there is two options:

• Either you save the last value of your buffer so you can take M[0] = last for the next ones, and initialize last as 0, or whatever seems coherent with your expected signal;
• Either you start computing the derivative at M[1] and your processing will have a latency of 1 sample.

Suppose

length(Window)=L

Then you could try something like this: extend Window by adding a new value at the beginning and end:

Window[-1] = Window[0] - (Window[1]-Window[0])
Window[L]  = Window[L-1] + (Window[L-1]-Window[L-2])


Then for n=0..L-1 put:

M[n] = (Window[n+1] - Window[n-1])/2.0