GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
fec_mtrx.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 Free Software Foundation, Inc.
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 3, or (at your
8  * option) any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef INCLUDED_fec_mtrx_H
22 #define INCLUDED_fec_mtrx_H
23 
24 #include <gnuradio/fec/api.h>
25 #include <boost/shared_ptr.hpp>
26 #include <cstdlib>
27 
28 namespace gr {
29 namespace fec {
30 namespace code {
31 
32 typedef struct {
33  size_t size;
34  double* data;
35 } block_data;
36 
37 typedef struct {
38  size_t size1;
39  size_t size2;
40  size_t tda;
41  double* data;
43  int owner;
44 } matrix;
45 
46 FEC_API void matrix_free(matrix* x);
47 
48 typedef boost::shared_ptr<matrix> matrix_sptr;
49 
50 class fec_mtrx;
51 typedef boost::shared_ptr<fec_mtrx> fec_mtrx_sptr;
52 
53 /*!
54  * \brief Read in an alist file and produce the matrix object.
55  *
56  * \details
57  * Takes in a an alist file (the file name as a string) and creates
58  * the corresponding matrix. The format of alist files is described
59  * at: http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
60  *
61  * The result is returned as a matrix shared pointer.
62  *
63  * \param filename Name of an alist file to use. The alist
64  * format is described at:
65  * http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
66  */
67 FEC_API matrix_sptr read_matrix_from_file(const std::string filename);
68 FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M);
69 
70 /*!
71  * \brief Takes a parity check matrix (H) and returns the
72  * transpose of the generator matrix (G).
73  *
74  * The result is returned as a matrix shared pointer. The form
75  * of this matrix is [I_k | P]^T, where P is the parity check
76  * matrix. It is a n x k matrix where k is the information
77  * length and n is the codeword length.
78  *
79  * \param H_obj A parity check matrix; generally derived from
80  * using read_matrix_from_file with a given alist
81  * file format.
82  */
83 FEC_API matrix_sptr generate_G_transpose(matrix_sptr H_obj);
84 
85 /*!
86  * \brief Takes a parity check matrix (H) and returns the
87  * generator matrix (G).
88  *
89  * The result is returned as a matrix shared pointer. The form
90  * of this matrix is [I_k | P], where P is the parity check
91  * matrix. It is a k x n matrix where k is the information
92  * length and n is the codeword length.
93  *
94  * \param H_obj A parity check matrix; generally derived from
95  * using read_matrix_from_file with a given alist
96  * file format.
97  */
98 FEC_API matrix_sptr generate_G(matrix_sptr H_obj);
99 
100 /*!
101  * \brief Takes a generator matrix (G) and returns the
102  * parity check matrix (H).
103  *
104  * \param G_obj A parity check matrix; generally derived from
105  * using read_matrix_from_file with a given alist
106  * file format.
107  */
108 FEC_API matrix_sptr generate_H(matrix_sptr G_obj);
109 
110 /*!
111  * \brief Takes a matrix and prints it to screen.
112  *
113  * \param M a matrix_sptr; generally a G or H matrix for LDPC codes.
114  * \param numpy will output in a format that can be
115  * copy-and-pasted directly into a numpy.matrix(~) call
116  * in Python.
117  */
118 FEC_API void print_matrix(const matrix_sptr M, bool numpy = false);
119 
120 /*!
121  * \brief Base class for FEC matrix objects.
122  *
123  * \ingroup error_coding_blk
124  *
125  * \details
126  *
127  * Base class of ldpc_H_matrix and ldpc_G_matrix classes. The
128  * child objects can be either generator matrices or parity
129  * check matrices. This base class can be provided to the
130  * decoder ldpc_bit_flip_decoder, whereas the encoder classes
131  * ldpc_gen_mtrx_encoder and ldpc_encoder will not accept this
132  * base class; they require one of the child classes.
133  */
135 {
136 protected:
137  fec_mtrx(void) {} // allows pure virtual interface sub-classes
138 
139 public:
140  virtual ~fec_mtrx() {}
141 
142  //! Encode \p inbuffer with LDPC H matrix into \p outbuffer.
143  virtual void encode(unsigned char* outbuffer,
144  const unsigned char* inbuffer) const = 0;
145 
146  //! Decode \p inbuffer with LDPC H matrix into \p outbuffer.
147  virtual void decode(unsigned char* outbuffer,
148  const float* inbuffer,
149  unsigned int frame_size,
150  unsigned int max_iterations) const = 0;
151 
152  //! Get the codeword length n
153  virtual unsigned int n() const = 0;
154 
155  //! Get the information word length k
156  virtual unsigned int k() const = 0;
157 };
158 
159 } /* namespace code */
160 } /* namespace fec */
161 } /* namespace gr */
162 
163 #endif /* INCLUDED_fec_mtrx_H */
int owner
Definition: fec_mtrx.h:43
double * data
Definition: fec_mtrx.h:34
FEC_API matrix_sptr generate_G_transpose(matrix_sptr H_obj)
Takes a parity check matrix (H) and returns the transpose of the generator matrix (G)...
FEC_API matrix_sptr generate_H(matrix_sptr G_obj)
Takes a generator matrix (G) and returns the parity check matrix (H).
fec_mtrx(void)
Definition: fec_mtrx.h:137
FEC_API matrix_sptr read_matrix_from_file(const std::string filename)
Read in an alist file and produce the matrix object.
FEC_API void matrix_free(matrix *x)
block_data * block
Definition: fec_mtrx.h:42
Definition: fec_mtrx.h:37
FEC_API matrix_sptr generate_G(matrix_sptr H_obj)
Takes a parity check matrix (H) and returns the generator matrix (G).
size_t tda
Definition: fec_mtrx.h:40
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
size_t size1
Definition: fec_mtrx.h:38
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:30
FEC_API void print_matrix(const matrix_sptr M, bool numpy=false)
Takes a matrix and prints it to screen.
FEC_API unsigned char encode(unsigned char *symbols, unsigned char *data, unsigned int nbytes, unsigned char encstate)
size_t size
Definition: fec_mtrx.h:33
virtual ~fec_mtrx()
Definition: fec_mtrx.h:140
FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M)
size_t size2
Definition: fec_mtrx.h:39
Base class for FEC matrix objects.
Definition: fec_mtrx.h:134
Definition: fec_mtrx.h:32
double * data
Definition: fec_mtrx.h:41