I want the rms of audio over a several second period. Lets say I sample at 16KHz. 60usecs. A second would take 16K samples, and the rolling rms function I have saves the samps squared in an array, and 1023*1023 needs a long, so I just don't have enough ram for several seconds of rolling rms using longs. Uno with a 328 has 2K. What if I take the rms of 16 samps at 16KHz over 1ms, then take the rms of 50 of those, then take the rms of 50 of those. Do I have the rms over 2500ms? Or do I take the mean of the samps squared over 16 samps, 50samps, 50 samps and just take the sqrt of the sum of the means of the samps squared? Or the mean of the sums of the samps squared? This is better cuz I just have to take 1 sqrt.

## rms of the rms?

:oops:

My brain just barfed.....

OK, but the Big Idea is to calc the rolling rms over a couple seconds (heat in voice coil) using some computing trick to compensate for lack of ram for a brute force solution. Don't tell me to buy an AD analog RMS chip. That needs solder, not software.

It is possible to measure RMS for just a single cycle, if the sample interval is a multiple of a complete cycle. If you measure the frequency, it is the possible to choose the number of samples for x complete cycles to fit RAM capacity.

Also the standard deviation calculation, is a simple computer math way of doing RMS. It reduces math requirements. Not sure it will save RAM in your case because of 16KHz rate, may not let the sums and sums of squares happen on the fly.

Ran in to a similar problem when I made a 16 channel branch current monitor.

They way I alieviated the ram requirements was to square the samples on the fly and accumulate. Then when I had the right number of samples I performed the remainder of the rms calc, the root. The trick is to not overflow your accumulator.

Mind you this was for Mains power with fixed frequently.

Steve

Since this is audio, the concept of a cycle is sort of 20-20K. The rms of the instantaneous samples is the same as the dc equivalent heating in the voice coil of the speaker. I think. There isn't much amplitude above 4KHz, so I can get by with a sort of non hifi sample rate I think. I wish there was a 1280 arduino with 8K ram.

Bob,

Why not rely on heat generated in an RTD which is connected to the audio line voltage directly such that its resistance will be a measure of audio power directly.

Then all You would need is a very low level DCcurrent injected into the RTD and resultant DC voltage would be a measure of "RMS" audio signal over a longer period ( seconds) memorised by the RTD heat content.

Think about oldfashioned bolometers used in microwave power sensing except this could be much simpler.

Tricky. I guess a PT100 wouldn't load down an amp driving 2 ohms or 4 ohms, but does this mean there is no way to measure the rms with an ad converter using 3 bins of 1ms 10ms 100ms? Isnt this the way unix does file lookup? inode, 1 level indirect inode, 2 level indirect inode? The size multiplies by the space indexed by the inode?

Bob by definition

Vrms = squatre root of average of sum of squares

Given that audio is aperiodic then sampling, squaring and running a moving average over a fixed number of squared samples and square rooting ( sounds rude ) would result in an RMS value from sample to sample.

I am more of a hardware person ( old school )

OK, we agree its possible to compute the rms over a couple of seconds using a straight forward approach. Now we can look for a mathematically equivalent trick that uses less ram. How about calc samps squared for 16 samps at 16khz (1ms), then accum 50 of those (50ms), then accum 50 of those (2500ms), take the sqrt(sum of squares)/2500. Is that the same as the rms over 40K samps at 16KHz (2500ms)?

Another approach: since you want to calculate the heating effect (P=IV=v^2/R) and you know both R and the instantaneous value of V, why not simply take the absolute value of V, square it, make a long-period low-pass filter? It needs only an accumulator of sufficient resolution and a running average store, and it's updated each sample.

e.g. K1 = (K0*255)/256 + Sample/256 or some similar convenient multiplier.

I find trying these things out on Excel very helpful; it's easy to play with scaling and coefficients.

Neil,

I thnik it might work only in case of periodic waveform with fixed form factor which could then be scaled( compensated for).

(heat in voice coil)

What about the phase of U and I ?

perhaps you need to measure both!

Bob, I have no direct answer but start up your most convenient spreadsheet program (MS Excel, LibreOffice Calc, etc..) and try it out.

You could sum the squared values over say 100 milliseconds and save them in a 32 element circular buffer. When each 100 msec chunk is complete add it in after subtracting the oldest, and that will spit out a correct running average of the squares every 100 msec.

