我试图实现离散傅立叶的简单版本的python变换的复共轭。 我的代码如下:离散傅立叶变换使“正确”的答案
#!/usr/bin/env python
import cmath
def dft_simple(sequence):
# dft of seq defined as
# sigma from n=0 to N-1 of x(n) *exp(-2*pi*j*k*n/N)
seqLenth = len(sequence)
complexSequence = []
for k in range(seqLenth):
sigma = 0 - 0j
print("k = {}".format(k))
for n in range(seqLenth):
print("n = {}".format(n))
print("value = {}".format(sequence[n] * cmath.exp(-2*1j * cmath.pi * float(k) \
* float(n)/float(seqLenth))))
sigma = sigma + (sequence[n] * cmath.exp(-2*1j * cmath.pi * float(k) \
* float(n)/float(seqLenth)))
print("exp = {0}".format(-2*1j * cmath.pi * float(k) \
* float(n)/float(seqLenth)))
complexSequence.append(sigma)
print("sum = {}".format(sigma))
print("")
return(complexSequence)
seq4 = [1,1,1,1,0,0,0,0]
print(dft_simple(seq4))
我得到的结果是:
[(4+0j), (1-2.414213562373095j), (-1.8369701987210297e-16-2.220446049250313e-16j), (1-0.4142135623730949j), -2.449293598294706e-16j, (0.9999999999999992+0.4142135623730959j), (3.2904645469127765e-16-3.3306690738754696e-16j), (0.9999999999999997+2.4142135623730954j)]
这不同于答案以两种方式计算相同的序列here,的DFT当我在Wolfram Alpha的获得。首先,wolfram alpha除以sqrt(N),其中N是序列的长度,这只是正向和反向变换的不同对称定义。
第二,更容易混淆的,我的实现是给我的结果Wolfram Alpha的是给我的复共轭 - 该数值在其他方面大致相同。这是我的代码实现问题(例如语法错误)的问题,还是仅仅使用离散傅立叶变换的不同定义的问题?
[钨使用离散傅立叶不同的定义变换](https://reference.wolfram.com/language/tutorial/FourierTransforms.htmlhttps://reference.wolfram.com/language/tutorial/FourierTransforms.html# 19751) – SleuthEye
@SleuthEye修正你的链接:[钨使用DFT的定义不同(https://reference.wolfram.com/language/tutorial/FourierTransforms.html#19751) – Norman
嗯,好吧,这更有意义 - 我以前使用[钨数学世界(http://mathworld.wolfram.com/DiscreteFourierTransform.html)作为参照,谢谢你在清除了。你能否将其作为答案留下来,以便我可以将此问题标记为已解决? – Decimak