#include <packfreq.h>
Inheritance diagram for packfreq::
Public Methods  
packfreq (const double *vec, const size_t n, liftbase< packcontainer, double > *w)  
Construct a wavelet packet tree from a vector of double values. More...  
~packfreq ()  
destructor does nothing. More...  
void  getLevel (const size_t level) 
Build a level basis matrix. More...  
void  plotMat (const size_t N) 
Print out the level basis matrix so that it can be plotted as a three dimensional surface. More...  
void  prMat () 
Print the contents of the level basis matrix. More...  
Protected Methods  
packfreq (const packfreq &rhs)  
disallow the copy constructor. More...  
packfreq ()  
disallow the default constructor. More...  
Private Methods  
void  findLevel (packnode< double > *top, size_t cur_level, const size_t level) 
Traverse the tree, from left to right, and add a node at level to the level basis matrix. More...  
Private Attributes  
GrowableArray<packnode<double> *>  mat 
Level basis matrix. More... 
Wavelet frequency analysis uses a modified wavelet packet tree. Horizontal slices through the modified wavelet packet tree (the so called "level basis") are ordered in increasing frequency regions.
This class and the standard wavelet packet tree class are derived from the same base class. The standard wavelet class includes functions to calculate a minimal data representation relative to a cost function.
The constructor for this class is passed two arguments:
If the vector passed to the constructor contains N double values, the result of the constructor will be a wavelet packet tree with log_{2}(N) levels.
Definition at line 78 of file packfreq.h.

disallow the copy constructor.
Definition at line 89 of file packfreq.h. 00089 {}; 

disallow the default constructor.
Definition at line 91 of file packfreq.h. 00091 {}; 

