GNU Radio's LORA_SDR Package
signal_detector_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_SIGNAL_DETECTOR_IMPL_H
22 #define INCLUDED_LORA_SDR_SIGNAL_DETECTOR_IMPL_H
23 
25 #include <volk/volk.h>
26 #include "helpers.h"
27 #include <iostream>
28 #include <fstream>
29 extern "C"
30 {
31 #include "kiss_fft.h"
32 }
33 
34 // #define GRLORA_DEBUG //it will save the transparency state along with the decision value
35 // #define THREAD_MEASURE
36 
37 namespace gr
38 {
39  namespace lora_sdr
40  {
41 
43  {
44  private:
45  uint8_t m_sf; ///< Spreading factor
46  uint32_t m_samples_per_symbol; ///< Number of samples per LoRa symbol
47  uint32_t m_N; ///< 2^sf
48  uint8_t m_os_factor; ///< oversampling factor
49  double m_threshold; ///< detection threshold
50  int m_fft_symb; ///< number of symbols on which the fft will be made
51  int m_margin; ///< margin in the input buffer that will be output when a detection occurs [number of symbols]
52  int m_transp_len; ///< duration (in number of symbol of the transparency after signal detection)
53 
54  int transp_duration; ///< duration of transparency left in samples.
55  bool first_time_tag; ///< Indicate that a starting tag has been received. Any additional tag will signify an overflow and stop the receiver.
56 
57  std::vector<gr_complex> m_downchirp;///< the reference downchirp
58  std::vector<gr_complex> m_dechirped;///< the dechirped symbols on which we need to perform the FFT.
59  std::vector<gr_complex> cx_out; ///< the output of the FFT
60  kiss_fft_cfg fft_cfg; ///< the configuration of the FFT
61 
62  std::vector<gr_complex> m_input_decim; ///< decimated input
63  std::vector<float>::iterator m_max_it; ///< iterator used to find max and argmax of FFT
64  std::vector<float> m_dfts_mag; ///< vector containing the magnitude of the FFT.
65 
66 #ifdef GRLORA_DEBUG
67  std::ofstream out_file;
68 #endif
69 #ifdef THREAD_MEASURE
70  bool m_init; ///< variable use to set thread priority
71 #endif
72 
73  public:
74  /**
75  * @brief Construct a new signal detector impl object
76  *
77  * @param sf
78  * @param os_factor
79  * @param threshold
80  * @param margin
81  * @param fft_symb
82  * @param transp_len
83  */
84  signal_detector_impl(uint8_t sf, uint8_t os_factor, double threshold, int margin, int fft_symb, int transp_len);
85  /**
86  * @brief Destroy the signal detector impl object
87  *
88  */
90 
91  /**
92  * @brief
93  *
94  * @param noutput_items
95  * @param ninput_items_required
96  */
97  void forecast(int noutput_items, gr_vector_int &ninput_items_required);
98 
99  /**
100  * @brief
101  *
102  * @param noutput_items
103  * @param ninput_items
104  * @param input_items
105  * @param output_items
106  * @return int
107  */
108  int general_work(int noutput_items,
109  gr_vector_int &ninput_items,
110  gr_vector_const_void_star &input_items,
111  gr_vector_void_star &output_items);
112  };
113 
114  } // namespace lora_sdr
115 } // namespace gr
116 
117 #endif /* INCLUDED_LORA_SDR_SIGNAL_DETECTOR_IMPL_H */
gr::lora_sdr::signal_detector_impl::signal_detector_impl
signal_detector_impl(uint8_t sf, uint8_t os_factor, double threshold, int margin, int fft_symb, int transp_len)
Construct a new signal detector impl object.
kiss_fft.h
gr::lora_sdr::signal_detector_impl::~signal_detector_impl
~signal_detector_impl()
Destroy the signal detector impl object.
gr::lora_sdr::signal_detector_impl::general_work
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
gr::lora_sdr::signal_detector_impl
Definition: signal_detector_impl.h:42
signal_detector.h
helpers.h
gr::lora_sdr::signal_detector_impl::forecast
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
kiss_fft_state
Definition: _kiss_fft_guts.h:22
gr::lora_sdr::signal_detector
Definition: signal_detector.h:36
gr
Definition: add_crc.h:28