网友告知有个傅立叶变换这么个东西, 于是写了个Python程序来玩玩。
#!/usr/bin/python import math def main(): hello=[0]*100000 for i in range(0,100000): hello[i]=100*math.sin(i*2*math.pi/1000)+222*math.sin(i*2*math.pi/5000) print abs(FT(hello,0.001))/len(hello)*2 print abs(FT(hello,0.0002))/len(hello)*2 #print math.atan2() def FT(data, f): sum=0+0j; for i in range(0,len(data)): sum += data[i]*(math.e**(-1j*2*math.pi*f*i)) return sum if __name__ == '__main__': main()
傅立叶变换的快速算法叫FFT (Fast Fourier Transform)