4

我将一些简单的 IDL 代码传递给 Python。然而,从 SciPy/NumPy 包返回的 FFT 值与 IDL 不同,我不知道为什么。

将其全部简化为 8 个元素的简单示例,我发现 SciPy/NumPy 例程返回的值比 IDL 例程大 8 (2^3) 倍(我认为是规范化问题)。

这是两种语言的示例代码(从此处复制):

IDL

signal = ([-2., 8., -6., 4., 1., 0., 3., 5.])
fourier = fft(signal)
print, fourier

返回

(1.62500,000)(0.420495,0.506282)(0.250000,0.125000)(-1.17050,-1.74372)(-2.62500,-0.00000)(-1.17050,0.00000)(-1.17050,1.74372)(0.250000,-0.125000)(0.420495,-0.506282)

Python

from scipy.fftpack import fft
import numpy as N
…
signal = N.array([-2., 8., -6., 4., 1., 0., 3., 5.])
fourier = fft(signal)
print fourier

返回

[ 13. +0.j , 3.36396103 +4.05025253j, 2. +1.j , -9.36396103-13.94974747j, -21. +0.j,-9.36396103+13.94974747j,2.-1.j,3.36396103 -4.05025253j]

我用 NumPy 包做到了,我得到了相同的结果。我也尝试过print fft(signal, 8 )以防万一,但它返回的结果与预期的一样。

然而,这还不是全部,回到我真正的 256 个元素数组,我发现差异不再是 8 或 256,而是 256*8!这太疯狂了。

虽然我解决了这个问题,但我需要知道为什么会有这种差异。

已解决:这只是标准化,在某些时候我将 IDL 256 阵列除以 8 倍,但我忘记删除了。在 Dougal 的回答中有我错过的文档。

4

1 回答 1

9

IDL and numpy use slightly different definitions of the DFT. Numpy's is (from the documentation):


(source: scipy.org)

while IDL's is (from here):

Numpy's m is the same as IDL's x, k is u, n is N. I think a_m and f(x) are the same thing as well. So the factor of 1/N is the obvious difference, explaining the difference of 8 in your 8-elt case.

I'm not sure about the 256*8 one for the 256-elt case; could you maybe post the original array and both outputs somewhere? (Does this happen for all 256-elt arrays? What about other sizes? I don't have IDL....)

于 2012-04-24T17:05:54.837 回答