32 #define NFFT_PRECISION_DOUBLE
73 static int polar_grid(
int T,
int S, NFFT_R *x, NFFT_R *w)
76 NFFT_R W = (NFFT_R) T * (((NFFT_R) S / NFFT_K(2.0)) * ((NFFT_R) S / NFFT_K(2.0)) + NFFT_K(1.0) / NFFT_K(4.0));
78 for (t = -T / 2; t < T / 2; t++)
80 for (r = -S / 2; r < S / 2; r++)
82 x[2 * ((t + T / 2) * S + (r + S / 2)) + 0] = (NFFT_R) (r) / (NFFT_R)(S) * NFFT_M(cos)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
83 x[2 * ((t + T / 2) * S + (r + S / 2)) + 1] = (NFFT_R) (r) / (NFFT_R)(S) * NFFT_M(sin)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
85 w[(t + T / 2) * S + (r + S / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
87 w[(t + T / 2) * S + (r + S / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
95 static int polar_dft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int S,
99 NFFT(plan) my_nfft_plan;
111 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
115 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
120 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
123 FFTW_MEASURE | FFTW_DESTROY_INPUT);
127 for (j = 0; j < my_nfft_plan.M_total; j++)
129 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
130 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
134 for (k = 0; k < my_nfft_plan.N_total; k++)
135 my_nfft_plan.f_hat[k] = f_hat[k];
138 NFFT(trafo_direct)(&my_nfft_plan);
141 for (j = 0; j < my_nfft_plan.M_total; j++)
142 f[j] = my_nfft_plan.f[j];
145 NFFT(finalize)(&my_nfft_plan);
153 static int polar_fft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int S,
157 NFFT(plan) my_nfft_plan;
169 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
173 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
178 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
181 FFTW_MEASURE | FFTW_DESTROY_INPUT);
185 for (j = 0; j < my_nfft_plan.M_total; j++)
187 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
188 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
193 NFFT(precompute_lin_psi)(&my_nfft_plan);
195 if (my_nfft_plan.flags &
PRE_PSI)
196 NFFT(precompute_psi)(&my_nfft_plan);
199 NFFT(precompute_full_psi)(&my_nfft_plan);
202 for (k = 0; k < my_nfft_plan.N_total; k++)
203 my_nfft_plan.f_hat[k] = f_hat[k];
206 NFFT(trafo)(&my_nfft_plan);
209 for (j = 0; j < my_nfft_plan.M_total; j++)
210 f[j] = my_nfft_plan.f[j];
213 NFFT(finalize)(&my_nfft_plan);
222 int NN,
int max_i,
int m)
225 NFFT(plan) my_nfft_plan;
226 SOLVER(plan_complex) my_infft_plan;
239 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
243 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
248 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
251 FFTW_MEASURE | FFTW_DESTROY_INPUT);
254 SOLVER(init_advanced_complex)(&my_infft_plan,
259 for (j = 0; j < my_nfft_plan.M_total; j++)
261 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
262 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
263 my_infft_plan.y[j] = f[j];
264 my_infft_plan.w[j] = w[j];
269 NFFT(precompute_lin_psi)(&my_nfft_plan);
271 if (my_nfft_plan.flags &
PRE_PSI)
272 NFFT(precompute_psi)(&my_nfft_plan);
275 NFFT(precompute_full_psi)(&my_nfft_plan);
279 for (j = 0; j < my_nfft_plan.N[0]; j++)
280 for (k = 0; k < my_nfft_plan.N[1]; k++)
282 my_infft_plan.w_hat[j * my_nfft_plan.N[1] + k] = (
284 NFFT_M(pow)((NFFT_R) (j - my_nfft_plan.N[0] / 2), NFFT_K(2.0))
285 + NFFT_M(pow)((NFFT_R) (k - my_nfft_plan.N[1] / 2), NFFT_K(2.0)))
286 > ((NFFT_R) (my_nfft_plan.N[0] / 2)) ? 0 : 1);
290 for (k = 0; k < my_nfft_plan.N_total; k++)
291 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
294 SOLVER(before_loop_complex)(&my_infft_plan);
299 for (k = 0; k < my_nfft_plan.N_total; k++)
300 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
304 for (l = 1; l <=
max_i; l++)
306 SOLVER(loop_one_step_complex)(&my_infft_plan);
311 for (k = 0; k < my_nfft_plan.N_total; k++)
312 f_hat[k] = my_infft_plan.f_hat_iter[k];
315 SOLVER(finalize_complex)(&my_infft_plan);
316 NFFT(finalize)(&my_nfft_plan);
324 int main(
int argc,
char **argv)
330 NFFT_C *f_hat, *f, *f_direct, *f_tilde;
334 NFFT_R temp1, temp2, E_max = NFFT_K(0.0);
340 printf(
"polar_fft_test N T R \n");
342 printf(
"N polar FFT of size NxN \n");
343 printf(
"T number of slopes \n");
344 printf(
"R number of offsets \n");
351 printf(
"N=%d, polar grid with T=%d, R=%d => ", N, T, S);
353 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * 5 * (T / 2) * (S / 2)) * (
sizeof(NFFT_R)));
354 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * (T / 2) * (S / 2)) * (
sizeof(NFFT_R)));
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));
358 f_direct = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(T * S));
359 f_tilde = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
363 printf(
"M=%d.\n", M);
366 fp1 = fopen(
"input_data_r.dat",
"r");
367 fp2 = fopen(
"input_data_i.dat",
"r");
370 for (k = 0; k < N * N; k++)
372 fscanf(fp1, NFFT__FR__
" ", &temp1);
373 fscanf(fp2, NFFT__FR__
" ", &temp2);
374 f_hat[k] = temp1 + _Complex_I * temp2;
384 printf(
"\nTest of the polar FFT: \n");
385 fp1 = fopen(
"polar_fft_error.dat",
"w+");
386 for (m = 1; m <= 12; m++)
392 E_max = NFFT(error_l_infty_complex)(f_direct, f, M);
393 printf(
"m=%2d: E_max = %" NFFT__FES__
"\n", m, E_max);
394 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
399 for (m = 3; m <= 9; m += 3)
401 printf(
"\nTest of the inverse polar FFT for m=%d: \n", m);
402 sprintf(filename,
"polar_ifft_error%d.dat", m);
403 fp1 = fopen(filename,
"w+");
404 for (max_i = 0; max_i <= 100; max_i += 10)
417 E_max = NFFT(error_l_infty_complex)(f_hat, f_tilde, N * N);
418 printf(
"%3d iterations: E_max = %" NFFT__FES__
"\n", max_i, E_max);
419 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
429 NFFT(free)(f_direct);
static int max_i(int a, int b)
max
static int polar_fft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int S, int m)
NFFT-based polar FFT.
#define PRECOMPUTE_WEIGHT
static int polar_dft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int S, int m)
discrete polar FFT
static int polar_grid(int T, int S, NFFT_R *x, NFFT_R *w)
Generates the points with weights for the polar grid with angles and offsets. ...
static int inverse_polar_fft(NFFT_C *f, int T, int S, NFFT_C *f_hat, int NN, int max_i, int m)
inverse NFFT-based polar FFT
int main(int argc, char **argv)
test program for various parameters