-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_1d_wrapper.c
More file actions
53 lines (36 loc) · 1.06 KB
/
simple_1d_wrapper.c
File metadata and controls
53 lines (36 loc) · 1.06 KB
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
/*
* fftw test -- double precision
*/
#include <stdio.h>
#include "fftw3.h"
#define SIZE 2048
fftw_plan create_plan(int N, double* time_frame, fftw_complex* out, unsigned FLAG, int inverse) {
if (inverse)
return fftw_plan_dft_c2r_1d(N, out, time_frame, FLAG);
else
return fftw_plan_dft_r2c_1d(N, time_frame, out, FLAG);
}
void fft_forward(int N, double* time_frame, double* fft_real, double* fft_imag)
{
fftw_complex out[N / 2 + 1];
fftw_plan p1 = fftw_plan_dft_r2c_1d(N, time_frame, out, FFTW_ESTIMATE);
fftw_execute(p1);
for (int i = 0; i < (N / 2 + 1); i++) {
fft_real[i] = out[i][0];
fft_imag[i] = out[i][1];
}
fftw_destroy_plan(p1);
return;
}
void fft_inverse(int N, double* real, double* imag, double* time_frame)
{
fftw_complex out[N / 2 + 1];
fftw_plan p2 = fftw_plan_dft_c2r_1d(N, out, time_frame, FFTW_ESTIMATE);
for (int i = 0; i < (N / 2 + 1); i++) {
out[i][0] = real[i];
out[i][1] = imag[i];
}
fftw_execute(p2);
fftw_destroy_plan(p2);
return;
}