Main Page   Compound List   File List   Compound Members

# daub.h

Go to the documentation of this file.
```00001
00002 #include <math.h>
00003
00148 class Daubechies {
00149    private:
00151    double h0, h1, h2, h3;
00153    double g0, g1, g2, g3;
00154
00155    double Ih0, Ih1, Ih2, Ih3;
00156    double Ig0, Ig1, Ig2, Ig3;
00157
00161    void transform( double* a, const int n )
00162    {
00163       if (n >= 4) {
00164          int i, j;
00165          const int half = n >> 1;
00166
00167          double* tmp = new double[n];
00168
00169          for (i = 0, j = 0; j < n-3; j += 2, i++) {
00170             tmp[i]      = a[j]*h0 + a[j+1]*h1 + a[j+2]*h2 + a[j+3]*h3;
00171             tmp[i+half] = a[j]*g0 + a[j+1]*g1 + a[j+2]*g2 + a[j+3]*g3;
00172          }
00173
00174          tmp[i]      = a[n-2]*h0 + a[n-1]*h1 + a[0]*h2 + a[1]*h3;
00175          tmp[i+half] = a[n-2]*g0 + a[n-1]*g1 + a[0]*g2 + a[1]*g3;
00176
00177          for (i = 0; i < n; i++) {
00178             a[i] = tmp[i];
00179          }
00180          delete [] tmp;
00181       }
00182    }
00183
00187    void invTransform( double* a, const int n )
00188    {
00189      if (n >= 4) {
00190        int i, j;
00191        const int half = n >> 1;
00192        const int halfPls1 = half + 1;
00193
00194        double* tmp = new double[n];
00195
00196        //      last smooth val  last coef.  first smooth  first coef
00197        tmp[0] = a[half-1]*Ih0 + a[n-1]*Ih1 + a[0]*Ih2 + a[half]*Ih3;
00198        tmp[1] = a[half-1]*Ig0 + a[n-1]*Ig1 + a[0]*Ig2 + a[half]*Ig3;
00199        for (i = 0, j = 2; i < half-1; i++) {
00200          //     smooth val     coef. val       smooth val    coef. val
00201          tmp[j++] = a[i]*Ih0 + a[i+half]*Ih1 + a[i+1]*Ih2 + a[i+halfPls1]*Ih3;
00202          tmp[j++] = a[i]*Ig0 + a[i+half]*Ig1 + a[i+1]*Ig2 + a[i+halfPls1]*Ig3;
00203        }
00204        for (i = 0; i < n; i++) {
00205          a[i] = tmp[i];
00206        }
00207        delete [] tmp;
00208      }
00209    }
00210
00211
00212    public:
00213
00214    Daubechies()
00215    {
00216       const double sqrt_3 = sqrt( 3 );
00217       const double denom = 4 * sqrt( 2 );
00218
00219       //
00220       // forward transform scaling (smoothing) coefficients
00221       //
00222       h0 = (1 + sqrt_3)/denom;
00223       h1 = (3 + sqrt_3)/denom;
00224       h2 = (3 - sqrt_3)/denom;
00225       h3 = (1 - sqrt_3)/denom;
00226       //
00227       // forward transform wavelet coefficients
00228       //
00229       g0 =  h3;
00230       g1 = -h2;
00231       g2 =  h1;
00232       g3 = -h0;
00233
00234       Ih0 = h2;
00235       Ih1 = g2;  // h1
00236       Ih2 = h0;
00237       Ih3 = g0;  // h3
00238
00239       Ig0 = h3;
00240       Ig1 = g3;  // -h0
00241       Ig2 = h1;
00242       Ig3 = g1;  // -h2
00243    }
00244
00245    void daubTrans( double* ts, int N )
00246    {
00247       int n;
00248       for (n = N; n >= 4; n >>= 1) {
00249          transform( ts, n );
00250       }
00251    }
00252
00253
00254    void invDaubTrans( double* coef, int N )
00255    {
00256       int n;
00257       for (n = 4; n <= N; n <<= 1) {
00258          invTransform( coef, n );
00259       }
00260    }
00261
00262 }; // Daubechies
00263
```

Generated at Wed Jan 23 20:56:40 2002 for Daubechies D4 Wavelet Transform by 1.2.8.1 written by Dimitri van Heesch, © 1997-2001