from pylab import *
from numpy import *

def moving_average(interval, window_size):
   ''' Compute convoluted window for given size
   '''
   window = ones(int(window_size)) / float (window_size)
   return convolve(interval, window, 'same')

t = linspace(-4, 4, 100)
y = sin(t) + randn(len(t))* 0.1

plot(t, y, "k.")

# compute moving average
y_av = moving_average(y, 10)
plot(t, y_av, "r")
#xlim(0, 1000)

xlabel("Time")
ylabel("Value")
grid(True)
show()
