commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 08/43: fec: adding ldpc encoder and decoder


From: git
Subject: [Commit-gnuradio] [gnuradio] 08/43: fec: adding ldpc encoder and decoder, initial compile working
Date: Thu, 2 Apr 2015 19:15:50 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 37425aaa7c7a6067dd16c7e68a7a17067454cd37
Author: Tim O'Shea <address@hidden>
Date:   Tue Mar 31 19:28:30 2015 -0700

    fec: adding ldpc encoder and decoder, initial compile working
---
 gr-fec/include/gnuradio/fec/alist.h        | 123 ++++++++++++++++++++
 gr-fec/include/gnuradio/fec/awgn_bp.h      | 177 +++++++++++++++++++++++++++++
 gr-fec/include/gnuradio/fec/cldpc.h        | 124 ++++++++++++++++++++
 gr-fec/include/gnuradio/fec/gf2mat.h       | 119 +++++++++++++++++++
 gr-fec/include/gnuradio/fec/gf2vec.h       |  79 +++++++++++++
 gr-fec/include/gnuradio/fec/ldpc_decoder.h |  59 ++++++++++
 gr-fec/include/gnuradio/fec/ldpc_encoder.h |  49 ++++++++
 gr-fec/include/gnuradio/fec/maxstar.h      |  88 ++++++++++++++
 gr-fec/lib/CMakeLists.txt                  |   2 +
 gr-fec/lib/ldpc_decoder.cc                 |  86 ++++++++++++++
 gr-fec/lib/ldpc_encoder.cc                 |  57 ++++++++++
 11 files changed, 963 insertions(+)

