From b0e4c69bcb0d024e2923f69b3fc29b3e03184ae6 Mon Sep 17 00:00:00 2001 From: Enrique Condes Date: Tue, 25 Jul 2023 23:39:34 +0800 Subject: [PATCH] Fix issue 84 --- Examples/FFT_02/FFT_02.ino | 2 +- library.json | 2 +- library.properties | 2 +- src/arduinoFFT.cpp | 12 +++++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Examples/FFT_02/FFT_02.ino b/Examples/FFT_02/FFT_02.ino index 367814d..c71e588 100644 --- a/Examples/FFT_02/FFT_02.ino +++ b/Examples/FFT_02/FFT_02.ino @@ -3,7 +3,7 @@ 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 computing is taking. + The sketch shows the time that the computation takes. Copyright (C) 2014 Enrique Condes This program is free software: you can redistribute it and/or modify diff --git a/library.json b/library.json index eae9358..23366bd 100644 --- a/library.json +++ b/library.json @@ -20,7 +20,7 @@ "email": "contact@arduinoos.com" } ], - "version": "1.6", + "version": "1.6.1", "frameworks": ["arduino","mbed","espidf"], "platforms": "*", "headers": "arduinoFFT.h" diff --git a/library.properties b/library.properties index ee5f5ec..712867e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=arduinoFFT -version=1.6 +version=1.6.1 author=Enrique Condes maintainer=Enrique Condes sentence=A library for implementing floating point Fast Fourier Transform calculations on Arduino. diff --git a/src/arduinoFFT.cpp b/src/arduinoFFT.cpp index 15ab81f..417cd27 100644 --- a/src/arduinoFFT.cpp +++ b/src/arduinoFFT.cpp @@ -103,9 +103,10 @@ void arduinoFFT::Compute(FFTDirection dir) { } // Scaling for reverse transform / if (dir != FFT_FORWARD) { + double reciprocal = 1.0 / this->_samples; for (uint16_t i = 0; i < this->_samples; i++) { - this->_vReal[i] /= this->_samples; - this->_vImag[i] /= this->_samples; + this->_vReal[i] *= reciprocal; + this->_vImag[i] *= reciprocal; } } } @@ -169,9 +170,10 @@ void arduinoFFT::Compute(double *vReal, double *vImag, uint16_t samples, } // Scaling for reverse transform if (dir != FFT_FORWARD) { + double reciprocal = 1.0 / samples; for (uint16_t i = 0; i < samples; i++) { - vReal[i] /= samples; - vImag[i] /= samples; + vReal[i] *= reciprocal; + vImag[i] *= reciprocal; } } } @@ -535,7 +537,7 @@ uint8_t arduinoFFT::Exponent(uint16_t value) { #warning("This method may not be accessible on future revisions.") // Calculates the base 2 logarithm of a value uint8_t result = 0; - while (((value >> result) & 1) != 1) + while (value >>= 1) result++; return (result); }