在GPU下做fft和Ifft----pycuda

1.调用keikna库

keikna库中有fft,所以为了减小任务量我就调用keikan的fft的库来完成。
http://blog.sina.com.cn/s/blog_4513dde60102vstu.html
这个帖子里详细的介绍了keikna的一些东西。

2.介绍FFT和IFFT的实现

对于二维的傅里叶变换的实现,冈萨雷斯《数字图像处理》有详细的介绍。

通过对这两个图片的学习,可以开始写代码了。

3.代码实现

下面我就把代码贴上:

输出的结果为:
import numpy
from reikna.fft import FFT
import reikna.cluda as cluda

api = cluda.cuda_api()
thr = api.Thread.create()
x = numpy.array((
                        [[1,1,1,0], 
                         [0,1,1,1], 
                         [0,0,1,1], 
                         [0,0,1,1] 
                         ]), dtype=numpy.complex128)
R = x.shape[0]
L = x.shape[-1]
#print (x.real)
x=x.flatten()
NX = numpy.full((16,),0).astype(numpy.complex128)
for i in range(0,16):
    NX[i]=x[i]
NX = NX.reshape(4,4)
x = thr.to_device(NX)
X = thr.array((R,L), dtype=numpy.complex128)
fft = FFT(x)
fftc = fft.compile(thr)
fftc(X, x, 0)
xfft = X.get()
print (xfft)
aa = xfft.conjugate() 
#print (aa)
xx = thr.to_device(aa)
fft = FFT(xx)
fftc = fft.compile(thr)
fftc(X, xx, 0)
xifft = X.get()
xifft = xifft/(R*L)
thr.release()
print (xifft.real)









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值