-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_chirp.cpp
More file actions
69 lines (51 loc) · 2.15 KB
/
main_chirp.cpp
File metadata and controls
69 lines (51 loc) · 2.15 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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include "chirp_c.h"
#define TS 40.0e-6f
#define CHIRP_T1 5.0f
#define CHIRP_F0 (1.0f / CHIRP_T1)
#define CHIRP_F1 (1.0f / (2.0f * TS))
#define CHIRP_OFFSET 5.0f
#define CHIRP_AMPLITUDE 3.0f
#define CHIRP_T_SETTLE 0.0f
int main(int argc, char *argv[])
{
chirp_t chirp_c;
chirpInit(&chirp_c, CHIRP_F0, CHIRP_F1, CHIRP_T1, TS);
std::ofstream ofs ("output/data.txt");
uint64_t cntr = 0;
float chirp_exc_c = 0.0f;
float chirp_freq_c = 0.0f;
float chirp_sinarg_c = 0.0f;
float input_c = CHIRP_OFFSET;
float input_c_previous = CHIRP_OFFSET;
float diff_input_c = 0.0f;
bool chirp_update_finished = false;
while (true) {
const float time = cntr++ * TS;
if (time > CHIRP_T_SETTLE) {
if (chirpUpdate(&chirp_c)) {
chirp_exc_c = chirp_c.exc;
chirp_freq_c = chirp_c.fchirp;
chirp_sinarg_c = chirp_c.sinarg;
input_c = CHIRP_AMPLITUDE * chirp_exc_c + CHIRP_OFFSET;
diff_input_c = (input_c - input_c_previous) / TS;
input_c_previous = input_c;
} else {
chirp_update_finished = true;
}
}
if (chirp_update_finished)
break;
ofs << std::setprecision(9) << std::scientific << time << ", " // 0
<< chirp_exc_c << ", " // 1
<< chirp_freq_c << ", " // 2
<< chirp_sinarg_c << ", " // 3
<< input_c << ", " // 4
<< diff_input_c << std::endl; // 5
}
ofs.close();
return 0;
}