GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
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 <iostream>
32 #include <vector>
33 
35 {
36 public:
37  //! Default constructor
38  awgn_bp(){};
39 
40  //! A constructor for given GF2Mat and sigma
41  awgn_bp(const GF2Mat X, float sgma);
42 
43  //! A constructor for given alist and sigma
44  awgn_bp(alist _list, float sgma);
45 
46  //! Initializes the class using given alist and sigma
47  void set_alist_sigma(alist _list, float sgma);
48 
49  //! Returns the variable Q
50  std::vector<std::vector<double>> get_Q();
51 
52  //! Returns the variable R
53  std::vector<std::vector<double>> get_R();
54 
55  //! Returns the variable H
57 
58  //! Calculates the likelihood ratios given an input vector
59  void rx_lr_calc(std::vector<float> codeword);
60 
61  //! Returns the variable rx_lr
62  std::vector<double> get_rx_lr();
63 
64  //! Returns the variable lr
65  std::vector<double> get_lr();
66 
67  //! Initializes the sum product algorithm set-up
69 
70  //! Updates the check-nodes based on messages from variable nodes
71  void update_chks();
72 
73  //! Updates the variable-nodes based on messages from check nodes
74  void update_vars();
75 
76  //! Returns the current estimate
77  std::vector<uint8_t> get_estimate();
78 
79  //! Computes initial estimate based on the vector rx_word
80  void compute_init_estimate(std::vector<float> rx_word);
81 
82  //! Computes the estimate based on current likelihood-ratios lr
83  void decision();
84 
85  //! Returns the syndrome for the current estimate
86  std::vector<uint8_t> get_syndrome();
87 
88  //! Returns the syndrome for the input codeword
89  std::vector<uint8_t> get_syndrome(const std::vector<uint8_t> codeword);
90 
91  //! Checks if the current estimate is a codeword
92  bool is_codeword();
93 
94  //! Checks if the input is a codeword
95  bool is_codeword(const std::vector<uint8_t> codeword);
96 
97  //! Sets the variable K
98  void set_K(int k);
99 
100  //! Returns the variable K
101  int get_K();
102 
103  //! Sets the variable max_iterations
104  void set_max_iterations(int k);
105 
106  //! Returns the variable max_iterations
108 
109  /*!
110  * \brief Decodes the given vector rx_word by message passing.
111  *
112  * \param rx_word The received samples for decoding.
113  * \param niterations The number of message passing iterations
114  * done to decode this codeword.
115  */
116  std::vector<uint8_t> decode(std::vector<float> rx_word, int* niterations);
117 
118 private:
119  //! The number of check nodes in the tanner-graph
120  int M;
121 
122  //! The number of variable nodes in the tanner-graph
123  int N;
124 
125  //! The dimension of the code used
126  int K;
127 
128  //! The maximum number of message passing iterations allowed
129  int max_iterations;
130 
131  //! The parity check matrix of the LDPC code
132  GF2Mat H;
133 
134  //! The standard-deviation of the AWGN channel
135  float sigma;
136 
137  //! Matrix holding messages from check nodes to variable nodes
138  std::vector<std::vector<double>> R;
139 
140  //! Matrix holding messages from variable nodes to check nodes
141  std::vector<std::vector<double>> Q;
142 
143  //! The array of likelihood computed from the channel output
144  std::vector<double> rx_lr;
145 
146  //! The array for holding likelihoods computed on BP decoding
147  std::vector<double> lr;
148 
149  //! List of integer coordinates along each column with non-zero entries
150  std::vector<std::vector<int>> nlist;
151 
152  //! List of integer coordinates along each row with non-zero entries
153  std::vector<std::vector<int>> mlist;
154 
155  //! Weight of each column n
156  std::vector<int> num_nlist;
157 
158  //! Weight of each row m
159  std::vector<int> num_mlist;
160 
161  //! The array for holding estimate computed on BP decoding
162  std::vector<uint8_t> estimate;
163 };
164 #endif // ifndef AWGN_BP_H
Definition: gf2mat.h:18
Definition: alist.h:33
Definition: awgn_bp.h:35
std::vector< std::vector< double > > get_R()
Returns the variable R.
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.
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_alist_sigma(alist _list, float sgma)
Initializes the class using given alist and sigma.
void set_max_iterations(int k)
Sets the variable max_iterations.
awgn_bp()
Default constructor.
Definition: awgn_bp.h:38
awgn_bp(const GF2Mat X, float sgma)
A constructor for given GF2Mat and sigma.
int get_max_iterations()
Returns the variable max_iterations.
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.
awgn_bp(alist _list, float sgma)
A constructor for given alist and sigma.
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18