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