-
Notifications
You must be signed in to change notification settings - Fork 4
/
fft.h
115 lines (91 loc) · 3.6 KB
/
fft.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* fft.h
*
* Copyright (c) 2018 Disi A
*
* Author: Disi A
* Email: [email protected]
* https://www.mathworks.com/matlabcentral/profile/authors/3734620-disi-a
*
* http://www.netlib.org/fftpack/doc
*
* PARAMETERS:
* * int n; The length of the sequence to be transformed.
* * float *x; A real array of length n which contains the sequenceto be transformed
* * float *wsave; A work array which must be dimensioned at least 2*n+15.
* * the same work array can be used for both rfftf and rfftb
* * as long as n remains unchanged. different wsave arrays
* * are required for different values of n. the contents of
* * wsave must not be changed between calls of rfftf or rfftb.
* * int *ifac; Array containing factors of the problem dimensions.
* * (initialization requirements are probably similar to wsave)
* * Some docs say it needs to be 15 elements, others say n.
* * Maybe n + 15 is safest.
*
* More documentation from original FFTPACK
* http://www.netlib.org/fftpack/doc
*
* Some other usage reference: https://www.experts-exchange.com/questions/21416267/how-to-use-C-version-of-fftpack-a-public-domain-DFT-library.html
*/
#ifndef _fft_h
#define _fft_h
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#define USE_DOUBLE_PRECISION 1
#define FFT_SCALED_OUTPUT 1
#define FFT_UNSCALED_OUTPUT 0
#define FFT_IFAC 15
#if USE_DOUBLE_PRECISION
#define FFT_PRECISION double
#else
#define FFT_PRECISION float
#endif
typedef struct {
int n;
FFT_PRECISION * wsave;
int * ifac;
int scale_output; // 1 for scale and 0 for not scale
} FFTTransformer;
typedef struct {
int n;
FFT_PRECISION * wsave;
int * ifac;
int scale_output; // 1 for scale and 0 for not scale
} FFTCosqTransformer;
typedef enum {
NO_WINDOW = 0,
PARZEN = 1,
WELCH = 2,
HANNING = 3,
HAMMING = 4,
BLACKMAN = 5,
STEEPER = 6 // steeper 30-dB/octave rolloff window
} FFTWindow;
FFT_PRECISION* windowing(int n, const FFT_PRECISION *input, FFTWindow window_type, FFT_PRECISION scale);
// Initialization real fft transform (__ogg_fdrffti)
void __fft_real_init(int n, FFT_PRECISION *wsave, int *ifac);
// Forward transform of a real periodic sequence (__ogg_fdrfftf)
void __fft_real_forward(int n,FFT_PRECISION *r,FFT_PRECISION *wsave,int *ifac);
// Real FFT backward (__ogg_fdrfftb)
void __fft_real_backward(int n, FFT_PRECISION *r, FFT_PRECISION *wsave, int *ifac);
// Initialize cosine quarter-wave transform (__ogg_fdcosqi)
void __fft_cosq_init(int n, FFT_PRECISION *wsave, int *ifac);
// Real cosine quarter-wave forward transform (__ogg_fdcosqf)
void __fft_cosq_forward(int n,FFT_PRECISION *x,FFT_PRECISION *wsave,int *ifac);
// Real cosine quarter-wave backward transform (__ogg_fdcosqb)
void __fft_cosq_backward(int n,FFT_PRECISION *x,FFT_PRECISION *wsave,int *ifac);
// Wrapper method with all fftpack parameters properly initilized
FFTTransformer * create_fft_transformer(int signal_length, int scale_output);
void free_fft_transformer(FFTTransformer * transformer);
void fft_forward(FFTTransformer * transformer, FFT_PRECISION* input);
void fft_backward(FFTTransformer * transformer, FFT_PRECISION* input);
FFTCosqTransformer * create_fft_cosq_transformer(int signal_length, int scale_output);
void free_cosq_fft_transformer(FFTCosqTransformer * transformer);
void fft_cosq_forward(FFTCosqTransformer * transformer, FFT_PRECISION* input);
void fft_cosq_backward(FFTCosqTransformer * transformer, FFT_PRECISION* input);
#ifdef __cplusplus
}
#endif
#endif /* _fft_h */