我创建了一个简单的积分函数和DFT函数,可以与我编写的其他代码一起使用。在
from math import sin,pi
from time import time
def aintegral(d,step):
return sum(d)*step
def partialdft(d,step,w):
i = 0
x = d
while i/step < len(d):
x[int(i/step)]*=sin(w*pi*i)
i+=step
return aintegral(x,step)
x = []
y = 0
while y<100:
x.append(5*sin(4*pi*y))
y+=.01
print partialdft(x,.01,4)
此代码输出249.028500022,接近预期的250值。但是,当我迭代DFT时,在4处得到了一个完全不同的值。在
^{pr2}$此代码的输出为: 0.0514628731431
0.1 0.0514628731431
0.2 0.0514628731431
一。 . . . 在
4.0 0.0514628731431
一。 . . . 在
9.8 0.0514628731431
9.9 0.0514628731431
10.0 0.0514628731431
谁能告诉我是什么引起了这个问题?提前谢谢。在
注意:现在我不关心使用更有效的fft函数。样本量不大,所以没关系。在
partialdft
函数修改x
。第一个循环之后是x
:调用函数后,
^{pr2}$x
如下:要避免覆盖
x
,请制作一个副本:相关问题 更多 >
编程相关推荐