-
Notifications
You must be signed in to change notification settings - Fork 2
/
kiss_DFT.cpp
83 lines (73 loc) · 1.76 KB
/
kiss_DFT.cpp
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
#include "kiss_dft.h"
kiss_dft_state::kiss_dft_state()
{
this->nfft = this->inverse = 0;
this->matrix = nullptr;
}
kiss_dft_state::kiss_dft_state(int nfft, int inverse)
{
int i, j;
this->nfft = nfft;
this->inverse = inverse;
matrix = new kiss_fft_cpx*[this->nfft];
for (i = 0; i < this->nfft; i++)
{
matrix[i] = new kiss_fft_cpx[this->nfft];
for (j = 0; j < this->nfft; j++)
{
matrix[i][j].r = matrix[i][j].i = 0;
}
}
for (i = 0; i < this->nfft; i++)
{
matrix[i][0].r = 1;
matrix[0][i].r = 1;
}
const double pi = 3.141592653589793238462643383279502884197169399375105820974944;
double phase = -2 * pi / this->nfft;
if (this->inverse)
phase *= -1;
twiddles.r = cos(phase);
twiddles.i = sin(phase);
for (i = 1; i < this->nfft; i++)
{
C_MUL(matrix[i][1], matrix[i-1][1], twiddles);
}
for (i = 1; i < this->nfft; i++)
{
for (j = 2; j < this->nfft; j++)
{
C_MUL(matrix[i][j], matrix[i][j-1], matrix[i][1]);
}
}
}
kiss_dft_state::~kiss_dft_state()
{
if (matrix != nullptr)
{
int i;
for (i = 0; i < this->nfft; i++)
{
if (matrix[i] != nullptr)
{
free(matrix[i]);
matrix[i] = nullptr;
}
}
free(matrix);
matrix = nullptr;
}
}
void kiss_dft_state::runDFT(kiss_fft_cpx* inBuf, kiss_fft_cpx* outBuf)
{
for (int i = 0; i < this->nfft; i++)
{
outBuf[i].r = outBuf[i].i = 0;
kiss_fft_cpx tmp;
for (int j = 0; j < this->nfft; j++)
{
C_MUL(tmp, matrix[i][j], inBuf[j]);
C_ADDTO(outBuf[i], tmp);
}
}
}