NFFT Logo 3.0 API Reference
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

nfsft/simple_test.c

00001 /* Include standard C headers. */
00002 #include <stdio.h>
00003 #include <math.h>
00004 #include <string.h>
00005 #include <stdlib.h>
00006 
00007 /* Include NFFT3 library header. */
00008 #include "nfft3.h"
00009 
00010 /* Include NFFT 3 utilities headers. */
00011 #include "util.h"
00012 
00013 void simple_test_nfsft()
00014 {
00015   int j;                      
00016   int k;                      
00017   int n;                      
00018   nfsft_plan plan;            
00019   const int N = 8;            
00020   const int M = 8;            
00021   const int THRESHOLD = 1000; 
00024   /* Precompute. */
00025   nfsft_precompute(N,THRESHOLD,0U,0U);
00026 
00027   /* Init a transform plan using the guru interface. All arrays for input and
00028    * output variables are allocated by nfsft_init_guru(). Computations are
00029    * performed with respect to L^2-normalized spherical harmonics Y_k^n. The
00030    * array of spherical Fourier coefficients is preserved during
00031    * transformations. The internal NFFT uses a cut-off parameter of 6.
00032    */
00033   nfsft_init_guru(&plan, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F |
00034     NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT,
00035     ((N>512)?(0U):(PRE_PHI_HUT | PRE_PSI)) | FFTW_INIT |
00036     FFT_OUT_OF_PLACE, 6);
00037 
00038   /* Init pseudo random nodes. */
00039   for (j = 0; j < plan.M_total; j++)
00040   {
00041     plan.x[2*j]=((double)rand())/RAND_MAX-0.5;
00042     plan.x[2*j+1]=0.5*((double)rand())/RAND_MAX;
00043   }
00044 
00045   /* Do precomputation for nodes. */
00046   nfsft_precompute_x(&plan);
00047 
00048   /* Init pseudo random Fourier coefficients. */
00049   for (k = 0; k <= plan.N; k++)
00050   {
00051     for (n = -k; n <= k; n++)
00052     {
00053       plan.f_hat[NFSFT_INDEX(k,n,&plan)] =
00054         ((double)rand())/RAND_MAX - 0.5 +  I*(((double)rand())/RAND_MAX - 0.5);
00055     }
00056   }
00057 
00058   /*for (k = 0; k < plan.N_total; k++)
00059   {
00060      fprintf(stderr,"f_hat[%d] = %le +I*%le\n",k,creal(plan.f_hat[k]),
00061        cimag(plan.f_hat[k]));
00062   }*/
00063 
00064   //nfft_vpr_complex(plan.f_hat,plan.N_total,"given Fourier coefficients, vector f_hat");
00065 
00066   /* Compute direct transformation and display the result. */
00067   ndsft_trafo(&plan);
00068   nfft_vpr_complex(plan.f,plan.M_total,"ndsft, vector f");
00069 
00070   /* Compute approximate transformation and display the result. */
00071   nfsft_trafo(&plan);
00072   nfft_vpr_complex(plan.f, plan.M_total,"nfsft, vector f");
00073   /*for (k = 0; k < plan.N_total; k++)
00074   {
00075      fprintf(stderr,"f_hat[%d] = %le +I*%le\n",k,creal(plan.f_hat[k]),
00076        cimag(plan.f_hat[k]));
00077   }*/
00078 
00079   /* Compute direct adjoint transformation and display the result. */
00080   nfsft_adjoint(&plan);
00081   for (k = 0; k <= plan.N; k++)
00082   {
00083     for (n = -k; n <= k; n++)
00084     {
00085       fprintf(stdout,"f_hat[%d,%d] = %le + I*%le\n",k,n,
00086         creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]),
00087         cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)]));
00088     }
00089   }
00090   //nfft_vpr_complex(plan.f_hat,plan.N_total,"adjoint ndsft, vector f_hat");
00091 
00092   /* COmpute approximate adjoint transformation and display the result */
00093   ndsft_adjoint(&plan);
00094   for (k = 0; k <= plan.N; k++)
00095   {
00096     for (n = -k; n <= k; n++)
00097     {
00098       fprintf(stdout,"f_hat[%d,%d] = %le + I*%le\n",k,n,
00099         creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]),
00100         cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)]));
00101     }
00102   }
00103   //nfft_vpr_complex(plan.f_hat,plan.N_total,"adjoint nfsft, vector f_hat");
00104 
00105   /* Finalise the plan. */
00106   nfsft_finalize(&plan);
00107   nfsft_forget();
00108 }
00109 
00110 int main()
00111 {
00112   system("clear");
00113   printf("1) computing a ndsft, a nfsft, an adjoint ndsft, and an adjoint nfsft\n\n");
00114   simple_test_nfsft();
00115 
00116   return EXIT_SUCCESS;
00117 }

Generated on 1 Nov 2006 by Doxygen 1.4.4