GNU Radio's LORA_SDR Package
fft_demod_impl.h
Go to the documentation of this file.
1
2#ifndef INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H
3#define INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H
4// #define GRLORA_DEBUG
5// #define GRLORA_MEASUREMENTS
6//#define GRLORA_SNR_MEASUREMENTS_SAVE
7//#define GRLORA_BESSEL_MEASUREMENTS_SAVE
8//#define GRLORA_LLR_MEASUREMENTS_SAVE
9
11#include <iostream>
12#include <fstream>
13#include <volk/volk.h>
14#include <gnuradio/io_signature.h>
17
18namespace gr {
19 namespace lora_sdr {
20
22 {
23 private:
24 uint8_t m_sf; ///< Spreading factor
25 uint8_t m_cr; ///< Coding rate
26 bool m_soft_decoding; ///< Hard/Soft decoding
27 bool max_log_approx; ///< use Max-log approximation in LLR formula
28 bool m_new_frame; ///< To be notify when receive a new frame to estimate SNR
29 bool m_ldro; ///< use low datarate optimisation
30 unsigned int m_symb_numb; ///< number of symbols in the frame
31 unsigned int m_symb_cnt; ///< number of symbol already output in current frame
32
33 double m_Ps_est = 0; // Signal Power estimation updated at each rx symbol
34 double m_Pn_est = 0; // Signal Power estimation updated at each rx symbo
35
36 uint32_t m_samples_per_symbol; ///< Number of samples received per lora symbols
37 int CFOint; ///< integer part of the CFO
38
39 // variable used to perform the FFT demodulation
40 std::vector<gr_complex> m_upchirp; ///< Reference upchirp
41 std::vector<gr_complex> m_downchirp; ///< Reference downchirp
42 std::vector<gr_complex> m_dechirped; ///< Dechirped symbol
43 std::vector<gr_complex> m_fft; ///< Result of the FFT
44
45 std::vector<uint16_t> output; ///< Stores the value to be outputted once a full bloc has been received
46 std::vector< std::vector<LLR> > LLRs_block; ///< Stores the LLRs to be outputted once a full bloc has been received
47 bool is_header; ///< Indicate that the first block hasn't been fully received
48 uint8_t block_size; ///< The number of lora symbol in one block
49
50 #ifdef GRLORA_MEASUREMENTS
51 std::ofstream energy_file;
52 #endif
53 #ifdef GRLORA_DEBUG
54 std::ofstream idx_file;
55 #endif
56 #ifdef GRLORA_SNR_MEASUREMENTS_SAVE
57 std::ofstream SNRestim_file;
58 #endif
59 #ifdef GRLORA_BESSEL_MEASUREMENTS_SAVE
60 std::ofstream bessel_file;
61 #endif
62
63 /**
64 * \brief Recover the lora symbol value using argmax of the dechirped symbol FFT.
65 *
66 * \param samples
67 * The pointer to the symbol beginning.
68 */
69 uint16_t get_symbol_val(const gr_complex *samples);
70
71 /**
72 * @brief Set spreading factor and init vector sizes accordingly
73 *
74 */
75 void set_sf(int sf);
76
77 /**
78 * \brief Reset the block variables when a new lora packet needs to be decoded.
79 */
80 void new_frame_handler(int cfo_int);
81
82 /**
83 * \brief Handles the reception of the coding rate received by the header_decoder block.
84 */
85 void header_cr_handler(pmt::pmt_t cr);
86
87 /**
88 * \brief Compute the FFT and fill the class attributes
89 */
90 float* compute_fft_mag(const gr_complex *samples);
91
92 /**
93 * \brief Compute the Log-Likelihood Ratios of the SF nbr of bits
94 */
95 std::vector<LLR> get_LLRs(const gr_complex *samples);
96
97 public:
98 fft_demod_impl( bool soft_decoding, bool max_log_approx);
100
101 // Where all the action really happens
102 void forecast (int noutput_items, gr_vector_int &ninput_items_required);
103
104 int general_work(int noutput_items,
105 gr_vector_int &ninput_items,
106 gr_vector_const_void_star &input_items,
107 gr_vector_void_star &output_items);
108 };
109
110 } // namespace lora_sdr
111} // namespace gr
112
113#endif /* INCLUDED_LORA_SDR_FFT_DEMOD_IMPL_H */
Definition fft_demod_impl.h:22
fft_demod_impl(bool soft_decoding, bool max_log_approx)
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
<+description of block+>
Definition fft_demod.h:37
Definition add_crc.h:28