Updated Examples to use Non-Deprecated Methods

Updated the examples FFT_01, FFT_02, FFT_03, FFT_04, and FFT_05.
pull/81/head
Bjorn 2023-03-17 23:31:04 -07:00
rodzic 94453e54ac
commit fa12c7b8f0
5 zmienionych plików z 31 dodań i 27 usunięć

Wyświetl plik

@ -30,7 +30,7 @@
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
arduinoFFT FFT;
/*
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*/
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 */
Serial.println("Data:");
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:");
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:");
PrintVector(vReal, samples, SCL_INDEX);
Serial.println("Computed Imaginary values:");
PrintVector(vImag, samples, SCL_INDEX);
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
double x = FFT.MajorPeak();
Serial.println(x, 6);
while(1); /* Run Once */
// delay(2000); /* Repeat after delay */

Wyświetl plik

@ -23,7 +23,7 @@
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
arduinoFFT FFT;
/*
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 double sampling = 40;
const uint8_t amplitude = 4;
uint8_t exponent;
const double startFrequency = 2;
const double stopFrequency = 16.4;
const double step_size = 0.1;
@ -55,7 +54,6 @@ void setup()
Serial.begin(115200);
while(!Serial);
Serial.println("Ready");
exponent = FFT.Exponent(samples);
}
void loop()
@ -74,18 +72,19 @@ void loop()
/*Serial.println("Data:");
PrintVector(vReal, samples, SCL_TIME);*/
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:");
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:");
PrintVector(vReal, samples, SCL_INDEX);
Serial.println("Computed Imaginary values:");
PrintVector(vImag, samples, SCL_INDEX);*/
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
/*Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
double x = FFT.MajorPeak(vReal, samples, sampling);
double x = FFT.MajorPeak();
Serial.print(frequency);
Serial.print(": \t\t");
Serial.print(x, 4);

Wyświetl plik

@ -20,7 +20,7 @@
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
arduinoFFT FFT;
/*
These values can be changed in order to evaluate the functions
*/
@ -64,21 +64,22 @@ void loop()
}
microseconds += sampling_period_us;
}
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
/* Print the results of the sampling according to time */
Serial.println("Data:");
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:");
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:");
PrintVector(vReal, samples, SCL_INDEX);
Serial.println("Computed Imaginary values:");
PrintVector(vImag, samples, SCL_INDEX);
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
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.
while(1); /* Run Once */
// delay(2000); /* Repeat after delay */

Wyświetl plik

@ -31,7 +31,7 @@
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
arduinoFFT FFT;
/*
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*/
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.Compute(vReal, vImag, samples, FFT_FORWARD); /* Compute FFT */
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
FFT = arduinoFFT(vReal, vImag, samples, samplingFrequency); /* Create FFT object */
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
PrintVector(vReal, samples>>1, SCL_PLOT);
double x = FFT.MajorPeak(vReal, samples, samplingFrequency);
double x = FFT.MajorPeak();
while(1); /* Run Once */
// delay(2000); /* Repeat after delay */
}

Wyświetl plik

@ -31,7 +31,7 @@
#include "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
arduinoFFT FFT;
/*
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*/
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 */
Serial.println("Data:");
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:");
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:");
PrintVector(vReal, samples, SCL_INDEX);
Serial.println("Computed Imaginary values:");
PrintVector(vImag, samples, SCL_INDEX);
FFT.ComplexToMagnitude(vReal, vImag, samples); /* Compute magnitudes */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
double x;
double v;
FFT.MajorPeak(vReal, samples, samplingFrequency, &x, &v);
FFT.MajorPeak(&x, &v);
Serial.print(x, 6);
Serial.print(", ");
Serial.println(v, 6);