AudioAnalyzeRMS RMS range

sleitman

Member
Hi,

I am looking for some clarity about the AudioAnalyzeRMS function. I am applying it to the mic input and getting fine results but I am curious about what 1.0 scales to in this case. Is the maximum of the normalised value floating or is it set some where? I have set the micGain to the 36dB setting if that helps.

Thanks,
Sasha
 
Hi Kidestuarine, thanks for the response. I am using the Teensy audio processing library. With any normalisation, you need to know what the maximum and minimum values are that are to be scaled between 0 and 1.0. That is where I am getting confused. I understand RMS values but am having trouble figuring out what the actual measurements are before normalisation.
 
To really answer, the RMS output is a floating point number scaled according to the full input signal having +1.0 to -1.0 range.

So if you give it a full scale sine wave, expect to see 0.707 output. This is quite easy to test. For example...

Code:
#include <Audio.h>

AudioInputI2S        audioInput;  // needed on older Audio library to cause updates
AudioSynthWaveform   waveform1;
AudioAnalyzeRMS      rms1;
AudioConnection      patchCord1(waveform1, 0, rms1, 0);

void setup() {
  AudioMemory(20);
  //waveform1.begin(WAVEFORM_SQUARE); // result = 1.000
  waveform1.begin(WAVEFORM_SINE); // result = 0.707
  waveform1.frequency(440.0);
  waveform1.amplitude(1.0);
}

void loop() {
  delay(100);
  Serial.println(rms1.read(), 3);
}
 
Just to explain a bit more, internally the raw audio samples are 16 bit integers. Internally the RMS computation is done with highly optimized fixed point code which leverages the ARM Cortex-M4/M7 DSP extension instructions.

But it is all done in such a way that you get the same result as if the audio samples had been floating point numbers with +1.0 to -1.0 and all the math had been done in floating point. It's actually done as integers, but the answer is reported as a float, scaled as if everything had been done as float.
 
Thanks @Paul, for always helping me understand everything from spam bots to serial protocols.
I think I was trying to understand if the 0 to 1.0 output range corresponded to any known maximum voltage on the mic input. In the same way that on a 3.3v microcontroller input pin, the range of readings roughly corresponds to 0 to 3.3V. Does that make any sense?
 
The actual voltage to numerical range relationship happens in your I2S ADC (or if using a MEMS mic, whatever analog to digital process happens within the mic).

When AudioInputI2S receives the data at Teensy's pins, it's already digital data. While the actual raw data is integers, the audio library presents it as +1.0 to -1.0. Except for the queues (which provide access to raw data), the audio library functions all try to present a consistent interface where the signal is represented with +1.0 to -1.0 range.

AudioAnalyzeRMS is purely a math function. The input maximum full scale is +1.0 to -1.0, so you get numerical output of RMS computed over that range.

Of course if you want a final result scaled back to actual voltage, you can just multiply by a constant. But what that constant needs to be depends on the ADC hardware you connected to Teensy's pins.
 
Back
Top