GNU Radio's OWC Package
PPM_Demodulator_cplus_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/* gr-owc OOT module for optical wireless communications.
3 * gr-owc is compatible with GNU Radio v3.10
4 *
5 * Copyright 2024 Kunal Sangurmath from Ubiquitous Communications and Networking (UCAN) Lab, University of Massachusetts, Boston.
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef INCLUDED_OWC_PPM_DEMODULATOR_CPLUS_IMPL_H
25#define INCLUDED_OWC_PPM_DEMODULATOR_CPLUS_IMPL_H
26
28
29namespace gr {
30namespace owc {
31
33private:
34 int d_samples_per_symbol;
35 int d_samples_per_pulse;
36 int d_modulation_order;
37 std::vector<std::vector<float>> cases;
38
39 void initialize_vector_PPM(){
40 const int slot = samples_per_symbol() / modulation_order();
41
42 cases.assign(modulation_order(), std::vector<float>(samples_per_symbol(), 0.0f));
43
44 for (int k = 0; k < modulation_order(); k++) {
45 int start = k * slot;
46
47 for (int n = 0; n < samples_per_pulse(); n++) {
48 int i = start + n;
49 if (i < samples_per_symbol()) {
50 cases[k][i] = 1.0f;
51 }
52 }
53 }
54 }
55
56 float matched_filter_ppm(std::vector<float> samples_array){
57
58 int best_k = -1;
59 float best_metric = std::numeric_limits<float>::min();
60
61 for (int k = 0; k < modulation_order(); k++) {
62 float metric = 0.0f;
63 for (int x = 0; x < samples_per_symbol(); x++) {
64 metric += samples_array[x] * cases[k][x];
65 }
66
67 if (metric > best_metric) {
68 best_metric = metric;
69 best_k = k;
70 }
71 }
72
73 return (float)best_k;
74 }
75
76public:
79
81 int samples_per_symbol() { return d_samples_per_symbol; }
82
83 void set_samples_per_pulse(int samples_per_pulse) { d_samples_per_pulse = samples_per_pulse;}
84 int samples_per_pulse() { return d_samples_per_pulse; }
85
86 void set_modulation_order(int modulation_order) { d_modulation_order = modulation_order;}
87 int modulation_order() { return d_modulation_order; }
88
89 // Where all the action really happens
90 int work(int noutput_items, gr_vector_const_void_star &input_items,
91 gr_vector_void_star &output_items);
92};
93
94} // namespace owc
95} // namespace gr
96
97#endif /* INCLUDED_OWC_PPM_DEMODULATOR_CPLUS_IMPL_H */
int samples_per_symbol()
Definition PPM_Demodulator_cplus_impl.h:81
void set_samples_per_pulse(int samples_per_pulse)
Definition PPM_Demodulator_cplus_impl.h:83
void set_samples_per_symbol(int samples_per_symbol)
Definition PPM_Demodulator_cplus_impl.h:80
int modulation_order()
Definition PPM_Demodulator_cplus_impl.h:87
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
int samples_per_pulse()
Definition PPM_Demodulator_cplus_impl.h:84
void set_modulation_order(int modulation_order)
Definition PPM_Demodulator_cplus_impl.h:86
PPM_Demodulator_cplus_impl(int samples_per_symbol, int samples_per_pulse, int modulation_order)
<+description of block+>
Definition PPM_Demodulator_cplus.h:38
Definition Hermitian_Symmetry_i_o_same_vec_size_cplus.h:31
Definition Hermitian_Symmetry_i_o_same_vec_size_cplus.h:30