GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
awgn_bp.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  *
13  * This class defines functions for message passing mechanism for a
14  * AWGN channel. Message passing (also known as belief propagation)
15  * is used for decoding LDPC codes. Details of how LDPC codes are
16  * decoded is available in the link below
17  * - http://www.cs.utoronto.ca/~radford/ftp/LDPC-2012-02-11/decoding.html
18  *
19  * Belief propagation decoding is a suboptimal but efficient method of
20  * decoding LDPC codes.
21  *
22  */
23 
24 #ifndef AWGN_BP_H
25 #define AWGN_BP_H
26 
27 #include "alist.h"
28 #include "gf2mat.h"
29 #include <gnuradio/fec/api.h>
30 #include <cmath>
31 #include <vector>
32 
34 {
35 public:
36  //! Default constructor
37  awgn_bp(){};
38 
39  //! A constructor for given GF2Mat
40  awgn_bp(const GF2Mat X);
41 
42  //! A constructor for given alist
43  awgn_bp(alist _list);
44 
45  //! Initializes the class using given alist
46  void set_alist(alist _list);
47 
48  //! Returns the variable Q
49  std::vector<std::vector<double>> get_Q();
50 
51  //! Returns the variable R
52  std::vector<std::vector<double>> get_R();
53 
54  //! Returns the variable H
56 
57  //! Calculates the likelihood ratios given an input vector
58  void rx_lr_calc(std::vector<float> codeword);
59 
60  //! Returns the variable rx_lr
61  std::vector<double> get_rx_lr();
62 
63  //! Returns the variable lr
64  std::vector<double> get_lr();
65 
66  //! Initializes the sum product algorithm set-up
68 
69  //! Updates the check-nodes based on messages from variable nodes
70  void update_chks();
71 
72  //! Updates the variable-nodes based on messages from check nodes
73  void update_vars();
74 
75  //! Returns the current estimate
76  std::vector<uint8_t> get_estimate();
77 
78  //! Computes initial estimate based on the vector rx_word
79  void compute_init_estimate(std::vector<float> rx_word);
80 
81  //! Computes the estimate based on current likelihood-ratios lr
82  void decision();
83 
84  //! Returns the syndrome for the current estimate
85  std::vector<uint8_t> get_syndrome();
86 
87  //! Returns the syndrome for the input codeword
88  std::vector<uint8_t> get_syndrome(const std::vector<uint8_t> codeword);
89 
90  //! Checks if the current estimate is a codeword
91  bool is_codeword();
92 
93  //! Checks if the input is a codeword
94  bool is_codeword(const std::vector<uint8_t> codeword);
95 
96  //! Sets the variable K
97  void set_K(int k);
98 
99  //! Returns the variable K
100  int get_K();
101 
102  //! Sets the variable max_iterations
103  void set_max_iterations(int k);
104 
105  //! Returns the variable max_iterations
107 
108  /*!
109  * \brief Decodes the given vector rx_word by message passing.
110  *
111  * \param rx_word The received samples for decoding.
112  * \param niterations The number of message passing iterations
113  * done to decode this codeword.
114  */
115  std::vector<uint8_t> decode(std::vector<float> rx_word, int* niterations);
116 
117 private:
118  //! The number of check nodes in the tanner-graph
119  int M;
120 
121  //! The number of variable nodes in the tanner-graph
122  int N;
123 
124  //! The dimension of the code used
125  int K;
126 
127  //! The maximum number of message passing iterations allowed
128  int max_iterations;
129 
130  //! The parity check matrix of the LDPC code
131  GF2Mat H;
132 
133  //! Matrix holding messages from check nodes to variable nodes
134  std::vector<std::vector<double>> R;
135 
136  //! Matrix holding messages from variable nodes to check nodes
137  std::vector<std::vector<double>> Q;
138 
139  //! The array of likelihood computed from the channel output
140  std::vector<double> rx_lr;
141 
142  //! The array for holding likelihoods computed on BP decoding
143  std::vector<double> lr;
144 
145  //! List of integer coordinates along each column with non-zero entries
146  std::vector<std::vector<int>> nlist;
147 
148  //! List of integer coordinates along each row with non-zero entries
149  std::vector<std::vector<int>> mlist;
150 
151  //! Weight of each column n
152  std::vector<int> num_nlist;
153 
154  //! Weight of each row m
155  std::vector<int> num_mlist;
156 
157  //! The array for holding estimate computed on BP decoding
158  std::vector<uint8_t> estimate;
159 };
160 #endif // ifndef AWGN_BP_H
Definition: gf2mat.h:18
Definition: alist.h:33
Definition: awgn_bp.h:34
std::vector< std::vector< double > > get_R()
Returns the variable R.
void set_alist(alist _list)
Initializes the class using given alist.
void spa_initialize()
Initializes the sum product algorithm set-up.
std::vector< double > get_lr()
Returns the variable lr.
void update_chks()
Updates the check-nodes based on messages from variable nodes.
bool is_codeword(const std::vector< uint8_t > codeword)
Checks if the input is a codeword.
void decision()
Computes the estimate based on current likelihood-ratios lr.
bool is_codeword()
Checks if the current estimate is a codeword.
void rx_lr_calc(std::vector< float > codeword)
Calculates the likelihood ratios given an input vector.
std::vector< uint8_t > get_estimate()
Returns the current estimate.
void set_K(int k)
Sets the variable K.
std::vector< double > get_rx_lr()
Returns the variable rx_lr.
GF2Mat get_H()
Returns the variable H.
std::vector< uint8_t > get_syndrome()
Returns the syndrome for the current estimate.
int get_K()
Returns the variable K.
std::vector< std::vector< double > > get_Q()
Returns the variable Q.
awgn_bp(alist _list)
A constructor for given alist.
std::vector< uint8_t > get_syndrome(const std::vector< uint8_t > codeword)
Returns the syndrome for the input codeword.
void update_vars()
Updates the variable-nodes based on messages from check nodes.
void set_max_iterations(int k)
Sets the variable max_iterations.
awgn_bp()
Default constructor.
Definition: awgn_bp.h:37
int get_max_iterations()
Returns the variable max_iterations.
awgn_bp(const GF2Mat X)
A constructor for given GF2Mat.
void compute_init_estimate(std::vector< float > rx_word)
Computes initial estimate based on the vector rx_word.
std::vector< uint8_t > decode(std::vector< float > rx_word, int *niterations)
Decodes the given vector rx_word by message passing.
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18