0
votes

This may seem like a simple question but I've been trying to find the answer on the FFTW page and I am unable to.

I created the FFTW plans for forward and backward transforms and I fed some data into the fftw_complex *fft structure directly (instead of computing an FFT from input data first). Then I compute an IFFT on this and the result is not correct. Am I doing this right?

EDIT: So what I did is the following:

int ht=2, wd=2;
fftw_complex *inp  = fftw_alloc_complex(ht * wd);
fftw_complex *fft  = fftw_alloc_complex(ht * wd);
fftw_complex *ifft = fftw_alloc_complex(ht * wd);

fftw_plan plan_f = fftw_plan_dft_1d(wd *ht, inp, fft,  FFTW_FORWARD,  FFTW_ESTIMATE);
fftw_plan plan_b = fftw_plan_dft_1d(wd * ht, fft, ifft, FFTW_BACKWARD, FFTW_ESTIMATE );

for(int i =0 ; i < 2; i++)
{
    for(int j = 0; j<2; j++)
    {
        inp[wd*i + j][0] = 1.0;
        inp[wd*i + j][1] = 0.0;
    }
}

//    fftw_execute(plan_f);

for(int i =0 ; i < 2; i++)
{
    for(int j = 0; j<2; j++)
    {
        fft[wd*i + j][1] = 0.0;
        if(i == j == 0)
            fft[wd*i+j][0] = 4.0;
        else
            fft[wd*i+j][0] = 0.0;

        std::cout << fft[wd*i+j][0] << " and " << fft[wd*i+j][1] << std::endl;
    }
}

fftw_execute(plan_b);
for(int i =0 ; i < 2; i++)
{
    for(int j = 0; j<2; j++)
        std::cout << ifft[wd*i+j][0]/(double)(wd*ht) << " and " << ifft[wd*i+j][1]/(double)(wd*ht) << std::endl;
}

This is the full code. The ifft should return [1 1 1 1] for the real part. It doesn't.

1
Yes, it's completely valid to compute just an IFFT. Without seeing a minimal test-case, it's hard to say what you might be doing wrong.Oliver Charlesworth
"the result is not correct" -- what result are you expecting and what did you get instead ? Where is you data coming from ? Is it already in the frequency domain ?Paul R
I have made some edits - hope that is useful. Thanks in advance!user3936766
Yes, sorry about that - doing a ton of editing right now. Hopefully everything is fixed - I copied from my code base.user3936766
So you leave the complex part of fft the same?Dan Getz

1 Answers

0
votes

I did the stupidest thing - in the if condition I posted:

i == j == 0

instead of i ==0 && j == 0

when I fixed that, it works. Thank you all so much for helping me out.