GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
polar_encoder.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_ENCODER_H
13 #define INCLUDED_FEC_POLAR_ENCODER_H
14 
15 #include <gnuradio/fec/api.h>
18 
19 namespace gr {
20 namespace fec {
21 namespace code {
22 
23 /*!
24  * \brief POLAR encoder
25  * for basic details see 'polar_common' class.
26  * \ingroup error_coding_blk
27  *
28  * \details
29  * expects values with MSB first. It needs a full information word and encodes it in one
30  * pass. Output is a codeword of block_size.
31  */
33 {
34 public:
35  /*!
36  * Factory for a polar code encoder object.
37  *
38  * \param block_size defines the codeword size. It MUST be a
39  * power of 2.
40  * \param num_info_bits represents the number of information
41  * bits in a block. Also called frame_size.
42  * \param frozen_bit_positions is an integer vector which
43  * defines the position of all frozen bits in a block.
44  * Its size MUST be equal to block_size - num_info_bits.
45  * Also it must be sorted and every position must only
46  * occur once.
47  * \param frozen_bit_values holds an unpacked byte for every
48  * frozen bit position. It defines if a frozen bit is
49  * fixed to '0' or '1'. Defaults to all ZERO.
50  * \param is_packed choose 1 active bit/byte or 8 active
51  * bit/byte. if false, VOLK polar encoder is used.
52  */
53  static generic_encoder::sptr make(int block_size,
54  int num_info_bits,
55  std::vector<int> frozen_bit_positions,
56  std::vector<uint8_t> frozen_bit_values,
57  bool is_packed = false);
58  ~polar_encoder() override;
59 
60  // FECAPI
61  void generic_work(void* in_buffer, void* out_buffer) override;
62  double rate() override { return (1.0 * get_input_size() / get_output_size()); };
63  int get_input_size() override { return num_info_bits() / (d_is_packed ? 8 : 1); };
64  int get_output_size() override { return block_size() / (d_is_packed ? 8 : 1); };
65  bool set_frame_size(unsigned int frame_size) override { return false; };
66  const char* get_input_conversion() override { return d_is_packed ? "pack" : "none"; };
67  const char* get_output_conversion() override
68  {
69  return d_is_packed ? "packed_bits" : "none";
70  };
71 
72 private:
73  polar_encoder(int block_size,
74  int num_info_bits,
75  std::vector<int>& frozen_bit_positions,
76  std::vector<uint8_t>& frozen_bit_values,
77  bool is_packed);
78  bool d_is_packed;
79 
80  // Helper function to allow `d_frozen_bit_prototype` to be const.
81  volk::vector<unsigned char> make_prototype() const;
82 
83  // methods insert input bits and frozen bits into packed array for encoding
84  const volk::vector<unsigned char>
85  d_frozen_bit_prototype; // packed frozen bits are written onto it and
86  // later copies are used.
87  void insert_packed_frozen_bits_and_reverse(unsigned char* target,
88  const unsigned char* input) const;
89  void insert_unpacked_bit_into_packed_array_at_position(unsigned char* target,
90  const unsigned char bit,
91  const int pos) const;
92  void insert_packet_bit_into_packed_array_at_position(unsigned char* target,
93  const unsigned char bit,
94  const int target_pos,
95  const int bit_pos) const;
96 
97  // packed encoding methods
98  void encode_vector_packed(unsigned char* target) const;
99  void encode_vector_packed_subbyte(unsigned char* target) const;
100  void encode_packed_byte(unsigned char* target) const;
101  void encode_vector_packed_interbyte(unsigned char* target) const;
102 };
103 
104 } // namespace code
105 } // namespace fec
106 } // namespace gr
107 
108 #endif /* INCLUDED_FEC_POLAR_ENCODER_H */
POLAR code common operations and attributes.
Definition: polar_common.h:50
POLAR encoder for basic details see 'polar_common' class.
Definition: polar_encoder.h:33
void generic_work(void *in_buffer, void *out_buffer) override
const char * get_output_conversion() override
Definition: polar_encoder.h:67
static generic_encoder::sptr make(int block_size, int num_info_bits, std::vector< int > frozen_bit_positions, std::vector< uint8_t > frozen_bit_values, bool is_packed=false)
const char * get_input_conversion() override
Definition: polar_encoder.h:66
double rate() override
Definition: polar_encoder.h:62
int get_output_size() override
Definition: polar_encoder.h:64
bool set_frame_size(unsigned int frame_size) override
Definition: polar_encoder.h:65
int get_input_size() override
Definition: polar_encoder.h:63
Definition: generic_encoder.h:23
std::shared_ptr< generic_encoder > sptr
Definition: generic_encoder.h:37
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29