v9.1.1
Menu

Frequency Component Energy

easyFREEFourier TransformsSignal ProcessingCV: Image Processing

Implement a function to calculate the energy of a signal from its Discrete Fourier Transform (DFT) magnitudes. This task involves understanding the relationship between a signal's time-domain representation and its frequency-domain representation. The Fourier Transform is a mathematical tool used to decompose a signal into its constituent frequencies, and the DFT is a discrete-time equivalent.

The energy of a signal can be computed using the time-domain representation, but it can also be calculated using the frequency-domain representation, thanks to Parseval's theorem. This theorem states that the energy of a signal is equal to the sum of the squared magnitudes of its frequency components.

To compute the energy, follow these steps:

  1. Square each magnitude of the DFT
  2. Sum the squared magnitudes
  3. Divide the sum by the total number of frequency components, NN
E=1N∑k=0N−1∣X[k]∣2E = \frac{1}{N}\sum_{k=0}^{N-1} |X[k]|^2

This technique is widely used in image processing to analyze the frequency components of an image.

Example

Input
signal_energy([2, 0, 2, 0])
Output
2.0
Reasoning
  • The input is a list of N=4N = 4 DFT magnitudes, one per frequency bin k=0,1,2,3k = 0, 1, 2, 3: ∣X[0]∣=2|X[0]| = 2, ∣X[1]∣=0|X[1]| = 0, ∣X[2]∣=2|X[2]| = 2, ∣X[3]∣=0|X[3]| = 0. They are already magnitudes, so no complex arithmetic is needed.
  • Squaring each gives the power in that bin: 22=42^2 = 4, 02=00^2 = 0, 22=42^2 = 4, 02=00^2 = 0. Only bins 0 and 2 carry any energy.
  • Adding the bin powers: 4+0+4+0=84 + 0 + 4 + 0 = 8.
  • Normalising by the number of bins, as the formula requires: E=14⋅8=2E = \frac{1}{4} \cdot 8 = 2, which is 2.0 after rounding to 4 decimal places.
  • Notice that the zero bins still count toward NN: they add nothing to the sum but they do enlarge the denominator. Two magnitudes of 2 spread over 4 bins give 2.02.0, whereas one magnitude of 4 in 4 bins gives 164=4.0\frac{16}{4} = 4.0. Concentrating the same total magnitude in a single bin produces more energy because the magnitudes are squared.

Constraints

  • Return energy rounded to 4 decimal places

Learn this in

More from CV: Image Processing

solution.py

Test results

Sign in to run your code against the test cases.