Skip to content

Commit 78ec583

Browse files
authored
Merge pull request #81 from BjornTheProgrammer/master
Update Examples and Documentation to Reflect Real Status
2 parents 94453e5 + f9d6fa7 commit 78ec583

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

Examples/FFT_01/FFT_01.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include "arduinoFFT.h"
3232

33-
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
33+
arduinoFFT FFT;
3434
/*
3535
These values can be changed in order to evaluate the functions
3636
*/
@@ -67,21 +67,23 @@ void loop()
6767
//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*/
6868
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
6969
}
70+
71+
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
7072
/* Print the results of the simulated sampling according to time */
7173
Serial.println("Data:");
7274
PrintVector(vReal, samples, SCL_TIME);
73-
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
75+
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
7476
Serial.println("Weighed data:");
7577
PrintVector(vReal, samples, SCL_TIME);
76-
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
78+
FFT.Compute(FFT_FORWARD); /* Compute FFT */
7779
Serial.println("Computed Real values:");
7880
PrintVector(vReal, samples, SCL_INDEX);
7981
Serial.println("Computed Imaginary values:");
8082
PrintVector(vImag, samples, SCL_INDEX);
81-
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
83+
FFT.ComplexToMagnitude(); /* Compute magnitudes */
8284
Serial.println("Computed magnitudes:");
8385
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
84-
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
86+
double x = FFT.MajorPeak();
8587
Serial.println(x, 6);
8688
while(1); /* Run Once */
8789
// delay(2000); /* Repeat after delay */

Examples/FFT_02/FFT_02.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323

2424
#include "arduinoFFT.h"
2525

26-
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
26+
arduinoFFT FFT;
2727
/*
2828
These values can be changed in order to evaluate the functions
2929
*/
3030

3131
const uint16_t samples = 64;
3232
const double sampling = 40;
3333
const uint8_t amplitude = 4;
34-
uint8_t exponent;
3534
const double startFrequency = 2;
3635
const double stopFrequency = 16.4;
3736
const double step_size = 0.1;
@@ -55,7 +54,6 @@ void setup()
5554
Serial.begin(115200);
5655
while(!Serial);
5756
Serial.println("Ready");
58-
exponent = FFT.Exponent(samples);
5957
}
6058

6159
void loop()
@@ -74,18 +72,19 @@ void loop()
7472
/*Serial.println("Data:");
7573
PrintVector(vReal, samples, SCL_TIME);*/
7674
time=millis();
77-
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
75+
FFT = arduinoFFT(vReal, vImag, samples, sampling); /* Create FFT object */
76+
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
7877
/*Serial.println("Weighed data:");
7978
PrintVector(vReal, samples, SCL_TIME);*/
80-
FFT.Compute(vReal, vImag, samples, exponent, FFT_FORWARD); /* Compute FFT */
79+
FFT.Compute(FFT_FORWARD); /* Compute FFT */
8180
/*Serial.println("Computed Real values:");
8281
PrintVector(vReal, samples, SCL_INDEX);
8382
Serial.println("Computed Imaginary values:");
8483
PrintVector(vImag, samples, SCL_INDEX);*/
85-
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
84+
FFT.ComplexToMagnitude(); /* Compute magnitudes */
8685
/*Serial.println("Computed magnitudes:");
8786
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
88-
double x = FFT.MajorPeak(vReal, samples, sampling);
87+
double x = FFT.MajorPeak();
8988
Serial.print(frequency);
9089
Serial.print(": \t\t");
9190
Serial.print(x, 4);

Examples/FFT_03/FFT_03.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "arduinoFFT.h"
2222

23-
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
23+
arduinoFFT FFT;
2424
/*
2525
These values can be changed in order to evaluate the functions
2626
*/
@@ -64,21 +64,22 @@ void loop()
6464
}
6565
microseconds += sampling_period_us;
6666
}
67+
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
6768
/* Print the results of the sampling according to time */
6869
Serial.println("Data:");
6970
PrintVector(vReal, samples, SCL_TIME);
70-
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
71+
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
7172
Serial.println("Weighed data:");
7273
PrintVector(vReal, samples, SCL_TIME);
73-
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
74+
FFT.Compute(FFT_FORWARD); /* Compute FFT */
7475
Serial.println("Computed Real values:");
7576
PrintVector(vReal, samples, SCL_INDEX);
7677
Serial.println("Computed Imaginary values:");
7778
PrintVector(vImag, samples, SCL_INDEX);
78-
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
79+
FFT.ComplexToMagnitude(); /* Compute magnitudes */
7980
Serial.println("Computed magnitudes:");
8081
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
81-
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
82+
double x = FFT.MajorPeak();
8283
Serial.println(x, 6); //Print out what frequency is the most dominant.
8384
while(1); /* Run Once */
8485
// delay(2000); /* Repeat after delay */

Examples/FFT_04/FFT_04.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "arduinoFFT.h"
3333

34-
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
34+
arduinoFFT FFT;
3535
/*
3636
These values can be changed in order to evaluate the functions
3737
*/
@@ -68,11 +68,12 @@ void loop()
6868
//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*/
6969
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
7070
}
71-
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
72-
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
73-
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
71+
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
72+
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
73+
FFT.Compute(FFT_FORWARD); /* Compute FFT */
74+
FFT.ComplexToMagnitude(); /* Compute magnitudes */
7475
PrintVector(vReal, samples>>1, SCL_PLOT);
75-
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
76+
double x = FFT.MajorPeak();
7677
while(1); /* Run Once */
7778
// delay(2000); /* Repeat after delay */
7879
}

