Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Inverse Discrete Fourier Transform

In the previous lesson, we implemented the direct and separable Discrete Fourier Transform. Today, we will implement its inverse, called the Inverse Discrete Fourier Transform (IDFT), using the same two approaches.

We want to transform the complex frequency spectrum back to its spatial domain , which is an image. As before, is the number of rows and is the number of columns; the first matrix index denotes a row.

Direct 2D IDFT

The computation of the IDFT can be implemented using the following formula:

The basis function is defined as

Notice that the exponent has a positive sign, unlike the basis used in the DFT. Both transforms use the normalization factor ; do not introduce an additional factor in the inverse transform.

To compute the basis function, use Euler’s formula . Both the spectrum coefficients and the basis values are complex, so the multiplication and accumulation must use complex arithmetic.

As with the direct DFT, this implementation has complexity , or for a square image.

Separable 2D IDFT

The inverse transform is separable as well:

First, apply the 1D inverse transform to each row of and store the results in a complex intermediate matrix :

Then, apply the 1D inverse transform to each column of :

The two normalization factors again multiply to .

Reusing the 1D transform

Extend your 1D DFT function from the previous lesson with a sign parameter:

Use sign = -1 for the forward DFT and sign = +1 for the inverse DFT. With the normalization used in these exercises, only the exponent sign changes.

function TRANSFORM1D(input, sign):
    L = length(input)
    output = complex vector of length L

    for q = 0 .. L-1:
        sum = 0 + 0i
        for p = 0 .. L-1:
            angle = sign * 2 * pi * p * q / L
            sum += input[p] * (cos(angle) + i * sin(angle))
        output[q] = sum / sqrt(L)

    return output

Build the separable inverse transform in the same way as the forward transform:

function IDFT2D_SEPARABLE(F):
    M = number of rows in F
    N = number of columns in F
    H = complex matrix of size M x N
    result = complex matrix of size M x N

    for k = 0 .. M-1:
        H[k, :] = TRANSFORM1D(F[k, :], +1)

    for n = 0 .. N-1:
        result[:, n] = TRANSFORM1D(H[:, n], +1)

    return result

The notation A[r, :] denotes a row, and A[:, c] denotes a column. Copy values into temporary vectors if necessary. Keep the intermediate matrix complex; do not discard its imaginary components.

The row pass costs and the column pass costs . The total complexity is , or for a square image. This algorithm uses ordinary 1D IDFT sums, not an FFT.

Reconstruction and Verification

Use the original complex spectrum for reconstruction, not its amplitude, phase, power, logarithmic visualization, or normalized display image.

If the spectrum has been shifted to center the zero-frequency coefficient, undo that shift before computing either IDFT. For even dimensions, swapping the quadrants again is sufficient. For arbitrary dimensions, undo the circular shift by moving rows and columns toward decreasing indices (ifftshift). Applying the forward shift twice does not generally restore the original order for odd dimensions.

For an unmodified spectrum of a real image, the reconstructed values should be real, apart from small imaginary residuals caused by floating-point rounding. Measure those residuals, then use the real part as the reconstructed image. Do not use the magnitude: it would lose the sign of reconstructed values. Round and clamp values only when converting the result to an integer image for display or saving.

Hint: Use complex numbers with double real and imaginary components for all transform calculations, and double for the reconstructed image before conversion.

Tasks

  1. Implement the direct 2D IDFT using Equations (1) and (2).
  2. Extend your 1D transform with a direction parameter and implement the separable 2D IDFT. Implement the sums yourself; do not use a library DFT or FFT routine.
  3. Reconstruct the same unshifted spectrum using both inverse implementations. Compare their complex results using the maximum absolute difference.
  4. Verify the full round trip: input image separable DFT separable IDFT reconstructed image. Include a small rectangular image (for example, ), a constant image, and a nonconstant image.
  5. Before rounding or clamping, report the maximum reconstruction error and maximum imaginary residual:

Here, is the original image and is the complex output of the IDFT. Both quantities should be close to zero; exact equality is not required because of floating-point rounding.

  1. Test a round trip that includes centering and uncentering the spectrum, including an image with odd dimensions.
  2. Measure the execution time of the direct and separable IDFT on the same square image sizes used in the DFT exercise. Exclude visualization and image conversion. Compare the observed growth with and .