-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfft_spectrum.ino
165 lines (158 loc) · 3.14 KB
/
fft_spectrum.ino
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*This is a signal sum of 800 hz and 3.2 khz sine waves
which sampled in 10khz and 32 of this samples are
create a data array.
In this example spectrum of the signal showed using fft
*/
#include "simpleDSP_fft.h"
#define DATA_LEN 64
double data_magnitude[DATA_LEN];
COMPLEX data[DATA_LEN] =
{
450.527388478791,
0.0,
-101.597194769693,
0.0,
1031.37368065794,
0.0,
-613.160606150798,
0.0,
-1618.03398874990,
0.0,
-115.808021270615,
0.0,
-866.985966358939,
0.0,
-1567.20047563694,
0.0,
541.587312835687,
0.0,
618.033988749895,
0.0,
-263.146073893067,
0.0,
1504.40995610763,
0.0,
1504.40995610763,
0.0,
-263.146073893067,
0.0,
618.033988749894,
0.0,
541.587312835686,
0.0,
-1567.20047563694,
0.0,
-866.985966358938,
0.0,
-115.808021270616,
0.0,
-1618.03398874989,
0.0,
-613.160606150796,
0.0,
1031.37368065794,
0.0,
-101.597194769693,
0.0,
450.527388478786,
0.0,
2000,
0.0,
450.527388478790,
0.0,
-101.597194769691,
0.0,
1031.37368065794,
0.0,
-613.160606150791,
0.0,
-1618.03398874990,
0.0,
-115.808021270614,
0.0,
-866.985966358941,
0.0,
-1567.20047563694,
0.0,
541.587312835695,
0.0,
618.033988749887,
0.0,
-263.146073893066,
0.0,
1504.40995610763,
0.0,
1504.40995610762,
0.0,
-263.146073893069,
0.0,
618.033988749893,
0.0,
541.587312835687,
0.0,
-1567.20047563694,
0.0,
-866.985966358946,
0.0,
-115.808021270611,
0.0,
-1618.03398874989,
0.0,
-613.160606150798,
0.0,
1031.37368065794,
0.0,
-101.597194769688,
0.0,
450.527388478784,
0.0,
2000,
0.0,
450.527388478792,
0.0,
-101.597194769692,
0.0,
1031.37368065794,
0.0,
-613.160606150806,
0.0,
-1618.03398874989,
0.0,
-115.808021270608,
0.0,
-866.985966358952,
0.0,
-1567.20047563695,
0.0,
541.587312835680,
0.0,
618.033988749898,
0.0,
-263.146073893067,
0.0,
1504.40995610763,
0.0,
1504.40995610762,
0.0,
-263.146073893068,
0.0,
};
long startTime;
long calcTime;
void setup()
{
Serial.begin(9600);
startTime = millis();
FFT(data, DATA_LEN);
calcTime = millis() - startTime;
Serial.print("Total calculation time: ");
Serial.println(calcTime);
for (int i = 0; i < DATA_LEN; i++)
{
Serial.println(abs(data[i].real));
}
}
void loop()
{
// put your main code here, to run repeatedly:
}