commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 16/39: fec: LDPC: updates for LDPC function


From: git
Subject: [Commit-gnuradio] [gnuradio] 16/39: fec: LDPC: updates for LDPC functionality.
Date: Thu, 15 Oct 2015 21:21:29 +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 da60d809d5e9a391fc4fa379c240a1b571004d7d
Author: tracierenea <address@hidden>
Date:   Thu Feb 12 14:01:47 2015 -0600

    fec: LDPC: updates for LDPC functionality.
    
    Created a base class from which the LDPC parity check and generator
    matrix classes will inherit. Future work will have the bit flip
    decoder taking this base class instead of just the LDPC matrix class.
    
    Adding the classes for using a generator matrix for encoding but they
    are basically empty right now.
    
    This commit doesn't add any functionality to gr-fec yet, just a
    checkpoint.
---
 gr-fec/include/gnuradio/fec/CMakeLists.txt         |   3 +
 .../gnuradio/fec/{ldpc_R_U_mtrx.h => fec_mtrx.h}   |  53 ++---
 gr-fec/include/gnuradio/fec/generator_encoder.h    |  73 +++++++
 gr-fec/include/gnuradio/fec/generator_mtrx.h       |  60 ++++++
 gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h        |  38 +---
 gr-fec/lib/CMakeLists.txt                          |   3 +
 gr-fec/lib/{ldpc_R_U_mtrx.cc => fec_mtrx.cc}       | 180 ++--------------
 gr-fec/lib/generator_encoder_impl.cc               |  94 ++++++++
 gr-fec/lib/generator_encoder_impl.h                |  55 +++++
 gr-fec/lib/generator_mtrx.cc                       |  86 ++++++++
 gr-fec/lib/ldpc_R_U_mtrx.cc                        | 239 ---------------------
 11 files changed, 414 insertions(+), 470 deletions(-)

diff --git a/gr-fec/include/gnuradio/fec/CMakeLists.txt 
b/gr-fec/include/gnuradio/fec/CMakeLists.txt
index cc5cee1..8f5554d 100644
--- a/gr-fec/include/gnuradio/fec/CMakeLists.txt
+++ b/gr-fec/include/gnuradio/fec/CMakeLists.txt
@@ -56,6 +56,9 @@ install(FILES
     ldpc_R_U_mtrx.h
     ldpc_bit_flip_decoder.h
     ldpc_R_U_encoder.h
+    generator_mtrx.h
+    generator_encoder.h
+    fec_mtrx.h
     DESTINATION ${GR_INCLUDE_DIR}/gnuradio/fec
     COMPONENT "fec_devel"
 )
diff --git a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h 
b/gr-fec/include/gnuradio/fec/fec_mtrx.h
similarity index 61%
copy from gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
copy to gr-fec/include/gnuradio/fec/fec_mtrx.h
index 7b36589..f90898b 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/fec_mtrx.h
@@ -18,8 +18,8 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef INCLUDED_ldpc_R_U_mtrx_H
-#define INCLUDED_ldpc_R_U_mtrx_H
+#ifndef INCLUDED_fec_mtrx_H
+#define INCLUDED_fec_mtrx_H
 
 #include <gnuradio/fec/api.h>
 #include <string>
