Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb33149
Remove deprecated functions, templatize, Speedup
Feb 19, 2020
08e9288
Fix example FFT_02
Feb 19, 2020
49bc726
Add windowing compensation factors
Feb 19, 2020
6df8d2d
Add missing include if compiled from Visual Studio Code + Arduino Ext…
Feb 20, 2020
3e73c98
Use better sqrtf approximation (precise, no divisions)
Feb 22, 2020
4a36bd2
Add setArrays() function because of issue #32. Add API migration info…
Feb 22, 2020
35ea7e2
Fix README anchor
Feb 22, 2020
0a9cd2b
Fix compile error on Arduino due to small_type
Jul 1, 2020
5eaad08
Merge pull request #50 from HorstBaerbel/master
kosme Jul 2, 2020
7b107cf
Fixed compilation with -Wextra
drzony Nov 6, 2020
3fce8ac
Reordered variables in class to fix -Werror=reorder
blaz-r Sep 13, 2021
e7357cc
Merge pull request #59 from drzony/reordering-fix
kosme Nov 27, 2021
5f622f7
Merge branch 'develop' into develop
kosme Nov 27, 2021
bd164d1
Merge pull request #68 from blaz-r/develop
kosme Nov 27, 2021
11b1571
Correctly detect ESP32 boards
kosme Sep 26, 2022
8c925a7
Correctly detect ESP32 boards
kosme Sep 26, 2022
0565c88
Merge branch 'develop' of github.com:kosme/arduinoFFT into develop
kosme Sep 26, 2022
3a637a1
Merge branch 'develop' of github.com:kosme/arduinoFFT into develop
kosme Sep 26, 2022
32723c6
Merge branch 'develop' of github.com:kosme/arduinoFFT into develop
kosme Sep 26, 2022
81d62e1
Delete arduinoFFT.cpp
kosme Sep 26, 2022
e5e4c74
Delete lookup-table.ods
kosme Sep 26, 2022
5c652cd
Make the sqrt_internal macro customisable
FintasticMan Apr 3, 2023
419d7b0
Merge pull request #83 from FintasticMan/customisable_sqrt
kosme May 26, 2023
a9f64fb
Version 2.0
kosme Mar 6, 2024
909240f
Merge branch 'develop' into master
kosme Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Examples/FFT_01/FFT_01.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*

Example of use of the FFT library
Copyright (C) 2014 Enrique Condes
Example of use of the FFT libray

Copyright (C) 2014 Enrique Condes
Copyright (C) 2020 Bim Overbohm (template, speed improvements)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,21 +32,24 @@

#include "arduinoFFT.h"

arduinoFFT FFT;
/*
These values can be changed in order to evaluate the functions
*/
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
const double signalFrequency = 1000;
const double samplingFrequency = 5000;
const uint8_t amplitude = 100;

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double vReal[samples];
double vImag[samples];

/* Create FFT object */
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
Expand All @@ -67,23 +72,21 @@ void loop()
//vReal[i] = uint8_t((amplitude * (sin(i * ratio) + 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(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward); /* Weigh data */
Serial.println("Weighed data:");
PrintVector(vReal, samples, SCL_TIME);
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.compute(FFTDirection::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(); /* Compute magnitudes */
FFT.complexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
double x = FFT.MajorPeak();
double x = FFT.majorPeak();
Serial.println(x, 6);
while(1); /* Run Once */
// delay(2000); /* Repeat after delay */
Expand Down
32 changes: 17 additions & 15 deletions Examples/FFT_02/FFT_02.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*

Example of use of the FFT library to compute FFT for several signals over a range of frequencies.
The exponent is calculated once before the execution since it is a constant.
This saves resources during the execution of the sketch and reduces the compiled size.
The sketch shows the time that the computation takes.
Copyright (C) 2014 Enrique Condes
Example of use of the FFT libray to compute FFT for several signals over a range of frequencies.
The exponent is calculated once before the excecution since it is a constant.
This saves resources during the excecution of the sketch and reduces the compiled size.
The sketch shows the time that the computing is taking.

Copyright (C) 2014 Enrique Condes
Copyright (C) 2020 Bim Overbohm (template, speed improvements)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -23,11 +25,9 @@

#include "arduinoFFT.h"

arduinoFFT FFT;
/*
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;
Expand All @@ -42,7 +42,10 @@ Input vectors receive computed results from FFT
double vReal[samples];
double vImag[samples];

unsigned long time;
/* Create FFT object */
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, sampling);

