Go Down

Topic: Using Electret Mic to Identify Frequencies  (Read 3315 times) previous topic - next topic

Amanuella

Hi All,

I don't know if this question has been asked/answered before, but I'm new to Arduino and I have a few questions.

I have an Arduino Uno and Arduino Micro and I would like to use an Electret Microphone Breakout Board to identify if a sound is within some specified frequency range. I don't want  the frequencies to be displayed on a screen, but I do want the Arduino to execute certain commands if the sound is of the desired frequency(for testing, I'd use an LED). Is this possible? I can't use a large external circuit and I am working with limited supplies. Some instruction, schematics and perhaps some sample code would be super helpful.

Cheers!

AWOL

Can you give any idea of the frequency you're interested in?

Amanuella

I'm mostly interested in the frequencies within the normal human audible range. I'm still not exactly sure which frequency/ frequency range yet.

DVDdoug

The "obvious" answer is FFT.  (Technically, it's called DFT in the digital domain.)  

Or if you are looking for one (or a few) specific frequency bands, you can use DSP bandpass filters, which are easier than FFT.  

There is an FFT library (I've never used it) so you don't have to start from scratch, but DSP (Digital Signal Processing) is not simple.  There is a FREE online DSP book, but it's not specific to the Arduino -  The Scientist and Engineer's Guide to Digital Signal Processing,  by Steven W. Smith, Ph.D..

The Arduino isn't a super-powerful processor and I don't know what kind of FFT limitations you'll run into, but people have made audio spectrum analyzers.

If 7 frequency bands are enough, look into the MSGEQ7 chip.  It's got 7 bandpass filters on a chip.  It requires some tricky timing & programming, but it's not nearly as complicated as FFT.  (I've never used the MSGEQ7 chip either, but I understand what it does...)

Amanuella

Thank you so much for the help!

I had read about FFTs and I did try to test the sketches the have for that, but a lot of the sketches fail to compile. I am also not sure what type of circuit setup the sketches are designed for(although I could figure it out from the code-- not easy as most of the code doesn't work).

If you have a specific working example(with all the necessary details)that I could perhaps look at to get a better grasp of things and build off of, that would be much appreciated.

I hate to be asking so much, but I'm new at this and I am totally willing to learn so the more examples and instruction, the better.

Thanks again!!!

Grumpy_Mike

Quote
also not sure what type of circuit setup the sketches are designed for
Normally it is a biased AC input on an analogue input pin.

Quote
although I could figure it out from the code
No you couldn't.

See the front end of this project.
http://interface.khm.de/index.php/labor/experimente/arduino-realtime-audio-processing/

tmd3

#6
Aug 01, 2015, 07:29 am Last Edit: Aug 01, 2015, 07:31 am by tmd3
... I would like to use an Electret Microphone Breakout Board ...
Would that be the SparkFun Electret Microphone Breakout?

Quote
... interested in the frequencies within the normal human audible range.
Canonically, that runs from 20 Hz to 20 kHz - a wide range.  The upper portion of that range will be challenging for an Arduino, with its limited speed and memory.  Conventional wisdom says that the fundamental frequencies of adult speech run from about 80 to 260 Hz, and that the interesting harmonics are below 3 kHz.  Maybe you're more interested in ranges on the low end of the audible range.

Quote
FFTs ... a lot of the sketches fail to compile.
A lot of published FFT sketches require that you install a library in order to compile and run them.  You can see how to install a library here.  For the FFT libraries you might be interested in, the section entitled, "Manual installation," is likely to be the most useful.  If you could point to sketches that didn't compile for you, we might be able to tell you whether you need a library to run them.

There are other pitfalls that you might encounter in exploring existing FFT programs.  The FFT is a special case of the Digital Fourier Transform (DFT), carefully arranged for speedy calculation compared to a naive implementation of a DFT.  If you're unfamiliar with the DFT, you might have difficulty interpreting your results.

A number of FFT programs expect that you have a well-behaved signal source connected to a particular analog input in a well-conceived fashion.  If you run those with nothing connected to the analog input, you may well get results that are absolutely correct, but difficult to follow.  I'll recommend that you use known, calculated data as input to the FFT while you're developing the FFT portion of the code, and then switch to live analog input when you have developed a level of confidence in the FFT code.

Grumpy Mike is right:  there's no way that you could figure out how to connect an audio input to an analog pin on the Arduino just by looking at the code, unless you already have a fair knowledge of the Arduino's analog-to-digital-converter (ADC), and how it works.  You describe yourself as a neophyte with regard to the Arduino, but we don't know anything about your experience with electronics in general.  The ADC requires an input voltage that's between 0 volts and 5 volts in order to provide a meaningful reading.  Many audio sources provide something like a 1 to 2 volt peak-to-peak signal, centered at 0 volts, or ground.  If a signal like that is directly connected to an analog input, the reading will be zero whenever the input signal is negative.  And, it can damage your Arduino.  The project that Grumpy Mike references shows a method of shifting the level of an analog input to be at the middle of the ADC's range - 2.5 volts.  

Having said all that, I'll note that the SparkFun Electret Microphone Breakout internally level-shifts the analog signal from the electret to 2.5 volts, and uses a rail-to-rail op amp to boost the signal.  The output is Arduino-ready, and can be connected directly to an analog input.  If you're not using that device, though, you'll need to either verify that it has appropriate level-shifting, or do that shifting with your own components.



Go Up