# HAAR The Haar Transform

HAAR is a FORTRAN90 library which computes the Haar transform of data.

In the simplest case, one is given a vector X whose length N is a power of 2. We now consider consecutive pairs of entries of X, and for I from 0 to (N/2)-1 we define:

```        S[I] = ( X[2*I] + X[2*I+1] ) / sqrt ( 2 )
D[I] = ( X[2*I] - X[2*I+1] ) / sqrt ( 2 )
```
We now replace X by the vector S concatenated with D. Assuming that (N/2) is greater than 1, we repeat the operation on the (N/2) entries of S, and so on, until we have reached a stage where our resultant S and D each contain one entry.

For data in the form of a 2D array, the transform is applied to the columns and then the rows.

### Languages:

HAAR is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

### Related Data and Programs:

FFTPACK5, a FORTRAN90 library which implements the Fast Fourier Transform by Paul Swarztrauber and Dick Valent;

SFTPACK, a FORTRAN90 library which implements the "slow" Fourier transform, intended as a teaching tool and comparison with the fast Fourier transform.

SINE_TRANSFORM, a FORTRAN90 library which demonstrates some simple properties of the discrete sine transform.

WALSH, a FORTRAN90 library which implements versions of the Walsh and Haar transforms.

WAVELET, a FORTRAN90 library which does some simple wavelet calculations;

### Reference:

1. Ken Beauchamp,
Walsh functions and their applications,
ISBN: 0-12-084050-2,
LC: QA404.5.B33.

### Examples and Tests:

• haar_test.f90, a sample calling program.
• haar_test.txt, the output file.
• sierpinski.txt, a 128x128 matrix of 0's and 1's (essentially, a bit map image of the Sierpinski triangle), to which a 2D Haar transform is applied.

### List of Routines:

• HAAR_1D computes the Haar transform of a vector.
• HAAR_1D_INVERSE computes the inverse Haar transform of a vector.
• HAAR_2D computes the Haar transform of an array.
• HAAR_2D_INVERSE inverts the Haar transform of an array.
• R8MAT_PRINT prints an R8MAT.
• R8MAT_PRINT_SOME prints some of an R8MAT.
• R8MAT_UNIFORM_01 fills an R8MAT with unit pseudorandom numbers.
• R8VEC_LINSPACE returns a vector of linearly spaced values.
• R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the FORTRAN90 source codes.

Last revised on 22 May 2013.