unsigned long startTime;

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
Expand Down Expand Up @@ -71,25 +74,24 @@ void loop()
}
/*Serial.println("Data:");
PrintVector(vReal, samples, SCL_TIME);*/
time=millis();
FFT = arduinoFFT(vReal, vImag, samples, sampling); /* Create FFT object */
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
startTime=millis();
FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward); /* Weigh data */
/*Serial.println("Weighed data:");
PrintVector(vReal, samples, SCL_TIME);*/
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.compute(FFTDirection::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(); /* Compute magnitudes */
FFT.complexToMagnitude(); /* Compute magnitudes */
/*Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);*/
double x = FFT.MajorPeak();
double x = FFT.majorPeak();
Serial.print(frequency);
Serial.print(": \t\t");
Serial.print(x, 4);
Serial.print("\t\t");
Serial.print(millis()-time);
Serial.print(millis()-startTime);
Serial.println(" ms");
// delay(2000); /* Repeat after delay */
}
Expand Down
20 changes: 11 additions & 9 deletions Examples/FFT_03/FFT_03.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*

Example of use of the FFT library to compute FFT for a signal sampled through the ADC.
Copyright (C) 2018 Enrique Condés and Ragnar Ranøyen Homb
Example of use of the FFT libray to compute FFT for a signal sampled through the ADC.

Copyright (C) 2018 Enrique Condés and Ragnar Ranøyen Homb
Copyright (C) 2020 Bim Overbohm (template, speed improvements)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,14 +22,12 @@

#include "arduinoFFT.h"

arduinoFFT FFT;
/*
These values can be changed in order to evaluate the functions
*/
#define CHANNEL A0
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
const double samplingFrequency = 100; //Hz, must be less than 10000 due to ADC

unsigned int sampling_period_us;
unsigned long microseconds;

Expand All @@ -38,6 +38,9 @@ Input vectors receive computed results from FFT
double vReal[samples];
double vImag[samples];

/* Create FFT object */
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
Expand All @@ -64,22 +67,21 @@ 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(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward); /* Weigh data */
Serial.println("Weighed data:");
PrintVector(vReal, samples, SCL_TIME);
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.compute(FFTDirection::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(); /* Compute magnitudes */
FFT.complexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
double x = FFT.MajorPeak();
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 */
Expand Down
19 changes: 11 additions & 8 deletions Examples/FFT_04/FFT_04.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*

Example of use of the FFT library
Copyright (C) 2018 Enrique Condes
Example of use of the FFT libray

Copyright (C) 2018 Enrique Condes
Copyright (C) 2020 Bim Overbohm (template, speed improvements)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,21 +33,23 @@

#include "arduinoFFT.h"

arduinoFFT FFT;
/*
These values can be changed in order to evaluate the functions
*/
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
const double signalFrequency = 1000;
const double samplingFrequency = 5000;
const uint8_t amplitude = 100;

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double vReal[samples];
double vImag[samples];

ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
Expand All @@ -68,12 +72,11 @@ void loop()
//vReal[i] = uint8_t((amplitude * (sin(i * ratio) + 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 */
FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.ComplexToMagnitude(); /* Compute magnitudes */
FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward); /* Weigh data */
FFT.compute(FFTDirection::Forward); /* Compute FFT */
FFT.complexToMagnitude(); /* Compute magnitudes */
PrintVector(vReal, samples>>1, SCL_PLOT);
double x = FFT.MajorPeak();
double x = FFT.majorPeak();
while(1); /* Run Once */
// delay(2000); /* Repeat after delay */
}
Expand Down
20 changes: 12 additions & 8 deletions Examples/FFT_05/FFT_05.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*

Example of use of the FFT library
Copyright (C) 2014 Enrique Condes
Example of use of the FFT libray

Copyright (C) 2014 Enrique Condes
Copyright (C) 2020 Bim Overbohm (template, speed improvements)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,21 +33,24 @@

#include "arduinoFFT.h"

arduinoFFT FFT;
/*
These values can be changed in order to evaluate the functions
*/
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
const double signalFrequency = 1000;
const double samplingFrequency = 5000;
const uint8_t amplitude = 100;

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double vReal[samples];
double vImag[samples];

/* Create FFT object */
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02
Expand All @@ -68,24 +73,23 @@ void loop()
//vReal[i] = uint8_t((amplitude * (sin(i * ratio) + 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(FFT_WIN_TYP_HAMMING, FFT_FORWARD); /* Weigh data */
FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward); /* Weigh data */
Serial.println("Weighed data:");
PrintVector(vReal, samples, SCL_TIME);
FFT.Compute(FFT_FORWARD); /* Compute FFT */
FFT.compute(FFTDirection::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(); /* Compute magnitudes */
FFT.complexToMagnitude(); /* Compute magnitudes */
Serial.println("Computed magnitudes:");
PrintVector(vReal, (samples >> 1), SCL_FREQUENCY);
double x;
double v;
FFT.MajorPeak(&x, &v);
FFT.majorPeak(&x, &v);
Serial.print(x, 6);
Serial.print(", ");
Serial.println(v, 6);
Expand Down
Loading