diff --git a/gr-fec/include/gnuradio/fec/alist.h 
b/gr-fec/include/gnuradio/fec/alist.h
new file mode 100644
index 0000000..f9759f4
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/alist.h
@@ -0,0 +1,123 @@
+/*!
+ * \file
+ * \brief Definition of a class to hold sparse matrices in alist-format
+ * \author Manu T S
+ *
+ * -----------------------------------------------------------------
+ *
+ * Copyright 2013 IIT Bombay.
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ * -----------------------------------------------------------------
+ *
+ * This class handles sparse matrices specified in alist-format.
+ * For details about alist format please visit the link below.
+ * - http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
+ *
+ * Alist class is an efficient way of representing a sparse matrix
+ * the parity check matrix H of an LDPC code for instance.
+ *
+ */
+
+#ifndef ALIST_H
+#define ALIST_H
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+#include <stdlib.h>
+#include <gnuradio/fec/api.h>
+
+class FEC_API alist
+{
+  public:
+
+    //! Default Constructor
+    alist() : data_ok(false) {}
+
+    //! Constructor which loads alist class from an alist-file
+    alist(const char * fname);
+
+    //! Read alist data from a file
+    void read(const char * fname);
+
+    //! Write alist data to a file
+    void write(const char * fname) const;
+
+    //! Retuns N, the number of variable nodes
+    int get_N();
+
+    //! Return M, the number of check nodes
+    int get_M();
+
+    //! Return the m_list variable
+    std::vector< std::vector<int> > get_mlist();
+
+    //! Returns the n_list variable
+    std::vector< std::vector<int> > get_nlist();
+
+    //! Returns the num_mlist variable
+    std::vector<int> get_num_mlist();
+
+    //! Returns the num_nlist variable
+    std::vector<int> get_num_nlist();
+
+    //! Returns the max_num_nlist variable
+    int get_max_num_nlist();
+
+    //! Returns the max_num_mlist variable
+    int get_max_num_mlist();
+
+    //! Prints the nlist[i] variable
+    void print_nlist_i(int i);
+
+    //! Prints the mlist[i] variable
+    void print_mlist_i(int i);
+
+    //! Returns the corresponding H matrix
+    std::vector<std::vector<char> > get_matrix();
+
+  protected:
+    //! A variable indicating if data has been read from alist-file
+    bool data_ok;
+
+    //! Number of variable nodes
+    int N;
+
+    //! Number of check nodes
+    int M;
+
+    //! Maximum weight of rows
+    int max_num_mlist;
+
+    //! Maximum weight of columns
+    int max_num_nlist;
+
+    //! Weight of each column n
+    std::vector<int> num_nlist;
+
+    //! Weight of each row m
+    std::vector<int> num_mlist;
+
+    //! List of integer coordinates along each rows with non-zero entries
+    std::vector< std::vector<int> > mlist;
+
+    //! List of integer coordinates along each column with non-zero entries
+    std::vector< std::vector<int> > nlist;
+};
+#endif // ifndef ALIST_H
diff --git a/gr-fec/include/gnuradio/fec/awgn_bp.h 
b/gr-fec/include/gnuradio/fec/awgn_bp.h
new file mode 100644
index 0000000..bffaecf
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/awgn_bp.h
@@ -0,0 +1,177 @@
+/*!
+ * \file
+ * \brief Definition of a class for message passing for AWGN channel
+ * \author Manu T S
+ *
+ * -----------------------------------------------------------------
+ *
+ * Copyright 2013 IIT Bombay.
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ * -----------------------------------------------------------------
+ *
+ * This class defines functions for message passing mechanism for a
+ * AWGN channel. Message passing (also known as belief propagation)
+ * is used for decoding LDPC codes. Details of how LDPC codes are
+ * decoded is available in the link below
+ * - http://www.cs.utoronto.ca/~radford/ftp/LDPC-2012-02-11/decoding.html
+ *
+ * Belief propagation decoding is a suboptimal but efficient method of
+ * decoding LDPC codes.
+ *
+ */
+
+#ifndef AWGN_BP_H
+#define AWGN_BP_H
+
+#include <vector>
+#include <cmath>
+#include <iostream>
+#include "gf2mat.h"
+#include "alist.h"
+#include <gnuradio/fec/api.h>
+
+class FEC_API awgn_bp
+{
+  public:
+    //! Default constructor
+    awgn_bp () {};
+
+    //! A constructor for given GF2Mat and sigma
+    awgn_bp (const GF2Mat  X, float sgma);
+
+    //! A constructor for given alist and sigma
+    awgn_bp (alist  _list, float sgma);
+
+    //! Initializes the class using given alist and sigma
+    void set_alist_sigma(alist  _list, float sgma);
+
+    //! Returns the variable Q
+    std::vector< std::vector<double> > get_Q();
+
+    //! Returns the variable R
+    std::vector< std::vector<double> > get_R();
+
+    //! Returns the variable H
+    GF2Mat get_H();
+
+    //! Calculates the likelihood ratios given an input vector
+    void rx_lr_calc(std::vector<float> codeword);
+
+    //! Returns the variable rx_lr
+    std::vector<double> get_rx_lr();
+
+    //! Returns the variable lr
+    std::vector<double> get_lr();
+
+    //! Initializes the sum product algorithm set-up
+    void spa_initialize();
+
+    //! Updates the check-nodes based on messages from variable nodes
+    void update_chks();
+
+    //! Updates the variable-nodes based on messages from check nodes
+    void update_vars();
+
+    //! Returns the current estimate
+    std::vector<char> get_estimate();
+
+    //! Computes initial estimate based on the vector rx_word
+    void compute_init_estimate(std::vector<float> rx_word);
+
+    //! Computes the estimate based on current likelihood-ratios lr
+    void decision();
+
+    //! Returns the syndrome for the current estimate
+    std::vector<char> get_syndrome();
+
+    //! Returns the syndrome for the input codeword
+    std::vector<char> get_syndrome(const std::vector<char> codeword);
+
+    //! Checks if the current estimate is a codeword
+    bool is_codeword();
+
+    //! Checks if the input is a codeword
+    bool is_codeword(const std::vector<char> codeword);
+
+    //! Sets the variable K
+    void set_K(int k);
+
+    //! Returns the variable K
+    int get_K();
+
+    //! Sets the variable max_iterations
+    void set_max_iterations(int k);
+
+    //! Returns the variable max_iterations
+    int get_max_iterations();
+
+    /*!
+      \brief Decodes the given vector rx_word by message passing.
+
+      \param *niterations is the number of message passing iterations
+      done to decode this codeword
+    */
+    std::vector<char> decode (std::vector<float> rx_word,
+            int *niterations);
+  private:
+    //! The number of check nodes in the tanner-graph
+    int M;
+
+    //! The number of variable nodes in the tanner-graph
+    int N;
+
+    //! The dimension of the code used
+    int K;
+
+    //! The maximum number of message passing iterations allowed
+    int max_iterations;
+
+    //! The parity check matrix of the LDPC code
+    GF2Mat H;
+
+    //! The standard-deviation of the AWGN channel
+    float sigma;
+
+    //! Matrix holding messages from check nodes to variable nodes
+    std::vector< std::vector<double> > R;
+
+    //! Matrix holding messages from variable nodes to check nodes
+    std::vector< std::vector<double> > Q;
+
+    //! The array of likelihood computed from the channel output
+    std::vector<double> rx_lr;
+
+    //! The array for holding likelihoods computed on BP decoding
+    std::vector<double> lr;
+
+    //! List of integer coordinates along each column with non-zero entries
+    std::vector < std::vector<int> > nlist;
+
+    //! List of integer coordinates along each row with non-zero entries
+    std::vector < std::vector<int> > mlist;
+
+    //! Weight of each column n
+    std::vector <int> num_nlist;
+
+    //! Weight of each row m
+    std::vector <int> num_mlist;
+
+    //! The array for holding estimate computed on BP decoding
+    std::vector<char> estimate;
+};
+#endif // ifndef AWGN_BP_H
diff --git a/gr-fec/include/gnuradio/fec/cldpc.h 
b/gr-fec/include/gnuradio/fec/cldpc.h
new file mode 100644
index 0000000..58bdc1a
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/cldpc.h
@@ -0,0 +1,124 @@
+/*!
+ * \file
+ * \brief Definition of a class holding an LDPC code
+ * \author Manu T S
+ *
+ * -----------------------------------------------------------------
+ *
+ * Copyright 2013 IIT Bombay.
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ * -----------------------------------------------------------------
+ *
+ * This class defined various functions and variables needed to 
+ * implement an LDPC code class.
+ *
+ */
+
+#ifndef LDPC_H
+#define LDPC_H
+
+#include <iostream>
+#include <vector>
+
+#include "gnuradio/fec/gf2vec.h"
+#include "gnuradio/fec/gf2mat.h"
+#include "gnuradio/fec/alist.h"
+
+
+#include <gnuradio/fec/api.h>
+class FEC_API cldpc
+{
+  public:
+    //! Default constructor
+    cldpc() {};
+
+    //! Constructs the LDPC class from given GF2mat X
+    cldpc(const GF2Mat X);
+
+    //! Constructs the class from the given alist _list
+    cldpc(const alist _list);
+
+    //! Prints the variable permute
+    void print_permute();
+
+    /*!
+      \brief Encode the given vector dataword.
+
+      dataword is of length K where K is the dimension of the code.
+      The function returns a vector of length N where N is the
+      block-length of the code.
+
+      For encoding a G matrix in the form [I P] is obtained from the
+      parity matrix H, by (a) Column permutations, (b) Row additions
+      and (c) Row permutations. Details of encoding is given in
+      section A.1 of the reference given below.
+       - "Modern Coding Theory", T Richardson and R Urbanke.
+    */
+    std::vector<char> encode(std::vector<char> dataword);
+
+    //! Returns the dimension of the code
+    int dimension();
+
+    //! Returns the parity check matrix H
+    GF2Mat get_H();
+
+    //! Returns the matrix G used in encoding
+    GF2Mat get_G();
+
+    //! Returns the variable M
+    int get_M();
+
+    //! Returns the variable N
+    int get_N();
+
+    //! Returns the syndrome for a given vector "in"
+    std::vector<char> syndrome(const std::vector<char> in);
+
+    //! Returns true if "in" is a codeword, else false
+    bool is_codeword(const std::vector<char> in);
+
+    //! Set the variable _list
+    void set_alist(const alist _list);
+
+    //! Obtain systematic bits from "in"
+    std::vector<char> get_systematic_bits(std::vector<char> in);
+
+  private:
+    //! The parity check matrix
+    GF2Mat H;
+
+    //! An equivalent matrix obtained from H used for encoding
+    GF2Mat G;
+
+    //! Stores the column permutation in obtaining G from H
+    std::vector<int> permute;
+
+    //! Rank of the H matrix
+    int rank_H;
+
+    //! The number of check nodes in the Tanner-graph
+    int M;
+
+    //! The number of variable nodes in the Tanner-graph
+    int N;
+
+    //! The dimension of the code
+    int K;
+};
+
+#endif // ifndef LDPC_H
diff --git a/gr-fec/include/gnuradio/fec/gf2mat.h 
b/gr-fec/include/gnuradio/fec/gf2mat.h
new file mode 100644
index 0000000..e1cd3a2
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/gf2mat.h
@@ -0,0 +1,119 @@
+/*!
+ * \file
+ * \brief Definition of a class for GF2 matrix algebra
+ * \author Manu T S
+ *
+ * -----------------------------------------------------------------
+ *
+ * Copyright 2013 IIT Bombay.
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ * -----------------------------------------------------------------
+ *
+ * This is a class for handling GF2 matrices. 
+ *
+ */
+
+#ifndef GF2MAT_H
+#define GF2MAT_H
+#include <vector>
+#include "gf2vec.h"
+#include "alist.h"
+
+class GF2Mat
+{
+    //! The matrix H
+    std::vector < std::vector <char> > H;
+
+    //! Number of rows in H
+    int M;
+
+    //! Number of columns in H
+    int N;
+
+  public:
+    //! Default constructor
+    GF2Mat() {};
+
+    //! Construct an M x N matrix with all 0 entries
+    GF2Mat(int m, int n);
+
+    //! Loads the matrix from alist _list
+    GF2Mat(alist _list);
+
+    //! Initializes the class from a 2-D vector X
+    GF2Mat(std::vector <std::vector <char> > X);
+
+    //! Returns the variable M
+    int get_M();
+
+    //! Returns the variable N
+    int get_N(); 
+
+    //! Set the element at (i, j) coordinate to val
+    void set_element(int i, int j, char val);
+
+    //! Returns the element at coordinate (i, j)
+    char get_element(int i, int j);
+
+    //! Returns the ith row
+    GF2Vec get_row(int i);
+
+    //! Returns the ith column
+    GF2Vec get_col(int i);
+
+    //! Returns the ith row
+    GF2Vec operator[](int i);
+
+    //! Prints the matrix H
+    void print_matrix();
+
+    //! Sets the ith column with the given vector
+    void set_col(int i, GF2Vec vec);
+
+    //! Sets the ith row with the given vector
+    void set_row(int i, GF2Vec vec);
+
+    //! Swaps columns i and j
+    void swap_cols(int i, int j);
+
+    //! Adds column j to i and replace i with the sum
+    void add_cols(int i, int j);
+
+    //! Add row j to i and replace j with the sum
+    void add_rows(int i, int j);
+
+    //! Returns the variable H
+    std::vector<std::vector<char> > get_H();
+
+    /*!
+      \brief Obtains an equivalent representation of H for encoding
+
+      For encoding a G matrix in the form [I P] is obtained from the
+      parity matrix H, by (a) Column permutations, (b) Row additions
+      and (c) Row permutations. Details of encoding is given in
+      section A.1 of the reference given below.
+       - "Modern Coding Theory", T Richardson and R Urbanke.
+
+      \param p is the column permutation during this operation
+      \
+    */
+    GF2Mat get_G(std::vector<int> & p, int & rank);
+
+};
+
+#endif // #ifndef GF2MAT_H
diff --git a/gr-fec/include/gnuradio/fec/gf2vec.h 
b/gr-fec/include/gnuradio/fec/gf2vec.h
new file mode 100644
index 0000000..729e4d5
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/gf2vec.h
@@ -0,0 +1,79 @@
+/*!
+ * \file
+ * \brief Definition of a class for GF2 vector algebra
+ * \author Manu T S
+ *
+ * -----------------------------------------------------------------
+ *
+ * Copyright 2013 IIT Bombay.
+ * 
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ *
+ * -----------------------------------------------------------------
+ *
+ * This is a class for handling GF2 vectors. 
+ *
+ */
+
+#ifndef GF2VEC_H
+#define GF2VEC_H
+#include <vector>
+
+class GF2Vec
+{
+    //! The vector vec
+    std::vector<char> vec;
+
+    //! Resize the vector
+    void resize(int size);
+
+  public:
+
+    //! Default constructor
+    GF2Vec() {}
+
+    //! Constructs a vector of length "size" with all 0 entries
+    GF2Vec(int size);
+
+    //! Returns the vector
+    std::vector<char> get_vec();
+
+    //! Returns the size of the vector
+    int size();
+
+    //! Resets the vector with the given input
+    void set_vec(std::vector<char>);
+
+    //! Access the ith element
+    char & operator [](int i);
+
+    //! Overloading the operator '='
+    void operator=(GF2Vec x);
+
+    //! Obtain a subvector between the indices i to j
+    GF2Vec sub_vector(int i, int j);
+
+    //! Overloading the operator '+'
+    friend GF2Vec operator+(GF2Vec a, GF2Vec b);
+
+    //! Overloading the operator '*'
+    friend char operator*(GF2Vec a, GF2Vec b);
+
+    //! Prints the vector
+    void print_vec();
+};
+
+#endif // #ifndef GF2VEC_H
diff --git a/gr-fec/include/gnuradio/fec/ldpc_decoder.h 
b/gr-fec/include/gnuradio/fec/ldpc_decoder.h
new file mode 100644
index 0000000..bd9132c
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/ldpc_decoder.h
@@ -0,0 +1,59 @@
+#ifndef INCLUDED_LDPC_DECODER_H
+#define INCLUDED_LDPC_DECODER_H
+
+typedef float INPUT_DATATYPE;
+typedef unsigned char OUTPUT_DATATYPE;
+
+#include <map>
+#include <string>
+#include <gnuradio/fec/decoder.h>
+#include <vector>
+
+#include <gnuradio/fec/cldpc.h>
+#include <gnuradio/fec/alist.h>
+#include <gnuradio/fec/awgn_bp.h>
+
+namespace gr {
+ namespace fec {
+
+FEC_API generic_decoder::sptr
+ldpc_make_decoder (std::string alist_file, float sigma=0.5, int 
max_iterations=50);
+
+#define MAXLOG 1e7
+
+class FEC_API ldpc_decoder : public generic_decoder {
+    //befriend the global, swigged make function
+    friend generic_decoder::sptr
+    ldpc_make_decoder (std::string alist_file, float sigma, int 
max_iterations);
+
+    //private constructor
+    ldpc_decoder (std::string alist_file, float sigma, int max_iterations);
+
+    //plug into the generic fec api
+    int get_history();
+       float get_shift();
+       int get_input_item_size();
+       int get_output_item_size();
+       const char* get_conversion();
+    void generic_work(void *inBuffer, void *outbuffer);
+    int get_output_size();
+    int get_input_size();
+
+    int inputSize, outputSize;
+
+      alist d_list;
+      cldpc d_code;
+      awgn_bp d_spa;
+
+ public:
+    ~ldpc_decoder ();
+
+
+    double rate() { return 1; }
+    bool set_frame_size(unsigned int frame_size) { throw 
std::runtime_error("Nope"); }
+};
+
+}
+}
+
+#endif /* INCLUDED_LDPC_DECODER_H */
diff --git a/gr-fec/include/gnuradio/fec/ldpc_encoder.h 
b/gr-fec/include/gnuradio/fec/ldpc_encoder.h
new file mode 100755
index 0000000..359f3c3
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/ldpc_encoder.h
@@ -0,0 +1,49 @@
+#ifndef INCLUDED_LDPC_ENCODER_H
+#define INCLUDED_LDPC_ENCODER_H
+
+#include <map>
+#include <string>
+#include <gnuradio/fec/encoder.h>
+#include <vector>
+
+#include <gnuradio/fec/cldpc.h>
+#include <gnuradio/fec/alist.h>
+
+namespace gr {
+ namespace fec {
+
+FEC_API generic_encoder::sptr
+ldpc_make_encoder (std::string alist_file);
+
+
+class FEC_API ldpc_encoder : public generic_encoder {
+    //befriend the global, swigged make function
+    friend generic_encoder::sptr
+    ldpc_make_encoder (std::string alist_file);
+
+    //private constructor
+    ldpc_encoder (std::string alist_file);
+
+    //plug into the generic fec api
+    void generic_work(void *inBuffer, void *outbuffer);
+    int get_output_size();
+    int get_input_size();
+
+    // memory allocated for processing
+    int outputSize;
+    int inputSize;
+    alist d_list;
+    cldpc d_code;   
+
+    double rate() { return 1.0; }
+    bool set_frame_size(unsigned int frame_size) { throw 
std::runtime_error("Not supported!!!"); }
+
+ public:
+    ~ldpc_encoder ();
+
+};
+
+}
+}
+
+#endif /* INCLUDED_LDPC_ENCODER_H */
diff --git a/gr-fec/include/gnuradio/fec/maxstar.h 
b/gr-fec/include/gnuradio/fec/maxstar.h
new file mode 100644
index 0000000..bbebc39
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/maxstar.h
@@ -0,0 +1,88 @@
+/* File maxstar.h
+
+   Description: Performs the max* operations (Jacobian logarithm) defined as:
+               max*( x, y ) = max( x,y) + log( 1 + exp( - |x-y| ) )
+
+   There are several versions of this function, max_starX, where "X":
+      X = 0 For linear approximation to log-MAP
+        = 1 For max-log-MAP algorithm (i.e. max*(x,y) = max(x,y) )
+        = 2 For Constant-log-MAP algorithm
+           = 3 For log-MAP, correction factor from small nonuniform table and 
interpolation
+        = 4 For log-MAP, correction factor uses C function calls
+
+   Calling syntax:
+      output = max_starX( delta1, delta2 )
+
+   Where:
+         output =      The result of max*(x,y)
+
+         delta1 = T] he first argument (i.e. x) of max*(x,y)
+         delta2 = The second argument (i.e. y) of max*(x,y)
+
+   Copyright (C) 2005, Matthew C. Valenti
+
+   Functions max_star0, max_star1, max_star2, max_star3, and max_star4
+   are part of the Iterative Solutions Coded Modulation Library
+   The Iterative Solutions Coded Modulation Library is free software;
+   you can redistribute it and/or modify it under the terms of 
+   the GNU Lesser General Public License as published by the 
+   Free Software Foundation; either version 2.1 of the License, 
+   or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+  
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#ifndef INCLUDED_FECAPI_MAXSTAR_H
+#define INCLUDED_FECAPI_MAXSTAR_H
+
+/* values for the jacobian logarithm table (DecoderType=4) */
+#define BOUNDARY0    0
+#define BOUNDARY1    0.4200
+#define BOUNDARY2    0.8500
+#define BOUNDARY3    1.3100
+#define BOUNDARY4    1.8300
+#define BOUNDARY5    2.4100
+#define BOUNDARY6    3.1300
+#define BOUNDARY7    4.0800
+#define BOUNDARY8    5.6000
+
+#define SLOPE0  -0.44788139700522
+#define SLOPE1  -0.34691145436176
+#define SLOPE2  -0.25432579542705
+#define SLOPE3  -0.17326680196715
+#define SLOPE4  -0.10822110027877
+#define SLOPE5  -0.06002650498009
+#define SLOPE6  -0.02739265095522
+#define SLOPE7  -0.00860202759280
+
+#define VALUE0   0.68954718055995
+#define VALUE1   0.50153699381775
+#define VALUE2   0.35256506844219
+#define VALUE3   0.23567520254575
+#define VALUE4   0.14607646552283
+#define VALUE5   0.08360822736113
+#define VALUE6   0.04088914377547
+#define VALUE7   0.01516612536801
+
+/* values for the constant log-MAP algorithm (DecoderType=3) */
+#define CVALUE   0.5
+#define TVALUE   1.5
+
+/* values for the linear approximation (DecoderType=1) */
+#define TTHRESH  2.508
+#define AVALUE  -0.236
+#define BVALUE   0.592
+
+/* Values for linear approximation (DecoderType=5) */
+#define AJIAN -0.24904163195436
+#define TJIAN 2.50681740420944
+
+#endif
\ No newline at end of file
diff --git a/gr-fec/lib/CMakeLists.txt b/gr-fec/lib/CMakeLists.txt
index 884bb44..e4a55c2 100644
--- a/gr-fec/lib/CMakeLists.txt
+++ b/gr-fec/lib/CMakeLists.txt
@@ -71,6 +71,8 @@ list(APPEND gnuradio_fec_sources
   puncture_bb_impl.cc
   puncture_ff_impl.cc
   depuncture_bb_impl.cc
+  ldpc_encoder.cc
+  ldpc_decoder.cc
 )
 
 #Add Windows DLL resource file if using MSVC
