Implementing a finite impulse respone (FIR) filter for computing the derivative of a discrete signal I am trying to reimplement an algorithm on my own. In the description of the implementation, it's written that they compute the derivate of a series of value using a [-1/2, +1/2] finite impulse response filter for obtaining an array of the original length.
Basically, a FIR filter should be a convolution but I don't understand this description applied to this case.
I've tried to develop a simple algorithm using an interpolation:
import numpy as np
from scipy.interpolate import interp1d
x = np.arange(len(signal))
signal  = [2,2,2,3,4,5,5,5,3,4,2,2,2]
# classical differentiation
diff = np.diff(signal)

f = interp1d(x, signal,fill_value='extrapolate')
newx = np.arange(-0.5, len(signal)+0.5)
ynew = f(newx)
intdiff = np.diff(ynew)

And to compare it with the classical differentiation:
import matplotlib.pyplot as plt 
plt.plot(x,signal,marker='x',color='g',label='original signal')
plt.plot(x[:-1]+0.5,diff,marker='x',color='r',label='differenciated')
plt.plot(x,intdiff,marker='x',label='interpolation differenciated')
plt.legend()

I am wondering how to implement a derivate of a series of value using a [-1/2, +1/2] FIR filter? And what are the advantages compared to a derivative compute using I[n+1] - I[n].
FIR filter with impulse response $h[n] = {-\frac{1}{2}, \frac{1}{2}}$ means that :
$$y[n] = \frac{1}{2}x[n-1] - \frac{1}{2}x[n]$$
This is in some sense a mirror operation of Moving Average of two samples. This is Moving Difference (samples reversed). A High Pass Filter.
So, each output sample is the difference of current input sample with previous input sample. And, this is the result of convolution operation between $x[n]$ and $h[n]$.
But I am not sure that this is will correctly give the Derivative, since for a positively increasing discrete ramp, you would expect the discrete derivative to give positive result. Because for a increasing discrete ramp $x[n]&gt;x[n-1]$. And that FIR filter will give negative result and in addition to negative slope it will also scale the result by $\frac{1}{2}$, which is unwanted.
Correct definition of a Discrete Derivative would be in my understanding, the following:
$$\dot{x} = x[n] - x[n-1]$$
And this can be implemented using FIR filter with impulse response $h[n] = 1,-1$