-
Notifications
You must be signed in to change notification settings - Fork 18
/
fft.c
59 lines (47 loc) · 1.66 KB
/
fft.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
#include <stdlib.h>
#include "fft.h"
// Constructor for FFT routine
fft_vars* fft_con(int nfft) {
fft_vars* fftvars = (fft_vars*) malloc(sizeof(fft_vars));
fftvars->nfft = nfft;
fftvars->numfreqs = nfft/2 + 1;
fftvars->ffttime = fftwf_malloc(nfft* sizeof(float));
fftvars->complex = fftwf_malloc(fftvars->numfreqs* sizeof(fftwf_complex));
fftvars->forwardplan=fftwf_plan_dft_r2c_1d(nfft,fftvars->ffttime, fftvars->complex, FFTW_ESTIMATE);
fftvars->reverseplan=fftwf_plan_dft_c2r_1d(nfft,fftvars->complex,fftvars->ffttime, FFTW_ESTIMATE);
return fftvars;
}
// Destructor for FFT routine
void fft_des(fft_vars* fftvars)
{
fftwf_destroy_plan(fftvars->forwardplan);
fftwf_destroy_plan(fftvars->reverseplan);
fftwf_free(fftvars->ffttime);
fftwf_free(fftvars->complex);
free(fftvars);
}
// Perform forward FFT of real data
// Accepts:
// fftvars - pointer to struct of FFT variables
// input - pointer to an array of (real) input values, size nfft
// output_re - pointer to an array of the real part of the output,
// size nfft/2 + 1
// output_im - pointer to an array of the imaginary part of the output,
// size nfft/2 + 1
void fft_forward(fft_vars* fftvars)
{
fftwf_execute(fftvars->forwardplan);
}
// Perform inverse FFT, returning real data
// Accepts:
// fftvars - pointer to struct of FFT variables
// input_re - pointer to an array of the real part of the output,
// size nfft/2 + 1
// input_im - pointer to an array of the imaginary part of the output,
// size nfft/2 + 1
// output - pointer to an array of (real) input values, size nfft
void fft_inverse(fft_vars* fftvars)
{
fftwf_execute(fftvars->reverseplan);
}
// DONE WITH FFT CODE