This chapter describes functions for performing Discrete Wavelet Transforms (DWTs).  The library includes wavelets for real data in both one and two dimensions.  The wavelet functions are declared in the header files gsl_wavelet.h and gsl_wavelet2d.h.

Definitions
===========

The continuous wavelet transform and its inverse are defined by the relations,

     w(s,\tau) = \int f(t) * \psi^*_{s,\tau}(t) dt

and,

     f(t) = \int \int_{-\infty}^\infty w(s, \tau) * \psi_{s,\tau}(t) d\tau ds

where the basis functions $\psi_s,\tau$ \psi_{s,\tau} are obtained by scaling and translation from a single function, referred to as the mother wavelet.

The discrete version of the wavelet transform acts on equally-spaced samples, with fixed scaling and translation steps (s, \tau).  The frequency and time axes are sampled dyadically on scales of 2^j through a level parameter j. The resulting family of functions $\\psi_j,n\$ {\psi_{j,n}} constitutes an orthonormal basis for square-integrable signals.

The discrete wavelet transform is an O(N) algorithm, and is also referred to as the fast wavelet transform.

Initialization
==============

The gsl_wavelet structure contains the filter coefficients defining the wavelet and any associated offset parameters.

 -- Function: gsl_wavelet * gsl_wavelet_alloc (const gsl_wavelet_type * T, size_t K)
     This function allocates and initializes a wavelet object of type T.  The parameter K selects the specific member of the wavelet family.  A null pointer is returned if insufficient memory is available or if a unsupported member is selected.

The following wavelet types are implemented:

 -- Wavelet: gsl_wavelet_daubechies
 -- Wavelet: gsl_wavelet_daubechies_centered
     This is the Daubechies wavelet family of maximum phase with k/2 vanishing moments.  The implemented wavelets are $k=4, 6, \dots, 20$ k=4, 6, ..., 20, with K even.

 -- Wavelet: gsl_wavelet_haar
 -- Wavelet: gsl_wavelet_haar_centered
     This is the Haar wavelet.  The only valid choice of k for the Haar wavelet is k=2.

 -- Wavelet: gsl_wavelet_bspline
 -- Wavelet: gsl_wavelet_bspline_centered
     This is the biorthogonal B-spline wavelet family of order (i,j). The implemented values of k = 100*i + j are 103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309.

The centered forms of the wavelets align the coefficients of the various sub-bands on edges.  Thus the resulting visualization of the coefficients of the wavelet transform in the phase plane is easier to understand.

 -- Function: const char * gsl_wavelet_name (const gsl_wavelet * W)
     This function returns a pointer to the name of the wavelet family for W.

 -- Function: void gsl_wavelet_free (gsl_wavelet * W)
     This function frees the wavelet object W.

The gsl_wavelet_workspace structure contains scratch space of the same size as the input data and is used to hold intermediate results during the transform.

 -- Function: gsl_wavelet_workspace * gsl_wavelet_workspace_alloc (size_t N)
     This function allocates a workspace for the discrete wavelet transform. To perform a one-dimensional transform on N elements, a workspace of size N must be provided.  For two-dimensional transforms of N-by-N matrices it is sufficient to allocate a workspace of size N, since the transform operates on individual rows and columns. A null pointer is returned if insufficient memory is available.

 -- Function: void gsl_wavelet_workspace_free (gsl_wavelet_workspace * WORK)
     This function frees the allocated workspace WORK.

Transform Functions
===================

This sections describes the actual functions performing the discrete wavelet transform.  Note that the transforms use periodic boundary conditions.  If the signal is not periodic in the sample length then spurious coefficients will appear at the beginning and end of each level of the transform.

