简体   繁体   English

离散傅里叶变换:2D 周期信号的逆会导致频率加倍

[英]Discrete Fourier Transform: Inverse of a 2D periodic signal results in doubled frequency

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.我尝试使用 NumPy 和 OpenCV 的离散傅里叶变换,结果相同。 The problem does not occur when using a 1D DFT and IDFT.使用 1D DFT 和 IDFT 时不会出现此问题。

Do you have any ideas what is the source of this problem could be and how to fix it?你有什么想法这个问题的根源是什么以及如何解决它?

频率为 1 的水平余弦波(左)。频率为 2 的离散傅里叶变换和离散傅里叶逆变换后的重建图像

Here is a sample code in Python demonstrating the issue:这是 Python 中的示例代码,演示了该问题:

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.非常感谢你。

The call to abs() in the second plot is rectifying the cosine, inverting the negative part of the curve.第二个 plot 中对abs()的调用正在校正余弦,反转曲线的负部分。 If you replace it with real(im_back) the plots match as expected.如果将其替换为real(im_back) ,则绘图将按预期匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM