GNU Radio Manual and C++ API Reference  3.8.4.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 #include <string>
28 
29 namespace gr {
30 namespace fec {
31 namespace code {
32 
33 typedef struct {
34  size_t size;
35  double* data;
36 } block_data;
37 
38 typedef struct {
39  size_t size1;
40  size_t size2;
41  size_t tda;
42  double* data;
44  int owner;
45 } matrix;
46 
47 FEC_API void matrix_free(matrix* x);
48 
49 typedef boost::shared_ptr<matrix> matrix_sptr;
50 
51 class fec_mtrx;
52 typedef boost::shared_ptr<fec_mtrx> fec_mtrx_sptr;
53 
54 /*!
55  * \brief Read in an alist file and produce the matrix object.
56  *
57  * \details
58  * Takes in a an alist file (the file name as a string) and creates
59  * the corresponding matrix. The format of alist files is described
60  * at: http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
61  *
62  * The result is returned as a matrix shared pointer.
63  *
64  * \param filename Name of an alist file to use. The alist
65  * format is described at:
66  * http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
67  */
68 FEC_API matrix_sptr read_matrix_from_file(const std::string filename);
69 FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M);
70 
71 /*!
72  * \brief Takes a parity check matrix (H) and returns the
73  * transpose of the generator matrix (G).
74  *
75  * The result is returned as a matrix shared pointer. The form
76  * of this matrix is [I_k | P]^T, where P is the parity check
77  * matrix. It is a n x k matrix where k is the information
78  * length and n is the codeword length.
79  *
80  * \param H_obj A parity check matrix; generally derived from
81  * using read_matrix_from_file with a given alist
82  * file format.
83  */
84 FEC_API matrix_sptr generate_G_transpose(matrix_sptr H_obj);
85 
86 /*!
87  * \brief Takes a parity check matrix (H) and returns the
88  * generator matrix (G).
89  *
90  * The result is returned as a matrix shared pointer. The form
91  * of this matrix is [I_k | P], where P is the parity check
92  * matrix. It is a k x n matrix where k is the information
93  * length and n is the codeword length.
94  *
95  * \param H_obj A parity check matrix; generally derived from
96  * using read_matrix_from_file with a given alist
97  * file format.
98  */
99 FEC_API matrix_sptr generate_G(matrix_sptr H_obj);
100 
101 /*!
102  * \brief Takes a generator matrix (G) and returns the
103  * parity check matrix (H).
104  *
105  * \param G_obj A parity check matrix; generally derived from
106  * using read_matrix_from_file with a given alist
107  * file format.
108  */
109 FEC_API matrix_sptr generate_H(matrix_sptr G_obj);
110 
111 /*!
112  * \brief Takes a matrix and prints it to screen.
113  *
114  * \param M a matrix_sptr; generally a G or H matrix for LDPC codes.
115  * \param numpy will output in a format that can be
116  * copy-and-pasted directly into a numpy.matrix(~) call
117  * in Python.
118  */
119 FEC_API void print_matrix(const matrix_sptr M, bool numpy = false);
120 
121 /*!
122  * \brief Base class for FEC matrix objects.
123  *
124  * \ingroup error_coding_blk
125  *
126  * \details
127  *
128  * Base class of ldpc_H_matrix and ldpc_G_matrix classes. The
129  * child objects can be either generator matrices or parity
130  * check matrices. This base class can be provided to the
131  * decoder ldpc_bit_flip_decoder, whereas the encoder classes
132  * ldpc_gen_mtrx_encoder and ldpc_encoder will not accept this
133  * base class; they require one of the child classes.
134  */
136 {
137 protected:
138  fec_mtrx(void) {} // allows pure virtual interface sub-classes
139 
140 public:
141  virtual ~fec_mtrx() {}
142 
143  //! Encode \p inbuffer with LDPC H matrix into \p outbuffer.
144  virtual void encode(unsigned char* outbuffer,
145  const unsigned char* inbuffer) const = 0;
146 
147  //! Decode \p inbuffer with LDPC H matrix into \p outbuffer.
148  virtual void decode(unsigned char* outbuffer,
149  const float* inbuffer,
150  unsigned int frame_size,
151  unsigned int max_iterations) const = 0;
152 
153  //! Get the codeword length n
154  virtual unsigned int n() const = 0;
155 
156  //! Get the information word length k
157  virtual unsigned int k() const = 0;
158 };
159 
160 } /* namespace code */
161 } /* namespace fec */
162 } /* namespace gr */
163 
164 #endif /* INCLUDED_fec_mtrx_H */
int owner
Definition: fec_mtrx.h:44
double * data
Definition: fec_mtrx.h:35
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:138
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:43
Definition: fec_mtrx.h:38
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:41
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:46
size_t size1
Definition: fec_mtrx.h:39
#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:34
virtual ~fec_mtrx()
Definition: fec_mtrx.h:141
FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M)
size_t size2
Definition: fec_mtrx.h:40
Base class for FEC matrix objects.
Definition: fec_mtrx.h:135
Definition: fec_mtrx.h:33
double * data
Definition: fec_mtrx.h:42