@@ -33,50 +33,31 @@
 namespace gr {
   namespace fec {
     namespace code {
-      class FEC_API ldpc_R_U_mtrx
+      class FEC_API fec_mtrx
       {
-      private:
+      protected:
         // Codeword length n (also the number of columns in the H
         // matrix)
         unsigned int d_n;
         // Information word length k
         unsigned int d_k;
-        // Number of rows in the parity check matrix
+        // Number of rows in the matrix read in from alist file
         unsigned int d_num_rows;
-        // Gap (assumes matrix is in TABECD form)
-        unsigned int d_gap;
         // GSL matrix structure for the parity check matrix
         gsl_matrix *d_H_ptr;
-        // These are the submatrices found during preprocessing
-        // which are used for encoding. 
-        gsl_matrix_view d_A_view;
-        gsl_matrix_view d_B_view;
-        gsl_matrix_view d_D_view;
-        gsl_matrix_view d_E_view;
-        gsl_matrix_view d_T_view;
-        gsl_matrix *d_phi_inverse_ptr;
-
         // Read the matrix from a file in alist format
         void read_matrix_from_file(const std::string filename);
-        // Set the submatrix variables needed for encoding
-        void set_parameters_for_encoding();
+
         
       public:
-        ldpc_R_U_mtrx(const std::string filename, unsigned int gap);
-        // Default constructor, should not be used
-        ldpc_R_U_mtrx();
-        // Get the codeword length n
-        unsigned int n();
-        // Get the information word length k
-        unsigned int k();
-        // Access the matrices needed during encoding
-        const gsl_matrix *H();
-        const gsl_matrix *A();
-        const gsl_matrix *B();
-        const gsl_matrix *D();
-        const gsl_matrix *E();
-        const gsl_matrix *T();
-        const gsl_matrix *phi_inverse();
+        // Returns the parity check matrix H (needed by decoder)
+        virtual const gsl_matrix *H();
+
+        ///////////////////////////////////
+        // TODO add a boolean for whether or not parity part comes first
+        ///////////////////////////////////
+
+
         // Subtract matrices using mod2 operation
         gsl_matrix *add_matrices_mod2(const gsl_matrix *,
                                       const gsl_matrix *);
@@ -86,11 +67,11 @@ namespace gr {
         // Find the inverse of a square matrix using modulo 2
         // operations
         gsl_matrix *calc_inverse_mod2(const gsl_matrix *);
-        // Destructor
-        ~ldpc_R_U_mtrx();
+
+        virtual ~fec_mtrx(); 
       };
     }
   }
 }
 
- #endif /* INCLUDED_ldpc_R_U_mtrx_H */
\ No newline at end of file
+#endif /* INCLUDED_fec_mtrx_H */
\ No newline at end of file
diff --git a/gr-fec/include/gnuradio/fec/generator_encoder.h 
b/gr-fec/include/gnuradio/fec/generator_encoder.h
new file mode 100644
index 0000000..2cd1f3a
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/generator_encoder.h
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/* 
+ * Copyright 2013-2014 Free Software Foundation, Inc.
+ * 
+ * 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.
+ */
+
+#ifndef INCLUDED_FEC_GENERATOR_ENCODER_H
+#define INCLUDED_FEC_GENERATOR_ENCODER_H
+
+#include <gnuradio/fec/api.h>
+#include <gnuradio/fec/generic_encoder.h>
+#include <gnuradio/fec/generator_mtrx.h>
+
+namespace gr {
+  namespace fec {
+    namespace code {
+
+      /*!
+       * \brief LDPC Generic Encoder (method by Richardson & Urbanke)
+       * \ingroup error_coding_blk
+       *
+       * \details
+       * A standard encoder class. This method is discussed in many
+         textbooks. One is: Turbo Coding for Satellite and Wireless
+         Communications by Soleymani, Gao, and Vilaipornsawai.
+         The generator matrix G must be in systematic form, 
+         G = [I P], where I is an identity matrix and P is the
+         parity submatrix.
+       */
+      class FEC_API generator_encoder : virtual public generic_encoder
+      {
+      public:
+        /*!
+         * Build an encoding FEC API object.
+         *
+         * \param G_obj The generator matrix object to use
+         *        for encoding.
+        */
+        static generic_encoder::sptr make(generator_mtrx *G_obj);
+
+        /*!
+         * Sets the uncoded frame size to \p frame_size. If \p
+         * frame_size is greater than the value given to the
+         * constructor, the frame size will be capped by that initial
+         * value and this function will return false. Otherwise, it
+         * returns true.
+         */
+        virtual bool set_frame_size(unsigned int frame_size) = 0;
+
+        /*!
+         * Returns the coding rate of this encoder.
+         */
+        virtual double rate() = 0;
+      };
+    } /* namespace code */
+  } /* namespace fec */
+} /* namespace gr */
+
+#endif /* INCLUDED_FEC_GENERATOR_ENCODER_H */
\ No newline at end of file
diff --git a/gr-fec/include/gnuradio/fec/generator_mtrx.h 
b/gr-fec/include/gnuradio/fec/generator_mtrx.h
new file mode 100644
index 0000000..50e1853
--- /dev/null
+++ b/gr-fec/include/gnuradio/fec/generator_mtrx.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/* 
+ * Copyright 2013-2014 Free Software Foundation, Inc.
+ * 
+ * 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.
+ */
+
+#ifndef INCLUDED_generator_mtrx_H
+#define INCLUDED_generator_mtrx_H
+ 
+#include <gsl/gsl_randist.h>
+#include <gsl/gsl_permutation.h>
+#include <gsl/gsl_linalg.h>
+#include <gsl/gsl_blas.h>
+
+#include <gnuradio/fec/fec_mtrx.h>
+
+namespace gr {
+  namespace fec {
+    namespace code {
+      class FEC_API generator_mtrx : public fec_mtrx
+      {
+      private:
+        // GSL matrix structure for the generator matrix (encode)
+        gsl_matrix *d_G_ptr;
+        
+      public:
+        generator_mtrx(const std::string filename);
+        // Default constructor, should not be used
+        generator_mtrx();
+        // Get the codeword length n
+        unsigned int n();
+        // Get the information word length k
+        unsigned int k();
+        // Generator matrix used during encoding
+        const gsl_matrix *G();
+        // Parity check matrix used during decoding
+        const gsl_matrix *H();
+
+        // Destructor
+        ~generator_mtrx();
+      };
+    }
+  }
+}
+
+#endif /* INCLUDED_generator_mtrx_H */
\ No newline at end of file
diff --git a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h 
b/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
index 7b36589..bdde870 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
@@ -21,32 +21,21 @@
 #ifndef INCLUDED_ldpc_R_U_mtrx_H
 #define INCLUDED_ldpc_R_U_mtrx_H
 
-#include <gnuradio/fec/api.h>
-#include <string>
- 
-#include <gsl/gsl_matrix.h>
-#include <gsl/gsl_randist.h>
-#include <gsl/gsl_permutation.h>
-#include <gsl/gsl_linalg.h>
-#include <gsl/gsl_blas.h>
+// #include <gsl/gsl_randist.h>
+// #include <gsl/gsl_permutation.h>
+// #include <gsl/gsl_linalg.h>
+// #include <gsl/gsl_blas.h>
+
+#include <gnuradio/fec/fec_mtrx.h>
 
 namespace gr {
   namespace fec {
     namespace code {
-      class FEC_API ldpc_R_U_mtrx
+      class FEC_API ldpc_R_U_mtrx : public fec_mtrx
       {
       private:
-        // Codeword length n (also the number of columns in the H
-        // matrix)
-        unsigned int d_n;
-        // Information word length k
-        unsigned int d_k;
-        // Number of rows in the parity check matrix
-        unsigned int d_num_rows;
         // Gap (assumes matrix is in TABECD form)
         unsigned int d_gap;
-        // GSL matrix structure for the parity check matrix
-        gsl_matrix *d_H_ptr;
         // These are the submatrices found during preprocessing
         // which are used for encoding. 
         gsl_matrix_view d_A_view;
@@ -56,8 +45,6 @@ namespace gr {
         gsl_matrix_view d_T_view;
         gsl_matrix *d_phi_inverse_ptr;
 
-        // Read the matrix from a file in alist format
-        void read_matrix_from_file(const std::string filename);
         // Set the submatrix variables needed for encoding
         void set_parameters_for_encoding();
         
@@ -77,15 +64,6 @@ namespace gr {
         const gsl_matrix *E();
         const gsl_matrix *T();
         const gsl_matrix *phi_inverse();
-        // Subtract matrices using mod2 operation
-        gsl_matrix *add_matrices_mod2(const gsl_matrix *,
-                                      const gsl_matrix *);
-        // Perform matrix multiplication using mod 2 operations
-        gsl_matrix *mult_matrices_mod2(const gsl_matrix *,
-                                       const gsl_matrix *);
-        // Find the inverse of a square matrix using modulo 2
-        // operations
-        gsl_matrix *calc_inverse_mod2(const gsl_matrix *);
         // Destructor
         ~ldpc_R_U_mtrx();
       };
@@ -93,4 +71,4 @@ namespace gr {
   }
 }
 
- #endif /* INCLUDED_ldpc_R_U_mtrx_H */
\ No newline at end of file
+#endif /* INCLUDED_ldpc_R_U_mtrx_H */
\ No newline at end of file
diff --git a/gr-fec/lib/CMakeLists.txt b/gr-fec/lib/CMakeLists.txt
index f7b4558..9a067d0 100644
--- a/gr-fec/lib/CMakeLists.txt
+++ b/gr-fec/lib/CMakeLists.txt
@@ -93,6 +93,9 @@ list(APPEND gnuradio_fec_sources
   ldpc_R_U_mtrx.cc
   ldpc_bit_flip_decoder_impl.cc
   ldpc_R_U_encoder_impl.cc
+  generator_mtrx.cc
+  generator_encoder_impl.cc
+  fec_mtrx.cc
 )
 
 #Add Windows DLL resource file if using MSVC
diff --git a/gr-fec/lib/ldpc_R_U_mtrx.cc b/gr-fec/lib/fec_mtrx.cc
similarity index 65%
copy from gr-fec/lib/ldpc_R_U_mtrx.cc
copy to gr-fec/lib/fec_mtrx.cc
index 30a5f3b..9c4439e 100644
--- a/gr-fec/lib/ldpc_R_U_mtrx.cc
+++ b/gr-fec/lib/fec_mtrx.cc
@@ -21,7 +21,7 @@
 #include "config.h"
 #endif
 
-#include <gnuradio/fec/ldpc_R_U_mtrx.h>
+#include <gnuradio/fec/fec_mtrx.h>
 #include <math.h>
 #include <fstream>
 #include <vector>
@@ -32,85 +32,8 @@ namespace gr {
   namespace fec {
     namespace code {
 
-      ldpc_R_U_mtrx::ldpc_R_U_mtrx(const std::string filename, unsigned int 
gap) 
-      {
-        read_matrix_from_file(filename);
-        d_gap = gap;
-        set_parameters_for_encoding();
-      } // Constructor
-
-      // Default constructor, should not be used
-      ldpc_R_U_mtrx::ldpc_R_U_mtrx()
-      {
-        std::cout << "Error in ldpc_R_U_mtrx(): Default "
-                  << "constructor called.\nMust provide filename for"
-                  << " parity check matrix. \n\n";
-        exit(1);
-      } // Default constructor
-
-      unsigned int
-      ldpc_R_U_mtrx::n()
-      {
-        return d_n;
-      }
-
-      unsigned int
-      ldpc_R_U_mtrx::k()
-      {
-        return d_k;
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::H()
-      {
-        const gsl_matrix *H_ptr = d_H_ptr;
-        return H_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::A()
-      {
-        const gsl_matrix *A_ptr = &d_A_view.matrix;
-        return A_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::B()
-      {
-        const gsl_matrix *B_ptr = &d_B_view.matrix;
-        return B_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::D()
-      {
-        const gsl_matrix *D_ptr = &d_D_view.matrix;
-        return D_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::E()
-      {
-        const gsl_matrix *E_ptr = &d_E_view.matrix;
-        return E_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::T()
-      {
-        const gsl_matrix *T_ptr = &d_T_view.matrix;
-        return T_ptr; 
-      }
-
-      const gsl_matrix*
-      ldpc_R_U_mtrx::phi_inverse()
-      {
-        const gsl_matrix *phi_inverse_ptr = d_phi_inverse_ptr;
-        return phi_inverse_ptr; 
-      }
-
       void
-      ldpc_R_U_mtrx::read_matrix_from_file(const std::string filename)
+      fec_mtrx::read_matrix_from_file(const std::string filename)
       {
         /* This function reads in an alist file and creates the
            corresponding parity check matrix. The format of alist
@@ -173,91 +96,18 @@ namespace gr {
 
         // Length of information word = (# of columns) - (# of rows)
         d_k = d_n - d_num_rows;
-       }
+      }
 
-      void 
-      ldpc_R_U_mtrx::set_parameters_for_encoding() 
+      const gsl_matrix*
+      fec_mtrx::H()
       {
 
-        // This function defines all of the submatrices that will be
-        // needed during encoding. 
-        
-        unsigned int t = d_num_rows - d_gap; 
-
-        // T submatrix
-        d_T_view = gsl_matrix_submatrix(d_H_ptr, 0, 0, t, t);
-
-        gsl_matrix *d_T_inverse_ptr;
-        try {
-          d_T_inverse_ptr = calc_inverse_mod2(&d_T_view.matrix);
-        }
-        catch (char const *exceptionString) {
-          std::cout << "Error in set_parameters_for_encoding while "
-                    << "looking for inverse T matrix: " 
-                    << exceptionString
-                    << "Tip: verify that the correct gap is being "
-                    << "specified for this alist file.\n";
-
-          exit(1);
-        }
-
-        // E submatrix
-        d_E_view = gsl_matrix_submatrix(d_H_ptr, t, 0, d_gap,
-                                        d_n-d_k-d_gap);
-
-        // A submatrix
-        d_A_view = gsl_matrix_submatrix(d_H_ptr, 0, t, t, d_gap);
-
-        // C submatrix (used to find phi but not during encoding)
-        gsl_matrix_view C_view = gsl_matrix_submatrix(d_H_ptr, t, t,
-                                                      d_gap, d_gap);
-
-        // These are just temporary matrices used to find phi.
-        gsl_matrix *temp1 = mult_matrices_mod2(&d_E_view.matrix,
-                                               d_T_inverse_ptr);
-        gsl_matrix *temp2 = mult_matrices_mod2(temp1, 
-                                               &d_A_view.matrix);
-
-        // Solve for phi.
-        gsl_matrix *phi = add_matrices_mod2(&C_view.matrix, temp2);
-
-        // If phi has at least one nonzero entry, try for inverse.
-        if (gsl_matrix_max(phi)) {
-          try {
-            gsl_matrix *inverse_phi = calc_inverse_mod2(phi);
-              
-            // At this point, an inverse was found. 
-            d_phi_inverse_ptr = inverse_phi;
-
-          }
-          catch (char const *exceptionString) {
-
-            std::cout << "Error in set_parameters_for_encoding while"
-                      << " finding inverse_phi: " << exceptionString
-                      << "Tip: verify that the correct gap is being "
-                      << "specified for this alist file.\n";      
-            exit(1);
-          }
-        }
-
-        // B submatrix
-        d_B_view = gsl_matrix_submatrix(d_H_ptr, 0, t + d_gap, t,
-                                        d_n-d_gap-t);
-
-        // D submatrix
-        d_D_view = gsl_matrix_submatrix(d_H_ptr, t, t + d_gap, d_gap,
-                                        d_n-d_gap-t);
-
-        // Free memory
-        gsl_matrix_free(temp1);
-        gsl_matrix_free(temp2);
-        gsl_matrix_free(phi);
-        gsl_matrix_free(d_T_inverse_ptr);
-
+        ////// Compiler will throw warning as long as nothing is returned here
+ 
       }
 
       gsl_matrix*
-      ldpc_R_U_mtrx::add_matrices_mod2(const gsl_matrix *matrix1, const 
gsl_matrix *matrix2)
+      fec_mtrx::add_matrices_mod2(const gsl_matrix *matrix1, const gsl_matrix 
*matrix2)
       {
         // This function returns ((matrix1 + matrix2) % 2). 
 
@@ -302,7 +152,7 @@ namespace gr {
       }
 
       gsl_matrix*
-      ldpc_R_U_mtrx::mult_matrices_mod2(const gsl_matrix *matrix1, const 
gsl_matrix *matrix2) 
+      fec_mtrx::mult_matrices_mod2(const gsl_matrix *matrix1, const gsl_matrix 
*matrix2) 
       {
         // Verify that matrix sizes are appropriate
         unsigned int a = (*matrix1).size1;  // # of rows
@@ -311,7 +161,7 @@ namespace gr {
         unsigned int d = (*matrix2).size2;  // # of columns
         if (b != c) {
           std::cout << "Error in "
-                    << "ldpc_R_U_mtrx::mult_matrices_mod2."
+                    << "fec_mtrx::mult_matrices_mod2."
                     << " Matrix dimensions do not allow for matrix "
                     <<   "multiplication operation:\nmatrix1 is " 
                     << a << " x " << b << ", and matrix2 is " << c
@@ -341,7 +191,7 @@ namespace gr {
       }
 
       gsl_matrix*
-      ldpc_R_U_mtrx::calc_inverse_mod2(const gsl_matrix *original_matrix)
+      fec_mtrx::calc_inverse_mod2(const gsl_matrix *original_matrix)
       {
 
         // Let n represent the size of the n x n square matrix
@@ -429,12 +279,12 @@ namespace gr {
         return matrix_inverse;
       }
 
-      ldpc_R_U_mtrx::~ldpc_R_U_mtrx()
+
+      fec_mtrx::~fec_mtrx()
       {
-        // Call the gsl_matrix_free function to free memory.
-        gsl_matrix_free (d_H_ptr);
-        gsl_matrix_free (d_phi_inverse_ptr);
+
       }
+
     } /* namespace code */
   } /* namespace fec */
 } /* namespace gr */
\ No newline at end of file
diff --git a/gr-fec/lib/generator_encoder_impl.cc 
b/gr-fec/lib/generator_encoder_impl.cc
new file mode 100644
index 0000000..b507c9c
--- /dev/null
+++ b/gr-fec/lib/generator_encoder_impl.cc
@@ -0,0 +1,94 @@
+/* -*- c++ -*- */
+/* 
+ * Copyright 2013-2014 Free Software Foundation, Inc.
+ * 
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <generator_encoder_impl.h>
+#include <sstream>
+
+namespace gr {
+  namespace fec {
+    namespace code {
+      generic_encoder::sptr
+      generator_encoder::make(generator_mtrx *G_obj)
+      {
+        return generic_encoder::sptr
+          (new generator_encoder_impl(G_obj));
+      }
+
+      generator_encoder_impl::generator_encoder_impl(generator_mtrx *G_obj) 
+        : generic_encoder("generator_encoder")
+      {
+        // Generator matrix to use for encoding
+        d_G = G_obj;
+        // Set frame size to k, the # of bits in the information word
+        // All buffers and settings will be based on this value.
+        set_frame_size(d_G->k());
+      }
+
+      generator_encoder_impl::~generator_encoder_impl()
+      {
+      }
+
+      int
+      generator_encoder_impl::get_output_size()
+      {
+        return d_G->n();
+      }
+
+      int
+      generator_encoder_impl::get_input_size()
+      {
+        return d_frame_size;
+      }
+
+      bool
+      generator_encoder_impl::set_frame_size(unsigned int frame_size)
+      {
+        bool ret = true;
+        // TODO add some bounds check here? The frame size is
+        // constant and specified by the size of the parity check
+        // matrix used for encoding.
+        d_frame_size = frame_size;
+
+        return ret;        
+      }
+
+      double
+      generator_encoder_impl::rate()
+      {
+        return (d_G->n())/static_cast<double>(d_frame_size);
+      }
+
+      void
+      generator_encoder_impl::generic_work(void *inbuffer,
+                                           void *outbuffer)
+      {
+
+
+        // Free memory
+
+
+      }
+    } /* namespace code */
+  } /* namespace fec */
+} /* namespace gr */
\ No newline at end of file
diff --git a/gr-fec/lib/generator_encoder_impl.h 
b/gr-fec/lib/generator_encoder_impl.h
new file mode 100644
index 0000000..2d88539
--- /dev/null
+++ b/gr-fec/lib/generator_encoder_impl.h
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/* 
+ * Copyright 2013-2014 Free Software Foundation, Inc.
+ * 
+ * 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.
+ */
+
+#ifndef INCLUDED_FEC_GENERATOR_ENCODER_IMPL_H
+#define INCLUDED_FEC_GENERATOR_ENCODER_IMPL_H
+
+#include <map>
+#include <string>
+#include <gnuradio/fec/generator_encoder.h>
+#include <gnuradio/fec/generator_mtrx.h>
+
+namespace gr {
+  namespace fec {
+    namespace code {
+      class FEC_API generator_encoder_impl : public generator_encoder
+      {
+      private:
+        void generic_work(void *inbuffer, void *outbuffer);
+        int get_output_size();
+        int get_input_size();
+
+        // Number of bits in the information word
+        unsigned int d_frame_size;
+        // Generator matrix object to use for encoding
+        generator_mtrx *d_G;
+
+      public:
+        generator_encoder_impl(generator_mtrx *G_obj);
+        ~generator_encoder_impl();
+
+        bool set_frame_size(unsigned int frame_size);
+        double rate();
+      };
+    } /* namespace code */
+  } /* namespace fec */
+} /* namespace gr */
+
+#endif /* INCLUDED_FEC_GENERATOR_ENCODER_IMPL_H */
\ No newline at end of file
diff --git a/gr-fec/lib/generator_mtrx.cc b/gr-fec/lib/generator_mtrx.cc
new file mode 100644
index 0000000..fd94cac
--- /dev/null
+++ b/gr-fec/lib/generator_mtrx.cc
@@ -0,0 +1,86 @@
+/* -*- c++ -*- */
+/* 
+ * Copyright 2013-2014 Free Software Foundation, Inc.
+ * 
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gnuradio/fec/generator_mtrx.h>
+#include <math.h>
+#include <fstream>
+#include <vector>
+#include <sstream>
+#include <iostream>
+
+namespace gr {
+  namespace fec {
+    namespace code {
+
+      generator_mtrx::generator_mtrx(const std::string filename) 
+      {
+        // Read the matrix from a file in alist format
+        read_matrix_from_file(filename);
+
+      } // Constructor
+
+      // Default constructor, should not be used
+      generator_mtrx::generator_mtrx()
+      {
+        std::cout << "Error in generator_mtrx(): Default "
+                  << "constructor called.\nMust provide filename for"
+                  << " generator matrix. \n\n";
+        exit(1);
+      } // Default constructor
+
+      unsigned int
+      generator_mtrx::n()
+      {
+        return d_n;
+      }
+
+      unsigned int
+      generator_mtrx::k()
+      {
+        return d_k;
+      }
+      
+      const gsl_matrix*
+      generator_mtrx::G()
+      {
+        const gsl_matrix *G_ptr = d_G_ptr;
+        return G_ptr; 
+      }
+
+      const gsl_matrix*
+      generator_mtrx::H()
+      {
+        const gsl_matrix *H_ptr = d_H_ptr;
+        return H_ptr; 
+      }
+
+      generator_mtrx::~generator_mtrx()
+      {
+        ///////////////////////////////////
+        // TODO Call the gsl_matrix_free function to free memory.
+        ///////////////////////////////////
+
+      }
+    } /* namespace code */
+  } /* namespace fec */
+} /* namespace gr */
\ No newline at end of file
diff --git a/gr-fec/lib/ldpc_R_U_mtrx.cc b/gr-fec/lib/ldpc_R_U_mtrx.cc
index 30a5f3b..f3d48ec 100644
--- a/gr-fec/lib/ldpc_R_U_mtrx.cc
+++ b/gr-fec/lib/ldpc_R_U_mtrx.cc
@@ -109,72 +109,6 @@ namespace gr {
         return phi_inverse_ptr; 
       }
 
-      void
-      ldpc_R_U_mtrx::read_matrix_from_file(const std::string filename)
-      {
-        /* This function reads in an alist file and creates the
-           corresponding parity check matrix. The format of alist
-           files is described at:
-           http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
-        */
-        std::ifstream inputFile;
-
-        // Open the alist file (needs a C-string)
-        inputFile.open((filename).c_str());
-        if (!inputFile) {
-          std::cout << "There was a problem opening file "
-                    << filename << " for reading.\n";
-          exit(1);
-        }
-
-        // First line of file is matrix size: # columns, # rows
-        inputFile >> d_n >> d_num_rows; 
-
-        // Now we can allocate memory for the GSL matrix
-        d_H_ptr = gsl_matrix_alloc(d_num_rows, d_n);
-
-        // Since the matrix will be sparse, start by filling it with
-        // all 0s
-        gsl_matrix_set_zero(d_H_ptr);
-
-        // The next few lines in the file are not necessary in
-        // constructing the matrix.
-        std::string tempBuffer;
-        unsigned int counter;
-        for (counter = 0; counter < 4; counter++) {
-          getline(inputFile,tempBuffer);
-        }
-
-        // These next lines list the indices for where the 1s are in
-        // each column.
-        unsigned int column_count = 0;
-        std::string row_number;
-
-        while (column_count < d_n) {
-          getline(inputFile,tempBuffer);
-          std::stringstream ss(tempBuffer);
-
-          while (ss >> row_number) {
-            int row_i = atoi(row_number.c_str());
-            // alist files index starting from 1, not 0, so decrement
-            row_i--;
-            // set the corresponding matrix element to 1
-            gsl_matrix_set(d_H_ptr,row_i,column_count,1);
-          }
-          column_count++;
-        }
-
-        // The subsequent lines in the file list the indices for
-        // where the 1s are in the rows, but this is redundant
-        // information that we already have. 
-
-        // Close the alist file
-        inputFile.close();
-
-        // Length of information word = (# of columns) - (# of rows)
-        d_k = d_n - d_num_rows;
-       }
-
       void 
       ldpc_R_U_mtrx::set_parameters_for_encoding() 
       {
@@ -256,179 +190,6 @@ namespace gr {
 
       }
 
-      gsl_matrix*
-      ldpc_R_U_mtrx::add_matrices_mod2(const gsl_matrix *matrix1, const 
gsl_matrix *matrix2)
-      {
-        // This function returns ((matrix1 + matrix2) % 2). 
-
-        // Verify that matrix sizes are appropriate
-        unsigned int matrix1_rows = (*matrix1).size1;
-        unsigned int matrix1_cols = (*matrix1).size2;
-        unsigned int matrix2_rows = (*matrix2).size1;
-        unsigned int matrix2_cols = (*matrix2).size2;
-
-        if (matrix1_rows != matrix2_rows) {
-          std::cout << "Error in add_matrices_mod2. Matrices do"
-                    << " not have the same number of rows.\n";
-          exit(1);
-        }
-        if (matrix1_cols != matrix2_cols) {
-          std::cout << "Error in add_matrices_mod2. Matrices do"
-                    << " not have the same number of columns.\n";
-          exit(1);
-        }
-
-        // Allocate memory for the result
-        gsl_matrix *result = gsl_matrix_alloc(matrix1_rows,
-                                              matrix1_cols);
-
-        // Copy matrix1 into result
-        gsl_matrix_memcpy(result, matrix1);
-
-        // Do subtraction. This is not mod 2 yet.
-        gsl_matrix_add(result, matrix2);
-
-        // Take care of mod 2 manually
-        unsigned int row_index, col_index;
-        for (row_index = 0; row_index < matrix1_rows; row_index++) {
-          for (col_index = 0; col_index < matrix1_cols;col_index++) {
-            int value = gsl_matrix_get(result, row_index, col_index);
-            int new_value = abs(value) % 2;
-            gsl_matrix_set(result, row_index, col_index, new_value);
-          }
-        }
-
-        return result; 
-      }
-
-      gsl_matrix*
-      ldpc_R_U_mtrx::mult_matrices_mod2(const gsl_matrix *matrix1, const 
gsl_matrix *matrix2) 
-      {
-        // Verify that matrix sizes are appropriate
-        unsigned int a = (*matrix1).size1;  // # of rows
-        unsigned int b = (*matrix1).size2;  // # of columns
-        unsigned int c = (*matrix2).size1;  // # of rows
-        unsigned int d = (*matrix2).size2;  // # of columns
-        if (b != c) {
-          std::cout << "Error in "
-                    << "ldpc_R_U_mtrx::mult_matrices_mod2."
-                    << " Matrix dimensions do not allow for matrix "
-                    <<   "multiplication operation:\nmatrix1 is " 
-                    << a << " x " << b << ", and matrix2 is " << c
-                    << " x " << d << ".\n";
-          exit(1);
-        }
-
-        // Allocate memory for the result.
-        gsl_matrix *result = gsl_matrix_alloc(a,d);
-
-        // Perform matrix multiplication. This is not mod 2.
-        gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0, matrix1,
-                        matrix2, 0.0, result);
-
-        // Take care of mod 2 manually.
-        unsigned int row_index, col_index;
-        unsigned int rows = (*result).size1, 
-        cols = (*result).size2;
-        for (row_index = 0; row_index < rows; row_index++) {
-          for (col_index = 0; col_index < cols; col_index++) {
-            int value = gsl_matrix_get(result, row_index,col_index);
-            int new_value = value % 2;
-            gsl_matrix_set(result, row_index, col_index, new_value);
-          }
-        }
-        return result;
-      }
-
-      gsl_matrix*
-      ldpc_R_U_mtrx::calc_inverse_mod2(const gsl_matrix *original_matrix)
-      {
-
-        // Let n represent the size of the n x n square matrix
-        unsigned int n = (*original_matrix).size1;
-        unsigned int row_index, col_index;
-
-        // Make a copy of the original matrix, call it matrix_altered.
-        // This matrix will be modified by the GSL functions. 
-        gsl_matrix *matrix_altered = gsl_matrix_alloc(n, n);
-        gsl_matrix_memcpy(matrix_altered, original_matrix);
-
-        // In order to find the inverse, GSL must perform a LU 
-        // decomposition first. 
-        gsl_permutation *permutation = gsl_permutation_alloc(n);
-        int signum;
-        gsl_linalg_LU_decomp(matrix_altered, permutation, &signum);
-
-        // Allocate memory to store the matrix inverse
-        gsl_matrix *matrix_inverse = gsl_matrix_alloc(n,n);
-
-        // Find matrix inverse. This is not mod2.
-        int status = gsl_linalg_LU_invert(matrix_altered,
-                                          permutation,
-                                          matrix_inverse);
-
-        if (status) {
-          // Inverse not found by GSL functions.
-          throw "Error in calc_inverse_mod2(): inverse not found.\n";
-        }
-
-        // Find determinant
-        float determinant = gsl_linalg_LU_det(matrix_altered,signum);
-
-        // Multiply the matrix inverse by the determinant.
-        gsl_matrix_scale(matrix_inverse, determinant);
-
-        // Take mod 2 of each element in the matrix.
-        for (row_index = 0; row_index < n; row_index++) {
-          for (col_index = 0; col_index < n; col_index++) {
-
-            float value = gsl_matrix_get(matrix_inverse,
-                                         row_index,
-                                         col_index);
-
-            // take care of mod 2
-            int value_cast_as_int = static_cast<int>(value);
-            int temp_value = abs(fmod(value_cast_as_int,2));
-
-            gsl_matrix_set(matrix_inverse,
-                           row_index,
-                           col_index,
-                           temp_value);
-          }
-        } 
-
-        int max_value = gsl_matrix_max(matrix_inverse);
-        if (!max_value) {
-          throw "Error in calc_inverse_mod2(): The matrix inverse found is all 
zeros.\n";
-        }
-
-        // Verify that the inverse was found by taking matrix
-        // product of original_matrix and the inverse, which should
-        // equal the identity matrix.
-        gsl_matrix *test = gsl_matrix_alloc(n,n);
-        gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0,
-                        original_matrix, matrix_inverse, 0.0, test);
-        
-        // Have to take care of % 2 manually
-         for (row_index = 0; row_index < n; row_index++) {
-          for (col_index = 0; col_index < n; col_index++) {
-            int value = gsl_matrix_get(test, row_index, col_index);
-            int temp_value = value % 2;
-            gsl_matrix_set(test, row_index, col_index, temp_value);
-          }
-        }  
-
-        gsl_matrix *identity = gsl_matrix_alloc(n,n);
-        gsl_matrix_set_identity(identity);
-        int test_if_equal = gsl_matrix_equal(identity,test);
-
-        if (!test_if_equal) {
-          throw "Error in calc_inverse_mod2(): The matrix inverse found is not 
valid.\n";
-        }
-
-        return matrix_inverse;
-      }
-
       ldpc_R_U_mtrx::~ldpc_R_U_mtrx()
       {
         // Call the gsl_matrix_free function to free memory.



reply via email to

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