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

freqtest.cpp

Go to the documentation of this file.
00001 
00037 
00038 #include <assert.h>
00039 #include <stdio.h>
00040 
00041 #include "packcontainer.h"
00042 #include "haar_classicFreq.h"
00043 #include "daub.h"
00044 #include "packfreq.h"
00045 
00046 
00050 
00051 
00052 double data[] = { 32.0, 10.0, 20.0, 38.0, 37.0, 28.0, 38.0, 34.0,
00053                   18.0, 24.0, 18.0, 9.0, 23.0, 24.0, 28.0, 34.0 };
00054 
00055 
00056 /*
00057 double data[] = { 56.0, 40.0, 8.0, 24.0, 48.0, 48.0, 40.0, 16.0 };
00058 */
00059 
00060 
00061 
00067 void gen_freqMix( double *vecX, double *vecY, size_t N)
00068 {
00069   const double PI = 3.1415926535897932384626433832795;
00070   const double range = 2 * PI;
00071   const double incr = range / (double)N;
00072 
00073   double point = 0.0;
00074   int i;
00075   for (i = 0; i < N; i++) {
00076     vecX[i] = point;
00077     vecY[i] = 4 * sin( 64 * point ) + 
00078               2 * sin( 32 * point ) + 
00079               1 * sin( 16 * point ) +
00080             0.5 * sin( 8  * point );
00081     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00082     point = point + incr;
00083   }
00084 } // gen_freqMix
00085 
00086 
00087 
00091 void gen_sinCombo( double *vecX, double *vecY, size_t N )
00092 {
00093   const double PI = 3.1415926535897932384626433832795;
00094   const double range = 8 * PI;
00095   const double incr = range / (double)N;
00096 
00097   double point = 0.0;
00098 
00099   int stepCnt = 0;
00100   int i;
00101   for (i = 0; i < N; i++) {
00102     vecX[i] = point;
00103     // vecY[i] = sin( 64 * point ) + sin( 32 * point ) + sin( 16 * point ); 
00104     // vecY[i] = sin( 16 * PI * point ) + sin( 4 * PI * point ); 
00105     vecY[i] = sin( 4 * PI * point ); 
00106 
00107     // printf("x[%2d] = %7.4g, y[%2d] = %7.4g\n", i, vecX[i], i, vecY[i] );
00108     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00109     // printf("%d, %7.4g\n", i, vecY[i] );
00110 
00111     point = point + incr;
00112   }
00113 }
00114 
00115 
00119 void gen_steps( double *vecX, double *vecY, size_t N, size_t steps )
00120 {
00121   const double PI = 3.1415926535897932384626433832795;
00122   const double range = 32 * PI;
00123   const double incr = range / (double)N;
00124 
00125   double point = 0.0;
00126 
00127   double mult = 1;
00128   const size_t stepWidth = N / steps;
00129   int stepCnt = 0;
00130   int i;
00131   for (i = 0; i < N; i++) {
00132     vecX[i] = point;
00133     vecY[i] = sin( mult * point ); 
00134 
00135     // printf("x[%2d] = %7.4g, y[%2d] = %7.4g\n", i, vecX[i], i, vecY[i] );
00136     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00137     // printf("%d, %7.4g\n", i, vecY[i] );
00138 
00139     point = point + incr;
00140     stepCnt++;
00141     if (stepCnt == stepWidth) {
00142       mult = mult + (PI/2.0);
00143       stepCnt = 0;
00144     }
00145   }
00146 }
00147 
00148 
00152 void gen_chirp( double *vecX, double *vecY, size_t N )
00153 {
00154   const double PI = 3.1415926535897932384626433832795;
00155   const double range = 2;
00156   // const double range = 16 * PI;
00157   const double incr = range / (double)N;
00158 
00159   double point = 0.0;
00160 
00161   int i;
00162   for (i = 0; i < N; i++) {
00163     vecX[i] = point;
00164     vecY[i] = sin( 128 * PI * point * point );
00165     // printf("x[%2d] = %7.4g, y[%2d] = %7.4g\n", i, vecX[i], i, vecY[i] );
00166     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00167     // printf("%d, %7.4g\n", i, vecY[i] );
00168     point = point + incr;
00169   }
00170 }
00171 
00172 
00173 
00179 void prCoords( double *vecX, double *vecY, size_t len )
00180 {
00181   for (int i = 0; i < len; i++) {
00182     printf("%7.4f  %7.4f\n", vecX[i], vecY[i] );
00183   }
00184 }
00185 
00186 
00190 void prVec( double *vec, size_t len )
00191 {
00192   for (int i = 0; i < len; i++) {
00193     printf("%4d  %7.4f\n", i, vec[i] );
00194   }
00195 } // prVec
00196 
00197 
00206 int
00207 main()
00208 {
00209   const size_t N = 1024;
00210   // const size_t N = sizeof( data ) / sizeof( double );
00211   double vecX[N], vecY[N];
00212 
00213   // gen_chirp( vecX, vecY, N );
00214   // gen_steps( vecX, vecY, N, 8 );
00215   gen_freqMix( vecX, vecY, N );
00216   // gen_sinCombo( vecX, vecY, N );
00217   // prVec( vecY, N );
00218   // prCoords( vecX, vecY, N );
00219 
00220   // The "Haar" classic transform
00221   haar_classicFreq<packcontainer> h;
00222   // Daubechies<packcontainer> h;
00223 
00224   // calculate the wavelet packet tree, using the wavelet transform h
00225   packfreq tree( vecY, N, &h );
00226   // packfreq tree( data, N, &h );
00227   
00228   // tree.pr();
00229   // printf("\n");
00230 
00231   tree.getLevel( 5 );
00232 
00233   tree.plotMat(N);
00234 
00235   // free the memory pool
00236   block_pool mem_pool;
00237   mem_pool.free_pool();
00238 
00239   return 0;
00240 }

Generated at Tue May 27 21:56:16 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001