#include <haar_classic.h>
Inheritance diagram for haar_classic::
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... 
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 CourHarbo 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 a_{i} is an even element and an element b_{i} 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 b_{i} values. This means that the smoothing function values must be calculated with the result of the wavelet function. To recover the value of b_{i} 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.
Definition at line 111 of file haar_classic.h.

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 

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 