32 #define NFFT_PRECISION_DOUBLE
42 NFFT_R GLOBAL_elapsed_time;
50 NFFT_R W = (NFFT_R) T * (((NFFT_R) rr / NFFT_K(2.0)) * ((NFFT_R) rr / NFFT_K(2.0)) + NFFT_K(1.0) / NFFT_K(4.0));
52 for (t = -T / 2; t < T / 2; t++)
54 for (r = -rr / 2; r < rr / 2; r++)
58 x[2 * ((t + T / 2) * rr + (r + rr / 2)) + 0] = (NFFT_R) (r) / (NFFT_R)(rr);
59 x[2 * ((t + T / 2) * rr + (r + rr / 2)) + 1] = NFFT_K(4.0) * ((NFFT_R)(t) + (NFFT_R)(T) / NFFT_K(4.0)) / (NFFT_R)(T)
60 * (NFFT_R)(r) / (NFFT_R)(rr);
64 x[2 * ((t + T / 2) * rr + (r + rr / 2)) + 0] = -NFFT_K(4.0) * ((NFFT_R)(t) - (NFFT_R)(T) / NFFT_K(4.0)) / (NFFT_R)(T)
65 * (NFFT_R)(r) / (NFFT_R)(rr);
66 x[2 * ((t + T / 2) * rr + (r + rr / 2)) + 1] = (NFFT_R) r / (NFFT_R)(rr);
69 w[(t + T / 2) * rr + (r + rr / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
71 w[(t + T / 2) * rr + (r + rr / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
79 static int linogram_dft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int rr,
int m)
83 NFFT(plan) my_nfft_plan;
95 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * rr) * (
sizeof(NFFT_R)));
99 w = (NFFT_R *) NFFT(malloc)((size_t)(T * rr) * (
sizeof(NFFT_R)));
104 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
107 FFTW_MEASURE | FFTW_DESTROY_INPUT);
111 for (j = 0; j < my_nfft_plan.M_total; j++)
113 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
114 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
118 for (k = 0; k < my_nfft_plan.N_total; k++)
119 my_nfft_plan.f_hat[k] = f_hat[k];
122 t0 = NFFT(clock_gettime_seconds)();
123 NFFT(trafo_direct)(&my_nfft_plan);
124 t1 = NFFT(clock_gettime_seconds)();
125 GLOBAL_elapsed_time = (t1 - t0);
128 for (j = 0; j < my_nfft_plan.M_total; j++)
129 f[j] = my_nfft_plan.f[j];
132 NFFT(finalize)(&my_nfft_plan);
140 static int linogram_fft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int rr,
int m)
144 NFFT(plan) my_nfft_plan;
156 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * rr) * (
sizeof(NFFT_R)));
160 w = (NFFT_R *) NFFT(malloc)((size_t)(T * rr) * (
sizeof(NFFT_R)));
165 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
168 FFTW_MEASURE | FFTW_DESTROY_INPUT);
172 for (j = 0; j < my_nfft_plan.M_total; j++)
174 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
175 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
180 NFFT(precompute_lin_psi)(&my_nfft_plan);
182 if (my_nfft_plan.flags &
PRE_PSI)
183 NFFT(precompute_psi)(&my_nfft_plan);
186 NFFT(precompute_full_psi)(&my_nfft_plan);
189 for (k = 0; k < my_nfft_plan.N_total; k++)
190 my_nfft_plan.f_hat[k] = f_hat[k];
193 t0 = NFFT(clock_gettime_seconds)();
194 NFFT(trafo)(&my_nfft_plan);
195 t1 = NFFT(clock_gettime_seconds)();
196 GLOBAL_elapsed_time = (t1 - t0);
199 for (j = 0; j < my_nfft_plan.M_total; j++)
200 f[j] = my_nfft_plan.f[j];
203 NFFT(finalize)(&my_nfft_plan);
216 NFFT(plan) my_nfft_plan;
217 SOLVER(plan_complex) my_infft_plan;
230 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * rr) * (
sizeof(NFFT_R)));
234 w = (NFFT_R *) NFFT(malloc)((size_t)(T * rr) * (
sizeof(NFFT_R)));
239 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
242 FFTW_MEASURE | FFTW_DESTROY_INPUT);
245 SOLVER(init_advanced_complex)(&my_infft_plan,
250 for (j = 0; j < my_nfft_plan.M_total; j++)
252 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
253 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
254 my_infft_plan.y[j] = f[j];
255 my_infft_plan.w[j] = w[j];
260 NFFT(precompute_lin_psi)(&my_nfft_plan);
262 if (my_nfft_plan.flags &
PRE_PSI)
263 NFFT(precompute_psi)(&my_nfft_plan);
266 NFFT(precompute_full_psi)(&my_nfft_plan);
270 for (j = 0; j < my_nfft_plan.N[0]; j++)
271 for (k = 0; k < my_nfft_plan.N[1]; k++)
273 my_infft_plan.w_hat[j * my_nfft_plan.N[1] + k] = (
275 NFFT_M(pow)((NFFT_R)(j - my_nfft_plan.N[0] / 2), NFFT_K(2.0))
276 + NFFT_M(pow)((NFFT_R)(k - my_nfft_plan.N[1] / 2), NFFT_K(2.0)))
277 > (NFFT_R)(my_nfft_plan.N[0] / 2) ? 0 : 1);
281 for (k = 0; k < my_nfft_plan.N_total; k++)
282 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
284 t0 = NFFT(clock_gettime_seconds)();
286 SOLVER(before_loop_complex)(&my_infft_plan);
291 for (k = 0; k < my_nfft_plan.N_total; k++)
292 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
296 for (l = 1; l <=
max_i; l++)
298 SOLVER(loop_one_step_complex)(&my_infft_plan);
302 t1 = NFFT(clock_gettime_seconds)();
303 GLOBAL_elapsed_time = (t1 - t0);
306 for (k = 0; k < my_nfft_plan.N_total; k++)
307 f_hat[k] = my_infft_plan.f_hat_iter[k];
310 SOLVER(finalize_complex)(&my_infft_plan);
311 NFFT(finalize)(&my_nfft_plan);
322 FFTW(plan) my_fftw_plan;
325 NFFT_R t_fft, t_dft_linogram;
327 f_hat = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
328 f = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)((T * rr / 4) * 5));
330 my_fftw_plan = FFTW(plan_dft_2d)(N, N, f_hat, f, FFTW_BACKWARD, FFTW_MEASURE);
332 for (k = 0; k < N * N; k++)
333 f_hat[k] = NFFT(drand48)() + _Complex_I * NFFT(drand48)();
335 t0 = NFFT(clock_gettime_seconds)();
336 for (m = 0; m < 65536 / N; m++)
338 FFTW(execute)(my_fftw_plan);
340 f_hat[2] = NFFT_K(2.0) * f_hat[0];
342 t1 = NFFT(clock_gettime_seconds)();
343 GLOBAL_elapsed_time = (t1 - t0);
344 t_fft = (NFFT_R)(N) * GLOBAL_elapsed_time / NFFT_K(65536.0);
349 t_dft_linogram = GLOBAL_elapsed_time;
352 for (m = 3; m <= 9; m += 3)
354 if ((m == 3) && (N < 256))
355 fprintf(fp,
"%d\t&\t&\t%1.1" NFFT__FES__
"&\t%1.1" NFFT__FES__
"&\t%d\t", N, t_fft, t_dft_linogram,
358 fprintf(fp,
"%d\t&\t&\t%1.1" NFFT__FES__
"&\t &\t%d\t", N, t_fft, m);
360 fprintf(fp,
" \t&\t&\t &\t &\t%d\t", m);
362 printf(
"N=%d\tt_fft=%1.1" NFFT__FES__
"\tt_dft_linogram=%1.1" NFFT__FES__
"\tm=%d\t", N, t_fft,
366 fprintf(fp,
"%1.1" NFFT__FES__
"&\t", GLOBAL_elapsed_time);
367 printf(
"t_linogram=%1.1" NFFT__FES__
"\t", GLOBAL_elapsed_time);
370 fprintf(fp,
"%1.1" NFFT__FES__
"\\\\\\hline\n", GLOBAL_elapsed_time);
372 fprintf(fp,
"%1.1" NFFT__FES__
"\\\\\n", GLOBAL_elapsed_time);
373 printf(
"t_ilinogram=%1.1" NFFT__FES__
"\n", GLOBAL_elapsed_time);
385 int main(
int argc,
char **argv)
391 NFFT_C *f_hat, *f, *f_direct, *f_tilde;
395 NFFT_R temp1, temp2, E_max = NFFT_K(0.0);
402 printf(
"linogram_fft_test N T R \n");
404 printf(
"N linogram FFT of size NxN \n");
405 printf(
"T number of slopes \n");
406 printf(
"R number of offsets \n");
409 printf(
"\nHence, comparison FFTW, linogram FFT and inverse linogram FFT\n");
410 fp1 = fopen(
"linogram_comparison_fft.dat",
"w");
413 for (logN = 4; logN <= 8; logN++)
415 3 * (
int)(1U << (logN - 1)));
424 printf(
"N=%d, linogram grid with T=%d, R=%d => ", N, T, rr);
426 x = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * rr / 2) * (
sizeof(NFFT_R)));
427 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * T * rr / 4) * (
sizeof(NFFT_R)));
429 f_hat = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
430 f = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(5 * T * rr / 4));
431 f_direct = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(5 * T * rr / 4));
432 f_tilde = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
436 printf(
"M=%d.\n", M);
439 fp1 = fopen(
"input_data_r.dat",
"r");
440 fp2 = fopen(
"input_data_i.dat",
"r");
441 if ((fp1 == NULL) || (fp2 == NULL))
443 for (k = 0; k < N * N; k++)
445 fscanf(fp1, NFFT__FR__
" ", &temp1);
446 fscanf(fp2, NFFT__FR__
" ", &temp2);
447 f_hat[k] = temp1 + _Complex_I * temp2;
457 printf(
"\nTest of the linogram FFT: \n");
458 fp1 = fopen(
"linogram_fft_error.dat",
"w+");
459 for (m = 1; m <= 12; m++)
465 E_max = NFFT(error_l_infty_complex)(f_direct, f, M);
468 printf(
"m=%2d: E_max = %" NFFT__FES__
"\n", m, E_max);
469 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
474 for (m = 3; m <= 9; m += 3)
476 printf(
"\nTest of the inverse linogram FFT for m=%d: \n", m);
477 sprintf(filename,
"linogram_ifft_error%d.dat", m);
478 fp1 = fopen(filename,
"w+");
479 for (max_i = 0; max_i <= 20; max_i += 2)
485 E_max = NFFT(error_l_infty_complex)(f_hat, f_tilde, N * N);
486 printf(
"%3d iterations: E_max = %" NFFT__FES__
"\n", max_i, E_max);
487 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
497 NFFT(free)(f_direct);
static int max_i(int a, int b)
max
#define PRECOMPUTE_WEIGHT
static int inverse_linogram_fft(NFFT_C *f, int T, int rr, NFFT_C *f_hat, int NN, int max_i, int m)
NFFT-based inverse pseudo-polar FFT.
int main(int argc, char **argv)
test program for various parameters
static int linogram_dft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int rr, int m)
discrete pseudo-polar FFT
static int comparison_fft(FILE *fp, int N, int T, int rr)
Comparison of the FFTW, linogram FFT, and inverse linogram FFT.
static int linogram_fft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int rr, int m)
NFFT-based pseudo-polar FFT.
static int linogram_grid(int T, int rr, NFFT_R *x, NFFT_R *w)
Generates the points x with weights w for the linogram grid with T slopes and R offsets.