SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
costas.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "dsp/block_simple.h"
5
6namespace satdump
7{
8 namespace ndsp
9 {
10 class CostasBlock : public BlockSimple<complex_t, complex_t>
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 public:
27 uint32_t process(complex_t *input, uint32_t nsamples, complex_t *output);
28
29 public:
30 CostasBlock();
31 ~CostasBlock();
32
33 void init()
34 {
35 freq_limit_min = -freq_limit;
36 freq_limit_max = freq_limit;
37
38 error = 0;
39 phase = 0, freq = 0;
40
41 float damping = sqrtf(2.0f) / 2.0f;
42 float denom = (1.0 + 2.0 * damping * loop_bw + loop_bw * loop_bw);
43 alpha = (4 * damping * loop_bw) / denom;
44 beta = (4 * loop_bw * loop_bw) / denom;
45 }
46
47 nlohmann::ordered_json get_cfg_list()
48 {
49 nlohmann::ordered_json p;
50 add_param_simple(p, "loop_bw", "float");
51 add_param_simple(p, "order", "int");
52 add_param_simple(p, "freq_limit", "float");
53 return p;
54 }
55
56 nlohmann::json get_cfg(std::string key)
57 {
58 if (key == "loop_bw")
59 return loop_bw;
60 else if (key == "order")
61 return order;
62 else if (key == "freq_limit")
63 return freq_limit;
64 else
65 throw satdump_exception(key);
66 }
67
68 cfg_res_t set_cfg(std::string key, nlohmann::json v)
69 {
70 if (key == "loop_bw")
71 {
72 loop_bw = v;
73 init();
74 }
75 else if (key == "order")
76 order = v;
77 else if (key == "freq_limit")
78 {
79 freq_limit = v;
80 init();
81 }
82 else
83 throw satdump_exception(key);
84 return RES_OK;
85 }
86 };
87 } // namespace ndsp
88} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:241
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition costas.h:33
uint32_t process(complex_t *input, uint32_t nsamples, complex_t *output)
Simplified "work" function, called automatically by work(). This takes away all boilerplate work usua...
Definition costas.cpp:12
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition costas.h:47
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:68
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition costas.h:56