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