最近项目要用到快速傅立叶变换,自己写了个算法,测试了下,性能和精度还可以接受
len,time= 1048576 378.186167ms
diff=-0.00000000000225974794 I0.00000000000936106748成功: 进程退出代码 0.
百万级别,变换花了378ms
逆变换误差和0.000000000009
l :=mvm.PowerOf2(20)
arr :=make([]complex128,l)
for i,_ :=range arr{
arr[i]=complex(rand.Float64(),rand.Float64())
}
now :=time.Now()
fft:= mvm.CoreFFT(arr,false)
Println("len,time=",l,time.Now().Sub(now))
// Println("arr=",arr)
// Println("fft=",fft)
reverse:=mvm.CoreFFT(fft,true)
//Println("reverse=",reverse)
var sumDiff complex128
for i,v :=range reverse{
sumDiff =sumDiff+v-arr[i]
}
Printf("diff=%.20f I%.20f",real(sumDiff),imag(sumDiff))
有疑问加站长微信联系(非本文作者)