GNU Radio's CCSDS Package
examples/LDPC/ldpc_2/ldpc_decoder/debug.h
Go to the documentation of this file.
1 #ifndef DEBUG
2 #define DEBUG
3 #include <iostream>
4 #include <string>
5 //#include <itpp/itcomm.h>
6 using namespace std;
7 //using namespace itpp;
8 #include "ldpc.h"
9 string path = "/home/mbkitine/Dropbox/Lulea/GRC/DeepSpace/gr-ccsds/examples/LDPC/ldpc_2/";
10 
11 
12 void printRow(std::vector<int> row)
13 {
14  for(unsigned int i = 0; i < row.size(); i++)
15  {
16  std::cout << row[i] << " " ;
17  }
18  std::cout << std::endl;
19 }
20 void printParity(std::vector<std::vector<int> > parity)
21 {
22  int R = parity.size();
23  int C = parity.at(0).size();
24  std::cout << "Parity matrix size : " << R << " X " << C << std::endl;
25  for(int r = 0 ; r < R; r++)
26  {
27  printRow(parity[r]);
28  }
29 }
30 
31 
32 
33 template <class T>
34 std::vector<T> getCol(std::vector< std::vector<T> > mat2D,int index)
35 {
36  std::vector<T> col;
37  for(unsigned int i = 0; i < mat2D.size(); i++)
38  {
39  col.push_back(mat2D[i][index]);
40  }
41  return col;
42 }
43 
44 template <class T>
45 std::vector<T> getRow(std::vector< std::vector<T> > mat2D, int index)
46 {
47  return mat2D[index];
48 }
49 
51 {
52  std::vector<double> lq = node.getLq();
53  for(unsigned int i = 0; i < lq.size(); i++)
54  {
55  std::cout << "Lq(" << i << ") = " << lq[i] << " ";
56  }
57  std::cout << std::endl;
58 }
59 
61 {
62  std::vector<double> lq = node.getLq();
63  for(unsigned int i = 0; i < lq.size(); i++)
64  {
65  std::cout << "Lq(" << i << ") = " << lq[i] << " ";
66  }
67  std::cout << std::endl;
68 }
69 
71 {
72  std::vector<double> lr = node.getLr();
73  for(unsigned int i = 0; i < lr.size(); i++)
74  {
75  std::cout << "Lr(" << i << ") = " << lr[i] << " ";
76  }
77  std::cout << std::endl;
78 }
79 
80 void printVarNodeLogAPP(std::vector<variableNode> v)
81 {
82  //std::cout << "Size of logapp : " << v.size() << std::endl;
83  std::cout << "[ ";
84  for(unsigned int i = 0; i < v.size(); i++)
85  std::cout << v[i].getlogAPP() << " ";
86  std::cout << "]" << std::endl;
87  std::cout << "[ ";
88  for(unsigned int i = 0; i < v.size(); i++)
89  std::cout << ((v[i].getlogAPP() > 0) ? 0 : 1) << " ";
90  std::cout << "]" << std::endl;
91 }
92 std::vector< std::vector<int> > readAlist(string filename,
93  std::vector< std::vector<int> > &m_list,std::vector< std::vector<int> > &n_list)
94 {
95  filename = path + filename;
96  std::cout <<"File path : " << filename << std::endl;
97  alist myAlist(filename.c_str());
98  std::cout << "Alist file read" << std::endl;
99  std::vector< std::vector<char> > H = myAlist.get_matrix();
100  std::cout << "alist matrix read" << std::endl;
101  std::vector< std::vector<int> > H_int;
102  int R = H.size();
103  int C = H[0].size();
104 
105  std::cout << "Size of R : " << R << std::endl;
106  std::cout << "Size of C : " << C << std::endl;
107  for(int r = 0; r < R; r++)
108  {
109  std::vector<int> row;
110  for(int c = 0; c < C; c++)
111  {
112  //std::cout << int(H[r][c]);
113 
114  row.push_back(int(H[r][c]));
115  }
116  H_int.push_back(row);
117  row.clear();
118  }
119  m_list = myAlist.get_mlist();
120  n_list = myAlist.get_nlist();
121  /*
122  for (int i = 0; i < m_list.size(); i++)
123  {
124  for(int j = 0; j < m_list[0].size(); j++)
125  {
126  std::cout << m_list[i][j] << " ";
127  }
128  std::cout << std::endl;
129  }*/
130 
131  return H_int;
132 }
133 
134 void ldpcTDD()
135 {
136  const string filename = "/home/mbkitine/Dropbox/Lulea/GRC/DeepSpace/gr-ccsds/examples/LDPC/ldpc_2/myParity";
137  ldpc myCode(filename);
138  double coderate = myCode.getCodeRate();
139  std::vector<double> y1{+0.2, +0.2, -0.9, +0.6, +0.5, -1.1, -0.4, -1.2};
140  std::vector<double> logapp = myCode.decode(y1,7,0.5);
141  for(unsigned int i = 0; i < logapp.size(); i++)
142  std::cout << logapp[i] << " ";
143  std::cout << std::endl;
144 }
145 
146 /*
147  void saveAlist(string filename , std::vector<std::vector<int> > mat)
148  {
149  int R = mat.size();
150  int C = mat[0].size();
151  LDPC_Parity itppParity = LDPC_Parity(R,C);
152  for(int r = 0; r < R; r++)
153  {
154  for(int c = 0; c < C; c++)
155  itppParity.set(r,c,mat[r][c]);
156  }
157  //Save alist file
158  //string path = "/home/mbkitine/Dropbox/Lulea/GRC/DeepSpace/gr-ccsds/examples/LDPC/ldpc_2/" + filename;
159  itppParity.save_alist(path + filename);
160  }*/
161 
162 
163 #endif // DEBUG
164 
std::vector< double > getLq()
Definition: examples/LDPC/ldpc_2/ldpc_decoder/variablenode.h:21
void printVarNodeLq(variableNode node)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:50
Definition: examples/LDPC/ldpc_2/ldpc_decoder/variablenode.h:7
void printVarNodeLogAPP(std::vector< variableNode > v)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:80
void printChkNodeLr(checkNode node)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:70
STL namespace.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:45
std::vector< std::vector< int > > readAlist(string filename, std::vector< std::vector< int > > &m_list, std::vector< std::vector< int > > &n_list)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:92
std::vector< std::vector< char > > get_matrix()
Returns the corresponding H matrix.
std::vector< double > decode(std::vector< double > softBits, int iterations, double sigma)
double getLr(int index)
double getCodeRate()
Definition: examples/LDPC/ldpc_2/ldpc_decoder/ldpc.h:23
void printParity(std::vector< std::vector< int > > parity)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:20
void ldpcTDD()
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:134
Definition: examples/LDPC/ldpc_2/ldpc_decoder/ldpc.h:11
std::vector< T > getRow(std::vector< std::vector< T > > mat2D, int index)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:45
void printRow(std::vector< int > row)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:12
string path
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:9
Definition: examples/LDPC/ldpc_2/ldpc_decoder/checknode.h:6
void printChkNodeLq(checkNode node)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:60
std::vector< double > getLq()
Definition: examples/LDPC/ldpc_2/ldpc_decoder/checknode.h:19
std::vector< T > getCol(std::vector< std::vector< T > > mat2D, int index)
Definition: examples/LDPC/ldpc_2/ldpc_decoder/debug.h:34