From 1b4d271f94f85454e6abd3e8bb0dbb84c89ecce9 Mon Sep 17 00:00:00 2001 From: Enrique Condes Date: Tue, 25 Apr 2017 13:01:06 -0500 Subject: [PATCH] Define constants on the headers file --- arduinoFFT.cpp | 35 ++++++++++++++++------------------- arduinoFFT.h | 13 ++++++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/arduinoFFT.cpp b/arduinoFFT.cpp index 159e9ea..6c7e069 100644 --- a/arduinoFFT.cpp +++ b/arduinoFFT.cpp @@ -16,26 +16,23 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - + */ #include "arduinoFFT.h" -#define twoPi 6.28318531 -#define fourPi 12.56637061 - -arduinoFFT::arduinoFFT(void) +arduinoFFT::arduinoFFT(void) { /* Constructor */ } arduinoFFT::~arduinoFFT(void) -{ +{ /* Destructor */ } uint8_t arduinoFFT::Revision(void) -{ +{ return(FFT_LIB_REV); } @@ -44,7 +41,7 @@ void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t Compute(vReal, vImag, samples, Exponent(samples), dir); } -void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir) +void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir) { /* Computes in-place complex-to-complex FFT */ /* Reverse bits */ @@ -62,20 +59,20 @@ void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t j += k; } /* Compute the FFT */ - double c1 = -1.0; + double c1 = -1.0; double c2 = 0.0; uint8_t l2 = 1; for (uint8_t l = 0; (l < power); l++) { uint8_t l1 = l2; l2 <<= 1; - double u1 = 1.0; + double u1 = 1.0; double u2 = 0.0; for (j = 0; j < l1; j++) { for (uint16_t i = j; i < samples; i += l2) { uint16_t i1 = i + l1; double t1 = u1 * vReal[i1] - u2 * vImag[i1]; double t2 = u1 * vImag[i1] + u2 * vReal[i1]; - vReal[i1] = vReal[i] - t1; + vReal[i1] = vReal[i] - t1; vImag[i1] = vImag[i] - t2; vReal[i] += t1; vImag[i] += t2; @@ -84,7 +81,7 @@ void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t u2 = ((u1 * c2) + (u2 * c1)); u1 = z; } - c2 = sqrt((1.0 - c1) / 2.0); + c2 = sqrt((1.0 - c1) / 2.0); if (dir == FFT_FORWARD) { c2 = -c2; } @@ -99,7 +96,7 @@ void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t } } -void arduinoFFT::ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples) +void arduinoFFT::ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples) { /* vM is half the size of vReal and vImag */ for (uint8_t i = 0; i < samples; i++) { @@ -107,7 +104,7 @@ void arduinoFFT::ComplexToMagnitude(double *vReal, double *vImag, uint16_t sampl } } -void arduinoFFT::Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir) +void arduinoFFT::Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir) { /* Weighing factors are computed once before multiple use of FFT */ /* The weighing function is symetric; half the weighs are recorded */ @@ -145,13 +142,13 @@ void arduinoFFT::Windowing(double *vData, uint16_t samples, uint8_t windowType, vData[samples - (i + 1)] *= weighingFactor; } else { - vData[i] /= weighingFactor; + vData[i] /= weighingFactor; vData[samples - (i + 1)] /= weighingFactor; } } } -double arduinoFFT::MajorPeak(double *vD, uint16_t samples, double samplingFrequency) +double arduinoFFT::MajorPeak(double *vD, uint16_t samples, double samplingFrequency) { double maxY = 0; uint16_t IndexOfMaxY = 0; @@ -171,17 +168,17 @@ double arduinoFFT::MajorPeak(double *vD, uint16_t samples, double samplingFreque /* Private functions */ -void arduinoFFT::Swap(double *x, double *y) +void arduinoFFT::Swap(double *x, double *y) { double temp = *x; *x = *y; *y = temp; } -uint8_t arduinoFFT::Exponent(uint16_t value) +uint8_t arduinoFFT::Exponent(uint16_t value) { /* Computes the Exponent of a powered 2 value */ uint8_t result = 0; while (((value >> result) & 1) != 1) result++; return(result); -} \ No newline at end of file +} diff --git a/arduinoFFT.h b/arduinoFFT.h index e93604f..e509e9f 100644 --- a/arduinoFFT.h +++ b/arduinoFFT.h @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - + */ #ifndef arduinoFFT_h /* Prevent loading library twice */ @@ -48,7 +48,10 @@ #define FFT_WIN_TYP_BLACKMAN 0x04 /* blackmann */ #define FFT_WIN_TYP_FLT_TOP 0x05 /* flat top */ #define FFT_WIN_TYP_WELCH 0x06 /* welch */ - +/*Mathematial constants*/ +#define twoPi 6.28318531 +#define fourPi 12.56637061 + class arduinoFFT { public: /* Constructor */ @@ -61,13 +64,13 @@ public: void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir); double MajorPeak(double *vD, uint16_t samples, double samplingFrequency); uint8_t Revision(void); - void Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir); + void Windowing(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir); uint8_t Exponent(uint16_t value); - + private: /* Functions */ void Swap(double *x, double *y); - + }; #endif