I've been using the following for creating a moving average list to plot in matplotlib. However, I'm needing to change to using a moving median to avoid unseemly spikes in data.
y_av = movingaverage(yclipped, avgStep)
def movingaverage(interval, window_size):
window= np.ones(int(window_size))/float(window_size)
return np.convolve(interval, window, 'same')
Do you all have suggestions/examples on how to change this definition to do a moving average? FYI, my avgStep/window_size is usually between 5 and 8.
Thanks!