Noise with mic-in and notefreq

Status
Not open for further replies.

AdaZus

Member
Hi,
proud to be now also part of this forum. :)

And of course I have an issue I don`t know how to solve :/
I want to use the YIN frequency detection “notefreq” for my project.
The problem is that “notefreq” spits out a noise frequency of 83Hz (at CPU speed 48Mhz) even if it`s completely silence.

But let`s recapitulate...

My equipment:
Hardware
Teensy 3.2
Audioboard
Microphone
Software:
arduino-1.6.11-windows.exe
TeensyduinoInstall_1.30.exe

Firstly I have test “notefreq” algorithm which a lot of recordings. I transformed my wav files with wav2sketch and include it to the example NoteFrequency:
File > Examples > Audio > Analysis > NoteFrequency

It works fine.

Next step was to test the mic... video tutorial and documentation helped me:
https://www.youtube.com/watch?v=wqt55OAabVs
See Part 2-4: Using the Microphone
https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf
Code:
// Advanced Microcontroller-based Audio Workshop
//
// https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 2-4: Using The Microphone
///////////////////////////////////
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           //xy=64,105
AudioOutputI2S           i2s3;           //xy=301,212
AudioConnection          patchCord1(i2s2, 0, i2s3, 0);
AudioConnection          patchCord2(i2s2, 0, i2s3, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=203,275
// GUItool: end automatically generated code

///////////////////////////////////
void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(30);
  delay(1000);
}

void loop() {
  // do nothing
}
Also until this point everything ok. Mic and output to my stereo works fine!
Next step:
Design of note frequency detection via mic.
Note_Freq_mic1.JPG
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=246,135
AudioAnalyzeNoteFrequency notefreq1;      //xy=623,182
AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
// GUItool: end automatically generated code

void setup() {
    AudioMemory(30);
    /*
     *  Initialize the yin algorithm's absolute
     *  threshold, this is good number.
     */
    notefreq1.begin(.15);
   // pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {
    // read back fundamental frequency
    if (notefreq1.available()) {
        float note = notefreq1.read();
        float prob = notefreq1.probability();
        Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
    }
}
At that point serial monitor gives me ca. 83Hz…
Note_Freq_mic1_80Hz.JPG
To understand the problem better I connect also the output (to stereo) to hear what happens.
Note_Freq_mic_output.JPG
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=352,135
AudioAnalyzeNoteFrequency notefreq1;      //xy=600,228
AudioOutputI2S           i2s2;           //xy=626,144
AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection          patchCord2(i2s1, 0, i2s2, 0);
AudioConnection          patchCord3(i2s1, 0, i2s2, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=525,305
// GUItool: end automatically generated code

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

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(30);
  delay(1000);
    /*
     *  Initialize the yin algorithm's absolute
     *  threshold, this is good number.
     */
    notefreq1.begin(.15);
    //pinMode(LED_BUILTIN, OUTPUT);
  
}

void loop() {
    // read back fundamental frequency
    if (notefreq1.available()) {
       float note = notefreq1.read();
       float prob = notefreq1.probability();
        Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
    }
}
Now I heard that noise which gets a little bit louder every time it prints out a new line to serial monitor. If I halve the CPU to 24Mhz the frequency duplicates to ca. 170Hz.

Has anyone else got this error before?
Maybe some elementary error in programming?:confused:
 
First run at 96 MHz or higher. Second check the cpu usage. I think the way the library is configured it will use to much cpu for this to work. Let me know what the cpu usage is at 96MHz or higher. I wrote this library.
 
Hi duff,
many thanks for your prompt reply.
That’s great!.. it works with 96Mhz. :)
Also my voice now sounds clear and not anymore brazen.
For cpu and processor usage I found this library:
https://www.pjrc.com/teensy/td_libs_AudioProcessorUsage.html
I have inserted it in my code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=352,135
AudioAnalyzeNoteFrequency notefreq1;      //xy=600,228
AudioOutputI2S           i2s2;           //xy=626,144
AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection          patchCord2(i2s1, 0, i2s2, 0);
AudioConnection          patchCord3(i2s1, 0, i2s2, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=525,305
// GUItool: end automatically generated code

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

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(15);
  delay(1000);
    /*
     *  Initialize the yin algorithm's absolute
     *  threshold, this is good number.
     */
    notefreq1.begin(.15);
}


void loop() {
    // read back fundamental frequency
    if (notefreq1.available()) {
       float note = notefreq1.read();
       float prob = notefreq1.probability();
       int cpuusage = AudioProcessorUsageMax();
        Serial.printf("CPUusage: %i | Note: %3.2f | Probability: %.2f\n", cpuusage, note, prob);
    }

}
Yes CPU usage seems to be high, if I have implemented it in right way.

CPU usage of 92% at 96Mhz.
Note_Freq_mic_4_CPU_96Mhz.JPG

Doubles to 180% at 48Mhz.
Note_Freq_mic_4_CPU_48Mhz.JPG

BR
 
Last edited:
ok, so at 96MHz its below 100% cpu usage max so thats good but that doesn't leave much room for anything else. So there are a few things you can do to lower this usage, the first being what is your lowest fundmental frequency you expect to observe? The way it is setup now is that it can detect freq. at ~30Hz or higher. Since this seems to be for human voice I suspect you won't see anything this low i.e. (30 Hz)? Let me know what the lowest freq. you expect and i can show you how to update the library to save some cpu usage. I'm planning on working on an update to make it easier to change this but for now it's hardcoded in the library.
 
Hi Duff,
I have continued with my project this weekend and CPU usage has grown to 97% . It works, and for the moment I don`t need more, but if you can do some improvements/change in library would be fine. :)
The frequency range I want to operate is 60Hz to 300Hz.
Many thanks
BR
 
Status
Not open for further replies.
Back
Top