kopia lustrzana https://github.com/kosme/arduinoFFT
commit
0da88512f9
|
@ -25,7 +25,7 @@
|
||||||
"email": "bim.overbohm@googlemail.com"
|
"email": "bim.overbohm@googlemail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"frameworks": ["arduino","mbed","espidf"],
|
"frameworks": ["arduino","mbed","espidf"],
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
"headers": "arduinoFFT.h"
|
"headers": "arduinoFFT.h"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
name=arduinoFFT
|
name=arduinoFFT
|
||||||
version=2.0.1
|
version=2.0.2
|
||||||
author=Enrique Condes <enrique@shapeoko.com>
|
author=Enrique Condes <enrique@shapeoko.com>
|
||||||
maintainer=Enrique Condes <enrique@shapeoko.com>
|
maintainer=Enrique Condes <enrique@shapeoko.com>
|
||||||
sentence=A library for implementing floating point Fast Fourier Transform calculations on Arduino.
|
sentence=A library for implementing floating point Fast Fourier Transform calculations on the Arduino framework.
|
||||||
paragraph=With this library you can calculate the frequency of a sampled signal.
|
paragraph=With this library you can calculate the dominant frequency of a sampled signal.
|
||||||
category=Data Processing
|
category=Data Processing
|
||||||
url=https://github.com/kosme/arduinoFFT
|
url=https://github.com/kosme/arduinoFFT
|
||||||
architectures=*
|
architectures=*
|
||||||
|
|
|
@ -40,7 +40,7 @@ ArduinoFFT<T>::ArduinoFFT(T *vReal, T *vImag, uint_fast16_t samples,
|
||||||
template <typename T> ArduinoFFT<T>::~ArduinoFFT(void) {
|
template <typename T> ArduinoFFT<T>::~ArduinoFFT(void) {
|
||||||
// Destructor
|
// Destructor
|
||||||
if (_precompiledWindowingFactors) {
|
if (_precompiledWindowingFactors) {
|
||||||
delete [] _precompiledWindowingFactors;
|
delete[] _precompiledWindowingFactors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,10 @@ void ArduinoFFT<T>::compute(T *vReal, T *vImag, uint_fast16_t samples,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// The computation result at position 0 should be as close to 0 as possible.
|
||||||
|
// The DC offset on the signal produces a spike on position 0 that should be
|
||||||
|
// eliminated to avoid issues.
|
||||||
|
vReal[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void ArduinoFFT<T>::dcRemoval(void) const {
|
template <typename T> void ArduinoFFT<T>::dcRemoval(void) const {
|
||||||
|
@ -247,7 +251,7 @@ void ArduinoFFT<T>::majorPeakParabola(T *vData, uint_fast16_t samples,
|
||||||
|
|
||||||
// And magnitude is at the extrema of the parabola if you want It...
|
// And magnitude is at the extrema of the parabola if you want It...
|
||||||
if (magnitude != nullptr) {
|
if (magnitude != nullptr) {
|
||||||
*magnitude = a * x * x + b * x + c;
|
*magnitude = (a * x * x) + (b * x) + c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to frequency
|
// Convert to frequency
|
||||||
|
@ -270,7 +274,7 @@ void ArduinoFFT<T>::setArrays(T *vReal, T *vImag, uint_fast16_t samples) {
|
||||||
_oneOverSamples = 1.0 / samples;
|
_oneOverSamples = 1.0 / samples;
|
||||||
#endif
|
#endif
|
||||||
if (_precompiledWindowingFactors) {
|
if (_precompiledWindowingFactors) {
|
||||||
delete [] _precompiledWindowingFactors;
|
delete[] _precompiledWindowingFactors;
|
||||||
}
|
}
|
||||||
_precompiledWindowingFactors = new T[samples / 2];
|
_precompiledWindowingFactors = new T[samples / 2];
|
||||||
}
|
}
|
||||||
|
@ -501,7 +505,7 @@ template <typename T> double ArduinoFFT<T>::sqrt_internal(double x) const {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T ArduinoFFT<T>::_WindowCompensationFactors[10] = {
|
const T ArduinoFFT<T>::_WindowCompensationFactors[11] = {
|
||||||
1.0000000000 * 2.0, // rectangle (Box car)
|
1.0000000000 * 2.0, // rectangle (Box car)
|
||||||
1.8549343278 * 2.0, // hamming
|
1.8549343278 * 2.0, // hamming
|
||||||
1.8554726898 * 2.0, // hann
|
1.8554726898 * 2.0, // hann
|
||||||
|
@ -511,7 +515,10 @@ const T ArduinoFFT<T>::_WindowCompensationFactors[10] = {
|
||||||
2.7557840395 * 2.0, // blackman nuttall
|
2.7557840395 * 2.0, // blackman nuttall
|
||||||
2.7929062517 * 2.0, // blackman harris
|
2.7929062517 * 2.0, // blackman harris
|
||||||
3.5659039231 * 2.0, // flat top
|
3.5659039231 * 2.0, // flat top
|
||||||
1.5029392863 * 2.0 // welch
|
1.5029392863 * 2.0, // welch
|
||||||
|
// This is added as a precaution, since this index should never be
|
||||||
|
// accessed under normal conditions
|
||||||
|
1.0 // Custom, precompiled value.
|
||||||
};
|
};
|
||||||
|
|
||||||
template class ArduinoFFT<double>;
|
template class ArduinoFFT<double>;
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "enumsFFT.h"
|
||||||
|
|
||||||
// This definition uses a low-precision square root approximation instead of the
|
// This definition uses a low-precision square root approximation instead of the
|
||||||
// regular sqrt() call
|
// regular sqrt() call
|
||||||
|
@ -52,46 +53,7 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class FFTDirection { Forward, Reverse };
|
|
||||||
|
|
||||||
enum class FFTWindow {
|
|
||||||
Rectangle, // rectangle (Box car)
|
|
||||||
Hamming, // hamming
|
|
||||||
Hann, // hann
|
|
||||||
Triangle, // triangle (Bartlett)
|
|
||||||
Nuttall, // nuttall
|
|
||||||
Blackman, // blackman
|
|
||||||
Blackman_Nuttall, // blackman nuttall
|
|
||||||
Blackman_Harris, // blackman harris
|
|
||||||
Flat_top, // flat top
|
|
||||||
Welch, // welch
|
|
||||||
Precompiled // Placeholder for using custom or precompiled window values
|
|
||||||
};
|
|
||||||
#define FFT_LIB_REV 0x20
|
#define FFT_LIB_REV 0x20
|
||||||
/* Custom constants */
|
|
||||||
/* These defines keep compatibility with pre 2.0 code */
|
|
||||||
#define FFT_FORWARD FFTDirection::Forward
|
|
||||||
#define FFT_REVERSE FFTDirection::Reverse
|
|
||||||
|
|
||||||
/* Windowing type */
|
|
||||||
#define FFT_WIN_TYP_RECTANGLE FFTWindow::Rectangle /* rectangle (Box car) */
|
|
||||||
#define FFT_WIN_TYP_HAMMING FFTWindow::Hamming /* hamming */
|
|
||||||
#define FFT_WIN_TYP_HANN FFTWindow::Hann /* hann */
|
|
||||||
#define FFT_WIN_TYP_TRIANGLE FFTWindow::Triangle /* triangle (Bartlett) */
|
|
||||||
#define FFT_WIN_TYP_NUTTALL FFTWindow::Nuttall /* nuttall */
|
|
||||||
#define FFT_WIN_TYP_BLACKMAN FFTWindow::Blackman /* blackman */
|
|
||||||
#define FFT_WIN_TYP_BLACKMAN_NUTTALL \
|
|
||||||
FFTWindow::Blackman_Nuttall /* blackman nuttall */
|
|
||||||
#define FFT_WIN_TYP_BLACKMAN_HARRIS \
|
|
||||||
FFTWindow::Blackman_Harris /* blackman harris*/
|
|
||||||
#define FFT_WIN_TYP_FLT_TOP FFTWindow::Flat_top /* flat top */
|
|
||||||
#define FFT_WIN_TYP_WELCH FFTWindow::Welch /* welch */
|
|
||||||
/* End of compatibility defines */
|
|
||||||
|
|
||||||
/* Mathematial constants */
|
|
||||||
#define twoPi 6.28318531
|
|
||||||
#define fourPi 12.56637061
|
|
||||||
#define sixPi 18.84955593
|
|
||||||
|
|
||||||
template <typename T> class ArduinoFFT {
|
template <typename T> class ArduinoFFT {
|
||||||
public:
|
public:
|
||||||
|
@ -138,14 +100,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Variables */
|
/* Variables */
|
||||||
static const T _WindowCompensationFactors[10];
|
static const T _WindowCompensationFactors[11];
|
||||||
#ifdef FFT_SPEED_OVER_PRECISION
|
#ifdef FFT_SPEED_OVER_PRECISION
|
||||||
T _oneOverSamples = 0.0;
|
T _oneOverSamples = 0.0;
|
||||||
#endif
|
#endif
|
||||||
bool _isPrecompiled = false;
|
bool _isPrecompiled = false;
|
||||||
bool _precompiledWithCompensation = false;
|
bool _precompiledWithCompensation = false;
|
||||||
uint_fast8_t _power = 0;
|
uint_fast8_t _power = 0;
|
||||||
T *_precompiledWindowingFactors;
|
T *_precompiledWindowingFactors = nullptr;
|
||||||
uint_fast16_t _samples;
|
uint_fast16_t _samples;
|
||||||
T _samplingFrequency;
|
T _samplingFrequency;
|
||||||
T *_vImag;
|
T *_vImag;
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef enumsFFT_h
|
||||||
|
#define enumsFFT_h
|
||||||
|
/* Custom constants */
|
||||||
|
/* These defines keep compatibility with pre 2.0 code */
|
||||||
|
#define FFT_FORWARD FFTDirection::Forward
|
||||||
|
#define FFT_REVERSE FFTDirection::Reverse
|
||||||
|
|
||||||
|
/* Windowing type */
|
||||||
|
#define FFT_WIN_TYP_RECTANGLE FFTWindow::Rectangle /* rectangle (Box car) */
|
||||||
|
#define FFT_WIN_TYP_HAMMING FFTWindow::Hamming /* hamming */
|
||||||
|
#define FFT_WIN_TYP_HANN FFTWindow::Hann /* hann */
|
||||||
|
#define FFT_WIN_TYP_TRIANGLE FFTWindow::Triangle /* triangle (Bartlett) */
|
||||||
|
#define FFT_WIN_TYP_NUTTALL FFTWindow::Nuttall /* nuttall */
|
||||||
|
#define FFT_WIN_TYP_BLACKMAN FFTWindow::Blackman /* blackman */
|
||||||
|
#define FFT_WIN_TYP_BLACKMAN_NUTTALL \
|
||||||
|
FFTWindow::Blackman_Nuttall /* blackman nuttall */
|
||||||
|
#define FFT_WIN_TYP_BLACKMAN_HARRIS \
|
||||||
|
FFTWindow::Blackman_Harris /* blackman harris*/
|
||||||
|
#define FFT_WIN_TYP_FLT_TOP FFTWindow::Flat_top /* flat top */
|
||||||
|
#define FFT_WIN_TYP_WELCH FFTWindow::Welch /* welch */
|
||||||
|
/* End of compatibility defines */
|
||||||
|
|
||||||
|
/* Mathematial constants */
|
||||||
|
#define twoPi 6.28318531
|
||||||
|
#define fourPi 12.56637061
|
||||||
|
#define sixPi 18.84955593
|
||||||
|
|
||||||
|
enum class FFTWindow {
|
||||||
|
Rectangle, // rectangle (Box car)
|
||||||
|
Hamming, // hamming
|
||||||
|
Hann, // hann
|
||||||
|
Triangle, // triangle (Bartlett)
|
||||||
|
Nuttall, // nuttall
|
||||||
|
Blackman, // blackman
|
||||||
|
Blackman_Nuttall, // blackman nuttall
|
||||||
|
Blackman_Harris, // blackman harris
|
||||||
|
Flat_top, // flat top
|
||||||
|
Welch, // welch
|
||||||
|
Precompiled // Placeholder for using custom or precompiled window values
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class FFTDirection { Forward, Reverse };
|
||||||
|
#endif
|
Ładowanie…
Reference in New Issue