kopia lustrzana https://github.com/kosme/arduinoFFT
Merge pull request #81 from BjornTheProgrammer/master
Update Examples and Documentation to Reflect Real Statusv1.6.2
commit
78ec583c60
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#include "arduinoFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
arduinoFFT FFT;
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
|
@ -67,21 +67,23 @@ void loop()
|
||||||
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
||||||
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
|
||||||
/* Print the results of the simulated sampling according to time */
|
/* Print the results of the simulated sampling according to time */
|
||||||
Serial.println("Data:");
|
Serial.println("Data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
Serial.println("Weighed data:");
|
Serial.println("Weighed data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
FFT.Compute(FFT_FORWARD); /* Compute FFT */
|
||||||
Serial.println("Computed Real values:");
|
Serial.println("Computed Real values:");
|
||||||
PrintVector(vReal, samples, SCL_INDEX);
|
PrintVector(vReal, samples, SCL_INDEX);
|
||||||
Serial.println("Computed Imaginary values:");
|
Serial.println("Computed Imaginary values:");
|
||||||
PrintVector(vImag, samples, SCL_INDEX);
|
PrintVector(vImag, samples, SCL_INDEX);
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.ComplexToMagnitude(); /* Compute magnitudes */
|
||||||
Serial.println("Computed magnitudes:");
|
Serial.println("Computed magnitudes:");
|
||||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
double x = FFT.MajorPeak();
|
||||||
Serial.println(x, 6);
|
Serial.println(x, 6);
|
||||||
while(1); /* Run Once */
|
while(1); /* Run Once */
|
||||||
// delay(2000); /* Repeat after delay */
|
// delay(2000); /* Repeat after delay */
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include "arduinoFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
arduinoFFT FFT;
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
|
@ -31,7 +31,6 @@ These values can be changed in order to evaluate the functions
|
||||||
const uint16_t samples = 64;
|
const uint16_t samples = 64;
|
||||||
const double sampling = 40;
|
const double sampling = 40;
|
||||||
const uint8_t amplitude = 4;
|
const uint8_t amplitude = 4;
|
||||||
uint8_t exponent;
|
|
||||||
const double startFrequency = 2;
|
const double startFrequency = 2;
|
||||||
const double stopFrequency = 16.4;
|
const double stopFrequency = 16.4;
|
||||||
const double step_size = 0.1;
|
const double step_size = 0.1;
|
||||||
|
@ -55,7 +54,6 @@ void setup()
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while(!Serial);
|
while(!Serial);
|
||||||
Serial.println("Ready");
|
Serial.println("Ready");
|
||||||
exponent = FFT.Exponent(samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@ -74,18 +72,19 @@ void loop()
|
||||||
/*Serial.println("Data:");
|
/*Serial.println("Data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);*/
|
PrintVector(vReal, samples, SCL_TIME);*/
|
||||||
time=millis();
|
time=millis();
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT = arduinoFFT(vReal, vImag, samples, sampling); /* Create FFT object */
|
||||||
|
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
/*Serial.println("Weighed data:");
|
/*Serial.println("Weighed data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);*/
|
PrintVector(vReal, samples, SCL_TIME);*/
|
||||||
FFT.Compute(vReal, vImag, samples, exponent, FFT_FORWARD); /* Compute FFT */
|
FFT.Compute(FFT_FORWARD); /* Compute FFT */
|
||||||
/*Serial.println("Computed Real values:");
|
/*Serial.println("Computed Real values:");
|
||||||
PrintVector(vReal, samples, SCL_INDEX);
|
PrintVector(vReal, samples, SCL_INDEX);
|
||||||
Serial.println("Computed Imaginary values:");
|
Serial.println("Computed Imaginary values:");
|
||||||
PrintVector(vImag, samples, SCL_INDEX);*/
|
PrintVector(vImag, samples, SCL_INDEX);*/
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.ComplexToMagnitude(); /* Compute magnitudes */
|
||||||
/*Serial.println("Computed magnitudes:");
|
/*Serial.println("Computed magnitudes:");
|
||||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
|
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
|
||||||
double x = FFT.MajorPeak(vReal, samples, sampling);
|
double x = FFT.MajorPeak();
|
||||||
Serial.print(frequency);
|
Serial.print(frequency);
|
||||||
Serial.print(": \t\t");
|
Serial.print(": \t\t");
|
||||||
Serial.print(x, 4);
|
Serial.print(x, 4);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "arduinoFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
arduinoFFT FFT;
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
|
@ -64,21 +64,22 @@ void loop()
|
||||||
}
|
}
|
||||||
microseconds += sampling_period_us;
|
microseconds += sampling_period_us;
|
||||||
}
|
}
|
||||||
|
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
|
||||||
/* Print the results of the sampling according to time */
|
/* Print the results of the sampling according to time */
|
||||||
Serial.println("Data:");
|
Serial.println("Data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
Serial.println("Weighed data:");
|
Serial.println("Weighed data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
FFT.Compute(FFT_FORWARD); /* Compute FFT */
|
||||||
Serial.println("Computed Real values:");
|
Serial.println("Computed Real values:");
|
||||||
PrintVector(vReal, samples, SCL_INDEX);
|
PrintVector(vReal, samples, SCL_INDEX);
|
||||||
Serial.println("Computed Imaginary values:");
|
Serial.println("Computed Imaginary values:");
|
||||||
PrintVector(vImag, samples, SCL_INDEX);
|
PrintVector(vImag, samples, SCL_INDEX);
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.ComplexToMagnitude(); /* Compute magnitudes */
|
||||||
Serial.println("Computed magnitudes:");
|
Serial.println("Computed magnitudes:");
|
||||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
double x = FFT.MajorPeak();
|
||||||
Serial.println(x, 6); //Print out what frequency is the most dominant.
|
Serial.println(x, 6); //Print out what frequency is the most dominant.
|
||||||
while(1); /* Run Once */
|
while(1); /* Run Once */
|
||||||
// delay(2000); /* Repeat after delay */
|
// delay(2000); /* Repeat after delay */
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#include "arduinoFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
arduinoFFT FFT;
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
|
@ -68,11 +68,12 @@ void loop()
|
||||||
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
||||||
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
||||||
}
|
}
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
|
||||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.Compute(FFT_FORWARD); /* Compute FFT */
|
||||||
|
FFT.ComplexToMagnitude(); /* Compute magnitudes */
|
||||||
PrintVector(vReal, samples>>1, SCL_PLOT);
|
PrintVector(vReal, samples>>1, SCL_PLOT);
|
||||||
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
|
double x = FFT.MajorPeak();
|
||||||
while(1); /* Run Once */
|
while(1); /* Run Once */
|
||||||
// delay(2000); /* Repeat after delay */
|
// delay(2000); /* Repeat after delay */
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#include "arduinoFFT.h"
|
#include "arduinoFFT.h"
|
||||||
|
|
||||||
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
|
arduinoFFT FFT;
|
||||||
/*
|
/*
|
||||||
These values can be changed in order to evaluate the functions
|
These values can be changed in order to evaluate the functions
|
||||||
*/
|
*/
|
||||||
|
@ -68,23 +68,24 @@ void loop()
|
||||||
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
//vReal[i] = uint8_t((amplitude * (sin((i * (twoPi * cycles)) / samples) + 1.0)) / 2.0);/* Build data displaced on the Y axis to include only positive values*/
|
||||||
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
|
||||||
}
|
}
|
||||||
|
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
|
||||||
/* Print the results of the simulated sampling according to time */
|
/* Print the results of the simulated sampling according to time */
|
||||||
Serial.println("Data:");
|
Serial.println("Data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
|
||||||
Serial.println("Weighed data:");
|
Serial.println("Weighed data:");
|
||||||
PrintVector(vReal, samples, SCL_TIME);
|
PrintVector(vReal, samples, SCL_TIME);
|
||||||
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
|
FFT.Compute(FFT_FORWARD); /* Compute FFT */
|
||||||
Serial.println("Computed Real values:");
|
Serial.println("Computed Real values:");
|
||||||
PrintVector(vReal, samples, SCL_INDEX);
|
PrintVector(vReal, samples, SCL_INDEX);
|
||||||
Serial.println("Computed Imaginary values:");
|
Serial.println("Computed Imaginary values:");
|
||||||
PrintVector(vImag, samples, SCL_INDEX);
|
PrintVector(vImag, samples, SCL_INDEX);
|
||||||
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
|
FFT.ComplexToMagnitude(); /* Compute magnitudes */
|
||||||
Serial.println("Computed magnitudes:");
|
Serial.println("Computed magnitudes:");
|
||||||
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
|
||||||
double x;
|
double x;
|
||||||
double v;
|
double v;
|
||||||
FFT.MajorPeak(vReal, samples, samplingFrequency, &x, &v);
|
FFT.MajorPeak(&x, &v);
|
||||||
Serial.print(x, 6);
|
Serial.print(x, 6);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
Serial.println(v, 6);
|
Serial.println(v, 6);
|
||||||
|
|
21
README.md
21
README.md
|
@ -19,12 +19,14 @@ To install this library, just place this entire folder as a subfolder in your Ar
|
||||||
|
|
||||||
When installed, this library should look like:
|
When installed, this library should look like:
|
||||||
|
|
||||||
|
```
|
||||||
Arduino\libraries\arduinoFTT (this library's folder)
|
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.cpp (the library implementation file, uses 32 bits floats vectors)
|
||||||
Arduino\libraries\arduinoFTT\arduinoFTT.h (the library header file, uses 32 bits floats vectors)
|
Arduino\libraries\arduinoFTT\arduinoFTT.h (the library header file, uses 32 bits floats vectors)
|
||||||
Arduino\libraries\arduinoFTT\keywords.txt (the syntax coloring file)
|
Arduino\libraries\arduinoFTT\keywords.txt (the syntax coloring file)
|
||||||
Arduino\libraries\arduinoFTT\examples (the examples in the "open" menu)
|
Arduino\libraries\arduinoFTT\examples (the examples in the "open" menu)
|
||||||
Arduino\libraries\arduinoFTT\readme.md (this file)
|
Arduino\libraries\arduinoFTT\readme.md (this file)
|
||||||
|
```
|
||||||
|
|
||||||
### Building on Arduino
|
### Building on Arduino
|
||||||
|
|
||||||
|
@ -44,28 +46,31 @@ select arduinoFTT. This will add a corresponding line to the top of your sketch
|
||||||
<del>* Spectrum table? </del>
|
<del>* Spectrum table? </del>
|
||||||
|
|
||||||
### API
|
### API
|
||||||
|
The exclamation mark `!` denotes that this method is deprecated and may be removed on future revisions.
|
||||||
|
|
||||||
* **arduinoFFT**(void);
|
* **!arduinoFFT**(void);
|
||||||
* **arduinoFFT**(double *vReal, double *vImag, uint16_t samples, double samplingFrequency);
|
* **arduinoFFT**(double *vReal, double *vImag, uint16_t samples, double samplingFrequency);
|
||||||
Constructor
|
Constructor
|
||||||
* **~arduinoFFT**(void);
|
* **~arduinoFFT**(void);
|
||||||
Destructor
|
Destructor
|
||||||
* **ComplexToMagnitude**(double *vReal, double *vImag, uint16_t samples);
|
* **!ComplexToMagnitude**(double *vReal, double *vImag, uint16_t samples);
|
||||||
* **ComplexToMagnitude**();
|
* **ComplexToMagnitude**();
|
||||||
* **Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
|
* **!Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
|
||||||
* **Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
|
* **!Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
|
||||||
* **Compute**(uint8_t dir);
|
* **Compute**(uint8_t dir);
|
||||||
Calcuates the Fast Fourier Transform.
|
Calcuates the Fast Fourier Transform.
|
||||||
* **DCRemoval**(double *vData, uint16_t samples);
|
* **!DCRemoval**(double *vData, uint16_t samples);
|
||||||
* **DCRemoval**();
|
* **DCRemoval**();
|
||||||
Removes the DC component from the sample data.
|
Removes the DC component from the sample data.
|
||||||
* **MajorPeak**(double *vD, uint16_t samples, double samplingFrequency);
|
* **!MajorPeak**(double *vD, uint16_t samples, double samplingFrequency);
|
||||||
|
* **!MajorPeak**(double *vD, uint16_t samples, double samplingFrequency, double *f, double *v);
|
||||||
* **MajorPeak**();
|
* **MajorPeak**();
|
||||||
|
* **MajorPeak**(double *f, double *v);
|
||||||
* **MajorPeakParabola**();
|
* **MajorPeakParabola**();
|
||||||
Looks for and returns the frequency of the biggest spike in the analyzed signal.
|
Looks for and returns the frequency of the biggest spike in the analyzed signal.
|
||||||
* **Revision**(void);
|
* **Revision**(void);
|
||||||
Returns the library revision.
|
Returns the library revision.
|
||||||
* **Windowing**(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);
|
* **!Windowing**(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);
|
||||||
* **Windowing**(uint8_t windowType, uint8_t dir);
|
* **Windowing**(uint8_t windowType, uint8_t dir);
|
||||||
Performs a windowing function on the values array. The possible windowing options are:
|
Performs a windowing function on the values array. The possible windowing options are:
|
||||||
* FFT_WIN_TYP_RECTANGLE
|
* FFT_WIN_TYP_RECTANGLE
|
||||||
|
@ -78,5 +83,5 @@ Performs a windowing function on the values array. The possible windowing option
|
||||||
* FFT_WIN_TYP_BLACKMAN_HARRIS
|
* FFT_WIN_TYP_BLACKMAN_HARRIS
|
||||||
* FFT_WIN_TYP_FLT_TOP
|
* FFT_WIN_TYP_FLT_TOP
|
||||||
* FFT_WIN_TYP_WELCH
|
* FFT_WIN_TYP_WELCH
|
||||||
* **Exponent**(uint16_t value);
|
* **!Exponent**(uint16_t value);
|
||||||
Calculates and returns the base 2 logarithm of the given value.
|
Calculates and returns the base 2 logarithm of the given value.
|
||||||
|
|
Ładowanie…
Reference in New Issue