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

haar.h

Go to the documentation of this file.
00001 
00002 #ifndef _HAAR_H_
00003 #define _HAAR_H_
00004 
00005 #include <math.h>
00006 
00007 #include "liftbase.h"
00008 
00041 
00078 template <class T>
00079 class haar : public liftbase<T, double> {
00080 
00081 protected:
00085   void predict( T& vec, int N, transDirection direction )
00086   {
00087     int half = N >> 1;
00088 
00089     for (int i = 0; i < half; i++) {
00090       double predictVal = vec[i];
00091       int j = i + half;
00092 
00093       if (direction == forward) {
00094         vec[j] = vec[j] - predictVal;
00095       }
00096       else if (direction == inverse) {
00097         vec[j] = vec[j] + predictVal;
00098       }
00099       else {
00100         printf("haar::predict: bad direction value\n");
00101       }
00102     }
00103   }
00104 
00105 
00134   void update( T& vec, int N, transDirection direction )
00135   {
00136     int half = N >> 1;
00137 
00138     for (int i = 0; i < half; i++) {
00139       int j = i + half;
00140       double updateVal = vec[j] / 2.0;
00141 
00142       if (direction == forward) {
00143         vec[i] = vec[i] + updateVal;
00144       }
00145       else if (direction == inverse) {
00146         vec[i] = vec[i] - updateVal;
00147       }
00148       else {
00149         printf("update: bad direction value\n");
00150       }
00151     }
00152   }
00153 
00182   void normalize( T& vec, int N, transDirection direction )
00183   {
00184     const double sqrt2 = sqrt( 2.0 );
00185     int half = N >> 1;
00186 
00187     for (int i = 0; i < half; i++) {
00188       int j = i + half;
00189 
00190       if (direction == forward) {
00191         vec[i] = sqrt2 * vec[i];
00192         vec[j] = vec[j]/sqrt2;
00193       }
00194       else if (direction == inverse) {
00195         vec[i] = vec[i]/sqrt2;
00196         vec[j] = sqrt2 * vec[j];
00197       }
00198       else {
00199         printf("normalize: bad direction value\n");
00200       }
00201     } // for
00202   } // normalize
00203 
00207   void inverseStep( T& vec, const int n )
00208   {
00209     normalize( vec, n, inverse );
00210     update( vec, n, inverse );
00211     predict( vec, n, inverse );
00212     merge( vec, n );
00213   }  // inverseStep
00214 
00218   void forwardStep( T& vec, const int n )
00219   {
00220     split( vec, n );
00221     predict( vec, n, forward );
00222     update( vec, n, forward );
00223     normalize( vec, n, forward );
00224   } // forwardStep
00225 
00226 
00227 }; // haar
00228 
00229 #endif

Generated at Thu May 22 21:12:35 2003 for Hurst Exponent Calculation and Supporting Statistics by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001