function tv=tv(u)
% This is the function tv.m
% Simple routine made for computing total variation of time signal
%
%    u - time signal vector

% Initialize
tv=0;
i=1;

npoints=length(u);

% Sum up
while i  < npoints,

  du = u(i+1)-u(i);
  tv = tv + abs(du);
    i=i+1;
  
end

