Author Topic: RMS value of audio signal  (Read 5219 times)

0 Members and 1 Guest are viewing this topic.

Offline rakeshm55Topic starter

  • Regular Contributor
  • *
  • Posts: 207
RMS value of audio signal
« on: May 07, 2013, 06:54:31 am »
Hi,
 I want to calculate the RMS value of an audio signal. The audio(mic) is connected to a codec chipset. The PCM value are captured by a DSP.
Now I want to calculate the RMS value of the audio .

How to do this??  I believe simple square and add may not work. What will be the suitable procedure or algorithm.

Regards
 

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: RMS value of audio signal
« Reply #1 on: May 07, 2013, 07:08:56 am »
RMS what?

Lettuce?
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline rakeshm55Topic starter

  • Regular Contributor
  • *
  • Posts: 207
Re: RMS value of audio signal
« Reply #2 on: May 07, 2013, 07:53:03 am »
Hi
My aim is to detect silence or there is a voice activity.
For this purpose I would measure the energy level of the audio signal.If the level is above a threshold I would declare non silence mode.

I will deduct the energy level of the signal by calculating the RMS value of the audio signal received. The question is how to calculate the
root mean square of a given audio signal whose raw PCM values I have. The PCM values of the audio sample is unsigned and wont this inherently add an offset thus upsetting the normal procedure for calculating the RMS value.
 

Offline KJDS

  • Super Contributor
  • ***
  • Posts: 2442
  • Country: gb
    • my website holding page
Re: RMS value of audio signal
« Reply #3 on: May 07, 2013, 08:08:22 am »
Your issues is in squaring the unsigned number. Once you've worked out an algorithm for that, add them up, take the average and then the root.

Personally, I'd just look for a few spikes within a given time period that were above the threshold and decide on that.

Offline cyr

  • Frequent Contributor
  • **
  • Posts: 252
  • Country: se
Re: RMS value of audio signal
« Reply #4 on: May 07, 2013, 08:12:09 am »
In theory you unsigned data has a DC level of 50%, just subtract that and you get "AC" data to operate on.

In practice you may have another DC level because of offsets in the electronics, you may want to calculate an average level and subtract that instead... 
 

Offline michaelym

  • Regular Contributor
  • *
  • Posts: 65
Re: RMS value of audio signal
« Reply #5 on: May 07, 2013, 08:35:38 am »
I think you can calculate the energy mathematically using this:
http://en.wikipedia.org/wiki/Energy_(signal_processing)

Since your signal will be discrete you can use a sum instead of an integral.
 

Offline hlavac

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: RMS value of audio signal
« Reply #6 on: May 07, 2013, 03:09:49 pm »
First you need your samples to be signed integers with zero in the middle.
If you have 16bit unsigned sample format your zero will be probably 32768. Just subtract 32768 from each sample. Offset should not be s problem, audio ADCs are usually AC coupled properly.

Now you can square the samples to get their power.
Average across several samples to get average power in corresponding time interval.
You dont need to calculate RMS if you only want to test against threshold.

If you really want RMS value (root of mean squares)  just take square root of the average power.
But as i said you can as well square your threshold and save computing power of the square root...
Good enough is the enemy of the best.
 

Offline rakeshm55Topic starter

  • Regular Contributor
  • *
  • Posts: 207
Re: RMS value of audio signal
« Reply #7 on: May 09, 2013, 05:38:08 am »
First you need your samples to be signed integers with zero in the middle.
If you have 16bit unsigned sample format your zero will be probably 32768. Just subtract 32768 from each sample. Offset should not be s problem, audio ADCs are usually AC coupled properly.

[/quote

I tried the above technique but the results initially looked non promising
.Later I realized that the data format send by the codec (ADC) is I2S , (2s complement) this was the reason for the deviation from expected.
Now there is signed integer values available with me. Should i convert it to unsigned and apply the same logic or Is there a different approach when the data is 2s complement.

 

Offline hlavac

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: RMS value of audio signal
« Reply #8 on: May 09, 2013, 09:43:27 am »
If you have signed integer PCM samples on two's complement just proceed with averaging the squares (using signed int multiplication!)
Good enough is the enemy of the best.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf