Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

haar_classic Class Template Reference

A version of the classic Haar wavelet transform. More...

#include <haar_classic.h>

Inheritance diagram for haar_classic::

liftbase haar_classicFreq List of all members.

Protected Methods

void predict (T &vec, int N, transDirection direction)
 Calculate the Haar wavelet or difference function (high pass filter). More...

void update (T &vec, int N, transDirection direction)
 Calculate the smoothing or scaling function (low pass filter). More...


Detailed Description

template<class T> class haar_classic

A version of the classic Haar wavelet transform.

This particular version of the Haar wavelet transform is frequently given as the definition for the Haar transform. This version differs from the lifting scheme version. In the case of the lifting scheme version of the Haar transform, the inverse transform is a mirror of the forward transform. The only difference is that the plus and minus operators are interchanged. This algorithm does not have this symmetry.

For a data set of N elements, a wavelet transform will calculate N/2 smoothed values and N/2 difference values. In wavelet terminology the smoothed values are calculated by the scaling function and the difference (or coefficient) values are calculated by the wavelet function.

This class implements one version of the Haar wavelet transform. This particular version is used in the chapter 8 of Ripples in Mathematics by Jensen and la Cour-Harbo to illustrate the wavelet packet transform. I have used it to verify my version of the wavelet packet algorithm.

In the description below, an element ai is an even element and an element bi is an odd element.

In this version of the Haar wavelet transform the scaling (or smoothing) function is

     s = (a + b)/2

The wavelet function is

     d = (a - b)/2

A lifting scheme expression is used in this implementation. Here the wavelet function is calculated first. The wavelet results overwrite the odd bi values. This means that the smoothing function values must be calculated with the result of the wavelet function. To recover the value of bi we use the expression

     b = a - 2d

     s = (a + (a - 2d))/2

     s = (2a - 2d)/2

     s = a - d

The lifting scheme terminology is maintained in the algorithm, although it does not fully apply.

This is a template version of the Haar wavelet. The template must be instantiated with an array or an object that acts like an array. Objects that act like arrays define the left hand side and right hand side index operators: [].

See www.bearcave.com for more information on wavelets and the wavelet lifting scheme.

Author:
Ian Kaplan

Definition at line 111 of file haar_classic.h.


Member Function Documentation

template<class T>
void haar_classic<T>::predict ( T & vec,
int N,
transDirection direction ) [inline, protected, virtual]
 

Calculate the Haar wavelet or difference function (high pass filter).

Reimplemented from liftbase.

Definition at line 119 of file haar_classic.h.

00120   {
00121     int half = N >> 1;
00122     int cnt = 0;
00123 
00124     for (int i = 0; i < half; i++) {
00125       double predictVal = vec[i];
00126       int j = i + half;
00127 
00128       if (direction == forward) {
00129         vec[j] = (predictVal - vec[j] )/2;
00130       }
00131       else if (direction == inverse) {
00132         vec[j] =  predictVal - (2 * vec[j]);
00133       }
00134       else {
00135         printf("haar_classic::predict: bad direction value\n");
00136       }
00137     }
00138   } // predict

template<class T>
void haar_classic<T>::update ( T & vec,
int N,
transDirection direction ) [inline, protected, virtual]
 

Calculate the smoothing or scaling function (low pass filter).

Reimplemented from liftbase.

Definition at line 145 of file haar_classic.h.

00146   {
00147     int half = N >> 1;
00148 
00149     for (int i = 0; i < half; i++) {
00150       int j = i + half;
00151       double updateVal = vec[j];
00152 
00153       if (direction == forward) {
00154         vec[i] = vec[i] - updateVal;
00155       }
00156       else if (direction == inverse) {
00157         vec[i] = vec[i] + updateVal;
00158       }
00159       else {
00160         printf("update: bad direction value\n");
00161       }
00162     }
00163   } // update


The documentation for this class was generated from the following file:
Generated at Sat Aug 10 13:23:37 2002 for Wavelet Packet Transform and Lossless Compression by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001