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]
.