GNU Radio's LORA_SDR Package
partial_ml_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_PARTIAL_ML_IMPL_H
22#define INCLUDED_LORA_SDR_PARTIAL_ML_IMPL_H
23
24#include <lora_sdr/partial_ml.h>
25#include <volk/volk.h>
26#include "helpers.h"
27#include <iostream>
28#include <fstream>
29
30extern "C"
31{
32#include "kiss_fft.h"
33}
34// #define GRLORA_DEBUG
35/**
36 * @brief Permitted symbol types
37 *
38 */
47};
48
49namespace gr
50{
51 namespace lora_sdr
52 {
53
55 {
56 private:
57 struct window
58 {
59 double power1;
60 double power2;
61 long win_len;
62 long Tu;
63 long Ti1;
64 long Ti2;
65 double tau;
66 double delta_cfo;
67 };
68 uint8_t m_sf; ///< Spreading factor
69 uint32_t m_N; ///< 2^sf
70 uint8_t m_os_factor; ///< oversampling factor
71 uint8_t m_id; ///< bloc index
72 int m_Ki; ///< number of bin considered for Si
73
74 window window; ///< the window to process
75 bool m_init; ///< variable used to attach each partial ml block to a different thread
76
77 std::vector<gr_complex> m_ref_upchirp;
78 std::vector<gr_complex> m_ref_downchirp;
79
80 std::vector<gr_complex> mf; ///< matched filter
81 std::vector<bool> third_symbol_part; ///< variable used to handle the symbol of the non-synchronized user that is cut in three parts (because of the quarter downchirp of the synchronized user).
82
83 int Su; ///< symbol of the synchronized user
84 double theta_u; ///< phase estimation of the user u (based on the phase of the bin of maximum amplitude)
85 double Mu; ///< magnitude of the bin with index Su
86 double SNR_est;///<estimate of the SNR of the preamble of the first user
87
88 //---------- coherent demod--------------
89 std::vector<gr_complex> preamb_peak; ///< NOT USED
90
91 double prev_theta_u;
92 bool first_upchirp;
93
94 // dechirp the symbol and return the magnitude, the angle and the the fft
95 std::vector<std::tuple<int, double, double>> dechirp_and_fft(const gr_complex *samples, Symbol_type type);
96
97 gr_complex matched_filter1(const gr_complex *dechirped, int win_len, int Si, double tau, double delta_cfo, int win_type);
98
99 gr_complex matched_filter2(const gr_complex *dechirped, int win_len, int Si, double tau, double delta_cfo, int win_type);
100
101 void add_demod_tag(int Su, int Si1, int Si2, double Mu, double Mi1, double Mi2, double SNR_est);
102
103 bool is_kind_upchirp(long t);
104
105 bool is_kind_downchirp(long t);
106
107#ifdef GRLORA_DEBUG
108 std::ofstream out_file;
109#endif
110
111 public:
112 partial_ml_impl(uint8_t sf, uint8_t id);
114
115 // Where all the action really happens
116 void forecast(int noutput_items, gr_vector_int &ninput_items_required);
117
118 int general_work(int noutput_items,
119 gr_vector_int &ninput_items,
120 gr_vector_const_void_star &input_items,
121 gr_vector_void_star &output_items);
122 };
123
124 } // namespace lora_sdr
125} // namespace gr
126
127#endif /* INCLUDED_LORA_SDR_PARTIAL_ML_IMPL_H */
Definition: partial_ml_impl.h:55
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
partial_ml_impl(uint8_t sf, uint8_t id)
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Definition: partial_ml.h:37
Symbol_type
Permitted symbol types.
Definition: mu_synchro_impl.h:35
Definition: add_crc.h:28
@ PAYLOAD
Definition: partial_ml_impl.h:45
@ QUARTER_DOWN
Definition: partial_ml_impl.h:44
@ DOWNCHIRP
Definition: partial_ml_impl.h:43
@ UPCHIRP
Definition: partial_ml_impl.h:41
@ SYNC_WORD
Definition: partial_ml_impl.h:42
@ VOID
Definition: partial_ml_impl.h:40
@ UNDETERMINED
Definition: partial_ml_impl.h:46