How to use pyFFTW class to do a 2 d fourier transformation?

591 Views Asked by At

I want to use pyFFTW to create a 2d fft and ifft. However, the documentations were a bit confusing: https://pyfftw.readthedocs.io/en/latest/source/tutorial.html#the-workhorse-pyfftw-fftw-class

So, essentially, the code:

a = pyfftw.empty_aligned(128, dtype='complex128')
b = pyfftw.empty_aligned(128, dtype='complex128')

fft_object = pyfftw.FFTW(a, b)

I didn't understand what is a fft_object, and why it needs a and b as input, or even what is a and b doing here. Are they just some empty templet to simulate data of input and output? what's the function of this process?

import numpy

# Generate some data
ar, ai = numpy.random.randn(2, 128)
a[:] = ar + 1j*ai

fft_a = fft_object()

I also didn't understand in which way a was transformed into fft_a, there was not even function call. How did the function knew that a was the input? (I read the whole page and found a mention in the pyfftw.builders

fft_object = pyfftw.builders.fft(a)

Still, what is fft_object defined by pyfftw.builders.fft(a)? and what were builders doing?)

Also, if fft was

pyfftw.FFTW(a, b, axes=(0,1))

would the ifft be

pyfftw.FFTW(a, b, direction='FFTW_BACKWARD', axes=(0,1))#or
pyfftw.FFTW(a, b, direction='FFTW_BACKWARD', axes=(1,0))#or
pyfftw.FFTW(b, a, direction='FFTW_BACKWARD', axes=(0,1))#or
pyfftw.FFTW(b, a, direction='FFTW_BACKWARD', axes=(1,0))

?

Suppose I have a 3 by 3 matrix x=np.ones([3,3]);

How can I do a fft2(x) and ifft2(x)?

Further, how can I do a rfft2(x) and irfft2(x)?(rfft2 and irfft2 represent fast fourier transformation in real domain).

0

There are 0 best solutions below