Pages: [1]   Go Down
Author Topic: calculate RMS voltage of audio signal?  (Read 3576 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: February 28, 2010, 04:26:00 am by creyc » Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9627
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Lefty
« Last Edit: February 28, 2010, 08:07:18 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12190
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: March 02, 2010, 10:39:29 pm by creyc » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/
Logged

Pages: [1]   Go Up
Jump to: