Search - User list
Full Version: Fftw Transforms, 0,1,2,3 -> r2c-c2r -> 0,0,0,0 ?
Root » Houdini Lounge » Fftw Transforms, 0,1,2,3 -> r2c-c2r -> 0,0,0,0 ?
madjestic
Hi there,

I am trying to learn to handle properly the fftw library routines, more specifically fftw_plan_dft_r2c_1d (2d) real-to-complex forward and backward transforms. See the simple code – it looks like the whole thing works, however the input data of the array (0,1,2,3…9) turns into zeros after the transform. The in-place transform also results in all zeros. (I assume that forward-backward transform of arbitrary data must result in original unchanged data). Or am I missing something? Does anybody have experience with this and maybe can share a simple piece of code?
#include <cstdlib>
#include <fftw3.h>
#include <stdio.h>

using namespace std;
int main(int argc, char *argv)
{
fftw_plan pf, pb;
int N=10, i, j;
fftw_complex *data, array;
double *data_d, array_d;

data = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
data = array;

data_d = (double*) fftw_malloc(sizeof(fftw_complex) * N);
data_d = array_d;

for(i=0;i<N;i++){array_d=i;}

cout <<“******pointer *data_d values*********” << endl;
for(i=0;i<N;i++)cout<< data_d<< endl;

cout <<“******FFT Forward transform*********” << endl;
pf = fftw_plan_dft_r2c_1d(N, data_d, data, FFTW_FORWARD); fftw_execute(pf);
for(i=0;i<N;i++)cout<< data<< endl;

cout <<“*****FFT Backward transform********” << endl;
pb = fftw_plan_dft_c2r_1d(N, data, data_d, FFTW_BACKWARD); fftw_execute(pb);
for(i=0;i<N;i++)cout<< data_d<< endl;

return EXIT_SUCCESS;
}

thanks
Cano_Saiso
from your code here…

pf = fftw_plan_dft_r2c_1d(N, data_d, data, FFTW_FORWARD); fftw_execute(pf);
for(i=0;i<N;i++)cout<< data<< endl;

cout <<“*****FFT Backward transform********” << endl;
pb = fftw_plan_dft_c2r_1d(N, data, data_d, FFTW_BACKWARD);

I have read the instruction of fftw

it said that “fftw_plan_dft_r2c_1d” is always forward
and “fftw_plan_dft_c2r_1d” is always backward

so I think that your new code should be this one


pf = fftw_plan_dft_r2c_1d(N, data_d, data, FFTW_ESTIMATE); fftw_execute(pf);
for(i=0;i<N;i++)cout<< data<< endl;

cout <<“*****FFT Backward transform********” << endl;
pb = fftw_plan_dft_c2r_1d(N, data, data_d, FFTW_ESTIMATE);


It may works ))))))

Cano
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB