function smooth = median_smooth(input,n,ns);
%input array of length n
%ns is the number of elements in smoother. must be odd
%output is the output array
%first and last elements are set to the original values
half = (ns - 1)/2;
smooth(1:half)=input(1:half);
smooth(n-half+1:n)=input(n-half+1:n);
for i=half+1:n-half
values=input(i-half:i+half);
smooth(i)=median(values);
end
