function w = haar_step_1d_inverse ( v )

%*****************************************************************************80
%
%% haar_step_1d_inverse() inverts the Haar transform of a vector.
%
%  Discussion:
%
%    The length of the vector V 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 V(N,1), the transformed vector.
%
%  Output:
%
%    real W(N,1), the original vector.
%

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

  n = length ( v );
  nhalf = floor ( n / 2 );
  nhalf2 = 2 * nhalf;

  if ( mod ( n, 2 ) == 1 )
    wx = v(nhalf+1);
  else
    wx = [];
  end

  next = floor ( ( n + 1 ) / 2 ) + 1;

  A = [ v(1:nhalf), v(next:n) ];

  h = [ 1;  1 ];
  g = [ 1; -1 ];

  w = reshape ( [ A * g, A * h ]', nhalf2, 1 );

  w = [ w; wx ];

  return
end
