Go Down

Topic: calculate RMS voltage of audio signal? (Read 11076 times) previous topic - next topic


Feb 28, 2010, 09:23 am Last Edit: Feb 28, 2010, 10:26 am by creyc Reason: 1
I'm feeding a low voltage (0-1.4 vAC) audio signal to an analog input of an arduino and trying to output the RMS voltage of the signal.

I've tried a few methods I've found from googling this, such as:
Code: [Select]
void loop() {
 for (int i = 0; i < samples; i++) {
   sensorValue = analogRead(sensorPin);    // read analog input to sensorValue
   rmsValue = rmsValue + sq( (float)sensorValue );
 rmsValue = sqrt(rmsValue / (samples/2) );

(Where sample count is many many times larger than the frequency I'm measuring)

Unfortunately the results are not in agreement with my Fluke DMM, the readings start off good then drift further and further away as voltage drops.  

I know they make precise RMS chips to turn an AC signal to DC, but I was hoping the ADC on the Arduino could do this, especially since the max frequency is only 80Hz.


You may need an amplifying chip to change the peak audio voltage to the peak reference voltage of the arduino to get the best resolution.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Feb 28, 2010, 05:32 pm Last Edit: Mar 01, 2010, 02:07 am by retrolefty Reason: 1
You have several problems that would prevent this from working. First audio is usually not a pure sine wave (unless only inputting single pure tones) so any formula derived from peak value readings would not be valid. Second you would have a lot of trouble trying to read a peak value unless you read many many samples and save only the highest reading, kind of a highest value seen over a given time interval.

I think that external circuitry would have to be used. As you stated there are true ac to RMS analog converter chips that do the same function as the better digital voltmeters have have true rms functions. There are not cheap but do a good job. Analog devices has some that I've used in the past.

You could use a simple external full wave rectifier diode and filter circuit and read the DC voltage then developed and multiply by some factor to read a quasi peak value (again most audio is not a pure sine wave with the 1.4 ratio of peak Vs RMS).

External voltage amplification would be useful to give you more measure range, however you could also apply say a 2vdc voltage to the external reference pin on the Arduiono to give you a 0-2vdc measurement range.

Also keep in mind that audio is AC voltage (has both a positive and negative value referenced to ground) and you really should not be applying it directly to an Arduion analog input pin as the negative voltage portion of the audio is exceeding the maximum negative voltage specification for the input pin, it's something like -.5v max, plus the A/D conversion process will not give valid numbers below 0vdc anyway. i.e., -.1 volts reads the same digital value as 0vdc.



Thank you for the informative replies.

I think I will need to use both of your suggestions together to make this work as I wish.  Full wave bridge rectification drops too much of an already low voltage signal, I think I will need to first amplify it to make this work.

I have not used the true RMS chips, do you think these would still require additional amplification to get good resolution with a 1.4v source signal?


I think the important point is that you need to have an signal ground somewhere in the middle of the supply voltage range.  If you apply an AC signal centred on 0V to the analog input pin you will only be measuring the positive half waveforms, and this is losing information - AC signals are not all symmetrical!  Perhaps that is why you have a factor of 2 in the calculation?

So you need to condition the signal to an analog ground of say 2.5V before sampling, then subtract the mean signal value from each sample.  Also note that DMMs tend to have a limited bandwidth for AC measurement - if you don't match the filtering you could be looking at a very different signal.

(also I wondering if driving the analog input negative from a low-impedance source might fry the ATmega - at the very least the protection diodes will be affecting the impedance the AC source sees, and might lead to spurious A->D readings)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


Mar 02, 2010, 07:12 am Last Edit: Mar 03, 2010, 04:39 am by creyc Reason: 1
You mention conditioning the signal to an analog ground of ~2.5v.  Would this be accomplished by feeding a regulated 2.5v to the external "aref" pin?

I can understand the benefit of raising the center point to put the entire AC waveform in the ADC's useable range, any advice on how to go about  doing this would be great!


Found this article which uses the same biasing technique to bring the AC signal out of negative territory.  I think this might work with a bit of amplification on the signal.


Go Up