Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,192,669 members, 7,948,526 topics. Date: Saturday, 14 September 2024 at 12:07 AM |
Nairaland Forum / Science/Technology / Programming / Help With Fftw 3 Dimensional (927 Views)
Need A Developer For A Three Dimensional Store / Using 2-dimensional Array In C++ (2) (3) (4)
(1) (Reply)
Help With Fftw 3 Dimensional by nociton: 2:21pm On Jun 25, 2010 |
I am somewhat new to C and fftw but i have got the 1d and 2d transforms to work. My 3d results are wrong and I can not figure out what is wrong. Both the 3d transform results and the inverse results are 30% correct(have been checking against MatLAB) so i dont think I am too far off, maybe the way I am setting up my arrays. Any help would be appreciated. #include <stdio.h> #include <math.h> #include <complex.h> #include <fftw3.h> #include <stdlib.h> int main(void){ int n = 2; int m = 4; int p = 2; int i, j, k; double *x1; fftw_complex *x2; //////ALLOCATE MEM////////////// x1 = (double*) fftw_malloc(n*m*p*sizeof(double)); x2 = (fftw_complex*) fftw_malloc(n*m*p*sizeof(fftw_complex)); /////SET UP FFT PLANS////// fftw_plan p1=fftw_plan_dft_r2c_3d(n,m,p, x1, x2,FFTW_MEASURE); fftw_plan p2=fftw_plan_dft_c2r_3d(n,m,p, x2, x1,FFTW_MEASURE); //////CREATE INITIAL FUNCITON////// printf("\n\nINITIAL 3D ARRAY\n" for(k=0; k<p; k++){ for (i=0; i < n; i++){ for(j=0; j<m; j++){ x1[k+p*(j+m*i)]=sin(i+j*k*M_PI); printf("%lf\t", x1[k+p*(j+m*i)]); }printf("\n" }printf("\n" } printf("\n\n" //////FORWARD FFT////////////////// fftw_execute(p1); fftw_execute(p2); printf("FORWARD FFTW RESULTS\n" for(k=0; k<p; k++){ for (i=0; i<n; i++){ for(j=0; j<m; j++){ printf("%g + %gi\t", creal(x2[k+p*(j*m*i)]),cimag(x2[k+p*(j+m*i)])); }printf("\n"}printf("\n" } printf("\n\n" //////BACKWARD FFT//////// //fftw_execute(p2); printf("INVERSE FFTW RESULTS\n" for(k=0; k<p; k++){ for(i=0; i<n; i++){ for(j=0; j<m; j++){ printf("%lf\t", x1[k+p*(j*m*i)]/(n*p*m)); }printf("\n"}printf("\n" } //////DESTROY FFT PLANS/////// fftw_destroy_plan(p1); fftw_destroy_plan(p2); //////FREE FFT ALLOCATED MEM/////// fftw_free(x1); fftw_free(x2); return 0; } |
(1) (Reply)
[Help Request] How Do I Use PHP Regular Expression Functions? / 3 Issues Meganet Limited Should Fix On UNILAG Hostel Portal By Adedayo Moshood / Women Techmakers Port Harcourt Presents Code Day, 2015
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12 |