diff --git a/analyze_fft256_iq_F32.cpp b/analyze_fft256_iq_F32.cpp index 526fdbb..6dbf954 100644 --- a/analyze_fft256_iq_F32.cpp +++ b/analyze_fft256_iq_F32.cpp @@ -132,15 +132,20 @@ void AudioAnalyzeFFT256_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])-42.1442f; // Scaled to FS sine wave + + else if(outputType==FFT_DBFS) { + if(sumsq[i]>0.0f) + output[i] = 10.0f*log10f(inAf*sumsq[ii]) - 42.144f; // Scaled to FS sine wave + else + output[i] = -193.0f; // lsb for 23 bit mantissa + } else output[i] = 0.0f; - } - } - outputflag = true; + } // End, set output[i] over all 512 + outputflag = true; // moved; rev10mar2021 + } // End of average is finished release(prevblock_i); // Release the 2 blocks that were block_i release(prevblock_q); // and block_q on last time through update() prevblock_i = block_i; // We will use these 2 blocks on next update() prevblock_q = block_q; // Just change pointers -} + } diff --git a/analyze_fft256_iq_F32.h b/analyze_fft256_iq_F32.h index 47986e4..23f49ea 100644 --- a/analyze_fft256_iq_F32.h +++ b/analyze_fft256_iq_F32.h @@ -1,7 +1,8 @@ /* analyze_fft256_iq_F32.h Assembled by Bob Larkin 6 Mar 2021 * * Rev 6 Mar 2021 - Added setXAxis() - * Rev 7 Mar 2021 - Corrected bug in applying windowing + * Rev 7 Mar 2021 - Corrected bug in applying windowing + * Rev 10 Mar 2021 - Corrrected: dBFS offset (up 12 dB) & xAxis for dBFS * * Does Fast Fourier Transform of a 256 point complex (I-Q) input. * Output is one of three measures of the power in each of the 256 @@ -17,6 +18,7 @@ * * Windowing None, Hann, Kaiser and Blackman-Harris. * * Multiple bin-sum output to simulate wider bins. * * Power averaging of multiple FFT + * * Programmable frequency scale arrangement. * * Soon: F32 audio outputs for I & Q * * Conversion Copyright (c) 2021 Bob Larkin @@ -76,11 +78,10 @@ * If there is 180 degree phase shift to I or Q these all get reversed. * * Timing, max is longest update() time: - * T3.6 Windowed, RMS out, - uSec max - * T3.6 Windowed, Power Out, - uSec max - * T3.6 Windowed, dBFS out, - uSec max - * No Window saves 60 uSec on T3.6 for any output. - * T4.0 Windowed, RMS Out, - uSec + * T3.6 Windowed, Power Out, 285 uSec max + * T3.6 Windowed, dBFS out, 590 uSec max + * T3.6 No Window saves 28 uSec for any output. + * T4.0 Windowed, dBFS Out, 120 uSec * * Scaling: * Full scale for floating point DSP is a nebulous concept. Normally the diff --git a/examples/TestFFT256iq/TestFFT256iq.ino b/examples/TestFFT256iq/TestFFT256iq.ino index 2454014..88c11d2 100644 --- a/examples/TestFFT256iq/TestFFT256iq.ino +++ b/examples/TestFFT256iq/TestFFT256iq.ino @@ -18,14 +18,13 @@ AudioConnection_F32 patchCord2(sine_cos1, 1, FFT256iq1, 1); // GUItool: end automatically generated code void setup(void) { - float* pPwr; - Serial.begin(9600); delay(1000); AudioMemory_F32(20); - Serial.println("FFT256IQ Test v2"); + Serial.println("FFT256IQ Test v3"); sine_cos1.amplitude(1.0); // Initialize Waveform Generator + // bin spacing = 44117.648/256 = 172.335 172.3 * 4 = 689.335 Hz (T3.6) // Half bin higher is 775.3 for testing windows //sine_cos1.frequency(689.34f); @@ -39,7 +38,7 @@ void setup(void) { // or pick any old frequency sine_cos1.frequency(7100.0); - // elect the output format + // Select the output format: FFT_RMS, FFFT_POWER, FFT_DBFS FFT256iq1.setOutputType(FFT_DBFS); // Select the wndow function @@ -55,14 +54,12 @@ void setup(void) { // xAxis, bit 0 left/right; bit 1 low to high; default 0X03 FFT256iq1.setXAxis(0X03); - FFT256iq1.windowFunction(AudioWindowBlackmanHarris256); - //float* pw = FFT256iq1.getWindow(); // Print window - //for (int i=0; i<256; i++) Serial.println(pw[i], 4); - // Do power averaging (outputs appear less often, as well) - FFT256iq1.setNAverage(5); // nAverage >= 1 + FFT256iq1.setNAverage(1); // i.e., 16 or 50, etc. nAverage >= 1 + } - delay(1000); +void loop(void) { + float* pPwr; if( FFT256iq1.available() ) { pPwr = FFT256iq1.getData(); for(int i=0; i<256; i++) { @@ -72,7 +69,5 @@ void setup(void) { } Serial.print("\n\n"); } - } - -void loop(void) { + delay(500); }