GNU Radio's OWC Package
PAM_Modulator_two_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /* gr-owc OOT module for optical wireless communications.
3  *
4  * Copyright 2021 Arsalan Ahmed from The Ubiquitous Communications and Networking (UCAN) Lab, University of Massachusetts, Boston.
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this software; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef INCLUDED_OWC_PAM_MODULATOR_TWO_IMPL_H
24 #define INCLUDED_OWC_PAM_MODULATOR_TWO_IMPL_H
25 
26 #include <owc/PAM_Modulator_two.h>
27 
28 namespace gr {
29  namespace owc {
30 
32  {
33  private:
34  int d_modulation_order;
35  float d_amplitude;
36  float d_mean;
37  int d_samples_per_symbol;
38 
39  std::vector<int> d_symbol_array;
40  std::vector<float> d_level_array;
41 
42  public:
45 
46  void set_modulation_order(int modulation_order) { d_modulation_order = modulation_order; }
47  int modulation_order() { return d_modulation_order; }
48 
49  void set_amplitude(float amplitude) { d_amplitude = amplitude; }
50  float amplitude() { return d_amplitude; }
51 
52  void set_mean(float mean) { d_mean = mean; }
53  float mean() { return d_mean; }
54 
55  void set_samples_per_symbol(int samples_per_symbol) { d_samples_per_symbol = samples_per_symbol; }
56  int samples_per_symbol() { return d_samples_per_symbol; }
57 
59  {
60  int num_bits = floor(log2(modulation_order));
61  int max_symbol = pow(2,num_bits);
62 
63  for (int i = 0; i < max_symbol; i++)
64  {
65  d_symbol_array.push_back(i);
66  }
67 
68  }
69  std::vector<int> symbol_array() {return d_symbol_array;}
70 
71 
73  {
74 
75  d_level_array.clear();
76 
77  int num_bits = floor(log2(modulation_order));
78  int max_symbol = pow(2,num_bits);
79 
80  float max_magnitude = mean + amplitude;
81  float min_magnitude = mean - amplitude;
82 
83  float range = max_magnitude - min_magnitude;
84  float single_level_magnitude = range/(modulation_order-1);
85 
86  float levels = min_magnitude;
87 
88  for (int i = 0; i < max_symbol; i++)
89  {
90  d_level_array.push_back(levels);
91  levels += single_level_magnitude;
92  }
93 
94  }
95  std::vector<float> level_array() {return d_level_array;}
96 
97  // Where all the action really happens
98  int work(
99  int noutput_items,
100  gr_vector_const_void_star &input_items,
101  gr_vector_void_star &output_items
102  );
103  };
104 
105  } // namespace owc
106 } // namespace gr
107 
108 #endif /* INCLUDED_OWC_PAM_MODULATOR_TWO_IMPL_H */
109 
void set_samples_per_symbol(int samples_per_symbol)
Definition: PAM_Modulator_two_impl.h:55
void set_modulation_order(int modulation_order)
Definition: PAM_Modulator_two_impl.h:46
int samples_per_symbol()
Definition: PAM_Modulator_two_impl.h:56
float mean()
Definition: PAM_Modulator_two_impl.h:53
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
std::vector< int > symbol_array()
Definition: PAM_Modulator_two_impl.h:69
Definition: binary_to_decimal_mapper.h:29
<+description of block+>
Definition: PAM_Modulator_two.h:37
PAM_Modulator_two_impl(int modulation_order, float amplitude, float mean, int samples_per_symbol)
void set_symbol_array(int modulation_order)
Definition: PAM_Modulator_two_impl.h:58
void set_amplitude(float amplitude)
Definition: PAM_Modulator_two_impl.h:49
int modulation_order()
Definition: PAM_Modulator_two_impl.h:47
void set_mean(float mean)
Definition: PAM_Modulator_two_impl.h:52
void set_level_array(int modulation_order, float amplitude, float mean)
Definition: PAM_Modulator_two_impl.h:72
float amplitude()
Definition: PAM_Modulator_two_impl.h:50
Definition: PAM_Modulator_two_impl.h:31
std::vector< float > level_array()
Definition: PAM_Modulator_two_impl.h:95