Construct a wavelet packet tree from a vector of double values. The size of the vector, which must be a power of two, is passed in N. A pointer to a wavelet Lifting Scheme object is passed in w. The wavelet Lifting Scheme object is used to calculate the wavelet transform step which is applied at each level (where level > 0) of the wavelet packet tree. The first level (level 0) of the wavelet packet tree contains the original data set. The "newLevel" function is defined in the base class. This function is used to calculate both the standard and the modified wavelet packet trees. The modified wavelet packet tree is calculated by this class and is used for Wavelet frequency analysis. The wavelet transform step uses two filters H and G to calculate the low pass (scaling function) and the high pass (wavelet function). In the standard transform the low pass result is always placed in the lower half of the array and the high pass result is placed in the upper half of the array. Each of these two half arrays form the input for the next step. In the modified transform calculated by this class, the right child uses the standard algorithm where H and G results are in the upper and lower halves of the result array. However, the left child inverts the locations of the H and G results, placing the result of the G filter in the lower half and the result of the H filter in the upper half. The two boolean flags that are passed to the newLevel function determine whether a frequency ordered wavelet packet tree is calculated and whether the location of the filter results is inverted.
Definition at line 85 of file packfreq.cpp. 00088 { 00089 waveObj = w; 00090 00091 block_pool mem_pool; 00092 double *vecCopy = (double *)mem_pool.pool_alloc( N * sizeof( double ) ); 00093 00094 for (int i = 0; i < N; i++) { 00095 vecCopy[i] = vec[i]; 00096 } 00097 00098 root = new packnode<double>( vecCopy, N, packnode<double>::OriginalData ); 00099 root>mark( true ); 00100 // 00101 // The first level uses the standard wavelet calculation, so 00102 // reverse = false 00103 // freqCalc, reverse 00104 newLevel( root, true, false ); 00105 } // packfreq 

destructor does nothing.
Definition at line 99 of file packfreq.h. 00099 {} 

Traverse the tree, from left to right, and add a node at level to the level basis matrix. Levels are numbered from 0 at the root. Definition at line 115 of file packfreq.cpp. Referenced by getLevel().


Build a level basis matrix. The "level basis" is a horizontal slice through the wavelet packet tree. Here the levels are numbered from zero at root (which contains the original data). The most useful basis for frequency analysis is a square matrix. If the original data set consists of 1024 elements, level 5 of the tree consists of 32 tree nodes containing 32 elements each.
number of elements in a tree node level number of nodes 1024 0 1 512 1 2 256 2 4 128 3 8 64 4 16 32 5 32 The level basis is built from left to right, in the horizontal slice through the tree. The left most node contains the lowest frequency band. Definition at line 158 of file packfreq.cpp. Referenced by main().
00159 { 00160 findLevel( root, 0, level ); 00161 } // getLevel 

Print out the level basis matrix so that it can be plotted as a three dimensional surface. The level basis for a given level is constructed by the getLevel() function. In the discussion of this function below, we will consider the case where the modified wavelet packet tree was built from a data set of 1024 elements and the level basis was at level 5, resulting in a matrix of 32 nodes, each of which has 32 values. mat[0] is the left most node (and lowest frequency band), mat[31] is the right most (and highest frequency band). The values (*mat[0])[0] ... (*mat[0])[31] represent frequency values at particular time intervals. If we use two variables, x and y, to index the matrix then (*mat[y])[x] defines a time/frequency plane, where the xindex is time and the yindex is frequency. The value at (*mat[y])[x] is the magnitude a particular time/frequency point. In plotting a surface from this data, time or frequency are plotted on the x or y axis. The magnitude at (*mat[y])[x] is plotted on the Zaxis. Following Ripples in Mathematics by Jensen and laCour Harbo (Springer Verlag, 2001), the calculation for the zaxis value is:
m = (*mat)[y][x] z_val = log( 1 + val^2 ) Where log is the natural log. This function has been used to generate data for gnuPlot surface plots. Whether frequency is plotted on the xaxis or the yaxis depends on the nature of the data. If a signal line sin(x) is analyzed, the frequency is constant. To avoid the ridge produced by the sin(x) frequency obscuring the surface, it is better to plot time on the yaxis and frequency on the xaxis. In the case of a constantly changing frequency (like the linear chirp), time is plotted on the xaxis and frequency is plotted on the yaxis. Another wrinkle involves the values plotted on the x and y axis. The simplest plot of time (say on the xaxis) would consist of the 32 time regions (e.g., (*mat[y][x])). Similarly, frequency would consist of 32 frequency regions (on the yaxis). This would yield a surface numbered from 0..31 on both the x and y axis. The axis labels can be scaled to represent the frequency and time ranges. This function was used to generate different plots, so various parts are commented out, making it a bit of a hack. Definition at line 228 of file packfreq.cpp. Referenced by main().
00229 { 00230 size_t num_y = mat.length(); 00231 const double incr = (double)N / (double)num_y; 00232 if (num_y > 0) { 00233 size_t num_x = mat[0]>length(); 00234 00235 double freq_start = 0.0; 00236 for (size_t y = 0; y < num_y; y++) { 00237 double time_start = 0.0; 00238 for (size_t x = 0; x < num_x; x++) { 00239 double val = (*mat[y])[ x ]; 00240 // plot time on the x, frequency on y 00241 // printf(" %d %d %7.4f\n", x, y, log(1+(val*val)) ); 00242 00243 // plot frequency on x, time on y 00244 printf(" %d %d %7.4f\n", y, x, log(1+(val*val)) ); 00245 00246 // plot actual frequency and time values, 00247 // with frequency on x and time on y 00248 // printf(" %7.4f %7.4f %7.4f\n", 00249 // freq_start, time_start, log(1+(val*val)) ); 00250 00251 time_start = time_start + incr; 00252 } 00253 freq_start = freq_start + incr; 00254 printf("\n"); 00255 } 00256 } 00257 } // plotMat 

Print the contents of the level basis matrix.
Definition at line 264 of file packfreq.cpp. 00265 { 00266 int num_y = mat.length(); 00267 if (num_y > 0) { 00268 size_t num_x = mat[0]>length(); 00269 for (int y = num_y1; y >= 0; y) { 00270 for (size_t x = 0; x < num_x; x++) { 00271 printf(" %7.4f ", (*mat[y])[ x ] ); 00272 } 00273 printf("\n"); 00274 fflush(stdout); 00275 } 00276 } 00277 } // prMat 

Level basis matrix.
Definition at line 81 of file packfreq.h. 