diff --git a/gr-fec/lib/ldpc_decoder.cc b/gr-fec/lib/ldpc_decoder.cc
new file mode 100644
index 0000000..d33bee7
--- /dev/null
+++ b/gr-fec/lib/ldpc_decoder.cc
@@ -0,0 +1,86 @@
+#include <gnuradio/fec/ldpc_decoder.h>
+//#include <debug_macros.h>
+
+#include <math.h>
+#include <boost/assign/list_of.hpp>
+//#include <volk_typedefs.h>
+#include <volk/volk.h>
+#include <sstream>
+#include <stdio.h>
+#include <vector>
+#include <gnuradio/fec/decoder.h>
+//#include <cc_common.h>
+
+#include <algorithm>            // for std::reverse
+#include <string.h>             // for memcpy
+
+#include <gnuradio/fec/maxstar.h>
+
+
+namespace gr {
+ namespace fec {
+
+generic_decoder::sptr
+ldpc_make_decoder(std::string alist_file, float sigma, int max_iterations)
+{
+    return generic_decoder::sptr(new ldpc_decoder(alist_file, sigma, 
max_iterations));
+}
+
+ldpc_decoder::ldpc_decoder (std::string alist_file, float sigma, int 
max_iterations)
+    : generic_decoder("ldpc_decoder")
+{
+        d_list.read(alist_file.c_str());
+        d_code.set_alist(d_list);
+        d_spa.set_alist_sigma(d_list, sigma);
+        inputSize = d_code.get_N();
+        outputSize = d_code.dimension();
+        d_spa.set_K(outputSize);
+        d_spa.set_max_iterations(max_iterations);
+}
+
+int ldpc_decoder::get_output_size() {
+    return outputSize;
+}
+
+int ldpc_decoder::get_input_size() {
+    return inputSize;
+}
+
+void ldpc_decoder::generic_work(void *inBuffer, void *outBuffer) {
+    const float *inPtr = (const float *) inBuffer;
+    unsigned char *out = (unsigned char *) outBuffer;
+ 
+    std::vector<float> rx(inputSize);
+    for(int i=0; i<inputSize; i++){ rx[i] = inPtr[i] * (-1); }
+    //memcpy(&rx[0], inPtr, inputSize*sizeof(float));
+    int n_iterations = 0;
+    std::vector<char> estimate( d_spa.decode(rx, &n_iterations) );   
+    std::vector<char> data( d_code.get_systematic_bits(estimate) );
+    memcpy(out, &data[0], outputSize);
+}
+
+int ldpc_decoder::get_input_item_size() {
+    return sizeof(INPUT_DATATYPE);
+}
+
+int ldpc_decoder::get_output_item_size() {
+    return sizeof(OUTPUT_DATATYPE);
+}
+
+int ldpc_decoder::get_history() {
+    return 0;
+}
+
+float ldpc_decoder::get_shift() {
+    return 0.0;
+}
+
+const char* ldpc_decoder::get_conversion() {
+    return "none";
+}
+
+ldpc_decoder::~ldpc_decoder() {
+}
+
+}
+}
diff --git a/gr-fec/lib/ldpc_encoder.cc b/gr-fec/lib/ldpc_encoder.cc
new file mode 100755
index 0000000..fa91a3e
--- /dev/null
+++ b/gr-fec/lib/ldpc_encoder.cc
@@ -0,0 +1,57 @@
+#include <gnuradio/fec/ldpc_encoder.h>
+//#include <debug_macros.h>
+
+#include <math.h>
+#include <boost/assign/list_of.hpp>
+//#include <volk_typedefs.h>
+#include <volk/volk.h>
+#include <sstream>
+#include <stdio.h>
+#include <vector>
+//#include <cc_common.h>
+
+#include <algorithm>            // for std::reverse
+#include <string.h>             // for memcpy
+
+namespace gr {
+  namespace fec {
+
+generic_encoder::sptr
+ldpc_make_encoder(std::string alist_file)
+{
+    return generic_encoder::sptr(new ldpc_encoder(alist_file));
+}
+
+ldpc_encoder::ldpc_encoder (std::string alist_file)
+{
+    d_list.read(alist_file.c_str());
+    d_code.set_alist(d_list);
+    inputSize = d_code.dimension();
+    outputSize = d_code.get_N();
+    printf("ENCODER: inputSize = %d, outputSize = %d\n",inputSize, outputSize);
+}
+
+int ldpc_encoder::get_output_size() {
+    return outputSize;
+}
+
+int ldpc_encoder::get_input_size() {
+    return inputSize;
+}
+
+void ldpc_encoder::generic_work(void *inBuffer, void *outBuffer) {
+    const unsigned char *in = (const unsigned char *) inBuffer;
+    float *out = (float *) outBuffer;
+    std::vector<char> inbuf(inputSize);
+    memcpy(&inbuf[0], in, inputSize);
+    std::vector<char> coded(d_code.encode(inbuf));
+    for(int i=0; i<coded.size();i++){ out[i] = coded[i]; }
+}
+
+
+ldpc_encoder::~ldpc_encoder()
+{
+}
+
+}
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]