Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

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

  1. #1

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

    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 by ahinduja; 04-13-2020 at 09:16 PM. Reason: Added some more result information.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,424
    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

  3. #3
    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

  4. #4
    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!

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,424
    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

  6. #6
    Great, thanks Pete!

    -Akshay

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,575
    careful, others have had problems with T4 and that microphone when using teenyduino 1.52-beta2, see
    https://forum.pjrc.com/threads/60408...I2S-Microphone
    or https://forum.pjrc.com/threads/60354...l=1#post235163
    Last edited by manitou; 04-15-2020 at 11:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •