function av=moveav(x,w)
% w is vector of (odd number of) weights.
w=w/sum(w);
m=length(w);
M = 0:(m-1);
n = length(x);
for i=1:(n-m+1)
av = [av sum(w.*x(i+M))];
end
for i=2:(floor(m/2)+1)
q=sum(w(1:i).*x(1:i))/sum(w(1:i));
av=[q av];
end
for i=(floor(m/2)+1):(m-1)
q=sum(w(i:m).*x(n-m+i:n))/sum(w(i:m));
av=[ av q];
end

