Tuesday, October 14, 2014

Measure audio level using Root Mean Square on Spark Core

A Spark.io library to retrive RMS and Spl value from an audio input.


This library reads data from an ADC pin and returns the RMS value of the input simply using RMS avarage.
The root mean square (abbreviated RMS or rms), also known as the quadratic mean, is a statistical measure of the magnitude of a varying quantity.
Here is simply implemented by getting samples, for each of them making the root, then the mean for all the collected samples, and finally square the result.

This library is a derivation of the work you can find here: http://davidegironi.blogspot.it/2013/05/avr-atmega-audio-input-root-mean-square.html
So for more information about RMS, you can read the post above.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

6 comments:

  1. hmmm... what do you get on console on your side, here it seems quite scrambled...

    ReplyDelete
    Replies
    1. You have to use the processing.org display tool provided. Value are printed out not as ascii, so a uart terminal will not work as expected.

      Delete
  2. Seems I saw that ;-) can I use it as a SPL meter this way ?

    I guess I can do this:
    soundDbl = (double)audioGet.getSpl(voltageRms, AUDIO_VOLTREF, AUDIO_DBREF);
    Spark.publish("librato_bc2_dbl", String((int)soundDbl));

    ReplyDelete
    Replies
    1. Yes you can, but an FFT library like the one used here it will be better: http://davidegironi.blogspot.it/2014/02/a-simple-sound-pressure-level-meter-spl.html

      Delete
  3. here it is stuck at 72 all the time, what can I do to make it more reactive ?

    also do you think the fft radix would work on a spark as is ?

    ReplyDelete
    Replies
    1. That could be due to pre board noise. You could try disable the dynamicbias and set the biaszeroraw value according to your adc reading with no noise. To make it more reactive you have to set the smooth filter. You also could set an rms correction (offset) value. But the very first thing to do, is check you pre board noise with a scope or a frequency analyzer.

      Delete