Can't get FFT1024 to work with Teensy 4.0 and SPH0645 I2S Mic

Status
Not open for further replies.

ahinduja

Member
Hello!

I am trying out an audio project which would require me to listen to a fixed frequency pulse which my microphone would hear and record the time of hearing. For this I am using the Teensy 4 + the SPH0645 I2S microphone (No audio shield). I have had success in using the peak and rms analyzers and the microphone seems to work fine. However when I try to use the FFT module in the audio library it fails. The connecting pins remain constant for the three (peak, rms, fft). Would be glad to get some help on this! Here is my source code which is based on the FFT example with the audio shield. The only output I get is the "failed" print I have inserted. If I remove the if statements and just print the read() value for all bins, I get 0.00 for everything. The same result for the FF256.

Code:
/*
 SD -> pin 8 (in1)/pin 5 (in2)
 L/R -> GND/VCC (left/right channel)
 WS -> pin 20 (LRCLK1)/pin 3 (LRCLK2)
 SCK -> pin21 (BCLK1)/pin 4 (BCLK2)
 */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=500,322
AudioAnalyzeFFT1024      fft1024_1;      //xy=701,316
AudioConnection          patchCord1(i2s1, 0, fft1024_1, 0);
// GUItool: end automatically generated code


void setup() {
  //Serial.begin(9600);
  AudioMemory(70);

fft1024_1.windowFunction(AudioWindowHanning1024);
  
}


void loop() {

float n;
  int i;

  if (fft1024_1.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (i=0; i<40; i++) {
      n = fft1024_1.read(i);
      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00"
      }
    }
    Serial.println();
  }
  else
  {
   Serial.println("failed");
  }



}
 
Last edited:
Your code prints the FFT: information once each time there's a new FFT result. But the rest of the time it is printing "failed" as fast as it can, which on a T4 and at USB speeds is a lot of lines.
Comment the statement which prints "failed". Does it print anything now?

Pete
 
Hi Pete,

Yes if I remove the "failed" print I do get some low values for the first two bins. I tried a sweeping sine wave to see the response in other bins but nothing turns up just the "-" for them based on else statement (I kept the speaker close to the microphone, so it should have been sufficient in magnitude). If I snap my fingers I do see a few bins in the slightly higher ranges pick it up, but no response from the sweep.

I'd like to try using a constant frequency tone instead to see if that works, but for that I need to know which bin corresponds to which frequency. I was wondering whats the sampling rate here (Is it 44.1khz?) and if I can control it to limit the bins to the frequencies I am interested in to save on computation time. Could you direct me towards something which might help? Thanks!

-Akshay
 
I tried again and now I do get a response for the higher bins. Its more easy to see the change in the serial plotter, than monitor. I'd still like to know about the sampling rate and if it can be changed!
 
The sampling rate is 44.1kHz. It can be changed but not all library functions will work with a different rate.
The function you need is setI2SFreq which is in this message

Pete
 
Status
Not open for further replies.
Back
Top