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,
126 for (j = 0; j < my_nfft_plan.M_total; j++)
128 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
129 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
133 for (k = 0; k < my_nfft_plan.N_total; k++)
134 my_nfft_plan.f_hat[k] = f_hat[k];
137 NFFT(trafo_direct)(&my_nfft_plan);
140 for (j = 0; j < my_nfft_plan.M_total; j++)
141 f[j] = my_nfft_plan.f[j];
144 NFFT(finalize)(&my_nfft_plan);
152 static int polar_fft(NFFT_C *f_hat,
int NN, NFFT_C *f,
int T,
int S,
156 NFFT(plan) my_nfft_plan;
168 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
172 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
177 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
180 FFTW_MEASURE | FFTW_DESTROY_INPUT);
184 for (j = 0; j < my_nfft_plan.M_total; j++)
186 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
187 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
192 NFFT(precompute_lin_psi)(&my_nfft_plan);
194 if (my_nfft_plan.flags &
PRE_PSI)
195 NFFT(precompute_psi)(&my_nfft_plan);
198 NFFT(precompute_full_psi)(&my_nfft_plan);
201 for (k = 0; k < my_nfft_plan.N_total; k++)
202 my_nfft_plan.f_hat[k] = f_hat[k];
205 NFFT(trafo)(&my_nfft_plan);
208 for (j = 0; j < my_nfft_plan.M_total; j++)
209 f[j] = my_nfft_plan.f[j];
212 NFFT(finalize)(&my_nfft_plan);
221 int NN,
int max_i,
int m)
224 NFFT(plan) my_nfft_plan;
225 SOLVER(plan_complex) my_infft_plan;
238 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
242 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
247 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, m,
250 FFTW_MEASURE | FFTW_DESTROY_INPUT);
253 SOLVER(init_advanced_complex)(&my_infft_plan,
258 for (j = 0; j < my_nfft_plan.M_total; j++)
260 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
261 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
262 my_infft_plan.y[j] = f[j];
263 my_infft_plan.w[j] = w[j];
268 NFFT(precompute_lin_psi)(&my_nfft_plan);
270 if (my_nfft_plan.flags &
PRE_PSI)
271 NFFT(precompute_psi)(&my_nfft_plan);
274 NFFT(precompute_full_psi)(&my_nfft_plan);
278 for (j = 0; j < my_nfft_plan.N[0]; j++)
279 for (k = 0; k < my_nfft_plan.N[1]; k++)
281 my_infft_plan.w_hat[j * my_nfft_plan.N[1] + k] = (
283 NFFT_M(pow)((NFFT_R) (j - my_nfft_plan.N[0] / 2), NFFT_K(2.0))
284 + NFFT_M(pow)((NFFT_R) (k - my_nfft_plan.N[1] / 2), NFFT_K(2.0)))
285 > ((NFFT_R) (my_nfft_plan.N[0] / 2)) ? 0 : 1);
289 for (k = 0; k < my_nfft_plan.N_total; k++)
290 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
293 SOLVER(before_loop_complex)(&my_infft_plan);
298 for (k = 0; k < my_nfft_plan.N_total; k++)
299 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
303 for (l = 1; l <=
max_i; l++)
305 SOLVER(loop_one_step_complex)(&my_infft_plan);
310 for (k = 0; k < my_nfft_plan.N_total; k++)
311 f_hat[k] = my_infft_plan.f_hat_iter[k];
314 SOLVER(finalize_complex)(&my_infft_plan);
315 NFFT(finalize)(&my_nfft_plan);
323 int main(
int argc,
char **argv)
329 NFFT_C *f_hat, *f, *f_direct, *f_tilde;
333 NFFT_R temp1, temp2, E_max = NFFT_K(0.0);
339 printf(
"polar_fft_test N T R \n");
341 printf(
"N polar FFT of size NxN \n");
342 printf(
"T number of slopes \n");
343 printf(
"R number of offsets \n");
350 printf(
"N=%d, polar grid with T=%d, R=%d => ", N, T, S);
352 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * 5 * (T / 2) * (S / 2)) * (
sizeof(NFFT_R)));
353 w = (NFFT_R *) NFFT(malloc)((size_t)(5 * (T / 2) * (S / 2)) * (
sizeof(NFFT_R)));
355 f_hat = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
356 f = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(T * S));
357 f_direct = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(T * S));
358 f_tilde = (NFFT_C *) NFFT(malloc)(
sizeof(NFFT_C) * (
size_t)(N * N));
362 printf(
"M=%d.\n", M);
365 fp1 = fopen(
"input_data_r.dat",
"r");
366 fp2 = fopen(
"input_data_i.dat",
"r");
369 for (k = 0; k < N * N; k++)
371 fscanf(fp1, NFFT__FR__
" ", &temp1);
372 fscanf(fp2, NFFT__FR__
" ", &temp2);
373 f_hat[k] = temp1 + _Complex_I * temp2;
383 printf(
"\nTest of the polar FFT: \n");
384 fp1 = fopen(
"polar_fft_error.dat",
"w+");
385 for (m = 1; m <= 12; m++)
391 E_max = NFFT(error_l_infty_complex)(f_direct, f, M);
392 printf(
"m=%2d: E_max = %" NFFT__FES__
"\n", m, E_max);
393 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
398 for (m = 3; m <= 9; m += 3)
400 printf(
"\nTest of the inverse polar FFT for m=%d: \n", m);
401 sprintf(filename,
"polar_ifft_error%d.dat", m);
402 fp1 = fopen(filename,
"w+");
416 E_max = NFFT(error_l_infty_complex)(f_hat, f_tilde, N * N);
417 printf(
"%3d iterations: E_max = %" NFFT__FES__
"\n",
max_i, E_max);
418 fprintf(fp1,
"%" NFFT__FES__
"\n", E_max);
428 NFFT(free)(f_direct);
static int max_i(int a, int b)
max
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_fft(NFFT_C *f_hat, int NN, NFFT_C *f, int T, int S, int m)
NFFT-based 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.
int main(int argc, char **argv)
test program for various parameters
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
#define PRECOMPUTE_WEIGHT