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

packtest.cpp

Go to the documentation of this file.
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 } // testWaveletTrans
00114 
00115 
00116 
00125 int
00126 main()
00127 {
00128   size_t len = sizeof(data)/sizeof(double);
00129   // testWaveletTrans( data, len );
00130 
00131   // The "Haar" classic transform
00132   haar_classic<packcontainer> h;
00133 
00134   // calculate the wavelet packet tree, using the wavelet transform h
00135   packtree tree( data, len, &h );
00136   // print the wavelet transform tree (breadth first)
00137   tree.pr();
00138 
00139   // get the root of the wavelet packet transform tree
00140   packnode<double> *treeRoot = tree.getRoot();
00141 
00142   // assign the Shannon entropy cost function to the tree
00143   costshannon cost( treeRoot );
00144 
00145   // Calculate a simple threshold cost function on the 
00146   // wavelet packet transform tree
00147   // costthresh thresh( treeRoot, 1.0 );
00148 
00149   printf("\n");
00150   // Print the wavelet packet transform tree showing the cost
00151   // function result.
00152   tree.prCost();
00153 
00154   // Calculate the "best basis" function from the tree
00155   tree.bestBasis();
00156 
00157   printf("\n");
00158 
00159   // Print the wavelet packet tree showing the nodes selected
00160   // as part of the "best basis" set.
00161   tree.prBestBasis();
00162 
00163   // Check that the best basis function succeeded.  That is,
00164   // that the best basis function does not include the 
00165   // original data.
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   // Get the best basis list.  This will be a list of
00176   // nodes consisting of the best basis set.  This set is
00177   // obtained by traversing the tree, top down, left to
00178   // right.
00179   packdata_list<double> bestBasis = tree.getBestBasisList();
00180 
00181   // Print the "best basis" set.
00182   bestBasis.pr();
00183 
00184   printf("\n");
00185 
00186   // Calculate the inverse wavelet packet transform from the
00187   // "best basis" list.
00188   invpacktree invtree( bestBasis, &h );
00189 
00190   printf("Inverse wavelet packet transform result:\n");
00191   invtree.pr();
00192 
00193   // free the memory pool
00194   block_pool mem_pool;
00195   mem_pool.free_pool();
00196 
00197   return 0;
00198 }

Generated at Sat Aug 10 13:23:34 2002 for Wavelet Packet Transform and Lossless Compression by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001