function A = mavg(D, w=1)

  for i = 1 : length(D)
    n1 = max(1, i - w);
    n2 = min(length(D), i + w);
    s = 0;
    for j = n1:n2
      s = s + D(j);
    endfor
    A(i) = s / (n2 - n1 + 1);
  endfor

endfunction
