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.
fft
the same? – Dan Getz