Yes, in general to add precomputed RMS values you square each one, multiply by the number of corresponding samples, add all together, divide by the total number of samples, and take the square root.

?

The signal is neither periodic nor bi-polar, so why bother with "RMS" values.

Audio is pretty symmetric. Take some samples of your favorite music, sample them on a PC, and integrate the "area above 0" and the "area below 0" on a voltage vs time plot. In the long term the difference will approach 0.

So skip all the negative parts of the waveform.

Now, without any negative signal data, skip the "RMS", as "RMS" is a methodology for dealing with bi-polar data.

Now, as mentioned above, track your samples, (peaks). With a uniform sampling rate you know the "delta time" for each sample.

Simple average is equal to the "DC heat power".

Simplify the problem to solve it.

JC

I wish there was a 1280 arduino with 8K ram.

??? http://arduino.cc/en/Main/arduin...

The Arduino Mega is a microcontroller board based on the ATmega1280 (datasheet). ...

**DocJC wrote:**

?...

Now, without any negative signal data, skip the "RMS", as "RMS" is a methodology for dealing with bi-polar data....

Simple average is equal to the "DC heat power".Simplify the problem to solve it.

JC

You need the square term even for unipolar signals - the power in the load increases as the square of the voltage.

kevin

Real power is the instantaneous V, I product of point data. To do that a tandem ADC, or the use of a sample and hold is required for coincident data. AC RMS, is possible with unipolar data, the average of the readings, or bias is subtracted out. In the case of power subtract the aveV * aveI from the average if V*I products.

Due to the speed requirements, an analog power metering chip may help in your application.

Hi Bob,

Where are you actually sampling the audio? At the loudspeaker directly? Upstream somewhere (e.g. the input to the power amp which actually drive the speaker)?

These RMS calculations always seem so mysterious & ominous until you consider that they simply determine, as a few responders have stated, equivalent DC power. With a resistive load like your loudspeaker that's Power = V x I or V-squared/R. Therein lies several computational shortcuts you can take.

I may have a few suggestions once you answer the above question.

My intention is to have a diode into a 16K:1K divider (1/17th) so 85 volts peak gets divided down to less than 5V. My test is a pot on an uno with a text lcd and a hard coded threshold of 100W into 8 ohms, about 28.26V rms or 40V peak, multiplied by the divider attenuation factor. I can sample about 16KHz (60 usec interrupt where I read ADC and restart ADSC). I keep 16 samps squared (1 ms worth) in the int handler and set a flag. Main loop accums 50 of these 1ms sums and sets a flag, then I accum 50 of these sums and take a sqrt over the sum/2500. I can hold my hand on the voice coil of a speaker cone removed from the magnet basket and feel the temp rise in a couple secs as I turn up the volume of the amp. I assume that a voice coil that can handle 100W is glowing cherry red (1300 deg F?) and its cooling off as fast as its heating up. Its in equilibrium. I want to calc the rms over a several (2.5?) sec rolling avg and turn on an led at 100 watts so I can pull the fader down before the smoke comes out. Compri? Clever gadget? How much could I sell it for?

Why not actively protect the speakers in turning them off instead of just glowing a LED, hoping that the guy at the amplifier will ever notice the tiny LED? If you instead switch off the speakers via a big relay for every other second, he surely will notice...

I'm not asking you to design the system, I'm asking you for an algorithmic way of computing a mathematically accurate rms over several seconds in a ram limited microcontroller. I have offered that 50 50ms hunks makes 2.5 seconds worth.

I'm not asking you to design the system, I'm asking you for an algorithmic way of computing a mathematically accurate rms over several seconds

No Bob, you did not!

Compri? Clever gadget? How much could I sell it for?

With that you explicitly went beyond any purely mathematical/algorithmic help and asked explicitly for a judgement of this gadget. But i can pretty well live with you going thru the roof by reading about a suggestion to enhance/improve a design. Ever heard of constructive criticism? Had a bad sleep?

Have fun!

Bob,

Neat idea!

Let's see if I've got the metrics right:

So, it sounds like the source can deliver 85 Vpp indefinitely. This is the equivalent of about 58 Vrms and thus about 420 watts burning up in the voice coil. But you want to "catch" a situation which rises above 100 watts within a 2.5 second rolling time window. Correct?

