kopia lustrzana https://github.com/kosme/arduinoFFT
Porównaj commity
2 Commity
1936a46549
...
7059599c59
Autor | SHA1 | Data |
---|---|---|
Enrique Condes | 7059599c59 | |
Enrique Condes | 04fbc35bda |
|
@ -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=*
|
||||||
|
|
|
@ -247,7 +247,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
|
||||||
|
@ -423,7 +423,9 @@ template <typename T>
|
||||||
void ArduinoFFT<T>::findMaxY(T *vData, uint_fast16_t length, T *maxY,
|
void ArduinoFFT<T>::findMaxY(T *vData, uint_fast16_t length, T *maxY,
|
||||||
uint_fast16_t *index) const {
|
uint_fast16_t *index) const {
|
||||||
*maxY = 0;
|
*maxY = 0;
|
||||||
*index = 0;
|
// A signal with a DC offset produces a spike on bin 0 that should be ignored.
|
||||||
|
// Start the search on bin 1.
|
||||||
|
*index = 1;
|
||||||
// If sampling_frequency = 2 * max_frequency in signal,
|
// If sampling_frequency = 2 * max_frequency in signal,
|
||||||
// value would be stored at position samples/2
|
// value would be stored at position samples/2
|
||||||
for (uint_fast16_t i = 1; i < length; i++) {
|
for (uint_fast16_t i = 1; i < length; i++) {
|
||||||
|
@ -501,7 +503,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 +513,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