在测试过程中我注意到了一些奇怪的东西。奇特的numpy fft性能
我对很多矢量进行了FFT处理,并且时不时的FFT函数似乎崩溃了。
我对此进行了简要调试,发现一些向量长度触发了该行为。
事情发生后,我一直在运行一个脚本,令我惊讶的是,它并没有崩溃,它只是花了一点时间。
有没有人知道发生了什么,以及如何对付这种情况。我已经看到了许多不同的FFT大小,下面只是一个例子。
import numpy as np
import time
a = np.zeros(166400)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165039)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165038)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165036)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165035)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165034)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
a = np.zeros(165037)
start = time.time()
audio_fft = np.fft.fft(a,len(a))
print "it took %fs"%(time.time() -start)
print "done"
此输出:
c:\Users\sol_sf\Desktop\math>fftTest.py
it took 0.029000s
it took 0.101000s
it took 0.176000s
it took 0.220000s
it took 0.671000s
it took 0.065000s
it took 369.132000s
done
c:\Users\sol_sf\Desktop\math>
根据len(a)的因式分解,使用了许多不同的算法。正如你所知道的,2的能力是最快的,所以如果你能垫上这是最好的路线。 http://en.wikipedia.org/wiki/Fast_Fourier_transform#Cooley.E2.80.93Tukey_algorithm有更多的信息。 – marshall