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