Wavelet transforms in one dimension
-----------------------------------

 -- Function: int gsl_wavelet_transform (const gsl_wavelet * W, double * DATA, size_t STRIDE, size_t N, gsl_wavelet_direction DIR, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet_transform_forward (const gsl_wavelet * W, double * DATA, size_t STRIDE, size_t N, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet_transform_inverse (const gsl_wavelet * W, double * DATA, size_t STRIDE, size_t N, gsl_wavelet_workspace * WORK)

     These functions compute in-place forward and inverse discrete wavelet transforms of length N with stride STRIDE on the array DATA. The length of the transform N is restricted to powers of two.  For the transform version of the function the argument DIR can be either forward (+1) or backward (-1).  A workspace WORK of length N must be provided.

     For the forward transform, the elements of the original array are replaced by the discrete wavelet transform $f_i \rightarrow w_j,k$ f_i -> w_{j,k} in a packed triangular storage layout, where J is the index of the level $j = 0 \dots J-1$ j = 0 ... J-1 and K is the index of the coefficient within each level, $k = 0 \dots 2^j - 1$ k = 0 ... (2^j)-1. The total number of levels is J = \log_2(n).  The output data has the following form,

          (s_{-1,0}, d_{0,0}, d_{1,0}, d_{1,1}, d_{2,0}, ...,
            d_{j,k}, ..., d_{J-1,2^{J-1}-1})

     where the first element is the smoothing coefficient $s_-1,0$ s_{-1,0}, followed by the detail coefficients $d_j,k$ d_{j,k} for each level j.  The backward transform inverts these coefficients to obtain the original data.

     These functions return a status of GSL_SUCCESS upon successful completion.  GSL_EINVAL is returned if N is not an integer power of 2 or if insufficient workspace is provided.

Wavelet transforms in two dimension
-----------------------------------

The library provides functions to perform two-dimensional discrete wavelet transforms on square matrices.  The matrix dimensions must be an integer power of two.  There are two possible orderings of the rows and columns in the two-dimensional wavelet transform, referred to as the ``standard'' and ``non-standard'' forms.

The ``standard'' transform performs a complete discrete wavelet transform on the rows of the matrix, followed by a separate complete discrete wavelet transform on the columns of the resulting row-transformed matrix.  This procedure uses the same ordering as a two-dimensional Fourier transform.

The ``non-standard'' transform is performed in interleaved passes on the rows and columns of the matrix for each level of the transform.  The first level of the transform is applied to the matrix rows, and then to the matrix columns.  This procedure is then repeated across the rows and columns of the data for the subsequent levels of the transform, until the full discrete wavelet transform is complete.  The non-standard form of the discrete wavelet transform is typically used in image analysis.

The functions described in this section are declared in the header file gsl_wavelet2d.h.

 -- Function: int gsl_wavelet2d_transform (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_direction DIR, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_transform_forward (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_transform_inverse (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_workspace * WORK)

     These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array DATA stored in row-major form with dimensions SIZE1 and SIZE2 and physical row length TDA.  The dimensions must be equal (square matrix) and are restricted to powers of two.  For the transform version of the function the argument DIR can be either forward (+1) or backward (-1).  A workspace WORK of the appropriate size must be provided.  On exit, the appropriate elements of the array DATA are replaced by their two-dimensional wavelet transform.

     The functions return a status of GSL_SUCCESS upon successful completion.  GSL_EINVAL is returned if SIZE1 and SIZE2 are not equal and integer powers of 2, or if insufficient workspace is provided.

 -- Function: int gsl_wavelet2d_transform_matrix (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_direction DIR, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_transform_matrix_forward (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_transform_matrix_inverse (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_workspace * WORK)
     These functions compute the two-dimensional in-place wavelet transform on a matrix A.

 -- Function: int gsl_wavelet2d_nstransform (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_direction DIR, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_nstransform_forward (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_nstransform_inverse (const gsl_wavelet * W, double * DATA, size_t TDA, size_t SIZE1, size_t SIZE2, gsl_wavelet_workspace * WORK)
     These functions compute the two-dimensional wavelet transform in non-standard form.

 -- Function: int gsl_wavelet2d_nstransform_matrix (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_direction DIR, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_nstransform_matrix_forward (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_workspace * WORK)
 -- Function: int gsl_wavelet2d_nstransform_matrix_inverse (const gsl_wavelet * W, gsl_matrix * M, gsl_wavelet_workspace * WORK)
     These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix A.

Examples
========

The following program demonstrates the use of the one-dimensional wavelet transform functions.  It computes an approximation to an input signal (of length 256) using the 20 largest components of the wavelet transform, while setting the others to zero.

          [file dwt.c not included]

The output can be used with the GNU plotutils graph program,

     $ ./a.out ecg.dat > dwt.dat
     $ graph -T ps -x 0 256 32 -h 0.3 -a dwt.dat > dwt.ps

References and Further Reading
==============================

The mathematical background to wavelet transforms is covered in the original lectures by Daubechies,

  Ingrid Daubechies. Ten Lectures on Wavelets. CBMS-NSF Regional Conference Series in Applied Mathematics (1992), SIAM, ISBN 0898712742.

An easy to read introduction to the subject with an emphasis on the application of the wavelet transform in various branches of science is,

  Paul S. Addison. The Illustrated Wavelet Transform Handbook. Institute of Physics Publishing (2002), ISBN 0750306920.

For extensive coverage of signal analysis by wavelets, wavelet packets and local cosine bases see,

  S. G. Mallat.  A wavelet tour of signal processing (Second edition). Academic Press (1999), ISBN 012466606X.

The concept of multiresolution analysis underlying the wavelet transform is described in,

  S. G. Mallat. Multiresolution Approximations and Wavelet Orthonormal Bases of L^2(R). Transactions of the American Mathematical Society, 315(1), 1989, 69--87.

  S. G. Mallat. A Theory for Multiresolution Signal Decomposition---The Wavelet Representation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 11, 1989, 674--693.

The coefficients for the individual wavelet families implemented by the library can be found in the following papers,

  I. Daubechies. Orthonormal Bases of Compactly Supported Wavelets. Communications on Pure and Applied Mathematics, 41 (1988) 909--996.

  A. Cohen, I. Daubechies, and J.-C. Feauveau. Biorthogonal Bases of Compactly Supported Wavelets. Communications on Pure and Applied Mathematics, 45 (1992) 485--560.

The PhysioNet archive of physiological datasets can be found online at http://www.physionet.org/ and is described in the following paper,

  Goldberger et al. PhysioBank, PhysioToolkit, and PhysioNet: Components of a New Research Resource for Complex Physiologic Signals. Circulation 101(23):e215-e220 2000.