GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
polar_common.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio 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  * GNU Radio 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 GNU Radio; 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_FEC_POLAR_COMMON_H
25 #define INCLUDED_FEC_POLAR_COMMON_H
26 
27 #include <vector>
28 
29 #include <gnuradio/fec/api.h>
30 #include <vector>
31 
32 // Forward declaration for those objects. SWIG doesn't like them to be #include'd.
33 namespace gr {
34 namespace blocks {
35 namespace kernel {
36 class unpack_k_bits;
37 }
38 } // namespace blocks
39 } // namespace gr
40 
41 namespace gr {
42 namespace fec {
43 namespace code {
44 
45 /*!
46  * \brief POLAR code common operations and attributes
47  * \ingroup error_coding_blk
48  *
49  * \details
50  * Polar codes are based on this paper by Erdal Arikan "Channel
51  * Polarization: A Method for Constructing Capacity-Achieving Codes
52  * for Symmetric Binary-Input Memoryless Channels", 2009 block
53  * holds common information for encoders and decoders. All polar
54  * encoder/decoders inherit from polar_common.
55  *
56  * class holds common info. It is common to all encoders and decoders.
57  */
59 {
60 public:
61  /*!
62  * \param block_size codeword size. MUST be a power of 2.
63  * \param num_info_bits represents the number of information
64  * bits in a block. Also called frame_size. <= block_size
65  * \param frozen_bit_positions is an integer vector which
66  * defines the position of all frozen bits in a block.
67  * Its size MUST be equal to block_size - num_info_bits.
68  * Also it must be sorted and every position must only
69  * occur once.
70  * \param frozen_bit_values holds an unpacked byte for every
71  * frozen bit position. It defines if a frozen bit is
72  * fixed to '0' or '1'. Defaults to all ZERO.
73  */
74  polar_common(int block_size,
75  int num_info_bits,
76  std::vector<int> frozen_bit_positions,
77  std::vector<char> frozen_bit_values);
78  ~polar_common();
79 
80 protected:
81  const int block_size() const { return d_block_size; };
82  const int block_power() const { return d_block_power; };
83  const int num_info_bits() const { return d_num_info_bits; };
84 
85  // helper functions
86  long bit_reverse(long value, int active_bits) const;
87  void print_packed_bit_array(const unsigned char* printed_array,
88  const int num_bytes) const;
89  void print_unpacked_bit_array(const unsigned char* bits,
90  const unsigned int num_bytes) const;
91 
92  std::vector<int> d_frozen_bit_positions;
93  std::vector<char> d_frozen_bit_values;
94  std::vector<int> d_info_bit_positions;
96  void setup_info_bit_positions_reversed();
97  // std::vector<int> d_info_bit_positions_reversed;
98 
99 
100  // VOLK methods
101  void setup_volk_vectors();
102  void volk_encode(unsigned char* out_buf, const unsigned char* in_buf);
103  void volk_encode_block(unsigned char* out_buf, unsigned char* in_buf);
104  unsigned char* d_volk_temp;
105  unsigned char* d_volk_frozen_bit_mask;
106  unsigned char* d_volk_frozen_bits;
107 
108 private:
109  int d_block_size; // depending on paper called 'N' or 'm'
110  int d_block_power;
111  int d_num_info_bits; // mostly abbreviated by 'K'
112 
113  void initialize_info_bit_position_vector();
114 
116  d_unpacker; // convenience for 'print_packed_bit_array' function.
117 };
118 
119 } // namespace code
120 } // namespace fec
121 } // namespace gr
122 
123 #endif /* INCLUDED_FEC_POLAR_COMMON_H */
std::vector< int > d_info_bit_positions_reversed
Definition: polar_common.h:95
const int num_info_bits() const
Definition: polar_common.h:83
std::vector< int > d_info_bit_positions
Definition: polar_common.h:94
unsigned char * d_volk_frozen_bits
Definition: polar_common.h:106
Converts a byte with k relevant bits to k output bytes with 1 bit in the LSB.
Definition: unpack_k_bits.h:48
const int block_size() const
Definition: polar_common.h:81
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
std::vector< char > d_frozen_bit_values
Definition: polar_common.h:93
const int block_power() const
Definition: polar_common.h:82
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:30
unsigned char * d_volk_temp
Definition: polar_common.h:104
POLAR code common operations and attributes.
Definition: polar_common.h:58
unsigned char * d_volk_frozen_bit_mask
Definition: polar_common.h:105
std::vector< int > d_frozen_bit_positions
Definition: polar_common.h:92