function ma = mavg(d, w)
ma = cumsum([sum(d(1:w)); d(1+w:end) - d(1:end-w)])/w;
end