File: polar_decoder_sc_systematic.cc

package info (click to toggle)
gnuradio 3.7.13.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 45,992 kB
  • sloc: cpp: 155,723; python: 88,934; xml: 42,165; ansic: 41,036; fortran: 927; asm: 803; sh: 224; lisp: 31; makefile: 17
file content (104 lines) | stat: -rw-r--r-- 3,689 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* -*- 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.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/io_signature.h>
#include <gnuradio/fec/polar_decoder_sc_systematic.h>
#include <volk/volk.h>

namespace gr {
  namespace fec {
    namespace code {

      generic_decoder::sptr
      polar_decoder_sc_systematic::make(int block_size, int num_info_bits,
                                        std::vector<int> frozen_bit_positions)
      {
        return generic_decoder::sptr(
            new polar_decoder_sc_systematic(block_size, num_info_bits, frozen_bit_positions));
      }

      polar_decoder_sc_systematic::polar_decoder_sc_systematic(
          int block_size, int num_info_bits, std::vector<int> frozen_bit_positions) :
              polar_decoder_common(block_size, num_info_bits, frozen_bit_positions, std::vector<char>())
      {
        d_llr_vec = (float*) volk_malloc(sizeof(float) * block_size * (block_power() + 1), volk_get_alignment());
        memset(d_llr_vec, 0, sizeof(float) * block_size * (block_power() + 1));
        d_u_hat_vec = (unsigned char*) volk_malloc(block_size * (block_power() + 1), volk_get_alignment());
        memset(d_u_hat_vec, 0, sizeof(unsigned char) * block_size * (block_power() + 1));
        d_frame_vec = (unsigned char*) volk_malloc(block_size, volk_get_alignment());
        memset(d_frame_vec, 0, sizeof(unsigned char) * block_size);
      }

      polar_decoder_sc_systematic::~polar_decoder_sc_systematic()
      {
          volk_free(d_llr_vec);
          volk_free(d_u_hat_vec);
          volk_free(d_frame_vec);
      }

      void
      polar_decoder_sc_systematic::generic_work(void* in_buffer, void* out_buffer)
      {
        const float *in = (const float*) in_buffer;
        unsigned char *out = (unsigned char*) out_buffer;

        initialize_decoder(d_u_hat_vec, d_llr_vec, in);
        sc_decode(d_llr_vec, d_u_hat_vec);
        volk_encode_block(d_frame_vec, d_u_hat_vec);
        extract_info_bits_reversed(out, d_frame_vec);
      }

      void
      polar_decoder_sc_systematic::sc_decode(float* llrs, unsigned char* u)
      {
        for(int i = 0; i < block_size(); i++){
          butterfly(llrs, u, 0, i, i);
          u[i] = retrieve_bit_from_llr(llrs[i], i);
        }
      }

      unsigned char
      polar_decoder_sc_systematic::retrieve_bit_from_llr(float llr, const int pos)
      {
        if(is_frozen_bit(pos)){
          return next_frozen_bit();
        }
        return llr_bit_decision(llr);
      }

      void
      polar_decoder_sc_systematic::extract_info_bits_reversed(unsigned char* outbuf,
                                                              const unsigned char* inbuf)
      {
        for(int i = 0; i < num_info_bits(); i++){
          *outbuf++ = inbuf[d_info_bit_positions_reversed[i]];
        }
      }

    } // namespace code
  } /* namespace fec */
} /* namespace gr */