Discrete Fourier Transform
Today’s exercise focuses on the implementation of the Discrete Fourier Transform (DFT). In the next lecture, we will implement the inverse transform.
The Fourier Transform computes the frequency spectrum of a given input image . This spectrum is denoted by ; it is a complex matrix with the same dimensions as the input image.
The basis function is defined as
To compute the basis function, it is useful to use Euler’s formula
Using this relation, the result can be split into real and imaginary parts:
The spectrum amplitude is computed as follows:
The phase is defined as
The power spectrum can be computed as
To display the power spectrum, first apply a logarithm to its values and then normalize them to the interval .
For a conventional visualization of the spectrum, swap the first and third quadrants, and also the second and fourth quadrants. This swap should be performed on both the real and imaginary parts of the computed spectrum. This will also be useful later when applying filters.
Hint: Use the double data type to represent the input image, the frequency spectrum values, and the phase.
Expected Output