-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfft.h
More file actions
executable file
·93 lines (81 loc) · 2.09 KB
/
fft.h
File metadata and controls
executable file
·93 lines (81 loc) · 2.09 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
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
#ifndef FFT_H_INCLUDED
#define FFT_H_INCLUDED
#include <stdint.h>
/* math lib */
#include <math.h>
#ifndef FFT_POINT
/* N */
#define FFT_POINT 512
#endif
#ifndef FFT_POINT_2
/* N/2 */
#define FFT_POINT_2 256
#endif
#ifndef FFT_STAGES
/* log(N)/log(2) */
#define FFT_STAGES 9
#endif
/**************
* Uncomment to calculate phase
* #define FFT_PHASE_USE
**************/
#ifdef FFT_PHASE_USE
/*
* Convert rad to degree
* (180 / pi)
*/
#define RAD_TO_DEGREE 57.2957795130823208768
#endif
/* Types of window */
#define FFT_WIN_RECTANGLE 0
#define FFT_WIN_TRIANGLE 1
#define FFT_WIN_HANNING 2
#define FFT_WIN_HAMMING 3
#define FFT_WIN_BLACKMAN 4
#define FFT_WIN_NUTTALL 5
#define FFT_WIN_FLAT_TOP 6
/* Complex structure */
typedef struct{
float re;
float im;
}Complex;
/* FFT structure */
typedef struct{
float dB;
float mag;
float phase;
}FFT;
/** Use once at start of program **/
/*
* Blocks per stage
* N/(2^stage)
*/
void fft_BlockPerStage(uint16_t *pblocks);
/*
* Butterflies per block per stage
* 2^(stage-1)
*/
void fft_ButterfliesPerBlocks(uint16_t *pbutterflies);
/* Bit Reversed LUT calculation */
void fft_BitReversedLUT(uint16_t *pbit_reversed);
/* Calculate twiddle factor */
void fft_TwiddleFactor(Complex *pW);
/* Calculate window */
void fft_Window(uint8_t type, float *pWin);
/** Use before each FFT **/
/* Multiply x(n) by window and convert to a bit reversed complex array */
void fft_DataToComplex(float *px, float *pWin, Complex *pdata_complex, uint16_t *pbit_reversed);
/** FFT funtcion **/
/* Compute FFT algorithm */
void fft_Compute(Complex *pdata_complex, Complex *pW, uint16_t *pblocks, uint16_t *pbutterflies);
/*
* Convert real & imaginary to magnitude & phase
* Normalize the magnitude if normalize is not NULL
*/
void fft_ComplexToMagnPhase(Complex *pdata_complex, FFT *pspectrum, uint8_t normalize);
/*
* Convert real & imaginary to a dB amplitude
* Complex to polar + normalize + 20 * log(...)
*/
void fft_ComplexTodB(Complex *pdata_complex, FFT *pspectrum);
#endif