Discrete Fourier Transform
Discrete Fourier Transform
The Discrete Fourier Transform (DFT) converts a finite sequence of N samples into a sequence of complex frequency components :
The DFT reveals which frequencies are present in the signal.
Power Spectrum
The power spectrum measures the energy at each frequency:
For a pure cosine , the power spectrum has peaks at and (the aliased component), each with value .
Inverse DFT
The inverse DFT reconstructs the original signal from frequency components:
The round-trip is exact (up to floating-point precision).
Frequency Resolution
If the signal has a sampling interval , the frequency resolution is:
Frequencies range from to , and the Nyquist frequency is .
Complexity
The direct DFT requires operations. The Fast Fourier Transform (FFT) reduces this to by exploiting symmetry, but here we implement the straightforward version to understand the definition.
Your Task
Implement the DFT, power spectrum, and inverse DFT. Represent complex numbers as (real, imag) tuples. Use only Python's built-in math and cmath modules.