Frequency detector in audible sound freq range. Teensy vs Arduino

Status
Not open for further replies.

teoeva

Member
Hi,
i'm trying to build a tone detector which is able to detect main frequency in an audio signal acquired by an amplified mic (20db) on Arduino/Teensy.

This is the mic -> http://electropit.com/index.php/2015/12/20/fc-109-max9812-microphone-amplifier-module/

Since the range i'm inspecting is very specific (50 to 205 Hz and 400 to 800 Hz) but i'm listening to very low sound, i'm looking for something that can give me a good resolution in amplitude AND in frequency. What i want to build is a sorta of guitar tuner that can hear very weak sound. I've analyzed the signal which is around 3.5mV.

I've tried the FreqMeasure library on an ArduinoMega, but i can only read frequency of very strong signal... i'm wondering if with Teensy 3.2, due to its higher resolution, i can work on such low amplitude...

Will Teensy help me? :rolleyes:

EDIT: audio signal acquired by an amplified mic (20db) on Arduino/Teensy... in REALTIME
 
Last edited:
Yes there is already a object for this here, and an example here using the Audio library.

Thank you duff, but i'm looking for the possibility to apply FFT (or YIN) in realtime, acquiring the signal with a mic and returning the main frequency, just like a guitar tuner does.
These examples show an YIN application on a recorded sound, am I right?
 
It sounds like you want a 'sliding DFT' if you want something in realtime

Collect 0.125 second samples and pass it through a YIN. This should account for the lowest audiable frequency 16Hz, of course complying to Nyquist
 
Code:
// Advanced Microcontroller-based Audio Workshop
// Advanced Microcontroller-based Audio Workshop
// 
// Part 2-1: Using the Microphone


///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////


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

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=177,216
AudioAnalyzeNoteFrequency notefreq1;      //xy=418,374
AudioOutputI2S           i2s2;           //xy=438,227
AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection          patchCord2(i2s1, 0, i2s2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=176,656
// GUItool: end automatically generated code

void setup() {
  Serial.begin(9600);
  AudioMemory(30);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(36);
  notefreq1.begin(.15);
  delay(1000);
}
float note, prob;
void loop() {

 if (notefreq1.available()) {
        note = notefreq1.read();
        prob = notefreq1.probability();
        Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
  }
 
}


Note this code was edited to remove reference to Gameduino2 display and has not been tested since
 
Last edited:
These examples show an YIN application on a recorded sound, am I right?

Yes, and no.

Yes, the example analyzes one of several recorded sounds. It wouldn't be a very effective or reliable example without known-good sound samples to analyze!

But no, the notefreq object is certainly not limited to analyzing only recorded sounds! It's meant to be used on live, real-time data streams.

Perhaps you've not understood how the audio library allows you to create your own connections of the many audio objects. Please, watch the tutorial video! Once you understand how to use the design tool, it's so very easy to simply connect a live sound source to the analysis object, rather than the memory player for the recorded samples.
 
Last edited:
Perhaps you've not understood how the audio library allows you to create your own connections of the many audio objects. Please, watch the tutorial video! Once you understand how to use the design tool, it's so very easy to simply connect a live sound source to the analysis object, rather than the memory player for the recorded samples.

I'll study it and I'll be back for the [RESOLVED] tag ;) Thank you Lord Paul ;)

A last question about supported hardware... here https://www.pjrc.com/teensy/td_libs_Audio.html i can't see Teensy 3.2... it's a lack of update or i have to buy a Teensy 3.1?
 
Yes, Teensy 3.2 is fully supported.

I've updated the "Supported Hardware" on that page. It also was missing the newer S/PDIF and quad channel support.
 
I've watched the tutorial video and i've tried also the design tool (which is really brilliant!!!), but... i can't understand if I have any chance to apply "notefreq" in 400-800Hz, since i understand that fft has a resolution that can't afford what i'm trying to do (43Hxz resolution of fft2014 doesn't fit with my project specifics)...
 
@teoeva do you have hardware? If you would try the supplied code I think you will find the frequency resolution to be adequate for a tuner type application.
 
notefreq uses the YIN algorithm, so it's not limited to 43 Hz steps like FFT1024.

You should try running the example. First, run it as-is with the bass guitar samples.

Then try adding some of your own sound samples.

Then, if those work, try adapting the program to run on live audio. But test first with your own recorded samples. The path to success in these sorts of projects involves small, achievable steps. Also, if there's a problem, you'll be able to share the samples here so we can try to help you. Obviously it'll be nearly impossible for anyone here to look into any issue if you go right to live streaming, so please do not skip the step to test with your own recorded samples that are similar to the live sound you wish to analyze.

If your sound samples are your own work or public domain or creative commons attribution-only, I've be happy to add a few more sounds to the example. Maybe next time someone needs to know if it works for different types of sounds, more samples in the example will help them?
 
Status
Not open for further replies.
Back
Top