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_ENCODER_SYSTEMATIC_H
25 #define INCLUDED_FEC_POLAR_ENCODER_SYSTEMATIC_H
26 
27 #include <gnuradio/fec/api.h>
28 #include <gnuradio/fec/generic_encoder.h>
29 #include <gnuradio/fec/polar_common.h>
30 
31 namespace gr {
32 namespace fec {
33 namespace code {
34 
35 /*!
36  * \brief systematic POLAR encoder
37  * for basic details see 'polar_common' class.
38  * \ingroup error_coding_blk
39  *
40  * \details
41  * expects values with MSB first. It needs a full information word and encodes it in one
42  * pass. Output is a codeword of block_size.
43  *
44  * Systematic encoding indicates that the info bit values are present in the codeword.
45  * 'info_bit_positions' may be obtained by ordering all non frozen_bit_positions in
46  * increasing order. One may extract them at their positions after a bit reversal
47  * operation. encoder -> decoder chain would need additional bit-reversal after encoding +
48  * before decoding. This is unnecessary.
49  */
50 class FEC_API polar_encoder_systematic : public generic_encoder, public polar_common
51 {
52 public:
53     /*!
54      * Factory for a polar code encoder object.
55      *
56      * \param block_size defines the codeword size. It MUST be a
57      *        power of 2.
58      * \param num_info_bits represents the number of information
59      *        bits in a block. Also called frame_size.
60      * \param frozen_bit_positions is an integer vector which
61      *        defines the position of all frozen bits in a block.
62      *        Its size MUST be equal to block_size - num_info_bits.
63      *        Also it must be sorted and every position must only
64      *        occur once. Frozen bit values will be set to ZERO!
65      */
66     static generic_encoder::sptr
67     make(int block_size, int num_info_bits, std::vector<int> frozen_bit_positions);
68 
69     // FECAPI
70     void generic_work(void* in_buffer, void* out_buffer);
rate()71     double rate() { return (1.0 * get_input_size() / get_output_size()); };
get_input_size()72     int get_input_size() { return num_info_bits(); };
get_output_size()73     int get_output_size() { return block_size(); };
set_frame_size(unsigned int frame_size)74     bool set_frame_size(unsigned int frame_size) { return false; };
75 
76     ~polar_encoder_systematic();
77 
78 private:
79     polar_encoder_systematic(int block_size,
80                              int num_info_bits,
81                              std::vector<int> frozen_bit_positions);
82 
83     void bit_reverse_and_reset_frozen_bits(unsigned char* outbuf,
84                                            const unsigned char* inbuf);
85     unsigned char* d_volk_syst_intermediate;
86 };
87 
88 } // namespace code
89 } // namespace fec
90 } // namespace gr
91 
92 #endif /* INCLUDED_FEC_POLAR_ENCODER_SYSTEMATIC_H */
93