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

signalUtil Class Reference

A collection of utility functions for signal generation and signal code debug. More...

#include <signalUtil.h>

List of all members.

Static Public Methods

void gen_freqMix (double *vecX, double *vecY, size_t N)
 Generate a signal composed of a sum of sine waves. More...

void gen_sinCombo (double *vecX, double *vecY, size_t N)
 Generate a signal composed of one or more sine waves. More...

void prCoords (double *vecX, double *vecY, size_t len)
 Print a vector of doubles whose length is len. More...

void prVec (double *vec, size_t len)
 Print a vector of doubles. More...

bool vecEqual (const double *d1, const double *d2, const size_t N)
 If two vectors are equal, return true, otherwise return false. More...

double new_y (size_t x1, double y1, size_t x2, double y2, size_t newX)
 Given two points {x1, y1} and {x2, y2}, where x1 and x2 are positive integer values, calculate the y value for a point {x, y}, where x is a positive integer such that x1 < x < x2 (e.g., x lies between x1 and x2). More...

void sawToothWave (double *vec, size_t N, size_t numCycles, double amplitude)
 Generate a sawtooth wave centered around zero on the x-axis. More...

void addSignal (double *C, const double *A, const double *B, const size_t N)
 Add vector A to vector B and place the result in vector C. More...


Private Methods

 signalUtil ()
 This class is designed to provide static functions, not to be declared as a class instance. More...

 ~signalUtil ()
 signalUtil (const signalUtil &rhs)


Detailed Description

A collection of utility functions for signal generation and signal code debug.

Definition at line 9 of file signalUtil.h.


Constructor & Destructor Documentation

signalUtil::signalUtil ( ) [inline, private]
 

This class is designed to provide static functions, not to be declared as a class instance.

Definition at line 13 of file signalUtil.h.

00013 {};

signalUtil::~signalUtil ( ) [inline, private]
 

Definition at line 14 of file signalUtil.h.

00014 {};

signalUtil::signalUtil ( const signalUtil & rhs ) [inline, private]
 

Definition at line 15 of file signalUtil.h.

00015 {}


Member Function Documentation

void signalUtil::addSignal ( double * C,
const double * A,
const double * B,
const size_t N ) [static]
 

Add vector A to vector B and place the result in vector C.

N is the size of the vectors.

Definition at line 168 of file signalUtil.cpp.

Referenced by genSawTooth().

00172 {
00173   for (size_t i = 0; i < N; i++) {
00174     C[i] = A[i] + B[i];
00175   }
00176 }

void signalUtil::gen_freqMix ( double * vecX,
double * vecY,
size_t N ) [static]
 

Generate a signal composed of a sum of sine waves.

The sine waves summed are in decreasing magnitude and decreasing frequency.

Definition at line 13 of file signalUtil.cpp.

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

void signalUtil::gen_sinCombo ( double * vecX,
double * vecY,
size_t N ) [static]
 

Generate a signal composed of one or more sine waves.

Definition at line 37 of file signalUtil.cpp.

Referenced by main().

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 }

double signalUtil::new_y ( size_t x1,
double y1,
size_t x2,
double y2,
size_t newX ) [static]
 

Given two points {x1, y1} and {x2, y2}, where x1 and x2 are positive integer values, calculate the y value for a point {x, y}, where x is a positive integer such that x1 < x < x2 (e.g., x lies between x1 and x2).

The "two-point equation" for a line given x1, y1 and x2, y2 is

     .          y2 - y1
     (y - y1) = -------- (x - x1)
     .          x2 - x1
     

Solving for y

     .    y2 - y1
     y = -------- (x - x1) + y1
     .    x2 - x1
     

Definition at line 89 of file signalUtil.cpp.

Referenced by sawToothWave().

00092 {
00093   double newY = 0.0;
00094 
00095   newY = (((y2 - y1)/(x2 - x1)) * (newX - x1)) + y1;
00096   return newY;
00097 } // new_y

void signalUtil::prCoords ( double * vecX,
double * vecY,
size_t len ) [static]
 

Print a vector of doubles whose length is len.

Definition at line 184 of file signalUtil.cpp.

Referenced by main().

00185 {
00186   for (int i = 0; i < len; i++) {
00187     printf("%7.4f  %7.4f\n", vecX[i], vecY[i] );
00188   }
00189 }

void signalUtil::prVec ( double * vec,
size_t len ) [static]
 

Print a vector of doubles.

Definition at line 195 of file signalUtil.cpp.

Referenced by main().

00196 {
00197   for (int i = 0; i < len; i++) {
00198     printf("%4d  %7.4f\n", i, vec[i] );
00199   }
00200 } // prVec

void signalUtil::sawToothWave ( double * vec,
size_t N,
size_t numCycles,
double amplitude ) [static]
 

Generate a sawtooth wave centered around zero on the x-axis.

There is probably a simpler way to do this, but hey, this works.

Parameters:
vec   array to be initialized with the sawtooth wave.
N   number of elements in vec
numCycles   number of sawtooth wave cycles
amplitude   the amplitude on the positive y-axis. So if the amplitude is 1.5, the wave will have a point at 1.5 on the y-axis for the positive part of the cycle and at -1.5 for the negative part of the cycle.

Definition at line 114 of file signalUtil.cpp.

Referenced by genSawTooth().

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

bool signalUtil::vecEqual ( const double * d1,
const double * d2,
const size_t N ) [static]
 

If two vectors are equal, return true, otherwise return false.

Definition at line 208 of file signalUtil.cpp.

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 }


The documentation for this class was generated from the following files:
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