SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
costas.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "dsp/block.h"
5
6namespace satdump
7{
8 namespace ndsp
9 {
10 class CostasBlock : public Block
11 {
12 private:
13 int order = 2;
14 float loop_bw = 0.004;
15 float freq_limit = 1.0;
16
17 private:
18 float error = 0;
19 float phase = 0, freq = 0;
20 float alpha, beta;
21
22 float freq_limit_min, freq_limit_max;
23
24 complex_t tmp_val;
25
26 bool work();
27
28 public:
29 CostasBlock();
30 ~CostasBlock();
31
32 void init()
33 {
34 freq_limit_min = -freq_limit;
35 freq_limit_max = freq_limit;
36
37 error = 0;
38 phase = 0, freq = 0;
39
40 float damping = sqrtf(2.0f) / 2.0f;
41 float denom = (1.0 + 2.0 * damping * loop_bw + loop_bw * loop_bw);
42 alpha = (4 * damping * loop_bw) / denom;
43 beta = (4 * loop_bw * loop_bw) / denom;
44 }
45
46 nlohmann::json get_cfg(std::string key)
47 {
48 if (key == "loop_bw")
49 return loop_bw;
50 else if (key == "order")
51 return order;
52 else if (key == "freq_limit")
53 return freq_limit;
54 else
55 throw satdump_exception(key);
56 }
57
58 cfg_res_t set_cfg(std::string key, nlohmann::json v)
59 {
60 if (key == "loop_bw")
61 {
62 loop_bw = v;
63 init();
64 }
65 else if (key == "order")
66 order = v;
67 else if (key == "freq_limit")
68 {
69 freq_limit = v;
70 init();
71 }
72 else
73 throw satdump_exception(key);
74 return RES_OK;
75 }
76 };
77 } // namespace ndsp
78} // 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
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition costas.h:32
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 costas.h:58
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition costas.h:46