33 #define NFFT_PRECISION_DOUBLE
43 NFFT_R GLOBAL_elapsed_time;
62 int R2 = 2 * (int)(NFFT_M(lrint)(NFFT_M(ceil)(NFFT_M(sqrt)(NFFT_K(2.0)) * (NFFT_R)(S) / NFFT_K(2.0))));
66 for (t = -T / 2; t < T / 2; t++)
68 for (r = -R2 / 2; r < R2 / 2; r++)
70 xx = (NFFT_R) (r) / (NFFT_R)(S) * NFFT_M(cos)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
71 yy = (NFFT_R) (r) / (NFFT_R)(S) * NFFT_M(sin)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
73 if (((-NFFT_K(0.5) - NFFT_K(1.0) / (NFFT_R) S) <= xx) & (xx <= (NFFT_K(0.5) + NFFT_K(1.0) / (NFFT_R) S))
74 & ((-NFFT_K(0.5) - NFFT_K(1.0) / (NFFT_R) S) <= yy)
75 & (yy <= (NFFT_K(0.5) + NFFT_K(1.0) / (NFFT_R) S)))
81 w[M] = NFFT_K(1.0) / NFFT_K(4.0);
83 w[M] = NFFT_M(fabs)((NFFT_R) r);
92 for (t = 0; t < M; t++)
95 for (t = 0; t < M; t++)
102 static int mpolar_dft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int S,
int m)
106 NFFT(plan) my_nfft_plan;
118 x = (NFFT_R *) NFFT(malloc)((size_t)(5 * (T / 2) * S) * (
sizeof(NFFT_R)));
122 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * (T * S) / 4) * (
sizeof(NFFT_R)));
128 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
131 FFTW_MEASURE | FFTW_DESTROY_INPUT);
134 for (j = 0; j < my_nfft_plan.M_total; j++)
136 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
137 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
141 for (k = 0; k < my_nfft_plan.N_total; k++)
142 my_nfft_plan.f_hat[k] = f_hat[k];
144 t0 = NFFT(clock_gettime_seconds)();
147 NFFT(trafo_direct)(&my_nfft_plan);
149 t1 = NFFT(clock_gettime_seconds)();
150 GLOBAL_elapsed_time = (t1 - t0);
153 for (j = 0; j < my_nfft_plan.M_total; j++)
154 f[j] = my_nfft_plan.f[j];
157 NFFT(finalize)(&my_nfft_plan);
165 static int mpolar_fft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int S,
int m)
169 NFFT(plan) my_nfft_plan;
181 x = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 2) * (
sizeof(NFFT_R)));
185 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 4) * (
sizeof(NFFT_R)));
191 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
194 FFTW_MEASURE | FFTW_DESTROY_INPUT);
198 for (j = 0; j < my_nfft_plan.M_total; j++)
200 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
201 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
206 NFFT(precompute_lin_psi)(&my_nfft_plan);
208 if (my_nfft_plan.flags &
PRE_PSI)
209 NFFT(precompute_psi)(&my_nfft_plan);
212 NFFT(precompute_full_psi)(&my_nfft_plan);
215 for (k = 0; k < my_nfft_plan.N_total; k++)
216 my_nfft_plan.f_hat[k] = f_hat[k];
218 t0 = NFFT(clock_gettime_seconds)();
221 NFFT(trafo)(&my_nfft_plan);
223 t1 = NFFT(clock_gettime_seconds)();
224 GLOBAL_elapsed_time = (t1 - t0);
227 for (j = 0; j < my_nfft_plan.M_total; j++)
228 f[j] = my_nfft_plan.f[j];
231 NFFT(finalize)(&my_nfft_plan);
244 NFFT(plan) my_nfft_plan;
245 SOLVER(plan_complex) my_infft_plan;
258 x = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 2) * (
sizeof(NFFT_R)));
262 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 4) * (
sizeof(NFFT_R)));
268 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
271 FFTW_MEASURE | FFTW_DESTROY_INPUT);
274 SOLVER(init_advanced_complex)(&my_infft_plan,
278 for (j = 0; j < my_nfft_plan.M_total; j++)
280 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
281 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
282 my_infft_plan.y[j] = f[j];
283 my_infft_plan.w[j] = w[j];
288 NFFT(precompute_lin_psi)(&my_nfft_plan);
290 if (my_nfft_plan.flags &
PRE_PSI)
291 NFFT(precompute_psi)(&my_nfft_plan);
294 NFFT(precompute_full_psi)(&my_nfft_plan);
298 for (j = 0; j < my_nfft_plan.N[0]; j++)
299 for (k = 0; k < my_nfft_plan.N[1]; k++)
301 my_infft_plan.w_hat[j * my_nfft_plan.N[1] + k] = (
303 NFFT_M(pow)((NFFT_R)(j - my_nfft_plan.N[0] / 2), NFFT_K(2.0))
304 + NFFT_M(pow)((NFFT_R)(k - my_nfft_plan.N[1] / 2), NFFT_K(2.0)))
305 > (NFFT_R)(my_nfft_plan.N[0] / 2) ? NFFT_K(0.0) : NFFT_K(1.0));
309 for (k = 0; k < my_nfft_plan.N_total; k++)
310 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
312 t0 = NFFT(clock_gettime_seconds)();
315 SOLVER(before_loop_complex)(&my_infft_plan);
320 for (k = 0; k < my_nfft_plan.N_total; k++)
321 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
325 for (l = 1; l <=
max_i; l++)
327 SOLVER(loop_one_step_complex)(&my_infft_plan);
331 t1 = NFFT(clock_gettime_seconds)();
332 GLOBAL_elapsed_time = (t1 - t0);
335 for (k = 0; k < my_nfft_plan.N_total; k++)
336 f_hat[k] = my_infft_plan.f_hat_iter[k];
339 SOLVER(finalize_complex)(&my_infft_plan);
340 NFFT(finalize)(&my_nfft_plan);
351 FFTW(plan) my_fftw_plan;
354 NFFT_R t_fft, t_dft_mpolar;
356 f_hat = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
357 f = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)((T * S / 4) * 5));
359 my_fftw_plan = FFTW(plan_dft_2d)(N, N, f_hat, f, FFTW_BACKWARD, FFTW_MEASURE);
361 for (k = 0; k < N * N; k++)
362 f_hat[k] = NFFT(drand48)() + _Complex_I * NFFT(drand48)();
364 t0 = NFFT(clock_gettime_seconds)();
365 for (m = 0; m < 65536 / N; m++)
367 FFTW(execute)(my_fftw_plan);
369 f_hat[2] = NFFT_K(2.0) * f_hat[0];
371 t1 = NFFT(clock_gettime_seconds)();
372 GLOBAL_elapsed_time = (t1 - t0);
373 t_fft = (NFFT_R)(N) * GLOBAL_elapsed_time / NFFT_K(65536.0);
378 t_dft_mpolar = GLOBAL_elapsed_time;
381 for (m = 3; m <= 9; m += 3)
383 if ((m == 3) && (N < 256))
384 fprintf(fp,
"%d\t&\t&\t%1.1" NFFT__FES__
"&\t%1.1" NFFT__FES__
"&\t%d\t", N, t_fft, t_dft_mpolar, m);
386 fprintf(fp,
"%d\t&\t&\t%1.1" NFFT__FES__
"&\t &\t%d\t", N, t_fft, m);
388 fprintf(fp,
" \t&\t&\t &\t &\t%d\t", m);
390 printf(
"N=%d\tt_fft=%1.1" NFFT__FES__
"\tt_dft_mpolar=%1.1" NFFT__FES__
"\tm=%d\t", N, t_fft,
394 fprintf(fp,
"%1.1" NFFT__FES__
"&\t", GLOBAL_elapsed_time);
395 printf(
"t_mpolar=%1.1" NFFT__FES__
"\t", GLOBAL_elapsed_time);
398 fprintf(fp,
"%1.1" NFFT__FES__
"\\\\\\hline\n", GLOBAL_elapsed_time);
400 fprintf(fp,
"%1.1" NFFT__FES__
"\\\\\n", GLOBAL_elapsed_time);
401 printf(
"t_impolar=%1.1" NFFT__FES__
"\n", GLOBAL_elapsed_time);
413 int main(
int argc,
char **argv)
419 NFFT_C *f_hat, *f, *f_direct, *f_tilde;
423 NFFT_R temp1, temp2, E_max = NFFT_K(0.0);
430 printf(
"mpolar_fft_test N T R \n");
432 printf(
"N mpolar FFT of size NxN \n");
433 printf(
"T number of slopes \n");
434 printf(
"R number of offsets \n");
437 printf(
"\nHence, comparison FFTW, mpolar FFT and inverse mpolar FFT\n");
438 fp1 = fopen(
"mpolar_comparison_fft.dat",
"w");
441 for (logN = 4; logN <= 8; logN++)
443 3 * (
int)(1U << (logN - 1)));
452 printf(
"N=%d, modified polar grid with T=%d, R=%d => ", N, T, S);
454 x = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 2) * (
sizeof(NFFT_R)));
455 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * S / 4) * (
sizeof(NFFT_R)));
457 f_hat = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
458 f = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(1.25 * T * S));
459 f_direct = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(1.25 * T * S));
460 f_tilde = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
464 printf(
"M=%d.\n", M);
467 fp1 = fopen(
"input_data_r.dat",
"r");
468 fp2 = fopen(
"input_data_i.dat",
"r");
469 if ((fp1 == NULL) || (fp2 == NULL))
471 for (k = 0; k < N * N; k++)
473 fscanf(fp1, NFFT__FR__
" ", &temp1);
474 fscanf(fp2, NFFT__FR__
" ", &temp2);
475 f_hat[k] = temp1 + _Complex_I * temp2;
485 printf(
"\nTest of the mpolar FFT: \n");
486 fp1 = fopen(
"mpolar_fft_error.dat",
"w+");
487 for (m = 1; m <= 12; m++)
493 E_max = NFFT(error_l_infty_complex)(f_direct, f, M);
494 printf(
"m=%2d: E_max = %" NFFT__FES__
"\n", m, E_max);
495 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
500 for (m = 3; m <= 9; m += 3)
502 printf(
"\nTest of the inverse mpolar FFT for m=%d: \n", m);
503 sprintf(filename,
"mpolar_ifft_error%d.dat", m);
504 fp1 = fopen(filename,
"w+");
505 for (max_i = 0; max_i <= 20; max_i += 2)
511 E_max = NFFT(error_l_infty_complex)(f_hat, f_tilde, N * N);
512 printf(
"%3d iterations: E_max = %" NFFT__FES__
"\n", max_i, E_max);
513 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
523 NFFT(free)(f_direct);
static int max_i(int a, int b)
max
#define PRECOMPUTE_WEIGHT
static int inverse_mpolar_fft(NFFT_C *f, int T, int S, NFFT_C *f_hat, int NN, int max_i, int m)
inverse NFFT-based mpolar FFT
static int mpolar_fft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int S, int m)
NFFT-based mpolar FFT.
static int mpolar_dft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int S, int m)
discrete mpolar FFT
int main(int argc, char **argv)
test program for various parameters
static int mpolar_grid(int T, int S, NFFT_R *x, NFFT_R *w)
Generates the points with weights for the modified polar grid with angles and offsets...
static int comparison_fft(FILE *fp, int N, int T, int S)
Comparison of the FFTW, mpolar FFT, and inverse mpolar FFT.