- Change class name from PlainFFT to arduinoFFT.

- Fix referencies in Readme file.
- Exponent is now a public function.
- Create another Compute function that takes the exponent as a parameter
so it is calculated only once.
- Update Revision info.
pull/8/head
Enrique Condes 2014-07-19 22:42:36 -05:00
rodzic 5e30d11a7d
commit 81296ca08f
4 zmienionych plików z 38 dodań i 30 usunięć

1
.gitignore vendored
Wyświetl plik

@ -1 +1,2 @@
/.project /.project
/sync.ffs_db

Wyświetl plik

@ -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 fork from https://code.google.com/p/makefurt/ which has been abandoned since 2011.
This is a C++ library for Arduino for computing FFT. This is a C++ library for Arduino for computing FFT.
Tested on Arduino 0022 Alpha.
Tested on Arduino 1.0.5
Installation 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: When installed, this library should look like:
Arduino\libraries\PlainFTT (this library's folder) Arduino\libraries\arduinoFTT (this library's folder)
Arduino\libraries\PlainFTT\PlainFTT.cpp (the library implementation file, uses 32 bits floats vectors) Arduino\libraries\arduinoFTT\arduinoFTT.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\arduinoFTT\arduinoFTT.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\arduinoFTT\keywords.txt (the syntax coloring file)
Arduino\libraries\PlainFTT\PlainFTT_INT.h (the library description file, experimental signed 16 bits vectors) Arduino\libraries\arduinoFTT\examples (the examples in the "open" menu)
Arduino\libraries\PlainFTT\keywords.txt (the syntax coloring file) Arduino\libraries\arduinoFTT\readme.md (this file)
Arduino\libraries\PlainFTT\examples (the examples in the "open" menu)
Arduino\libraries\PlainFTT\readme.txt (this file)
Building 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. 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 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: select arduinoFTT. This will add a corresponding line to the top of your sketch:
#include <PlainFTT.h> (or #include <PlainFTT_INT.h> #include <arduinoFTT.h>

Wyświetl plik

@ -2,6 +2,7 @@
FFT libray FFT libray
Copyright (C) 2010 Didier Longueville Copyright (C) 2010 Didier Longueville
Copyright (C) 2014 Enrique Condes
This program is free software: you can redistribute it and/or modify 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 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 twoPi 6.28318531
#define fourPi 12.56637061 #define fourPi 12.56637061
PlainFFT::PlainFFT(void) arduinoFFT::arduinoFFT(void)
{ {
/* Constructor */ /* Constructor */
} }
PlainFFT::~PlainFFT(void) arduinoFFT::~arduinoFFT(void)
{ {
/* Destructor */ /* Destructor */
} }
uint8_t PlainFFT::Revision(void) uint8_t arduinoFFT::Revision(void)
{ {
return(FFT_LIB_REV); 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 */ /* Computes in-place complex-to-complex FFT */
/* Reverse bits */ /* Reverse bits */
@ -59,7 +65,7 @@ void PlainFFT::Compute(double *vReal, double *vImag, uint16_t samples, uint8_t d
double c1 = -1.0; double c1 = -1.0;
double c2 = 0.0; double c2 = 0.0;
uint8_t l2 = 1; 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; uint8_t l1 = l2;
l2 <<= 1; l2 <<= 1;
double u1 = 1.0; 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 */ /* vM is half the size of vReal and vImag */
for (uint8_t i = 0; i < samples; i++) { 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 */ /* Weighing factors are computed once before multiple use of FFT */
/* The weighing function is symetric; half the weighs are recorded */ /* 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; double maxY = 0;
uint16_t IndexOfMaxY = 0; uint16_t IndexOfMaxY = 0;
@ -165,14 +171,14 @@ double PlainFFT::MajorPeak(double *vD, uint16_t samples, double samplingFrequenc
/* Private functions */ /* Private functions */
void PlainFFT::Swap(double *x, double *y) void arduinoFFT::Swap(double *x, double *y)
{ {
double temp = *x; double temp = *x;
*x = *y; *x = *y;
*y = temp; *y = temp;
} }
uint8_t PlainFFT::Exponent(uint16_t value) uint8_t arduinoFFT::Exponent(uint16_t value)
{ {
/* Computes the Exponent of a powered 2 value */ /* Computes the Exponent of a powered 2 value */
uint8_t result = 0; uint8_t result = 0;

Wyświetl plik

@ -2,6 +2,7 @@
FFT libray FFT libray
Copyright (C) 2010 Didier Longueville Copyright (C) 2010 Didier Longueville
Copyright (C) 2014 Enrique Condes
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -18,8 +19,8 @@
*/ */
#ifndef PlainFFT_h /* Prevent loading library twice */ #ifndef arduinoFFT_h /* Prevent loading library twice */
#define PlainFFT_h #define arduinoFFT_h
#if ARDUINO >= 100 #if ARDUINO >= 100
#include "Arduino.h"; #include "Arduino.h";
@ -27,7 +28,7 @@
#include "WProgram.h" /* This is where the standard Arduino code lies */ #include "WProgram.h" /* This is where the standard Arduino code lies */
#endif #endif
#define FFT_LIB_REV 0x02 #define FFT_LIB_REV 0x02a
/* Custom constants */ /* Custom constants */
#define FFT_FORWARD 0x01 #define FFT_FORWARD 0x01
#define FFT_REVERSE 0x00 #define FFT_REVERSE 0x00
@ -40,22 +41,23 @@
#define FFT_WIN_TYP_FLT_TOP 0x05 /* flat top */ #define FFT_WIN_TYP_FLT_TOP 0x05 /* flat top */
#define FFT_WIN_TYP_WELCH 0x06 /* welch */ #define FFT_WIN_TYP_WELCH 0x06 /* welch */
class PlainFFT { class arduinoFFT {
public: public:
/* Constructor */ /* Constructor */
PlainFFT(void); arduinoFFT(void);
/* Destructor */ /* Destructor */
~PlainFFT(void); ~arduinoFFT(void);
/* Functions */ /* Functions */
void ComplexToMagnitude(double *vReal, double *vImag, uint16_t samples); 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 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); double MajorPeak(double *vD, uint16_t samples, double samplingFrequency);
uint8_t Revision(void); 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: private:
/* Functions */ /* Functions */
uint8_t Exponent(uint16_t value);
void Swap(double *x, double *y); void Swap(double *x, double *y);
}; };