#include <assert.h>
#include <stdio.h>
#include "haar.h"
#include "haar_classic.h"
#include "haar_classicFreq.h"
#include "packnode.h"
#include "packcontainer.h"
#include "packtree.h"
#include "invpacktree.h"
#include "costshannon.h"
#include "costthresh.h"
Go to the source code of this file.
Functions | |
void | prVec (double *vec, size_t len) |
\function. More... | |
void | testWaveletTrans (const double *data, const size_t len) |
Test that the wavelet transform is invertable. More... | |
int | main () |
The entry point for code to test the wavelet packet transform. More... | |
Variables | |
double | data [] |
The documentation in this file is formatted for doxygen (see www.doxygen.org).
You may use this source code without limitation and without fee as long as you include: This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2002.
This software is provided "as is", without any warranty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.
Please send any bug fixes or suggested source changes to:
iank@bearcave.com
Definition in file packtest.cpp.
|
The entry point for code to test the wavelet packet transform. The code in main provides a simple example of how to call the wavelet packet transform code. Definition at line 126 of file packtest.cpp. 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 } |
|
\function. Print a vector of doubles whose length is len. Definition at line 74 of file packtest.cpp. Referenced by testWaveletTrans().
00075 { 00076 for (int i = 0; i < len; i++) { 00077 printf("%7.4f ", vec[i] ); 00078 } 00079 printf("\n"); 00080 } |
|
Test that the wavelet transform is invertable.
Definition at line 88 of file packtest.cpp. 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 |
|
Initial value: { 32.0, 10.0, 20.0, 38.0, 37.0, 28.0, 38.0, 34.0, 18.0, 24.0, 18.0, 9.0, 23.0, 24.0, 28.0, 34.0 } Definition at line 60 of file packtest.cpp. |