function [ s, d ] = r8vec_swtf ( n, x )

%*****************************************************************************80
%
%% R8VEC_SWTF computes a "slow" forward wavelet transform of an R8VEC.
%
%  Discussion:
%
%    This function applies the D4 Daubechies wavelet.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 August 2010
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of data values.
%
%    Input, real X(N), the data sequence.
%
%    Output, real S((N+1)/2), D((N+1)/2), the transformed data.
%
  if ( mod ( n, 2 ) == 1 )
    y = [ x, 0 ];
    n2 = n + 1;
  else
    y = x;
    n2 = n;
  end
%
%  Force a row vector.
%
  y = ( y ( : ) )';

  s = y(1:2:n2-1) + sqrt ( 3.0 ) * y(2:2:n2);

  d = y(2:2:n2) ...
    - sqrt ( 3.0 ) / 4.0 * s ...
    - ( sqrt ( 3.0 ) - 2.0 ) / 4.0 * [ s(n2/2), s(1:n2/2-1) ];

  s = s - [ d(2:n2/2), d(1) ];

  s = ( sqrt ( 3.0 ) - 1.0 ) / sqrt ( 2.0 ) * s;
  d = ( sqrt ( 3.0 ) + 1.0 ) / sqrt ( 2.0 ) * d;

  return
end
