-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_1d_r2c.c
61 lines (44 loc) · 1.33 KB
/
test_1d_r2c.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
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>
#include <fftw3.h>
#include "util.h"
int test_1d_r2c(int n) {
double real, imag, phi;
int nCplx = n / 2 + 1;
printf("n=%d nCplx=%d\n", n, nCplx);
double *in = fftw_alloc_real(n);
fftw_complex *ref_out = fftw_alloc_complex(nCplx);
fftw_complex *fftw_out = fftw_alloc_complex(nCplx);
fftw_plan p = fftw_plan_dft_r2c_1d(n, in, fftw_out, FFTW_ESTIMATE);
// fill the input array with random data
fill_random_1d_real(n, in);
// compute the reference output
for (int k = 0; k < nCplx; ++k) {
// DC component is always real
ref_out[k] = in[0];
for (int j = 1; j < n; ++j) {
phi = -2.0 * M_PI * j * k / ((double) n);
real = in[j] * cos(phi);
imag = in[j] * sin(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(nCplx, 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_r2c(32);
status += test_1d_r2c(33);
return status;
}