window_len = 8
taps = [1 / window_len] * window_len
taps

"""
Explanation: Overview
Moving average is useful construct:

It is a matched filter for rectangular pulses
Cheap low pass filter
DC/bias removal applications

Model
Moving average filter can be implemented as a FIR filter, here is an example for
window length of 4.
End of explanation
"""


x = np.linspace(0,2*2*np.pi,512)
y = 0.9*np.sin(x)
noise = 0.1*np.random.normal(size=512)
y += noise

filt = np.convolve(y, taps, mode='full') # filter
plt.plot(y, label='noisy')
plt.plot(filt, color='red', label='moving averaged')
plt.legend()
plt.grid()
plt.show()

"""
Explanation: To demonstrate the effect of this filter lets make a noisy sine wave and use the filer on it:
End of explanation
"""


