function xnew=boxfilt(x,n)
%function xnew=boxfilt(x,n)
%                     box car filter of length n
%                     the time base is maintained, and the points
%                     at the beginning and end are returned as their 
%                     original values.

lg=length(x(:));
filt=ones(1:n)/n;
xnew=conv(x(:),filt);
nbeg=ceil((n+1)/2);
xnew=xnew(nbeg:nbeg-1+lg);
xnew(1:nbeg-1)=x(1:nbeg-1);
xnew(lg-nbeg+2:lg)=x(lg-nbeg+2:lg);

[imax,jmax]=size(x);
if (imax>1)&(jmax>1)
   xnew=remat(xnew,x);
   for i=0:floor(n/2)-1;
	xnew(1+i,:)=x(1+i,:);
	xnew(imax-i,:)=x(imax-i,:);
   end
elseif size(xnew)~=size(x)
     xnew=xnew';
end


