Skip to content

Features | latest | energy

Energy

The energy of a signal is defined as the integral of its squared values over time. For discrete signals, this is expressed as:

E=Δti=0N1x[i]2,

where:

  • Δt=1fs is the sampling interval,
  • fs is the sampling rate.

References

Code

INFO

The following snippet is written in a generic and unoptimized manner. The code aims to be comprehensible to programmers familiar with various programming languages and may not represent the most efficient or idiomatic Python practices. Please refer to implementations for optimized implementations in different programming languages.

py
import numpy as np


def energy(signal: np.ndarray, samplerate: float) -> float:
    return 1 / samplerate * np.sum(signal**2)
Run in playground