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

Thread: FFT of Mic input results in all 0's

  1. #1
    Junior Member
    Join Date
    Nov 2022
    Posts
    4

    FFT of Mic input results in all 0's

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    AudioSynthWaveformSine sine1;
    AudioOutputI2S i2s1;
    AudioInputAnalog adc1;
    AudioAnalyzeFFT1024 fft;
    AudioConnection patchCord1(fft, adc1);
    AudioConnection patchCord2(sine1, i2s1);
    AudioControlSGTL5000 audioShield;
    const int freq_range = 32768;
    const int bins = 1024;
    const int bin_width = freq_range/bins;
    double mag[bins];
    void setup() {
    // put your setup code here, to run once:;
    analogReadResolution(12);
    AudioMemory(40);
    audioShield.enable();
    audioShield.inputSelect(AUDIO_INPUT_MIC);;
    audioShield.micGain(63);
    audioShield.volume(2);
    fft.windowFunction(AudioWindowHanning1024);
    Serial.begin(9600);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    for(int i=0; i<(bins/2); i++)
    {
    mag[i]=fft.read(i);
    Serial.println(mag[i], 1);
    }
    sine1.frequency(500);
    sine1.amplitude(0.95);
    delay(1000);
    }



    I am playing a sine wave with a 500Hz frequency, and that is working but the input settings for the microphone seem to be wrong. I am using a Teensy 4.1 with audio board revision D. The speaker is connected via an amplifier to the 3.5mm jack and the mic is soldered to the mic and gnd labeled holes. I have also tried to set the mic up the same way as the speaker with i2s2 instead of adc1. Looked for the last couple hours through the Audio Projects listed to see their setups but wasn't able to get a working reading. Probably something stupid on my end

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,900
    You have to wait for there to be a result from the fft before reading it. The delay is probably going to cause trouble too.
    Put these two in setup()
    Code:
      sine1.frequency(500);
      sine1.amplitude(0.95);
    and change the loop function to this:

    Code:
    void loop(void)
    {
      if(fft.available() > 0) {
        for(int i=0; i<(bins/2); i++) {
          mag[i]=fft.read(i);
          Serial.println(mag[i], 1);
        }
      }
      //sine1.frequency(500);
      //sine1.amplitude(0.95);
      //delay(1000);
    }
    Pete

  3. #3
    Junior Member
    Join Date
    Nov 2022
    Posts
    4
    Still getting the tone but the fft never becomes available, I feel like i must have messed up something in the sections above the loop function where the audio is configured. I have tested the microphone with my line-in on my computer's motherboard and was able to listen back to it, although the output was quiet. Could the signal be too small?

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,900
    Code:
    AudioConnection patchCord1(fft, adc1);
    This isn't right. You are trying to send the FFT to the ADC. You should be sending the audio to the FFT.
    Change patchcord2 to send the sine to the fft:
    Code:
    AudioConnection patchCord2(sine1, 0, fft, 0);
    [EDIT] and remove patchCord1

    Pete

  5. #5
    Junior Member
    Join Date
    Nov 2022
    Posts
    4
    Shouldn't I be sending the microphone to the fft? With The audio connection
    Code:
    AudioConnection patchCord2(sine1, 0, fft, 0);
    it skipped the speaker and mic. I think the issue is in which input is the mic, I think I've tried them all, but who knows. I just saw a picture labeling the I2S input L/R solder points, so I could try rewiring it there, but there must be a way to address the MIC solder point.

    Wired to I2S solder points mentioned and got zeroes still.
    Current Setup:
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    AudioSynthWaveformSine   sine5; //xy=55,609
    AudioSynthWaveformSine   sine3; //xy=59,527
    AudioSynthWaveformSine   sine4; //xy=59,566
    AudioSynthWaveformSine   sine6; //xy=61,660
    AudioSynthWaveformSine   sine7; //xy=62,706
    AudioSynthWaveformSine   sine8; //xy=64,756
    AudioSynthWaveformSine   sine2;          //xy=66,489.0000066757202
    AudioSynthWaveformSine   sine1;          //xy=67,438.0000047683716
    AudioMixer4              mixer2; //xy=199.00000190734863,579.0000076293945
    AudioMixer4              mixer1;         //xy=200,502
    AudioInputI2S            i2s1;           //xy=421.42857360839844,318.5714225769043
    AudioOutputI2S           i2s2;           //xy=422.85714285714283,532.8571428571428
    AudioAnalyzeFFT1024      fft;      //xy=577,303
    AudioConnection          patchCord1(sine5, 0, mixer2, 0);
    AudioConnection          patchCord2(sine3, 0, mixer1, 2);
    AudioConnection          patchCord3(sine4, 0, mixer1, 3);
    AudioConnection          patchCord4(sine6, 0, mixer2, 1);
    AudioConnection          patchCord5(sine7, 0, mixer2, 2);
    AudioConnection          patchCord6(sine8, 0, mixer2, 3);
    AudioConnection          patchCord7(sine2, 0, mixer1, 1);
    AudioConnection          patchCord8(sine1, 0, mixer1, 0);
    AudioConnection          patchCord9(mixer2, 0, i2s2, 1);
    AudioConnection          patchCord10(mixer1, 0, i2s2, 0);
    AudioConnection          patchCord11(i2s1, 0, fft, 0);
    AudioControlSGTL5000     audioShield;
    const int freq_range = 32768;
    const int bins = 1024; 
    const int bin_width = freq_range/bins; 
    double mag[bins];
    void setup() {
      // put your setup code here, to run once:;
      analogReadResolution(12);
      AudioMemory(40);
      audioShield.enable();
      audioShield.inputSelect(AUDIO_INPUT_MIC);;
      audioShield.micGain(63);
      audioShield.volume(2);
      fft.windowFunction(AudioWindowHanning1024);
      Serial.begin(9600);
      mixer1.gain(0, 1);
      mixer1.gain(1, 1);
      mixer1.gain(2, 1);
      mixer1.gain(3, 1);
      mixer2.gain(0, 1);
      mixer2.gain(1, 1);
      mixer2.gain(2, 1);
      mixer2.gain(3, 1);
      sine1.frequency(500);
      sine1.amplitude(0.95);
      sine5.frequency(500);
      sine5.amplitude(0.95);
    }
    void loop() {
      // put your main code here, to run repeatedly:
      if(fft.available())
      {
        for(int i=0; i<(bins/2); i++) {
          mag[i]=fft.read(i);
          Serial.println(mag[i], 1);
        }
      }
    }
    Last edited by ClassyBoots; 11-03-2022 at 04:04 PM.

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,900
    Sending the sine output to the fft would help debug things. Get that to produce good output from the FFT first.
    But your code in #5 should work with the mic.
    What kind of microphone are you using and post a photo of your audio board showing how the mic is connected.

    Pete

  7. #7
    Junior Member
    Join Date
    Nov 2022
    Posts
    4
    Appreciate the help. Yes the sine connected to the FFT did give an output. When i tried to move back to the mic it was back to nothing.

    https://drive.google.com/drive/folde...bL?usp=sharing
    Heres a drive link to a folder containing 3 photos.

    One is the XLR output of the mic soldered to the speaker wire that is connected to the audio board. Pins 1 and 3 are to the black wire and pin 2 is to the red wire.

    Next is the audio board. The black wire mentioned previously is soldered to the GND point where the MIC point is. I cut the red wire from the MIC point and soldered it to point L of Line-In.

    Finally, I have a photo of the AT2020 Mic i am using as well as the phantom power injector. I know this section is working as i can plug it into my computer from the phantom power injector and get a signal, although it is quiet when played back on my headphones.

  8. #8
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,900
    I'm not familiar (nor competent) to advise about hooking up condenser mic to the audio board but the board was designed for connection of an electret mic. See MarkT's comment here.

    Pete

Posting Permissions

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