PIXELBANKv9.1.0
Menu

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 list is interpreted as the DFT magnitudes: X=[2,0,2,0]X = [2, 0, 2, 0].
  • Compute squared magnitudes and sum: ∣2∣2+∣0∣2+∣2∣2+∣0∣2=4+0+4+0=8|2|^2 + |0|^2 + |2|^2 + |0|^2 = 4 + 0 + 4 + 0 = 8.
  • There are N=4N = 4 frequency bins, so energy is E=1N∑k=03∣X[k]∣2=14â‹…8=2.0E = \frac{1}{N} \sum_{k=0}^{3} |X[k]|^2 = \frac{1}{4} \cdot 8 = 2.0.
  • Thus, signal_energy([2, 0, 2, 0]) returns 2.02.0.

Constraints:

  • Return energy rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.
Frequency Component Energy - Easy | PixelBank