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

wavefreq.cpp File Reference

Wavelet spectral analysis, using stationary signals (e.g., signals composed from sine waves that can be viewed as infinitely repeating). More...

#include <assert.h>
#include <stdio.h>
#include <vector>
#include "signalUtil.h"
#include "spectrum.h"
#include "haar.h"
#include "daub.h"
#include "line.h"

Go to the source code of this file.

Functions

void genSawTooth (double *vec, size_t N)
int main ()
 \function. More...


Detailed Description

Wavelet spectral analysis, using stationary signals (e.g., signals composed from sine waves that can be viewed as infinitely repeating).

By calculating the energy of each wavelet coefficient band a spectral plot, similar to a Fourier spectral plot can be generated. The code in this file tests this for stationary combinations of sin waves.

The documentation in this file is formatted for doxygen (see www.doxygen.org).

Copyright and Use

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

Author:
Ian Kaplan

Definition in file wavefreq.cpp.


Function Documentation

void genSawTooth ( double * vec,
size_t N )
 

Definition at line 59 of file wavefreq.cpp.

Referenced by main().

00060 {
00061   double *A = new double[N];
00062   double *B = new double[N];
00063 
00064   signalUtil::sawToothWave( A, N, 8, 1.5 );  
00065   signalUtil::sawToothWave( B, N, 32, 0.25 );
00066   signalUtil::addSignal( vec, A, B, N );
00067   delete [] A;
00068   delete [] B;
00069 }

int main ( )
 

\function.

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.

This test case can be used with various wavelet functions (e.g., Haar, linear interpolation, Daubechies D4, polynomial interpolation). In the context of filters, the polynomial interpolation wavelets (see poly.h and polyHaar.h) are very bad choices. The polynomial interpolation wavelets do not divide the spectrum into high and low frequency components. Instead, the power spectrum shows one peak. I'm not sure if this means that the polynomial interpolation wavelets are bad for all applications. For example, another way to look at wavelets is as approximation functions. For example, wavelet compression relies approximation functions. In this case polynomial wavelets may be a good choice for some data sets.

Definition at line 95 of file wavefreq.cpp.

00096 {
00097   const size_t N = 1024;
00098   // const size_t N = sizeof( data ) / sizeof( double );
00099   double vecX[N], vecY[N];
00100 
00101   // signalUtil::gen_freqMix( vecX, vecY, N );
00102   // signalUtil::gen_sinCombo( vecX, vecY, N );
00103 
00104   genSawTooth( vecY, N );
00105   // signalUtil::prVec( vecY, N );
00106 
00107   // signalUtil::prVec( vecY, N );
00108   // signalUtil::prCoords( vecX, vecY, N );
00109 
00110   // The "Haar" transform
00111   // haar<double * > w;
00112 
00113   // Daubechies D4 wavelet
00114   // Daubechies<double * > w;
00115 
00116   // linear interpolation wavelet
00117   line<double *> w;
00118 
00119   //
00120   // Polynomial interpolation wavelets
00121   //
00122   // poly<double *> w;
00123   // polyHaar<double *> w;
00124 
00125   double *ptr = vecY;  
00126   w.forwardTrans( ptr, N );
00127 
00128   std::vector<double> powerVec;
00129   spectrum::spectralCalc( vecY, N, powerVec );
00130 
00131   //
00132   // Print out the power spectrum
00133   //
00134   size_t len = powerVec.size();
00135   for (size_t i = 0; i < len; i++) {
00136     //  printf("%2d, %7.4f\n", i, powerVec[i] );
00137   }
00138 
00139   double d1[N], d2[N];
00140 
00141   spectrum::copyBands( d1, vecY, N, 0, 6 );
00142   spectrum::copyBands( d2, vecY, N, 7, 10 );
00143 
00144   ptr = d1;
00145   w.inverseTrans( ptr, N );
00146 
00147   ptr = d2;
00148   w.inverseTrans( ptr, N );
00149 
00150   //
00151   // Print out the lower half of the spectrum
00152   //
00153   // signalUtil::prCoords( vecX, d1, N );
00154   // signalUtil::prVec( d1, N );
00155 
00156   //
00157   // Print out the upper half of the spectrum
00158   //
00159   // signalUtil::prCoords( vecX, d2, N );
00160   signalUtil::prVec( d2, N );
00161   return 0;
00162 }


Generated at Sun Aug 18 16:56:41 2002 for Wavelet Spectral Analysis by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001