Examples/FFT_05/FFT_05.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "arduinoFFT.h"
3333

34-
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
34+
arduinoFFT FFT;
3535
/*
3636
These values can be changed in order to evaluate the functions
3737
*/
@@ -68,23 +68,24 @@ void loop()
6868
//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*/
6969
vImag[i] = 0.0; //Imaginary part must be zeroed in case of looping to avoid wrong calculations and overflows
7070
}
71+
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
7172
/* Print the results of the simulated sampling according to time */
7273
Serial.println("Data:");
7374
PrintVector(vReal, samples, SCL_TIME);
74-
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
75+
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
7576
Serial.println("Weighed data:");
7677
PrintVector(vReal, samples, SCL_TIME);
77-
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
78+
FFT.Compute(FFT_FORWARD); /* Compute FFT */
7879
Serial.println("Computed Real values:");
7980
PrintVector(vReal, samples, SCL_INDEX);
8081
Serial.println("Computed Imaginary values:");
8182
PrintVector(vImag, samples, SCL_INDEX);
82-
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
83+
FFT.ComplexToMagnitude(); /* Compute magnitudes */
8384
Serial.println("Computed magnitudes:");
8485
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
8586
double x;
8687
double v;
87-
FFT.MajorPeak(vReal, samples, samplingFrequency, &x, &v);
88+
FFT.MajorPeak(&x, &v);
8889
Serial.print(x, 6);
8990
Serial.print(", ");
9091
Serial.println(v, 6);

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ To install this library, just place this entire folder as a subfolder in your Ar
1919

2020
When installed, this library should look like:
2121

22+
```
2223
Arduino\libraries\arduinoFTT (this library's folder)
2324
Arduino\libraries\arduinoFTT\arduinoFTT.cpp (the library implementation file, uses 32 bits floats vectors)
2425
Arduino\libraries\arduinoFTT\arduinoFTT.h (the library header file, uses 32 bits floats vectors)
2526
Arduino\libraries\arduinoFTT\keywords.txt (the syntax coloring file)
2627
Arduino\libraries\arduinoFTT\examples (the examples in the "open" menu)
2728
Arduino\libraries\arduinoFTT\readme.md (this file)
29+
```
2830

2931
### Building on Arduino
3032

@@ -44,28 +46,31 @@ select arduinoFTT. This will add a corresponding line to the top of your sketch
4446
<del>* Spectrum table? </del>
4547

4648
### API
49+
The exclamation mark `!` denotes that this method is deprecated and may be removed on future revisions.
4750

48-
* **arduinoFFT**(void);
51+
* **!arduinoFFT**(void);
4952
* **arduinoFFT**(double *vReal, double *vImag, uint16_t samples, double samplingFrequency);
5053
Constructor
5154
* **~arduinoFFT**(void);
5255
Destructor
53-
* **ComplexToMagnitude**(double *vReal, double *vImag, uint16_t samples);
56+
* **!ComplexToMagnitude**(double *vReal, double *vImag, uint16_t samples);
5457
* **ComplexToMagnitude**();
55-
* **Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
56-
* **Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
58+
* **!Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t dir);
59+
* **!Compute**(double *vReal, double *vImag, uint16_t samples, uint8_t power, uint8_t dir);
5760
* **Compute**(uint8_t dir);
5861
Calcuates the Fast Fourier Transform.
59-
* **DCRemoval**(double *vData, uint16_t samples);
62+
* **!DCRemoval**(double *vData, uint16_t samples);
6063
* **DCRemoval**();
6164
Removes the DC component from the sample data.
62-
* **MajorPeak**(double *vD, uint16_t samples, double samplingFrequency);
65+
* **!MajorPeak**(double *vD, uint16_t samples, double samplingFrequency);
66+
* **!MajorPeak**(double *vD, uint16_t samples, double samplingFrequency, double *f, double *v);
6367
* **MajorPeak**();
68+
* **MajorPeak**(double *f, double *v);
6469
* **MajorPeakParabola**();
6570
Looks for and returns the frequency of the biggest spike in the analyzed signal.
6671
* **Revision**(void);
6772
Returns the library revision.
68-
* **Windowing**(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);
73+
* **!Windowing**(double *vData, uint16_t samples, uint8_t windowType, uint8_t dir);
6974
* **Windowing**(uint8_t windowType, uint8_t dir);
7075
Performs a windowing function on the values array. The possible windowing options are:
7176
* FFT_WIN_TYP_RECTANGLE
@@ -78,5 +83,5 @@ Performs a windowing function on the values array. The possible windowing option
7883
* FFT_WIN_TYP_BLACKMAN_HARRIS
7984
* FFT_WIN_TYP_FLT_TOP
8085
* FFT_WIN_TYP_WELCH
81-
* **Exponent**(uint16_t value);
86+
* **!Exponent**(uint16_t value);
8287
Calculates and returns the base 2 logarithm of the given value.

0 commit comments

Comments
 (0)