00001 
00036 
00037 #include <assert.h>
00038 #include <stdio.h>
00039 
00040 #include "haar.h"
00041 #include "haar_classic.h"
00042 #include "haar_classicFreq.h"
00043 
00044 #include "packnode.h"
00045 #include "packcontainer.h"
00046 #include "packtree.h"
00047 #include "invpacktree.h"
00048 
00049 #include "costshannon.h"
00050 #include "costthresh.h"
00051 
00058 
00059 
00060 double data[] = { 32.0, 10.0, 20.0, 38.0, 37.0, 28.0, 38.0, 34.0,
00061                   18.0, 24.0, 18.0, 9.0, 23.0, 24.0, 28.0, 34.0 };
00062 
00063 
00067 
00068 
00074 void prVec( double *vec, size_t len )
00075 {
00076   for (int i = 0; i < len; i++) {
00077     printf("%7.4f ", vec[i] );
00078   }
00079   printf("\n");
00080 }
00081 
00082 
00088 void testWaveletTrans(const double *data, const size_t len )
00089 {
00090   haar<double *> haarVec;
00091   block_pool mem_pool;
00092   
00093   size_t num_bytes = len * sizeof(double);
00094   double *vec = (double *)mem_pool.pool_alloc( num_bytes );
00095 
00096   for (int i = 0; i < len; i++) {
00097     vec[i] = data[i];
00098   }
00099 
00100   printf("Before forward trans:\n");
00101   prVec( vec, len );
00102 
00103   haarVec.forwardTrans( vec, len );
00104   printf("After forward trans:\n");
00105   prVec( vec, len );
00106 
00107   haarVec.inverseTrans( vec, len );
00108   printf("After inverse trans:\n");
00109   prVec( vec, len );
00110 
00111   printf("\n");
00112 
00113 } 
00114 
00115 
00116 
00125 int
00126 main()
00127 {
00128   size_t len = sizeof(data)/sizeof(double);
00129   
00130 
00131   
00132   haar_classic<packcontainer> h;
00133 
00134   
00135   packtree tree( data, len, &h );
00136   
00137   tree.pr();
00138 
00139   
00140   packnode<double> *treeRoot = tree.getRoot();
00141 
00142   
00143   costshannon cost( treeRoot );
00144 
00145   
00146   
00147   
00148 
00149   printf("\n");
00150   
00151   
00152   tree.prCost();
00153 
00154   
00155   tree.bestBasis();
00156 
00157   printf("\n");
00158 
00159   
00160   
00161   tree.prBestBasis();
00162 
00163   
00164   
00165   
00166   if (tree.bestBasisOK()) {
00167     printf("Best basis calculation succeeded\n");
00168   }
00169   else {
00170     printf("Best basis calculation failed\n");
00171   }
00172 
00173   printf("\n");
00174 
00175   
00176   
00177   
00178   
00179   packdata_list<double> bestBasis = tree.getBestBasisList();
00180 
00181   
00182   bestBasis.pr();
00183 
00184   printf("\n");
00185 
00186   
00187   
00188   invpacktree invtree( bestBasis, &h );
00189 
00190   printf("Inverse wavelet packet transform result:\n");
00191   invtree.pr();
00192 
00193   
00194   block_pool mem_pool;
00195   mem_pool.free_pool();
00196 
00197   return 0;
00198 }