-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
99 lines (77 loc) · 2.87 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#define COSTAS 0
#define TANLOCK 0
#define FDESC 1
#include <iostream>
#include <iomanip>
#if COSTAS
#include "src/Costas.h"
#endif
#if TANLOCK
#include "src/TanLock.h"
#endif
#if FDESC
#include "src/FreqDesc.h"
#endif
int main() {
const int order = 8;
// sampling rate here 1kHz as an example
const double sampleRate = 3000;
const double centreFrequency = 600;
const double modulationRate = 50;
const double trackingRate = 10;
#if COSTAS
rose::Costas costas{sampleRate, centreFrequency, modulationRate, trackingRate};
double phi = 0.;
double w = 0.;
double dt = (centreFrequency + 20) / sampleRate;
double lp = 0;
for (int i = 0; i < 1000; i++) {
if (i < 500)
dt = (centreFrequency + 20) / sampleRate;
else
dt = (centreFrequency - 20) / sampleRate;
w = fmod(w + (2.f * (double)M_PI * dt), 2. * M_PI);
auto a = std::sin(w + phi);
costas.sample(a);
printf( "%4d, w%9.5f, phi%9.5f, c.w%9.5f, dw%9.5f, a%9.5f, aI%9.5f, aQ%9.5f, bI%9.5f, bQ%9.5f, vF%9.5f, vC%9.5f",
i, w, phi, costas.w, (w+phi)-costas.w, a, costas.aI, costas.aQ, costas.bI, costas.bQ, costas.vFine, costas.vCoarse);
std::cout << (costas.locked ? " locked\n" : "\n" );
}
#endif
#if TANLOCK
rose::TanLock tanLock{sampleRate, centreFrequency, modulationRate, modulationRate * 2};
double phi = 0.;
double w = 0.;
double dt = (centreFrequency + 20) / sampleRate;
for (int i = 0; i < 1000; i++) {
if (i < 500)
dt = (centreFrequency + 50) / sampleRate;
else
dt = (centreFrequency - 50) / sampleRate;
w = fmod(w + (2.f * (double) M_PI * dt), 2. * M_PI);
auto a = std::sin(w + phi);
tanLock.sample(a);
printf( "%4d, w%9.5f, phi%9.5f, c.w%9.5f, dw%9.5f, a%9.5f, aI%9.5f, aQ%9.5f, bI%9.5f, bQ%9.5f, tl.phi%9.5f, tl.bPhi%9.5f\n",
i, w, phi, tanLock.w, (w+phi)-tanLock.w, a, tanLock.aI, tanLock.aQ, tanLock.bI, tanLock.bQ, tanLock.phi, tanLock.bPhi);
// std::cout << (2. * M_PI * (dt)) << ' ' << (2. * M_PI * (tanLock.dt)) + tanLock.phi * 0.1 << '\n';
}
#endif
#if FDESC
rose::FreqDesc freqDesc{sampleRate, centreFrequency, modulationRate};
double phi = 0.;
double w = 0.;
double dt = 0.;
for (int i = 0; i < 1000; i++) {
if (i < 500)
dt = (centreFrequency + 50) / sampleRate;
else
dt = (centreFrequency - 50) / sampleRate;
w = std::fmod(w + (2. * M_PI * (dt)), 2. * M_PI);
auto a = std::sin(w + phi);
auto b = freqDesc.sample(a);
printf( "%4d, w%9.5f, phi%9.5f, c.w%9.5f, a%9.5f, b%9.5f, aI%9.5f, aQ%9.5f, bI%9.5f, bQ%9.5f, tl.phi%9.5f, tl.bPhi%9.5f\n",
i, w, phi, freqDesc.w, a, b, freqDesc.aI, freqDesc.aQ, freqDesc.bI, freqDesc.bQ, freqDesc.phi, freqDesc.bPhi);
}
#endif
return 0;
}