function sm_U = smoothr(abs_U, filter_width, iterations)
%
% smooths the absolute reference layer velocity
% using simple convolution with the given filter_width,
% for the specified number of iterations
%
% Used by the "loadrun" system.

%editglob
global NPRFS

if (nargin < 4)
  iterations = 1;
end
if (nargin < 3)
  filter_width = 3;
else
  if (rem(filter_width, 2) ~= 1)
    error('Filter width must be odd-valued')
  end
end

%--- generate weights array for given width ---
midwidth = (filter_width - 1) / 2;
weights = 2 .^ [0 : midwidth];
weights = [weights weights((length(weights)-1):-1:1)];
weights = weights / sum(weights);

%--- smoothing ---
sm_U = abs_U;
for (iter = 1 : iterations)
  Usmooth = [conv(weights, abs_U(1,2:NPRFS)); ...
             conv(weights, abs_U(2,2:NPRFS))];

  %--- use only the central part ---
  sm_U(:,midwidth+2:NPRFS-midwidth) = Usmooth(:,filter_width:NPRFS-1);
end


