I am using pyfftw for a simple fft. I am unsure how to use pyfftw because I am getting the error:
KeyError Traceback (most recent call last)
pyfftw\pyfftw.pyx in pyfftw.pyfftw.FFTW.__cinit__()
KeyError: (dtype('float64'), dtype('float64'))
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-31-dc32579f60f3> in <module>()
3 start = time.time()
4 b4 = numpy.zeros_like(a)
----> 5 fft = pyfftw.FFTW( a, b4, direction='FFTW_FORWARD', flags=('FFTW_MEASURE', ), threads=nthread, planning_timelimit=None )
6 fft()
7 end4 = time.time() - start
pyfftw\pyfftw.pyx in pyfftw.pyfftw.FFTW.__cinit__()
ValueError: Invalid scheme: The output array and input array dtypes do not correspond to a valid fftw scheme.
This is the code im using:
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) )
import time
import numpy
import pyfftw
import multiprocessing
nthread = multiprocessing.cpu_count()
a = signal
pyfftw.forget_wisdom()
start = time.time()
b4 = numpy.zeros_like(a)
fft = pyfftw.FFTW( a, b4, direction='FFTW_FORWARD', flags=('FFTW_MEASURE', ), threads=nthread, planning_timelimit=None )
fft()
end4 = time.time() - start
print(end4)
Any insight on why this isnt working would be greatly appreciated
You may want to use complex128 as the output type, since the DFT of a real-valued signal is complex-valued in general (unless the real-valued signal is symmetric).
See https://hgomersall.github.io/pyFFTW/pyfftw/pyfftw.html#scheme-table