Python-执行FFT,然后执行不同于原始信号(GPU)的IFFT

时间:2019-06-05 18:17:33

标签: python scipy fft pycuda cufft

我试图对这样的信号进行fft:

import numpy as np
from scipy.signal import hilbert, chirp

duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
signal = chirp(t, 20.0, t[-1], 100.0)
signal *= (1.0 + 0.5 * np.sin(2.0*np.pi*3.0*t) )

from skcuda.fft import Plan
import skcuda

def fft_gpu_pycuda(signal):
  x_gpu = gpuarray.to_gpu(signal)
  x_hat = gpuarray.empty_like(x_gpu, dtype=np.complex64)
  plan = Plan(x_gpu.shape,np.float64,np.complex128)
  skcuda.fft.fft(x_gpu, x_hat, plan)
  return x_hat.get()

然后我尝试将原始信号与fft的ifft进行比较,例如:

fft = fft_gpu_pycuda(signal)
inverse = scipy.fftpack.ifft(fft)
print('inverse matches original: %s',np.allclose(inverse, signal, atol=1e-6))

输出为:

inverse matches original: %s False

所以我认为我的fft函数有问题。任何见识将不胜感激。谢谢!

0 个答案:

没有答案