function y = mavg(x,lag,lead);
%MAVG        is a simple two-sided moving average.
%            y = mavg(x,lag,lead) computes:
%
%            y[t] = mean([x[t-lag],...x[t-1],x[t],x[t+1],...,x[t+lead]])
%
%            For the initial and end points, use available observations,
%            e.g.,  y[1] = mean([x[1],...,x[1+lead]]), 
%                   y[2] = mean([x[1],x[2], ... x[2+lead]]), if lag>0
%                          mean([x[2], ... x[2+lead]]),      otherwise
% 
%              
 
%            Ellen McGrattan, 9-8-00

n    = length(x);
for i=1:n;
  y(i,1) = mean(x(max(1,i-lag):min(n,i+lead)));
end;
