-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_1d_c2c.c
56 lines (42 loc) · 1.32 KB
/
test_1d_c2c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>
#include <fftw3.h>
#include "util.h"
int test_1d_c2c(int n) {
int dir = FFTW_BACKWARD;
double real, imag, phi;
fftw_complex *in = fftw_alloc_complex(n);
fftw_complex *ref_out = fftw_alloc_complex(n);
fftw_complex *fftw_out = fftw_alloc_complex(n);
fftw_plan p = fftw_plan_dft_1d(n, in, fftw_out, dir, FFTW_ESTIMATE);
// fill the input array with random data
fill_random_1d_cplx(n, in);
// compute the reference output
for (int k = 0; k < n; ++k) {
ref_out[k] = 0.0;
for (int j = 0; j < n; ++j) {
phi = dir * 2.0 * M_PI * j * k / ((double) n);
real = creal(in[j]) * cos(phi) - cimag(in[j]) * sin(phi);
imag = creal(in[j]) * sin(phi) + cimag(in[j]) * cos(phi);
ref_out[k] += real + I * imag;
}
}
// compute the DFT of in using FFTW
fftw_execute(p);
// compare reference output with FFTW output
double eps = 1e-12;
int status = compare_1d_cplx(n, ref_out, fftw_out, eps);
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(ref_out);
fftw_free(fftw_out);
return status;
}
int main(int argc, char** argv) {
int status = 0;
status += test_1d_c2c(32);
status += test_1d_c2c(33);
return status;
}