It sounds like the VC could smoke in 0.675 seconds if the full power (signal = 85 Vpp) were delivered to the speaker for that fractional second time period. Is there something in the source that prevents it from delivering the peak power for this 675 milliSec time period?

You stated,

" so I can pull the fader down before the smoke comes out." Do you mean manually, or by some automatic mechanism within your device?

Is your audio source delivering "standard" musical content? Or is this a "special" case of some sort? E.g a bass guitar amplifier which could deliver a low E note (165 Hz, I think) indefinitely.

Are you planning on any sort of front-end audio pass band filtering ahead of your ADC?

I am thinking along the following lines to simplify the calculations needed in your limited computational horsepower platform:

Take each 50 mSec "packet" of RMS data and quantize it into an "equivalent wattage" (the equivalent power (watts=joules/sec) of the energy contained in the 50 mSec period if it were extrapolated to a one second time period. Then, if you accumulate enough of these "energy credits" in a 2.5 second period (or even before that), you jump on the fader, flash the lights, superimpose a blanking period in the audio, etc. to get the operator's attention.

Back in the early centuries of the Micro-Processor Age, we didn't have the luxury of real-time calculations, so we did a lot of "pre-calcs". These "pre-calcs" became constants & look-up tables in the micro's operating program, which substituted for some part of the calculations those early-era micro's were incapable of performing. A similar tactic may be applicable to your situation - you calculate the danger limits with the computational power of a PC, then use these calculated limits in your AtMega program as "trip points", comparison levels, integration constants, etc. to accomplish the end-goal.

Clever idea. Watts is Watts. Accum the watt-secs. The test is 100W for 8 hrs, so I want the rolling avg to be slow enough to watch the watts tic up on the diplay. User can set watts threshold, speaker impedance 4 ohms or 8 ohms, etc. Its hard to see the amps clipping if you are 50 feet out front at the board. I want to have a 2 chan system so I can monitor the watts in the los and his, so the lo chan could sample slower.

I'm not sure I'm understanding what you are saying hr Bob.

"The test is 100W for 8 hrs" Does this mean you will run the speaker at 100 Watts level continuously for 8 hours? What would be th pass/fail criteria of this test?

"I want the rolling avg to be slow enough to watch the watts tic up on the diplay." Power (expressed here in Watts) is a rate( Joules PER Second) not a cummulative parameter. If you were measuring, or more appropriatley "logging", energy in units of watt-seconds, watt-minutes or the like, then I could see whee you can see this parameter "tick up on the display".

This brings up an interesting feature you may have been contemplating anyway. A horizontal rolling histogram of the power history of the speaker's output. Perhaps a small dot-matrix LCD where each column represents a one-second time period and the one-pixel-wide vertical bar displayed in that column represent watts (peak or average) for that one-second time interval. With a 120 column display you could display a 2 minute history of the speaker's output. The histogram would scroll horizontally at a one-column-per-second rate from left to right, with the freshest data showing up at the left hand edge of the display. That would allow the operator to view a large time chunk of "power history" by occasionally glancing at the display. Add color to the bars to denote over-powered levels in various degrees.

So, you would install your "power monitor" in the sound board and control the volume of the loudspeaker with the existing facilities of the sound board to dynamically limit the power delivered to the speaker. Now, that's pretty darn clever!

RMS is a SINGLE number. RMS value of a signal between 0ms and 16.6666ms is X. It has no time variance. So, RMS of a single number is the same number since the mean of a single number is that single number.

However, the RMS value of a sequence of "RMS" values is a different matter.To get the effective RMS value from a series of "RMS" measurements, square each value, sum those, and (I think) divide by the number of samples used for the sum, then square root.

Doing a simple example with 4 data points, two each used for one of two "RMS" values, would demonstrate the correct process.

Why not just do a running sum of the squared values, then divide by N and square-root when done? It will probably take less memory in the end.

Jim

Just to get a trip point there is no need to take the square root - which is relatively slow. Just summing the squares is enough. The two step process using 1 ms (possibly longer) chunks is one possible solution.

Earlier Neil already gave a good alternative, by using a simple low pass filter to model the heating/cooling of the coil. This is likely even closer to reality than the rolling average, an uses much less memory. It's just to find the right time constant, e.g. by measuring the cooling of the coil.

Having such a kind of overloud protection is a good idea. Though with more modern 2 or 3 way speakers, separate protection per frequency band may be advisable, but more of a challenge.