Lesson 4 of 15

Signal Power and Energy

Signal Power and Energy

Two fundamental quantities describe the "strength" of a signal.

Signal Energy

The energy of a discrete signal x[n]x[n] over NN samples is the sum of squared values:

E=n=0N1x[n]2E = \sum_{n=0}^{N-1} x[n]^2

Signal Power

The average power is energy normalized by the number of samples:

P=1Nn=0N1x[n]2P = \frac{1}{N} \sum_{n=0}^{N-1} x[n]^2

RMS (Root Mean Square)

The RMS value is the square root of average power — it represents the effective amplitude:

RMS=1Nn=0N1x[n]2=P\text{RMS} = \sqrt{\frac{1}{N} \sum_{n=0}^{N-1} x[n]^2} = \sqrt{P}

For a pure sinusoid x[n]=Asin(θ)x[n] = A\sin(\theta), the RMS is A/20.707AA/\sqrt{2} \approx 0.707 A.

Example

For the signal [1,1,1,1][1, -1, 1, -1] (alternating ±1\pm 1):

  • Energy =1+1+1+1=4= 1 + 1 + 1 + 1 = 4
  • Power =4/4=1.0= 4/4 = 1.0
  • RMS =1.0=1.0= \sqrt{1.0} = 1.0

For [0,1,0,1][0, 1, 0, -1]:

  • Power =(0+1+0+1)/4=0.5= (0+1+0+1)/4 = 0.5
  • RMS =0.50.7071= \sqrt{0.5} \approx 0.7071

Your Task

Implement:

  • signal_power(samples) — returns 1Nx[n]2\frac{1}{N}\sum x[n]^2
  • signal_energy(samples) — returns x[n]2\sum x[n]^2
  • rms(samples) — returns power\sqrt{\text{power}}
import math

def signal_power(samples):
    return sum(x**2 for x in samples) / len(samples)

def signal_energy(samples):
    return sum(x**2 for x in samples)

def rms(samples):
    return math.sqrt(signal_power(samples))
Python runtime loading...
Loading...
Click "Run" to execute your code.