Home > front end >  Discrete Fourier Transform: Inverse of a 2D periodic signal results in doubled frequency
Discrete Fourier Transform: Inverse of a 2D periodic signal results in doubled frequency

Time:12-11

When converting a periodic 2D signal from image space to Fourier space and back, the reconstructed signal has twice the frequency of the original signal (see picture below). I tried to use the Discrete Fourier Transform from NumPy and OpenCV, both with the same result. The problem does not occur when using a 1D DFT and IDFT.

Do you have any ideas what is the source of this problem could be and how to fix it?

Horizontal cosine wave of frequency 1 (left). Reconstructed image after discrete Fourier transform and inverse discrete Fourier transform with frequency 2

Here is a sample code in Python demonstrating the issue:

import matplotlib.pyplot as plt
import numpy as np

# image width and height
w = 320
h = 320

# frequency of cosine wave w.r.t. the image width
frequency = 1

# function to create a horizontal 2D cosine wave
def create_cos_horizontal(frequency, w, h):
    img = np.zeros((h,w),np.float32)
    base_period = w/(2*np.pi)
    print(frequency)
    for x in range(0, w):
        img[0:, x] = np.cos(x*frequency/base_period)      
    return img

img = create_cos_horizontal(frequency, w, h)

# transform from image space to fourier space
dft = np.fft.fft2(img)
# transform back from fourier space to image space
im_back = np.fft.ifft2(dft)

# show original and reconstructed image side by side
ax1 = plt.subplot(1,2,1)
ax1.imshow(img, cmap='gray')
ax1.set_title("original signal")
ax2 = plt.subplot(1,2,2)
ax2.imshow(np.abs(im_back), cmap='gray')
ax2.set_title("signal after DFT and IDFT")

Thank you so much in advance.

CodePudding user response:

The call to abs() in the second plot is rectifying the cosine, inverting the negative part of the curve. If you replace it with real(im_back) the plots match as expected.

  • Related