SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
hilbert.h
1#pragma once
2
3#include "common/dsp/block.h"
4#include "common/dsp/complex.h"
5#include "common/dsp/filter/firdes.h"
6#include "dsp/block.h"
7#include <volk/volk.h>
8
9namespace satdump
10{
11 namespace ndsp
12 {
13 class HilbertBlock : public Block
14 {
15 private:
16 bool needs_reinit = false;
17 int p_ntaps = 65;
18 int p_buffer_size = 8192 * 8;
19
20 private:
21 int buffer_size = 0;
22 float *buffer = nullptr;
23 float *taps = nullptr;
24
25 bool work();
26
27 size_t lbuf_size;
28 size_t lbuf_offset;
29
30 public:
31 HilbertBlock();
32 ~HilbertBlock();
33
34 void init()
35 {
36 // Free if needed
37 if (taps != nullptr)
38 volk_free(taps);
39 if (buffer != nullptr)
40 volk_free(buffer);
41
42 // Init buffer
43 buffer = dsp::create_volk_buffer<float>(p_buffer_size); // TODOREWORK How to handle this from the initial buffer size?
44 buffer_size = p_buffer_size;
45
46 // Init taps
47 auto p_taps = dsp::firdes::hilbert(p_ntaps, dsp::fft::window::WIN_HAMMING, 6.76);
48
49 // Init taps
50 p_ntaps = p_taps.size();
51 taps = (float *)volk_malloc(p_ntaps * sizeof(float), volk_get_alignment());
52 for (int j = 0; j < p_ntaps; j++)
53 taps[j] = p_taps[(p_ntaps - 1) - j]; // Reverse taps
54 }
55
56 nlohmann::ordered_json get_cfg_list()
57 {
58 nlohmann::ordered_json p;
59 add_param_simple(p, "ntaps", "int");
60 return p;
61 }
62
63 nlohmann::json get_cfg(std::string key)
64 {
65 if (key == "ntaps")
66 return p_ntaps;
67 else if (key == "buffer_size")
68 return p_buffer_size;
69 else
70 throw satdump_exception(key);
71 }
72
73 cfg_res_t set_cfg(std::string key, nlohmann::json v)
74 {
75 if (key == "ntaps")
76 {
77 p_ntaps = v;
78 needs_reinit = true;
79 }
80 else if (key == "buffer_size")
81 p_buffer_size = v;
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: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
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition hilbert.h:56
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 hilbert.h:73
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition hilbert.h:34
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition hilbert.h:63