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

signalUtil.cpp

Go to the documentation of this file.
00001 
00002 #include <math.h>
00003 #include <stdio.h>
00004 
00005 #include "signalUtil.h"
00006 
00007 
00013 void signalUtil::gen_freqMix( double *vecX, double *vecY, size_t N)
00014 {
00015   const double PI = 3.1415926535897932384626433832795;
00016   const double range = 2 * PI;
00017   const double incr = range / (double)N;
00018 
00019   double point = 0.0;
00020   int i;
00021   for (i = 0; i < N; i++) {
00022     vecX[i] = point;
00023     vecY[i] = 4 * sin( 64 * point ) + 
00024               2 * sin( 32 * point ) + 
00025               1 * sin( 16 * point ) +
00026             0.5 * sin( 8  * point );
00027     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00028     point = point + incr;
00029   }
00030 } // gen_freqMix
00031 
00032 
00033 
00037 void signalUtil::gen_sinCombo( double *vecX, double *vecY, size_t N )
00038 {
00039   const double PI = 3.1415926535897932384626433832795;
00040   const double range = 1 * PI;
00041   const double incr = range / (double)N;
00042 
00043   double point = 0.0;
00044 
00045   int stepCnt = 0;
00046   int i;
00047   for (i = 0; i < N; i++) {
00048     vecX[i] = point;
00049     // vecY[i] = sin( 64 * point ) + sin( 32 * point ) + sin( 16 * point ); 
00050     // vecY[i] = sin( 16 * PI * point ) + sin( 4 * PI * point ); 
00051     vecY[i] = sin( 4 * PI * point ); 
00052 
00053     // printf("x[%2d] = %7.4g, y[%2d] = %7.4g\n", i, vecX[i], i, vecY[i] );
00054     // printf("%7.4g, %7.4g\n", vecX[i], vecY[i] );
00055     // printf("%d, %7.4g\n", i, vecY[i] );
00056 
00057     point = point + incr;
00058   }
00059 }
00060 
00089 double signalUtil::new_y( size_t x1, double y1, 
00090                           size_t x2, double y2,
00091                           size_t newX )
00092 {
00093   double newY = 0.0;
00094 
00095   newY = (((y2 - y1)/(x2 - x1)) * (newX - x1)) + y1;
00096   return newY;
00097 } // new_y
00098 
00099 
00114 void signalUtil::sawToothWave( double *vec,
00115                                size_t N,
00116                                size_t numCycles,
00117                                double amplitude )
00118 {
00119   size_t spacing = N / numCycles;
00120   size_t step = spacing / 4;
00121   bool positive = true;
00122 
00123   size_t x1, x2;
00124   double y1, y2;
00125 
00126   for (size_t i = 0; i < N; i = i + spacing) {
00127     x1 = i;
00128     x2 = i + step;
00129     for (size_t j = 1; j <= 4; j++) {
00130       switch (j) {
00131         case 1: {
00132           y1 = 0.0;
00133           y2 = amplitude;
00134         }
00135         break;
00136         case 2:{
00137           y1 = amplitude;
00138           y2 = 0.0;
00139         }
00140         break;
00141         case 3:{
00142           y1 = 0.0;
00143           y2 = -amplitude;
00144         }
00145         break;
00146         case 4:{
00147           y1 = -amplitude;
00148           y2 = 0.0;
00149         }
00150         break;
00151       } // switch
00152       vec[x1] = y1;
00153       for (size_t k = x1+1; k < x2; k++) {
00154         vec[k] = new_y( x1, y1, x2, y2, k );
00155       }
00156       x1 = x2;
00157       x2 = x2 + step;
00158     }
00159   }
00160 } // sawToothWave
00161 
00162 
00163 
00168 void signalUtil::addSignal( double *C, 
00169                             const double *A,
00170                             const double *B,
00171                             const size_t N )
00172 {
00173   for (size_t i = 0; i < N; i++) {
00174     C[i] = A[i] + B[i];
00175   }
00176 }
00177 
00178 
00184 void signalUtil::prCoords( double *vecX, double *vecY, size_t len )
00185 {
00186   for (int i = 0; i < len; i++) {
00187     printf("%7.4f  %7.4f\n", vecX[i], vecY[i] );
00188   }
00189 }
00190 
00191 
00195 void signalUtil::prVec( double *vec, size_t len )
00196 {
00197   for (int i = 0; i < len; i++) {
00198     printf("%4d  %7.4f\n", i, vec[i] );
00199   }
00200 } // prVec
00201 
00202 
00203 
00208 bool signalUtil::vecEqual( const double *d1,
00209                            const double *d2,
00210                            const size_t N )
00211 {
00212   bool rslt = true;
00213 
00214   for (size_t i = 0; i < N; i++) {
00215     if (d1[i] != d2[i]) {
00216       rslt = false;
00217       break;
00218     }
00219   }
00220   return rslt;
00221 }

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