summaryrefslogtreecommitdiff
path: root/gr-fec/include/gnuradio/fec/polar_decoder_common.h
blob: 6f192e5fdd81660c5f5823114bda3ac724a4abe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*- c++ -*- */
/* 
 * Copyright 2015 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */


#ifndef INCLUDED_FEC_POLAR_DECODER_COMMON_H
#define INCLUDED_FEC_POLAR_DECODER_COMMON_H

#include <gnuradio/fec/api.h>
#include <gnuradio/fec/generic_decoder.h>
#include <gnuradio/fec/polar_common.h>

namespace gr {
  namespace fec {

    /*!
     * \brief Class holds common methods and attributes for different decoder implementations
     *
     */
    class FEC_API polar_decoder_common : public generic_decoder, public polar_common
    {
    public:
      polar_decoder_common(int block_size, int num_info_bits, std::vector<int> frozen_bit_positions, std::vector<char> frozen_bit_values);
      ~polar_decoder_common();

      // FECAPI
      double rate(){return (1.0 * get_input_size() / get_output_size());};
      int get_input_size(){return block_size();};
      int get_output_size(){return num_info_bits();};
      bool set_frame_size(unsigned int frame_size){return false;};

    private:
      static const float D_LLR_FACTOR = -2.19722458f;
      unsigned int d_frozen_bit_counter;

    protected:
      // calculate LLRs for stage
      float llr_odd(const float la, const float lb) const;
      float llr_even(const float la, const float lb, const unsigned char f) const;
      unsigned char llr_bit_decision(const float llr) const {return (llr < 0.0f) ? 1 : 0;};

      // control retrieval of frozen bits.
      const bool is_frozen_bit(const int u_num) const;
      const unsigned char next_frozen_bit();

      // preparation for decoding
      void initialize_decoder(unsigned char* u, float* llrs, const float* input);

      // basic algorithm methods
      void butterfly(float* llrs, unsigned char* u, const int stage, const int u_num, const int row);
      void butterfly_volk(float* llrs, unsigned char* u, const int stage, const int u_num, const int row);
      void butterfly_generic(float* llrs, unsigned char* u, const int stage, const int u_num, const int row);
      void even_u_values(unsigned char* u_even, const unsigned char* u, const int u_num);
      void odd_xor_even_values(unsigned char* u_xor, const unsigned char* u, const int u_num);
      void extract_info_bits(unsigned char* output, const unsigned char* input) const;

      // helper functions.
      void print_pretty_llr_vector(const float* llr_vec) const;

    };

  } // namespace fec
} // namespace gr

#endif /* INCLUDED_FEC_POLAR_DECODER_COMMON_H */