How to read frequencies from electret mic

Hello everyone,

I am new to Arduino. I am trying to make a 7 band spectrum analyser. I bought electret microphone amplifier from Adafruit (MAX4466).

I have connected the mic to Arduino as recommended by Adafruit and also used the sample code they provided to measure sound levels, it works fine and also reacts to sound.

This is the link that I followed to set it up and measure sound levels

I tried Piccolo Music Visualizer example (which uses FFT) from Adafruit (Overview | Tiny Arduino Music Visualizer | Adafruit Learning System) but the output I get from this example is different. It doesn't react to music.

The output I get for peak[8] is (peak is an array of 8 columns)

6
3
0
0
0
0
0
0
6
3
0
0
0
0
0
0
6
3
0
0
0
0
0
0

So I don't know what I have to do to make it react to music and read the frequencies for 7 different bands.

The frequency range I am looking for is 20Hz - 16KHz.

Could someone help me please?

Thank you

The frequency range I am looking for is 20Hz - 16KHz.

But tha words on the piccolo project page says the sample rate is 9.6KHz, this means you can not detect any frequency higher than 4.8KHz.

However you give scant information other that I tried this project and it doesn’t do what I expected. What did you expect? What was your code? To get a printout you must have changed the code in some way, so please post that code. Do you have the hardware that is exactly the same? If not what has changed? Can you post a photograph of your wiring so we can try and see if anything is wrong.

I've never done anything frequency-related but I've thought about it, and I'd use an [u]MSGEQ7 chip[/u]. The software is probably 100 times simpler.

That might not be "fair" because you're not writing the FFT library yourself, but it does free-up processor power/time that can be used for the display. The potential downside to the MSGEQ7 is that it's only 7-bands, and you can't choose the bands.

Lots of people have had success with FFT/FHT and with the MSGEQ7... And lots of people struggle with both approaches. (There may be some counterfeit or defective MSGEQ7 chips on the market.)

BTW - Adafruit is usually a very good source of information.

As I understand it you're using the code from here and are not seeing what you expect when you print data at essentially the end of the processing chain.

As a general principle of debug, the next step is to look at intermediate data to verify that it is or isn't what might be expected, thus narrowing the problem to either the code before or after that intermediate point. For this case, I'd start by printing the contents of the "capture" buffer after the while statement (so line 146). This will validate that you are getting audio correctly.

At least one problem you should see at this point is that the signal data will be negatively biased, that is there will be more and larger negative numbers than positive. This is because the MAX4466 output is centered at about 1.5 V rather than 5V/2 = 2.5V -> 512 on the ADC as implicitly assumed in the ISR at the bottom of the code listing. This is likely the source of the constant 6, 3 in your two lowest frequency bins, but it's not obvious how it might affect other bins apparently staying at zero, so there may be additional issues.

MrMark:
This is likely the source of the constant 6, 3 in your two lowest frequency bins, but it's not obvious how it might affect other bins apparently staying at zero, so there may be additional issues.

It doesn't, the spectral leakage is defined by the window function and shouldn't be more than a few bins.
With no window function spectral leakage is generally awful, except that the DC offset bin cannot leak at all, as DC is an exact multiple of the sampling frequency.