SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
channel_model_simple.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "common/dsp/utils/random.h"
5#include "dsp/block.h"
6#include "dsp/block_simple.h"
7#include <cstdint>
8
9namespace satdump
10{
11 namespace ndsp
12 {
13 class ChannelModelSimpleBlock : public BlockSimple<complex_t, complex_t>
14 {
15 private:
16 bool needs_reinit = true;
17
18 double samplerate = 1e6;
19 double noise_level = -150;
20 double signal_level = -120;
21 double freq_shift = 0;
22
23 float curr_phase = 0, curr_freq = 0; // Current phase & freq
24 float d_alpha = 0.1; // Rate at which we catch up with target_freq
25
26 dsp::Random d_rng;
27
28 public:
29 ChannelModelSimpleBlock();
30 ~ChannelModelSimpleBlock();
31
32 uint32_t process(complex_t *input, uint32_t nsamples, complex_t *output);
33
34 void init() {}
35
36 nlohmann::ordered_json get_cfg_list()
37 {
38 nlohmann::ordered_json p;
39 add_param_simple(p, "samplerate", "float", "Samplerate");
40 add_param_simple(p, "noise_level", "float", "Noise Level (dBm)");
41 add_param_simple(p, "signal_level", "float", "Signal Level (dBm)");
42 add_param_simple(p, "freq_shift", "float", "Frequency Shift");
43 add_param_simple(p, "d_alpha", "float", "Alpha");
44 return p;
45 }
46
47 nlohmann::json get_cfg(std::string key)
48 {
49 if (key == "samplerate")
50 return samplerate;
51 else if (key == "noise_level")
52 return noise_level;
53 else if (key == "signal_level")
54 return signal_level;
55 else if (key == "freq_shift")
56 return freq_shift;
57 else if (key == "alpha")
58 return d_alpha;
59 else
60 throw satdump_exception(key);
61 }
62
63 Block::cfg_res_t set_cfg(std::string key, nlohmann::json v)
64 {
65 if (key == "samplerate")
66 {
67 samplerate = v;
68 needs_reinit = true;
69 }
70 else if (key == "noise_level")
71 {
72 noise_level = v;
73 }
74 else if (key == "signal_level")
75 {
76 signal_level = v;
77 }
78 else if (key == "freq_shift")
79 {
80 freq_shift = v;
81 }
82 else if (key == "alpha")
83 {
84 d_alpha = v;
85 }
86 else
87 throw satdump_exception(key);
88 return Block::RES_OK;
89 }
90 };
91 } // namespace ndsp
92} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:241
Block::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 channel_model_simple.h:63
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 channel_model_simple.cpp:17
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition channel_model_simple.h:34
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition channel_model_simple.h:47
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition channel_model_simple.h:36