-
Notifications
You must be signed in to change notification settings - Fork 171
/
fft_fftw.c
47 lines (40 loc) · 1.34 KB
/
fft_fftw.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
#ifdef USE_FFTW
#include "fft_fftw.h"
#include <stdlib.h>
FFT_PLAN_T* make_fft_c2c(int size, complexf* input, complexf* output, int forward, int benchmark)
{
FFT_PLAN_T* plan=(FFT_PLAN_T*)malloc(sizeof(FFT_PLAN_T));
plan->plan = fftwf_plan_dft_1d(size, (fftwf_complex*)input, (fftwf_complex*)output, (forward)?FFTW_FORWARD:FFTW_BACKWARD, (benchmark)?FFTW_MEASURE:FFTW_ESTIMATE);
plan->size=size;
plan->input=(void*)input;
plan->output=(void*)output;
return plan;
}
FFT_PLAN_T* make_fft_r2c(int size, float* input, complexf* output, int benchmark) //always forward DFT
{
FFT_PLAN_T* plan=(FFT_PLAN_T*)malloc(sizeof(FFT_PLAN_T));
plan->plan = fftwf_plan_dft_r2c_1d(size, input, (fftwf_complex*)output, (benchmark)?FFTW_MEASURE:FFTW_ESTIMATE);
plan->size=size;
plan->input=(void*)input;
plan->output=(void*)output;
return plan;
}
FFT_PLAN_T* make_fft_c2r(int size, complexf* input, float* output, int benchmark) //always backward DFT
{
FFT_PLAN_T* plan=(FFT_PLAN_T*)malloc(sizeof(FFT_PLAN_T));
plan->plan = fftwf_plan_dft_c2r_1d(size, (fftwf_complex*)input, output, (benchmark)?FFTW_MEASURE:FFTW_ESTIMATE);
plan->size=size;
plan->input=(void*)input;
plan->output=(void*)output;
return plan;
}
void fft_execute(FFT_PLAN_T* plan)
{
fftwf_execute(plan->plan);
}
void fft_destroy(FFT_PLAN_T* plan)
{
fftwf_destroy_plan(plan->plan);
free(plan);
}
#endif