SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
clock_recovery_mm.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "common/dsp/resamp/polyphase_bank.h"
5#include "dsp/block.h"
6
7namespace satdump
8{
9 namespace ndsp
10 {
11 template <typename T>
12 class MMClockRecoveryBlock : public Block
13 {
14 public:
15 float p_omega = 0;
16 float p_omegaGain = pow(8.7e-3, 2) / 4.0;
17 float p_mu = 0.5f;
18 float p_muGain = 8.7e-3;
19 float p_omegaLimit = 0.005;
20 int p_nfilt = 128;
21 int p_ntaps = 8;
22
23 bool needs_reinit = false;
24
25 private:
26 // Buffer
27 T *buffer = nullptr;
28
29 // Variables
30 float mu;
31 float omega;
32 float omega_gain;
33 float mu_gain;
34 float omega_relative_limit;
35 float omega_mid;
36 float omega_limit;
37
38 float sample;
39 float last_sample;
40
41 complex_t p_2T, p_1T, p_0T;
42 complex_t c_2T, c_1T, c_0T;
43
44 dsp::PolyphaseBank pfb;
45
46 float phase_error = 0;
47
48 int ouc = 0;
49 int inc = 0;
50
51 bool work();
52
53 public:
54 MMClockRecoveryBlock();
55 ~MMClockRecoveryBlock();
56
57 void init();
58
59 nlohmann::ordered_json get_cfg_list()
60 {
61 nlohmann::ordered_json p;
62 add_param_simple(p, "omega", "float");
63 add_param_simple(p, "omegaGain", "float");
64 add_param_simple(p, "mu", "float");
65 add_param_simple(p, "muGain", "float");
66 add_param_simple(p, "omegaLimit", "float");
67 add_param_simple(p, "nfilt", "int");
68 add_param_simple(p, "ntaps", "int");
69 return p;
70 }
71
72 nlohmann::json get_cfg(std::string key)
73 {
74 if (key == "omega")
75 return p_omega;
76 else if (key == "omegaGain")
77 return p_omegaGain;
78 else if (key == "mu")
79 return p_mu;
80 else if (key == "muGain")
81 return p_muGain;
82 else if (key == "omegaLimit")
83 return p_omegaLimit;
84 else if (key == "nfilt")
85 return p_nfilt;
86 else if (key == "ntaps")
87 return p_ntaps;
88 else
89 throw satdump_exception(key);
90 }
91
92 cfg_res_t set_cfg(std::string key, nlohmann::json v)
93 {
94 if (key == "omega")
95 {
96 p_omega = v;
97 needs_reinit = true;
98 }
99 else if (key == "omegaGain")
100 {
101 p_omegaGain = v;
102 needs_reinit = true;
103 }
104 else if (key == "mu")
105 {
106 p_mu = v;
107 needs_reinit = true;
108 }
109 else if (key == "muGain")
110 {
111 p_muGain = v;
112 needs_reinit = true;
113 }
114 else if (key == "omegaLimit")
115 {
116 p_omegaLimit = v;
117 needs_reinit = true;
118 }
119 else if (key == "nfilt")
120 {
121 p_nfilt = v;
122 needs_reinit = true;
123 }
124 else if (key == "ntaps")
125 {
126 p_ntaps = v;
127 needs_reinit = true;
128 }
129 else
130 throw satdump_exception(key);
131 return RES_OK;
132 }
133 };
134 } // namespace ndsp
135} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:227
virtual bool work()=0
The actual looping work function meant to handle all the DSP (well, in most blocks)
Block(std::string id, std::vector< BlockIO > in={}, std::vector< BlockIO > out={})
Generic constructor, to be overloaded.
Definition block.h:206
cfg_res_t set_cfg(std::string key, nlohmann::json v)
Set parameters of the block from JSON, including potentially IO configurations for blocks that may ha...
Definition clock_recovery_mm.h:92
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition clock_recovery_mm.h:59
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition clock_recovery_mm.h:72
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition clock_recovery_mm.cpp:29