function u = taper(u,Ni,Nf)
% u = taper(u,Ni,Nf)
% taper the initial Ni points and final Nf points of m time series of N points
% the taper is a smooth function ... "1 - cos(pi t/T)" 
%
%  INPUT             DESCRIPTION
% =======            ==========================================================
%   u                a set of m time series, as row vectors             (m x N)
%  Ni                number of initial points to taper                  (1 x 1)
%  Nf                number of  final  points to taper                  (1 x 1)

%  OUTPUT            DESCRIPTION
% =======            ==========================================================
%   u                the set of m tapered time series, as row vectors   (m x N)

 [m,N] = size(u);

 if nargin < 3
   Nf = floor(N/20);           % number of initial taper points
 end
 if nargin < 2
   Ni = floor(N/20);           % number of  final  taper points
 end

 w  = [ 0.5*(1-cos(pi*[0:Ni]/(Ni+1))) ones(1,N-Ni-Nf-2) 0.5*(1+cos(pi*[0:Nf]/(Nf+1))) ];
 u  = u .* (ones(m,1)*w);      % multiply the time series with the taper function 

% -----------------------------------------------------------------------
