diff --git a/analyze_fft1024_iq_F32.cpp b/analyze_fft1024_iq_F32.cpp index 10346cc..10b76e2 100644 --- a/analyze_fft1024_iq_F32.cpp +++ b/analyze_fft1024_iq_F32.cpp @@ -1,6 +1,7 @@ /* * analyze_fft1024_iq_F32.cpp Assembled by Bob Larkin 3 Mar 2021 * Rev 6 Mar 2021 - Added setXAxis() + * Rev 10 Mar 2021 Corrected averaging bracket - Bob L * * Converted to F32 floating point input and also extended * for complex I and Q inputs @@ -144,6 +145,7 @@ void AudioAnalyzeFFT1024_IQ_F32::update(void) { sumsq[i] += ss1; } } + if (count >= nAverage) { // Average is finished count = 0; float inAf = 1.0f/(float)nAverage; @@ -160,13 +162,17 @@ void AudioAnalyzeFFT1024_IQ_F32::update(void) { output[i] = sqrtf(inAf*sumsq[ii]); else if(outputType==FFT_POWER) output[i] = inAf*sumsq[ii]; - else if(outputType==FFT_DBFS) - output[i] = 10.0f*log10f(inAf*sumsq[ii])-54.1854f; // Scaled to FS sine wave + else if(outputType==FFT_DBFS) { + if(sumsq[i]>0.0f) + output[i] = 10.0f*log10f(inAf*sumsq[ii])-54.1854f; // Scaled to FS sine wave + else + output[i] = -193.0f; // lsb for 23 bit mantissa + } else output[i] = 0.0f; - } - } // end of Average is Finished - outputflag = true; + } // End, set output[i] over all 512 + outputflag = true; // moved; rev10mar2021 + } // End of average is finished release(blocklist_i[0]); release(blocklist_q[0]); release(blocklist_i[1]); release(blocklist_q[1]); diff --git a/analyze_fft1024_iq_F32.h b/analyze_fft1024_iq_F32.h index 392f641..992e33d 100644 --- a/analyze_fft1024_iq_F32.h +++ b/analyze_fft1024_iq_F32.h @@ -2,6 +2,8 @@ * Analyze_fft1024_iq_F32.h Assembled by Bob Larkin 3 Mar 2021 * * Rev 6 Mar 2021 - Added setXAxis() + * Rev 11 Mar 2021 - Fixed xAxis correction for dBFS output + * * Does Fast Fourier Transform of a 1024 point complex (I-Q) input. * Output is one of three measures of the power in each of the 1024 * output bins, Power, RMS level or dB relative to a full scale diff --git a/examples/TestFFT1024iq/TestFFT1024iq.ino b/examples/TestFFT1024iq/TestFFT1024iq.ino index 9ca422f..7d43423 100644 --- a/examples/TestFFT1024iq/TestFFT1024iq.ino +++ b/examples/TestFFT1024iq/TestFFT1024iq.ino @@ -51,8 +51,10 @@ void setup(void) { //float* pw = FFT1024iq1.getWindow(); // Print window //for (int i=0; i<512; i++) Serial.println(pw[i], 4); + FFT1024iq1.setNAverage(4); + // xAxis, bit 0 left/right; bit 1 low to high; default 0X03 - FFT1024iq1.setXAxis(0X03); + FFT1024iq1.setXAxis(0X02); delay(1000); // Print output, once