GNU Radio's LORA_SDR Package
mu_detection_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Joachim Tapparel TCL@EPFL.
4 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef INCLUDED_LORA_SDR_MU_DETECTION_IMPL_H
22#define INCLUDED_LORA_SDR_MU_DETECTION_IMPL_H
23
24// #define GRLORA_DEBUG //The output of the downchirps matched filters will be
25// saved (including all polyphases) #ifdef THREAD_MEASURE
26#include <fstream>
27#include <iostream>
29#include "helpers.h"
30#include <volk/volk.h>
31
32extern "C" {
33#include "kiss_fft.h"
34}
35
36namespace gr {
37namespace lora_sdr {
38struct est_param {
39
40 long sto_int;
41 double sto_frac;
42 long cfo_int;
43 double cfo_frac;
44 int s_up;
45 int s_down;
46 double power;
47 double snr;
48};
49
51private:
52 uint32_t m_bw; ///< Bandwidth
53
54 uint8_t m_sf; ///< Spreading factor
55
56 uint8_t m_n_up; ///< number of upchirps in preample
57
58 uint32_t m_samples_per_symbol; ///< Number of samples per lora symbols
59
60 uint32_t m_N; ///< 2^sf
61
62 uint8_t m_os_factor; ///< oversampling factor
63
64 float m_snr_threshold; ///< minimal SNR to consider a new user
65
66
67 bool m_init = true; ///< variable used to initialise thread affinity
68
69 float m_prod_max_mag; ///< magnitude of the max bin of the product of the dft
70 ///< of the 7 upchirps
71 float m_power_avg; ///< average of the power of the main bin of the lasts
72 ///< FFTs. Used to avoid false detection caused by payload.
73
74 float m_noise_est; ///< estimation of the noise amplitude
75
76 est_param m_param; ///< parameters estimated s_up, lambda_cfo
77
78 double m_lamda_cfo; ///< estimated CFO fractional part
79 std::vector<gr_complex>
80 m_deci_preamb_up; ///< decimated part of the preamble that could
81 ///< potentially contain the upchirps
82 std::vector<gr_complex> m_downchirp; ///< Reference downchirp
83 std::vector<std::vector<gr_complex>>
84 m_dfts; ///< vector of the dft of the symbols 1 to 7 in m_preamble
85 std::vector<std::vector<float>>
86 m_dfts_mag; ///< vector of the dft magnitude of the symbols 1 to 7 in
87 ///< m_preamble
88 std::vector<float> m_dft_mag_prod; ///< contain the multiplication of the
89 ///< n_up-1 upchirps dfts
90 bool m_wait_one_symb; ///< variable used to indicate that a new user has been
91 ///< found but that his parameter estimation might not
92 ///< be ideal and a better approx. might come if we wait
93 ///< one additional symbol
94 bool m_ignore_next; ///< variable used to indicate that a new user has been
95 ///< found but it can lead to an additional detection in
96 ///< the next symbol, which might be ignored.
97
98 float m_L_threshold; ///< threshold used to check that we found the wanted
99 ///< pattern in the matched filter output (mf of the 2
100 ///< downchirps)
101
102 std::vector<gr_complex>
103 m_preamble; ///< buffer storing the preamble + 2 symbols (7 upchirps, 2
104 ///< net_id and 2 downchirps)
105 std::vector<gr_complex>
106 m_matched_filter; ///< matched filter for two downchirps detection
107 std::vector<gr_complex>
108 m_deci_preamb_down; ///< decimated part of the preamble that could
109 ///< potentially contain downchirps
110 std::vector<gr_complex> m_mf_conv_out; ///< output of the convolution of the
111 ///< preamble end with the match filter
112 std::vector<std::vector<float>>
113 m_mf_conv_out_abs; ///< the magnitude of m_mf_conv_out
114
115 /**
116 * @brief Dechirped symbol
117 *
118 */
119 std::vector<gr_complex> m_dechirped;
120
121 /**
122 * @brief Result of the FFT
123 *
124 */
125 std::vector<gr_complex> m_fft;
126
127 /**
128 * @brief Estimate the value of fractional part of the CFO using Berniers
129 * algorithm
130 *
131 * @param delay
132 */
133 void estimate_CFO_frac(int delay);
134
135 /**
136 * @brief add a tag to the first sample of the newly detected user,
137 * containing his power, sto and cfo estimations.
138 *
139 * @param input_symb
140 */
141 void add_user_tag(int input_symb);
142
143 /**
144 * \brief handle message containing the noise estimation.
145 */
146 void noise_handler(pmt::pmt_t noise_est);
147
148#ifdef GRLORA_DEBUG
149 std::ofstream out_file;
150 int m_matched_filter_en;
151#endif
152
153public:
154 /**
155 * @brief Construct a new mu detection impl object
156 *
157 * @param sf
158 * @param os_factor
159 * @param snr_threshold
160 */
161 mu_detection_impl(uint8_t sf, uint8_t os_factor, int snr_threshold);
162 /**
163 * @brief Destroy the mu detection impl object
164 *
165 */
167
168 /**
169 * @brief
170 *
171 * @param noutput_items
172 * @param ninput_items_required
173 */
174 void forecast(int noutput_items, gr_vector_int &ninput_items_required);
175
176 /**
177 * @brief
178 *
179 * @param noutput_items
180 * @param ninput_items
181 * @param input_items
182 * @param output_items
183 * @return int
184 */
185 int general_work(int noutput_items, gr_vector_int &ninput_items,
186 gr_vector_const_void_star &input_items,
187 gr_vector_void_star &output_items);
188};
189
190} // namespace lora_sdr
191} // namespace gr
192
193#endif /* INCLUDED_LORA_SDR_MU_DETECTION_IMPL_H */
Definition: mu_detection_impl.h:50
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)
mu_detection_impl(uint8_t sf, uint8_t os_factor, int snr_threshold)
Construct a new mu detection impl object.
~mu_detection_impl()
Destroy the mu detection impl object.
Definition: mu_detection.h:37
Definition: noise_est.h:37
Definition: add_crc.h:28
Definition: mu_detection_impl.h:38
long sto_int
Definition: mu_detection_impl.h:40
double power
Definition: mu_detection_impl.h:46
long cfo_int
Definition: mu_detection_impl.h:42
double sto_frac
Definition: mu_detection_impl.h:41
int s_up
Definition: mu_detection_impl.h:44
double cfo_frac
Definition: mu_detection_impl.h:43
int s_down
Definition: mu_detection_impl.h:45
double snr
Definition: mu_detection_impl.h:47