Frequency Component Energy
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:
- Square each magnitude of the DFT
- Sum the squared magnitudes
- Divide the sum by the total number of frequency components,
This technique is widely used in image processing to analyze the frequency components of an image.
Example
signal_energy([2, 0, 2, 0])
2.0
- The input is a list of DFT magnitudes, one per frequency bin : , , , . They are already magnitudes, so no complex arithmetic is needed.
- Squaring each gives the power in that bin: , , , . Only bins 0 and 2 carry any energy.
- Adding the bin powers: .
- Normalising by the number of bins, as the formula requires: , which is
2.0after rounding to 4 decimal places. - Notice that the zero bins still count toward : they add nothing to the sum but they do enlarge the denominator. Two magnitudes of 2 spread over 4 bins give , whereas one magnitude of 4 in 4 bins gives . 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