I'm doing some research and I'm implementing a moving average in Python based on this mathematical expression:
Where: n = sample and W1 = Window
I implemented like that:
def movingAverage(signal, window):
sum = 0
mAver = []
k = int((window-1)/2)
for i in np.arange(k, len(signal)-k):
for ii in np.arange(i-k, i+k):
sum = sum + signal[ii]
#end-for
mAver.append(sum / window)
sum = 0
#end-for
zeros = [0]*k
mAver = zeros + mAver + zeros
return mAver
It work very well. But I'm trying to discover some way to implement the k variant to minimize the signal lost in beginning and in final (Now I'm using an list with zeros).
Can someone help me?