#if 0 #include "Arduino.h" #include "AudioStream_F32.h" #include "arm_math.h" #include "mathDSP_F32.h" #if defined(__IMXRT1062__) #include "arm_const_structs.h" #endif #define NFFT 1024 #define NFFT_D2 NFFT/2 #define FFT_PI 3.14159265359f #define PI2 2.0f*FFT_PI void setup(void) { float x[NFFT]; // Real DFT input float Xre[NFFT], Xim[NFFT]; // DFT of x float P[NFFT]; // power spectrum of x float kf, nf; float fft_buffer[2*NFFT]; // 2 is fo CMSIS FFT float sinN[NFFT_D2]; float cosN[NFFT_D2]; uint32_t tt; // Instantiate FFT, T4.x ONLY arm_cfft_instance_f32 Sfft; Sfft = arm_cfft_sR_f32_len1024; // Instantiate FFT, T4.x ONLY arm_cfft_instance_f32 Sfft_128; Sfft_128 = arm_cfft_sR_f32_len512; Serial.begin(300); // Any speed works delay(1000); // Factors for using half size complex FFT for(int n=0; n #include "OpenAudio_ArduinoLibrary.h" // Create the Audio components. These should be created in the // order data flows, inputs/sources -> processing -> outputs // // AudioInputI2S_F32 audioInput; // audio shield: mic or line-in AudioSynthSineCosine_F32 sinewave; AudioAnalyzeFFT1024_F32 myFFT; AudioOutputI2S_F32 audioOutput; // audio shield: headphones & line-out NU // Connect either the live input or synthesized sine wave // AudioConnection_F32 patchCord1(audioInput, 0, myFFT, 0); AudioConnection_F32 patchCord1(sinewave, 0, myFFT, 0); AudioControlSGTL5000 audioShield; float xxx[1024]; uint32_t ct = 0; uint32_t count = 0; void setup() { Serial.begin(300); // Any speed works delay(1000); AudioMemory_F32(20); // Enable the audio shield and set the output volume. audioShield.enable(); audioShield.inputSelect(AUDIO_INPUT_LINEIN); // Create a synthetic sine wave, for testing // To use this, edit the connections above // sinewave.frequency(1033.99f); // Bin 24 T3.x // sinewave.frequency(1033.59375f); // Bin 24 T4.x at 44100 // sinewave.frequency(1055.0f); // Bin 24.5, demonstrates windowing // Or some random frequency: sinewave.frequency(1234.5f); sinewave.amplitude(1.0f); // Set windowing function // myFFT.windowFunction(AudioWindowNone); // myFFT.windowFunction(AudioWindowHanning1024); // default // The next Kaiser window needs a dB peak sidelobe number // myFFT.windowFunction(AudioWindowKaiser1024, 70.0f); myFFT.windowFunction(AudioWindowBlackmanHarris1024); // To print the window function: // float* pw=myFFT.getWindow(); // for(int jj=0; jj<1024; jj++) // Serial.println(*pw++, 6); myFFT.setNAverage(1); myFFT.setOutputType(FFT_DBFS); // FFT_RMS or FFT_POWER or FFT_DBFS } void loop() { if (myFFT.available() /*&& ++ct == 4*/ ) { // each time new FFT data is available // print it all to the Arduino Serial Monitor float* pin = myFFT.getData(); for (int gg=0; gg<512; gg++) xxx[gg]= *(pin + gg); for (int i=0; i<512; i++) { Serial.print(i); Serial.print(", "); Serial.println(xxx[i], 8); } Serial.println(); } /* if(count++<200) { Serial.print("CPU: Max Percent Usage: "); Serial.println(AudioProcessorUsageMax()); Serial.print(" Max Float 32 Memory: "); Serial.println(AudioMemoryUsageMax_F32()); } */ }