function [y] = quickClean(x,niter,r0,tol);
% Usage [y] = quickClean(x,niter,r0,tol);
diff = 0;
if(diff)
  x1 = x(1);
  x = diff(x);
  xbar = mean(x);
  mad0 = 0;
  k = 1;
  x = x-xbar;
  a = abs(x);
  mad = mean(a);
  while (( k < niter) & (mad>tol*mad0))
     x( a > r0*mad) = 0;
     a = abs(x);
     mad0 = mad;
     mad = mean(a);
     k = k + 1;
  end 
  y = cumsum([x1 x+xbar]);
else
  xbar = mean(x);
  mad0 = 0;
  k = 1;
  x = x-xbar;
  a = abs(x);
  mad = mean(a);
  while (( k < niter) & (mad>tol*mad0))
     x( a > r0*mad) = 0;
     a = abs(x);
     mad0 = mad;
     mad = mean(a);
     k = k + 1;
  end 
  y = x+xbar;
end
