Skip to content

Commit

Permalink
Merge pull request #88 from kosme/v1.6.2
Browse files Browse the repository at this point in the history
Fix bug on synthetic data generation
  • Loading branch information
kosme authored Dec 29, 2023
2 parents b0e4c69 + c7845ab commit bb90780
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Examples/FFT_01/FFT_01.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ void setup()
void loop()
{
/* Build raw data */
double cycles = (((samples-1) * signalFrequency) / samplingFrequency); //Number of signal cycles that the sampling will read
double ratio = twoPi * signalFrequency / samplingFrequency; // Fraction of a complete cycle stored at each sample (in radians)
for (uint16_t i = 0; i < samples; i++)
{
vReal[i] = int8_t((amplitude * (sin((i * (twoPi * cycles)) / samples))) / 2.0);/* Build data with positive and negative 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*/
vReal[i] = int8_t(amplitude * sin(i * ratio) / 2.0);/* Build data with positive and negative values*/
//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
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/FFT_02/FFT_02.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void loop()
for(double frequency = startFrequency; frequency<=stopFrequency; frequency+=step_size)
{
/* Build raw data */
double cycles = (((samples-1) * frequency) / sampling);
double ratio = twoPi * frequency / sampling; // Fraction of a complete cycle stored at each sample (in radians)
for (uint16_t i = 0; i < samples; i++)
{
vReal[i] = int8_t((amplitude * (sin((i * (twoPi * cycles)) / samples))) / 2.0);
vReal[i] = int8_t(amplitude * sin(i * ratio) / 2.0);/* Build data with positive and negative values*/
vImag[i] = 0; //Reset the imaginary values vector for each new frequency
}
/*Serial.println("Data:");
Expand Down
6 changes: 3 additions & 3 deletions Examples/FFT_04/FFT_04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ void setup()
void loop()
{
/* Build raw data */
double cycles = (((samples-1) * signalFrequency) / samplingFrequency); //Number of signal cycles that the sampling will read
double ratio = twoPi * signalFrequency / samplingFrequency; // Fraction of a complete cycle stored at each sample (in radians)
for (uint16_t i = 0; i < samples; i++)
{
vReal[i] = int8_t((amplitude * (sin((i * (twoPi * cycles)) / samples))) / 2.0);/* Build data with positive and negative 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*/
vReal[i] = int8_t(amplitude * sin(i * ratio) / 2.0);/* Build data with positive and negative values*/
//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 */
Expand Down
6 changes: 3 additions & 3 deletions Examples/FFT_05/FFT_05.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ void setup()
void loop()
{
/* Build raw data */
double cycles = (((samples-1) * signalFrequency) / samplingFrequency); //Number of signal cycles that the sampling will read
double ratio = twoPi * signalFrequency / samplingFrequency; // Fraction of a complete cycle stored at each sample (in radians)
for (uint16_t i = 0; i < samples; i++)
{
vReal[i] = int8_t((amplitude * (sin((i * (twoPi * cycles)) / samples))) / 2.0);/* Build data with positive and negative 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*/
vReal[i] = int8_t(amplitude * sin(i * ratio) / 2.0);/* Build data with positive and negative values*/
//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 */
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Destructor
* **!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**(uint8_t dir);
Calcuates the Fast Fourier Transform.
Calculates the Fast Fourier Transform.
* **!DCRemoval**(double *vData, uint16_t samples);
* **DCRemoval**();
Removes the DC component from the sample data.
Expand Down
6 changes: 6 additions & 0 deletions changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
28/12/23 v1.6.2
Fix issue 52 and symplify calculation of synthetic data for examples 1, 2, 4, and 5.

25/07/23 v1.6.1
Code optimization for speed improvements. See issue 84 for more details.

03/09/23 v1.6
Include some functionality from development branch.

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"email": "[email protected]"
}
],
"version": "1.6.1",
"version": "1.6.2",
"frameworks": ["arduino","mbed","espidf"],
"platforms": "*",
"headers": "arduinoFFT.h"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=arduinoFFT
version=1.6.1
version=1.6.2
author=Enrique Condes <[email protected]>
maintainer=Enrique Condes <[email protected]>
sentence=A library for implementing floating point Fast Fourier Transform calculations on Arduino.
Expand Down
2 changes: 1 addition & 1 deletion src/arduinoFFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void arduinoFFT::Windowing(FFTWindow windowType, FFTDirection dir) {
void arduinoFFT::Windowing(double *vData, uint16_t samples,
FFTWindow windowType, FFTDirection dir) {
// Weighing factors are computed once before multiple use of FFT
// The weighing function is symetric; half the weighs are recorded
// The weighing function is symmetric; half the weighs are recorded
#warning("This method is deprecated and may be removed on future revisions.")
double samplesMinusOne = (double(samples) - 1.0);
for (uint16_t i = 0; i < (samples >> 1); i++) {
Expand Down

0 comments on commit bb90780

Please sign in to comment.