• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

Root Mean Square And Average Values Of A Function

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 9, 2017
Messages
13,769
Location
seattle
Basic Beliefs
secular-skeptic

The average value of a function can be problematic because it can have a zero mean value. Put a zero mean sine current through a resistor and the resistor heats up, but the average value is not meaningful in calculating the power dissipation.

The solution is Root Mean Square or RMS. RMS squares the values so both positive and negate areas under the curve do not cancel each other out.

Any function r curve with the same RMS is said to represent the same thermal energy, at least in ;electric circuits.

The Numpy trapz() integration function makes it easy to code.

Sometimes it is required to separate the RMS value of a waveform and the average value.

I looked up the integral of sin()^2 in a table of integrals and compared to the numerical solution.


Results
Total RMS 1.422729023749446
AC RMS 0.707106781186547 Average -1.234567890000000
Average Value -1.234567890000000
From Table 0.707106781186548
1/sqrt(2) 0.707106781186547

Code:
import numpy as np
import math as ma
import array as ar
import matplotlib.pyplot as plt

#--------------------------------------------------------------------------
def plotxy(xlo,xhi,ylo,yhi,x,y,title,xlabel,ylabel):
        font1 = {'family': 'arial',
        'color':  'black',
        'weight': 'heavy',
        'size': 15,
        }
        [fig, p1] = plt.subplots(1)
        p1.plot(x,y,linewidth=2.0,color="k")
        p1.grid(color='k', linestyle='-', linewidth=1)
        p1.grid(which='major', color='k',linestyle='-', linewidth=0.8)
        p1.grid(which='minor', color='k', linestyle='-', linewidth=0.3)
        p1.set_xlim(xlo,xhi)
        p1.set_ylim(ylo,yhi)            
        p1.set_title(title, fontdict = font1)
        p1.set_xlabel(xlabel, fontdict = font1)
        p1.set_ylabel(ylabel, fontdict = font1)
        p1.minorticks_on()
        plt.show()
#-----------------------------------------------------------------
def rmsacdc(yin,t):
        # RMS Root Mean Squared
        # ac dc components
        dc = np.trapz(yin,t)/(max(t)-min(t))
        #remove the DC(average) component
        yac = abs((yin - dc)**2)
        rms_ac = np.sqrt(np.trapz(yac,t)/(max(t)-min(t)) )
        return rms_ac,dc
#-------------------------------------------------------------------
def rms(t,yin):
    # the rms integral
    rms = np.sqrt( np.trapz(y**2,t)/(max(t)-min(t)) )
    return rms
#-----------------------------------------------------------------------
def dc_ave(t,y):return np.trapz(y,t)/(max(t)-min(t))
#-------------------------------------------------------------------------
t = np.linspace(0,1,100);
f = 1
y = np.sin(2*np.pi*f*t)
y = y + -1.23456789  #dd avdc to waveform
rm = rms(t,y)
print("Total RMS  %.15f" %rm)

ac,dc = rmsacdc(y,t)
print("AC RMS  %.15f  Average  %.15f" %(ac,dc))

dcav = dc_ave(t,y)
print("Average Value  %.15f" %dcav)

b = np.pi*2 #integral 0 - 2*pi
a = 0
integ = (.5*b - .25*np.sin(2*b))-(.5*a - .25*np.sin(2*a))
rmstable = np.sqrt(abs(integ)/(b-a))
print("From Table %.15f" %rmstable)
print("1/sqrt(2)   %.15f" %(1/np.sqrt(2)))
plotxy(min(t),max(t),-5,5,t,y," ","t","volts")
 
The  Quasi-arithmetic mean is
\( \displaystyle{ {\bar x} = f^{(-1)} \left( \frac{1}{n} \sum_x f(x) \right) } \)

for some function f applied to the members x of a list of n values. This function must be invertible, with inverse f(-1). A weighted version for wi for each xi is
\( \displaystyle{ {\bar x} = f^{(-1)} \left( \frac{1}{W} \sum_i w_i f(x_i) \right) } \)
where
\( \displaystyle{ W = \sum_i w_i } \)

A common subset of possible functions is a power law, giving the [wiiki]Generalized mean[/wiki]:
  • Power mean: f(x) = xp for power p, given in the next entries
  • +infinity -- Maximum
  • 2 -- Root mean square (quadratic mean): f(x) = x2
  • 1 -- Arithmetic mean: f(x) = x
  • 0 -- Geometric mean: f(x) = log(x)
  • -1 -- Harmonic mean: f(x) = 1/x
  • -infinity -- Minimum

A related one is the  Lehmer mean
\( \displaystyle{ L_p(x) = \frac{ \sum_x x^p }{ \sum_x x^{p-1} } } \)

with weighted version
\( \displaystyle{ L_p(x) = \frac{ \sum_i w_i x_i^p }{ \sum_i w_i x_i^{p-1} } } \)
 
Back
Top Bottom