GNU Radio Manual and C++ API Reference 3.7.14.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
28namespace gr {
29namespace fec {
30namespace code {
31
32typedef struct {
33 size_t size;
34 double* data;
36
37typedef struct {
38 size_t size1;
39 size_t size2;
40 size_t tda;
41 double* data;
43 int owner;
44} matrix;
45
47
48typedef boost::shared_ptr<matrix> matrix_sptr;
49
50class fec_mtrx;
51typedef 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 */
67FEC_API matrix_sptr read_matrix_from_file(const std::string filename);
68FEC_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 */
83FEC_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 */
98FEC_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 */
108FEC_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 */
118FEC_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{
136protected:
137 fec_mtrx(void) {} // allows pure virtual interface sub-classes
138
139public:
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 */
Base class for FEC matrix objects.
Definition: fec_mtrx.h:135
virtual ~fec_mtrx()
Definition: fec_mtrx.h:140
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:137
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:30
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).
Include this header to use the message passing features.
Definition: basic_block.h:45
Definition: fec_mtrx.h:32
size_t size
Definition: fec_mtrx.h:33
double * data
Definition: fec_mtrx.h:34
Definition: fec_mtrx.h:37
size_t size1
Definition: fec_mtrx.h:38
double * data
Definition: fec_mtrx.h:41
size_t tda
Definition: fec_mtrx.h:40
int owner
Definition: fec_mtrx.h:43
size_t size2
Definition: fec_mtrx.h:39
block_data * block
Definition: fec_mtrx.h:42