Main Page   Namespace List   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"
#include "poly.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 58 of file wavefreq.cpp.

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

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 94 of file wavefreq.cpp.

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


Generated at Tue May 27 21:56:17 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001