Matlab:对于偶实函数,FFT复数结果,IFFT实数结果

标签 matlab fft ifft

我正在 Matlab 中测试 FFT 和 IFFT 函数的有效性。

我可以将这些函数的输出与一个众所周知的数学事实进行比较:偶实函数(如以 0 为中心的高斯函数)的傅立叶变换是另一个偶实函数 (FFT[real, 0- centered Gaussian] = real, 0-centered Gaussian).这个事实应该适用于 FFT 和 IFFT。

首先我制作我的网格:

nx = 256; % grid total pixel count
X = 500; % grid size (um)
dx = X/nx; %  grid spacing (um)
x = linspace(-nx/2,nx/2-1,nx)*dx; % x grid (um)

df = 1/(nx*dx); % spectral grid spacing (1/um)
f = linspace(-nx/2,nx/2-1,nx)*df; % f grid (1/um)

然后我让我的高斯:

A = 1; % magnitude (arbitrary units) 
x_fwhm = 7; % Full width at half maximum diameter (um)

x0 = x_fwhm/sqrt(2*log(2)); % 1/e^2 radius (um)
y = A*exp(-2*x.^2./(x0)^2); % Gaussian (arbitrary units) 

然后使用 FFT 进行傅里叶变换:

yFFT = fftshift(fft(fftshift(y))); 

或者,使用 IFFT:

yIFFT = fftshift(ifft(fftshift(y))); 

绘制结果:Shown hare are (a) Gaussian defined in space: y, (b) real part of FFT(y), (c) real part if IFFT(y), (d) imaginary part of FFT(y), and (e) imaginary part of IFFT(y).

IFFT 做得很完美:yIFFT 是纯实数高斯分布。然而,FFT 产生一个复数:存在非常小的虚部。这很好,因为在傅立叶变换算法中应该会出现错误,而且无论如何都可以忽略不计。令我困惑的是为什么在 IFFT 中完全没有错误? FFT 和 IFFT 算法有很大不同吗?

*** 注意:fftshift 和 ifftshift 在这里是等价的,因为我的数组有偶数个元素。

最佳答案

实值时域信号的处理相当普遍。以至于 ifft function内置了对频域中出现的相应对称性的处理,如文档“算法”部分所述:

The ifft function tests whether the vectors in Y are conjugate symmetric. A vector v is conjugate symmetric when the ith element satisfies v(i) = conj(v([1,end:-1:2])). If the vectors in Y are conjugate symmetric, then the inverse transform computation is faster and the output is real.

换句话说,ifftyIFFT 的虚部构造为恰好为 0,因为它检测到您的输入具有共轭对称性。

另一方面,即使是时域信号也相对不太常见,Mathworks 认为没有必要在 fft function 中执行类似的测试。 .也就是说,您仍然可以通过使用 ifft 函数计算 FFT 来利用共轭对称性测试

% compute fft(x,[],dim) using ifft:
size(x,dim) * conj(ifft(conj(x),[],dim))

关于Matlab:对于偶实函数,FFT复数结果,IFFT实数结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48532509/

相关文章:

c++ - OpenCV 中的 Matlab fft2 函数

matlab - 如何在 MATLAB 中对矩阵进行采样?

matlab - 使用 uint64 将 64 位数字从二进制转换为十进制

excel - MATLAB:从 100,000 行和 300 列的 Excel 工作表中将数据导入 Matlab

python - 绘制图像的傅里叶变换时出现问题。 "ValueError: x and y can be no greater than 2-D, but have shapes (2592,) and (2592, 1, 3)"

c++ - 奇怪但接近 c++ 中图像的 fft 和 ifft

matlab - 如何让子字符串在 matlab 中工作?

hadoop - hadoop的fft算法实现

python - 使用 Python 进行傅里叶变换

python - FFT - 滤波 - 逆 FFT - 剩余偏移