function v = haar_step_1d ( u )

%*****************************************************************************80
%
%% haar_step_1d() computes the Haar transform of a vector.
%
%  Discussion:
%
%    Typically, given a vector of length N, one computes the
%    Haar transforms on V(1:N), then on V(1:N/2), then on V(1:N/4),
%    and so on, producing a sequence of compressed representations
%    of the data.
%
%    The length of the vector U does not have to be a power of 2,
%    nor does it have to be even.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real U(N,1), the vector to be transformed.
%
%  Output:
%
%    real V(N,1), the transformed vector.
%

%
%  Force U to be a dadblasted column vector of dimensions N by 1.
%
  u = u(:);

  n = length ( u );

  if ( mod ( n, 2 ) == 1 )
    vx = u(n);
  else
    vx = [];
  end

  nhalf = floor ( n / 2 );

  A = reshape ( u(1:2*nhalf), 2, nhalf );
  lp = A' * [  1/2; 1/2 ];
  hp = A' * [ -1/2; 1/2 ];
  v = [ lp; vx; hp ];

  return
end
