-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
54 lines (40 loc) · 1.23 KB
/
test.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
#include <math.h>
#include <fftw3.h>
#include <stdlib.h>
int main() {
int i, n, sign;
double ignore;
scanf( "%20i %20i", &n, &sign );
fftw_complex *in = fftw_malloc( n * sizeof( fftw_complex ) );
fftw_complex *out = fftw_malloc( n * sizeof( fftw_complex ) );
fftw_plan plan = fftw_plan_dft_1d( n, in, out, sign, FFTW_ESTIMATE );
for( i = 0 ; i < n ; i++ )
scanf( "%20lf %20lf %20lf %20lf %20lf",
&in[i][0], &in[i][1], &ignore, &ignore, &ignore );
fftw_execute( plan ); // where the magic happens
sign *= -1;
printf( "%i %i\n", n, sign );
for( i = 0 ; i < n ; i++ ) {
double re = out[i][0];
double im = out[i][1];
double mod = sqrt( re * re + im * im );
double arg = atan( im / re );
if( sign > 0 ) { /* footnote 1 */
re /= n;
im /= n;
mod /= n;
}
printf( "%.15lf %.15lf %.15lf %.15lf %.15lf\n",
re, im, mod, arg, 180 * M_1_PI * arg );
}
fftw_destroy_plan( plan );
fftw_free( in );
fftw_free( out );
}
/*
* Footnote 1:
*
* This should scale by 1/sqrt(n), not by 1/n; and it should do it in both
* directions - that is, it should not be conditional on sign > 0.
*
*/