3
votes

2D FFT/IFFT implementation with FFTW.

Currently I have an image loaded in using SFML and have decomposed it into its magnitude and phase components with fftw_plan_dft_2d.

This went okay and I've checked my magnitude image against known working software and the results are correct. (Forward FFT)

I've checked that the ifft is working by directly performing an inverse 2D FFT straight out of the forward FFT (Inverse FFT) using the real and imaginary output from the first FFT (there are problems with that as well somewhere, but that's for another day)

I'm more interested in the way I should recombine the magnitude and phase to form the real and complex parts in order to perform the IFFT.

Google returns a lot of MATLAB stuff, which I do not understand at all, thus doesn't really help.

Side note: Math is not my strong suit. Which is why I think I'm struggling a bit. Please explain like I'm a 10 year old if possible!

1
What do you mean by "the way I should recombine the magnitude and phase to form the real and complex parts in order to perform the IFFT?" Are you saying you want to do this by hand rather than using FFTW's implementation? (Why?) Are you saying you don't know which function to use? Are you saying you want to manipulate them first and then use FFTW's IFFT? (Note that the FFT is just a fast algorithm for the DFT. You can google formulae for the I/DFT, which is simpler to describe than the FFT, e.g., here.) - metal
I meant that I thought real and complex values are required for the inverse FFT, however all I had were the magnitude and the phase values. Paul's answer is what I was looking for, how to get the real and imaginary components back from the magnitude and phase. - finlaybob

1 Answers

4
votes

First you convert your magnitude and phase values back to complex (real + imaginary):

re = mag * cos(phi);
im = mag * sin(phi);

Then you do an inverse FFT on these complex values.