![]() |
NFFT
3.3.2
|
00001 /* 00002 * Copyright (c) 2002, 2016 Jens Keiner, Stefan Kunis, Daniel Potts 00003 * 00004 * This program is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU General Public License as published by the Free Software 00006 * Foundation; either version 2 of the License, or (at your option) any later 00007 * version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU General Public License along with 00015 * this program; if not, write to the Free Software Foundation, Inc., 51 00016 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 /* standard headers */ 00020 #include <stdio.h> 00021 #include <math.h> 00022 #include <string.h> 00023 #include <stdlib.h> 00024 /* It is important to include complex.h before nfft3.h. */ 00025 #include <complex.h> 00026 00027 #include "nfft3.h" /* NFFT3 header */ 00028 00029 #define __FES__ "E" 00030 #define K(x) ((double) x) 00031 00032 static void simple_test_nfsft(void) 00033 { 00034 const int N = 4; /* bandwidth/maximum degree */ 00035 const int M = 8; /* number of nodes */ 00036 nfsft_plan plan; /* transform plan */ 00037 int j, k, n; /* loop variables */ 00038 00039 /* precomputation (for fast polynomial transform) */ 00040 nfsft_precompute(N,1000.0,0U,0U); 00041 00042 /* Initialize transform plan using the guru interface. All input and output 00043 * arrays are allocated by nfsft_init_guru(). Computations are performed with 00044 * respect to L^2-normalized spherical harmonics Y_k^n. The array of spherical 00045 * Fourier coefficients is preserved during transformations. The NFFT uses a 00046 * cut-off parameter m = 6. See the NFFT 3 manual for details. 00047 */ 00048 nfsft_init_guru(&plan, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F | 00049 NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT, 00050 PRE_PHI_HUT | PRE_PSI | FFTW_INIT | FFT_OUT_OF_PLACE, 6); 00051 00052 /* pseudo-random nodes */ 00053 for (j = 0; j < plan.M_total; j++) 00054 { 00055 plan.x[2*j]= nfft_drand48() - K(0.5); 00056 plan.x[2*j+1]= K(0.5) * nfft_drand48(); 00057 } 00058 00059 /* precomputation (for NFFT, node-dependent) */ 00060 nfsft_precompute_x(&plan); 00061 00062 /* pseudo-random Fourier coefficients */ 00063 for (k = 0; k <= plan.N; k++) 00064 for (n = -k; n <= k; n++) 00065 plan.f_hat[NFSFT_INDEX(k,n,&plan)] = 00066 nfft_drand48() - K(0.5) + _Complex_I*(nfft_drand48() - K(0.5)); 00067 00068 /* Direct transformation, display result. */ 00069 nfsft_trafo_direct(&plan); 00070 printf("Vector f (NDSFT):\n"); 00071 for (j = 0; j < plan.M_total; j++) 00072 printf("f[%+2d] = %+5.3" __FES__ " %+5.3" __FES__ "*I\n",j, 00073 creal(plan.f[j]), cimag(plan.f[j])); 00074 00075 printf("\n"); 00076 00077 /* Fast approximate transformation, display result. */ 00078 nfsft_trafo(&plan); 00079 printf("Vector f (NFSFT):\n"); 00080 for (j = 0; j < plan.M_total; j++) 00081 printf("f[%+2d] = %+5.3" __FES__ " %+5.3" __FES__ "*I\n",j, 00082 creal(plan.f[j]), cimag(plan.f[j])); 00083 00084 printf("\n"); 00085 00086 /* Direct adjoint transformation, display result. */ 00087 nfsft_adjoint_direct(&plan); 00088 printf("Vector f_hat (NDSFT):\n"); 00089 for (k = 0; k <= plan.N; k++) 00090 for (n = -k; n <= k; n++) 00091 fprintf(stdout,"f_hat[%+2d,%+2d] = %+5.3" __FES__ " %+5.3" __FES__ "*I\n",k,n, 00092 creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]), 00093 cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)])); 00094 00095 printf("\n"); 00096 00097 /* Fast approximate adjoint transformation, display result. */ 00098 nfsft_adjoint(&plan); 00099 printf("Vector f_hat (NFSFT):\n"); 00100 for (k = 0; k <= plan.N; k++) 00101 { 00102 for (n = -k; n <= k; n++) 00103 { 00104 fprintf(stdout,"f_hat[%+2d,%+2d] = %+5.3" __FES__ " %+5.3" __FES__ "*I\n",k,n, 00105 creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]), 00106 cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)])); 00107 } 00108 } 00109 00110 /* Finalize the plan. */ 00111 nfsft_finalize(&plan); 00112 00113 /* Destroy data precomputed for fast polynomial transform. */ 00114 nfsft_forget(); 00115 } 00116 00117 int main(void) 00118 { 00119 printf("Computing an NDSFT, an NFSFT, an adjoint NDSFT, and an adjoint NFSFT" 00120 "...\n\n"); 00121 simple_test_nfsft(); 00122 return EXIT_SUCCESS; 00123 }