0

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.

  • 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 Aug 13 '14 at 09:41
  • "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 Aug 13 '14 at 09:41
  • I have made some edits - hope that is useful. Thanks in advance! –  Aug 13 '14 at 10:01
  • Yes, sorry about that - doing a ton of editing right now. Hopefully everything is fixed - I copied from my code base. –  Aug 13 '14 at 10:05
  • So you leave the complex part of `fft` the same? – Dan Getz Aug 13 '14 at 10:34
  • Yes, I do so. Will that be a problem? –  Aug 13 '14 at 10:37
  • Well, are you expecting the complex part to not influence any values of of `ifft`? – Dan Getz Aug 13 '14 at 11:04
  • You seem to be describing what amounts to a small, simple test case you've written. Why not just post that as code that others can run (after verifying that it really does reproduce the problem you have)? What you've posted leaves out a few things. – Dan Getz Aug 13 '14 at 11:07
  • Hi, I have now posted the simple example I am running and which doesn't report the correct result for some reason. Thank you for helping so much. –  Aug 13 '14 at 13:06

1 Answers1

0

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.