hi, I am using fftw for doing some stuff. i m trying to do the following but get 0 as output .can someone please tell me where am i going wrong. ///////////////////////CODE BEGINS HERE///////////////////////////////////// #include <stdlib.h> #include<math.h> #include <fftw3.h> int main() { int N = 256; fftw_complex *out; double **in; fftw_plan p; in = malloc(N*sizeof(double*));/*input*/ out = fftw_malloc(sizeof(double)*(N)); /*output complex type*/ p = fftw_plan_dft_r2c_1d(N,in,out,FFTW_ESTIMATE); int i; for (i = 0; i < (N); i++) { in[i] = malloc(N*sizeof(double)); in[i][0] = sin(i / 10.0 * M_PI); /* Real part */ in[i][1] = 0.0; /* Imaginary part */ } fftw_execute(p); /* repeat as needed */ for (i = 0; i < N/2+1; i++) printf("H0 %d: %f\n", i, out[i][0]); fftw_free(in); fftw_free(out); fftw_destroy_plan(p); } ////////////////////END//////////////////////////////////// thanks in advance sunderam
help with r2c
Started by ●October 26, 2005
Reply by ●October 27, 20052005-10-27
it appears u have problems understanding basic program flow .....try this ///////////////////////CODE BEGINS HERE//////////////////////////////////////// #include <stdlib.h> #include <math.h> #include <fftw3.h> int main() { int N = 256; fftw_complex *out; double **in; fftw_plan p; int i; in = malloc(N*sizeof(double*));/*input*/ out = fftw_malloc(sizeof(double)*(N)); /*output complex type*/ for (i = 0; i < (N); i++) { in[i] = malloc(N*sizeof(double)); in[i][0] = sin(i / 10.0 * M_PI); /* Real part */ in[i][1] = 0.0; /* Imaginary part */ } p = fftw_plan_dft_r2c_1d(N,in,out,FFTW_ESTIMATE); fftw_execute(p); /* repeat as needed */ for (i = 0; i < N/2+1; i++) printf("H0 %d: %f\n", i, out[i][0]); fftw_free(in); fftw_free(out); fftw_destroy_plan(p); return 0; } //////////////////////////////////END/////////////////////////////////////////
Reply by ●November 7, 20052005-11-07
You need to allocate your variables and free them correctly #include <stdlib.h> #include <math.h> #include <fftw3.h> int main() { int N = 256; fftw_complex *out; double *in; fftw_plan p; int i; in = malloc(N*sizeof(double*));/*input*/ out = fftw_malloc(sizeof(fftw_complex)*(N)); /*output complex type*/ for (i = 0; i < (N); i++) { in = malloc(N*sizeof(double)); in[i] = sin(i / 10.0 * M_PI); /* Real part */ } p = fftw_plan_dft_r2c_1d(N,in,out,FFTW_ESTIMATE); fftw_execute(p); /* repeat as needed */ for (i = 0; i < N/2+1; i++) printf("H0 %d: %f\n", i, out[i][0]); free(in); fftw_free(out); fftw_destroy_plan(p); return 0; }