Loading...
Searching...
No Matches
fec_mtrx.h
Go to the documentation of this file.
/* -*- c++ -*- */
/*
* Copyright 2015 Free Software Foundation, Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef INCLUDED_fec_mtrx_H
#define INCLUDED_fec_mtrx_H
#include <gnuradio/fec/api.h>
#include <cstdlib>
#include <memory>
#include <string>
namespace gr {
namespace fec {
namespace code {
typedef struct {
size_t size;
double* data;
} block_data;
typedef struct {
size_t size1;
size_t size2;
size_t tda;
double* data;
block_data* block;
int owner;
} matrix;
FEC_API void matrix_free(matrix* x);
typedef std::shared_ptr<matrix> matrix_sptr;
class fec_mtrx;
typedef std::shared_ptr<fec_mtrx> fec_mtrx_sptr;
/*!
* \brief Read in an alist file and produce the matrix object.
*
* \details
* Takes in a an alist file (the file name as a string) and creates
* the corresponding matrix. The format of alist files is described
* at: http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
*
* The result is returned as a matrix shared pointer.
*
* \param filename Name of an alist file to use. The alist
* format is described at:
* http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
*/
FEC_API matrix_sptr read_matrix_from_file(const std::string filename);
FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M);
/*!
* \brief Takes a parity check matrix (H) and returns the
* transpose of the generator matrix (G).
*
* The result is returned as a matrix shared pointer. The form
* of this matrix is [I_k | P]^T, where P is the parity check
* matrix. It is a n x k matrix where k is the information
* length and n is the codeword length.
*
* \param H_obj A parity check matrix; generally derived from
* using read_matrix_from_file with a given alist
* file format.
*/
FEC_API matrix_sptr generate_G_transpose(matrix_sptr H_obj);
/*!
* \brief Takes a parity check matrix (H) and returns the
* generator matrix (G).
*
* The result is returned as a matrix shared pointer. The form
* of this matrix is [I_k | P], where P is the parity check
* matrix. It is a k x n matrix where k is the information
* length and n is the codeword length.
*
* \param H_obj A parity check matrix; generally derived from
* using read_matrix_from_file with a given alist
* file format.
*/
FEC_API matrix_sptr generate_G(matrix_sptr H_obj);
/*!
* \brief Takes a generator matrix (G) and returns the
* parity check matrix (H).
*
* \param G_obj A parity check matrix; generally derived from
* using read_matrix_from_file with a given alist
* file format.
*/
FEC_API matrix_sptr generate_H(matrix_sptr G_obj);
/*!
* \brief Takes a matrix and prints it to screen.
*
* \param M a matrix_sptr; generally a G or H matrix for LDPC codes.
* \param numpy will output in a format that can be
* copy-and-pasted directly into a numpy.matrix(~) call
* in Python.
*/
FEC_API void print_matrix(const matrix_sptr M, bool numpy = false);
/*!
* \brief Base class for FEC matrix objects.
*
* \ingroup error_coding_blk
*
* \details
*
* Base class of ldpc_H_matrix and ldpc_G_matrix classes. The
* child objects can be either generator matrices or parity
* check matrices. This base class can be provided to the
* decoder ldpc_bit_flip_decoder, whereas the encoder classes
* ldpc_gen_mtrx_encoder and ldpc_encoder will not accept this
* base class; they require one of the child classes.
*/
class FEC_API fec_mtrx
{
protected:
fec_mtrx(void) {} // allows pure virtual interface sub-classes
public:
virtual ~fec_mtrx() {}
//! Encode \p inbuffer with LDPC H matrix into \p outbuffer.
virtual void encode(unsigned char* outbuffer,
const unsigned char* inbuffer) const = 0;
//! Decode \p inbuffer with LDPC H matrix into \p outbuffer.
virtual void decode(unsigned char* outbuffer,
const float* inbuffer,
unsigned int frame_size,
unsigned int max_iterations) const = 0;
//! Get the codeword length n
virtual unsigned int n() const = 0;
//! Get the information word length k
virtual unsigned int k() const = 0;
};
} /* namespace code */
} /* namespace fec */
} /* namespace gr */
#endif /* INCLUDED_fec_mtrx_H */
gr::fec::code::fec_mtrx
Base class for FEC matrix objects.
Definition fec_mtrx.h:124
gr::fec::code::fec_mtrx::~fec_mtrx
virtual ~fec_mtrx()
Definition fec_mtrx.h:129
gr::fec::code::fec_mtrx::decode
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.
gr::fec::code::fec_mtrx::k
virtual unsigned int k() const =0
Get the information word length k.
gr::fec::code::fec_mtrx::n
virtual unsigned int n() const =0
Get the codeword length n.
gr::fec::code::fec_mtrx::encode
virtual void encode(unsigned char *outbuffer, const unsigned char *inbuffer) const =0
Encode inbuffer with LDPC H matrix into outbuffer.
gr::fec::code::fec_mtrx::fec_mtrx
fec_mtrx(void)
Definition fec_mtrx.h:126
api.h
FEC_API
#define FEC_API
Definition gr-fec/include/gnuradio/fec/api.h:18
gr::fec::code
Definition cc_decoder.h:22
gr::fec::code::generate_H
FEC_API matrix_sptr generate_H(matrix_sptr G_obj)
Takes a generator matrix (G) and returns the parity check matrix (H).
gr::fec::code::print_matrix
FEC_API void print_matrix(const matrix_sptr M, bool numpy=false)
Takes a matrix and prints it to screen.
gr::fec::code::write_matrix_to_file
FEC_API void write_matrix_to_file(const std::string filename, matrix_sptr M)
gr::fec::code::read_matrix_from_file
FEC_API matrix_sptr read_matrix_from_file(const std::string filename)
Read in an alist file and produce the matrix object.
gr::fec::code::generate_G_transpose
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).
gr::fec::code::matrix_free
FEC_API void matrix_free(matrix *x)
gr::fec::code::generate_G
FEC_API matrix_sptr generate_G(matrix_sptr H_obj)
Takes a parity check matrix (H) and returns the generator matrix (G).
gr::fec
Definition async_decoder.h:20
gr
GNU Radio logging wrapper.
Definition basic_block.h:29
gr::fec::code::block_data
Definition fec_mtrx.h:21
gr::fec::code::block_data::size
size_t size
Definition fec_mtrx.h:22
gr::fec::code::block_data::data
double * data
Definition fec_mtrx.h:23
gr::fec::code::matrix
Definition fec_mtrx.h:26
gr::fec::code::matrix::size1
size_t size1
Definition fec_mtrx.h:27
gr::fec::code::matrix::data
double * data
Definition fec_mtrx.h:30
gr::fec::code::matrix::tda
size_t tda
Definition fec_mtrx.h:29
gr::fec::code::matrix::owner
int owner
Definition fec_mtrx.h:32
gr::fec::code::matrix::size2
size_t size2
Definition fec_mtrx.h:28
gr::fec::code::matrix::block
block_data * block
Definition fec_mtrx.h:31