diff --git a/.gitignore b/.gitignore index d8fe4fa..fcd85c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.project +/sync.ffs_db diff --git a/README.md b/README.md index cad7c21..385dee2 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,23 @@ Fast Fourier Transform for Arduino This is a fork from https://code.google.com/p/makefurt/ which has been abandoned since 2011. This is a C++ library for Arduino for computing FFT. -Tested on Arduino 0022 Alpha. + +Tested on Arduino 1.0.5 Installation -------------------------------------------------------------------------------- -To install this library, just place this entire folder as a subfolder in your +To install this library, just place this entire folder as a subfolder in your Arduino installation When installed, this library should look like: -Arduino\libraries\PlainFTT (this library's folder) -Arduino\libraries\PlainFTT\PlainFTT.cpp (the library implementation file, uses 32 bits floats vectors) -Arduino\libraries\PlainFTT\PlainFTT.h (the library description file, uses 32 bits floats vectors) -Arduino\libraries\PlainFTT\PlainFTT_INT.cpp (the library implementation file, experimental signed 16 bits vectors) -Arduino\libraries\PlainFTT\PlainFTT_INT.h (the library description file, experimental signed 16 bits vectors) -Arduino\libraries\PlainFTT\keywords.txt (the syntax coloring file) -Arduino\libraries\PlainFTT\examples (the examples in the "open" menu) -Arduino\libraries\PlainFTT\readme.txt (this file) +Arduino\libraries\arduinoFTT (this library's folder) +Arduino\libraries\arduinoFTT\arduinoFTT.cpp (the library implementation file, uses 32 bits floats vectors) +Arduino\libraries\arduinoFTT\arduinoFTT.h (the library description file, uses 32 bits floats vectors) +Arduino\libraries\arduinoFTT\keywords.txt (the syntax coloring file) +Arduino\libraries\arduinoFTT\examples (the examples in the "open" menu) +Arduino\libraries\arduinoFTT\readme.md (this file) Building -------------------------------------------------------------------------------- @@ -32,5 +31,5 @@ After this library is installed, you just have to start the Arduino application. You may see a few warning messages as it's built. To use this library in a sketch, go to the Sketch | Import Library menu and -select PlainFTT. This will add a corresponding line to the top of your sketch: -#include (or #include +select arduinoFTT. This will add a corresponding line to the top of your sketch: +#include diff --git a/PlainFFT.cpp b/arduinoFFT.cpp similarity index 84% rename from PlainFFT.cpp rename to arduinoFFT.cpp index 4153d3c..159e9ea 100644 --- a/PlainFFT.cpp +++ b/arduinoFFT.cpp @@ -2,6 +2,7 @@ FFT libray Copyright (C) 2010 Didier Longueville + Copyright (C) 2014 Enrique Condes This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,27 +19,32 @@ */ -#include "PlainFFT.h" +#include "arduinoFFT.h" #define twoPi 6.28318531 #define fourPi 12.56637061 -PlainFFT::PlainFFT(void) +arduinoFFT::arduinoFFT(void) { /* Constructor */ } -PlainFFT::~PlainFFT(void) +arduinoFFT::~arduinoFFT(void) { /* Destructor */ } -uint8_t PlainFFT::Revision(void) +uint8_t arduinoFFT::Revision(void) { return(FFT_LIB_REV); } -void PlainFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t dir) +void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t dir) +{ + Compute(vReal, vImag, samples, Exponent(samples), 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 */ @@ -59,7 +65,7 @@ void PlainFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t d double c1 = -1.0; double c2 = 0.0; uint8_t l2 = 1; - for (uint8_t l = 0; (l < Exponent(samples)); l++) { + for (uint8_t l = 0; (l < power); l++) { uint8_t l1 = l2; l2 <<= 1; double u1 = 1.0; @@ -93,7 +99,7 @@ void PlainFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t d } } -void PlainFFT::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++) { @@ -101,7 +107,7 @@ void PlainFFT::ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples } } -void PlainFFT::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,7 +151,7 @@ void PlainFFT::Windowing(double *vData, uint16_t samples, uint8_t windowType, ui } } -double PlainFFT::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; @@ -165,14 +171,14 @@ double PlainFFT::MajorPeak(double *vD, uint16_t samples, double samplingFrequenc /* Private functions */ -void PlainFFT::Swap(double *x, double *y) +void arduinoFFT::Swap(double *x, double *y) { double temp = *x; *x = *y; *y = temp; } -uint8_t PlainFFT::Exponent(uint16_t value) +uint8_t arduinoFFT::Exponent(uint16_t value) { /* Computes the Exponent of a powered 2 value */ uint8_t result = 0; diff --git a/PlainFFT.h b/arduinoFFT.h similarity index 85% rename from PlainFFT.h rename to arduinoFFT.h index 29efbac..55b7622 100644 --- a/PlainFFT.h +++ b/arduinoFFT.h @@ -2,6 +2,7 @@ FFT libray Copyright (C) 2010 Didier Longueville + Copyright (C) 2014 Enrique Condes This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,8 +19,8 @@ */ -#ifndef PlainFFT_h /* Prevent loading library twice */ -#define PlainFFT_h +#ifndef arduinoFFT_h /* Prevent loading library twice */ +#define arduinoFFT_h #if ARDUINO >= 100 #include "Arduino.h"; @@ -27,7 +28,7 @@ #include "WProgram.h" /* This is where the standard Arduino code lies */ #endif -#define FFT_LIB_REV 0x02 +#define FFT_LIB_REV 0x02a /* Custom constants */ #define FFT_FORWARD 0x01 #define FFT_REVERSE 0x00 @@ -40,22 +41,23 @@ #define FFT_WIN_TYP_FLT_TOP 0x05 /* flat top */ #define FFT_WIN_TYP_WELCH 0x06 /* welch */ -class PlainFFT { +class arduinoFFT { public: /* Constructor */ - PlainFFT(void); + arduinoFFT(void); /* Destructor */ - ~PlainFFT(void); + ~arduinoFFT(void); /* Functions */ void ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples); void Compute(double *vReal, double *vImag, uint16_t samples, uint8_t dir); + 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); + uint8_t Exponent(uint16_t value); private: /* Functions */ - uint8_t Exponent(uint16_t value); void Swap(double *x, double *y); };