-
Notifications
You must be signed in to change notification settings - Fork 0
/
fft.cpp
64 lines (54 loc) · 1.92 KB
/
fft.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
#include "fft.h"
void fft(int sizeData, coordinates input, coordinates* output, double collectionTime)
{
double samplingRate, inverseSamplingRate;
fftw_complex* inputDataX;
fftw_complex* inputDataY;
fftw_complex* inputDataZ;
fftw_complex* outputDataX;
fftw_complex* outputDataY;
fftw_complex* outputDataZ;
inputDataX = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
inputDataY = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
inputDataZ = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
outputDataX = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
outputDataY = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
outputDataZ = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * sizeData);
int i = 0;
for (auto& data : input)
{
inputDataX[i][REAL] = X(data);
inputDataY[i][REAL] = Y(data);
inputDataZ[i][REAL] = Z(data);
inputDataX[i][IMAG] = 0;
inputDataY[i][IMAG] = 0;
inputDataZ[i][IMAG] = 0;
i++;
}
fftw_plan plan;
// X
plan = fftw_plan_dft_1d(sizeData, inputDataX, outputDataX, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
fftw_cleanup();
// Y
plan = fftw_plan_dft_1d(sizeData, inputDataY, outputDataY, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
fftw_cleanup();
// Z
plan = fftw_plan_dft_1d(sizeData, inputDataZ, outputDataZ, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
fftw_cleanup();
for (i = 0; i < sizeData; i++)
{
(*output).push_back(make_tuple(outputDataX[i][REAL], outputDataY[i][REAL], outputDataZ[i][REAL]));
}
fftw_free(inputDataX);
fftw_free(inputDataY);
fftw_free(inputDataZ);
fftw_free(outputDataX);
fftw_free(outputDataY);
fftw_free(outputDataZ);
}