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