commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 18/39: fec: LDPC: Updates to LDPC-related m


From: git
Subject: [Commit-gnuradio] [gnuradio] 18/39: fec: LDPC: Updates to LDPC-related matrix classes.
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 e11a5a564b4c7ea16b47efc8728d4978a10a931f
Author: tracierenea <address@hidden>
Date:   Wed Feb 18 13:33:14 2015 -0600

    fec: LDPC: Updates to LDPC-related matrix classes.
    
     1) moved common functions to the base class (fec_mtrx)
    
     2) added a constructor (does nothing) to the base class, but I'm not
        sure if it's really required?
    
     3) added the word "virtual" to the derived class destructors just for
        clarity (I think this is best practice?)
    
     4) altered the bit flip decoder class to accept and use the new base
        class so that users can provide a matrix in either generator
        matrix form or parity check matrix form
    
     5) added the new classes to swig.i
---
 gr-fec/include/gnuradio/fec/fec_mtrx.h             | 11 +++++---
 gr-fec/include/gnuradio/fec/generator_mtrx.h       |  8 ++----
 gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h        |  6 +----
 .../include/gnuradio/fec/ldpc_bit_flip_decoder.h   |  6 +++--
 gr-fec/lib/fec_mtrx.cc                             | 30 +++++++++++++++++-----
 gr-fec/lib/generator_mtrx.cc                       | 16 ++----------
 gr-fec/lib/ldpc_R_U_mtrx.cc                        | 20 ++++-----------
 gr-fec/lib/ldpc_bit_flip_decoder_impl.cc           | 27 +++++++++----------
 gr-fec/lib/ldpc_bit_flip_decoder_impl.h            |  8 +++---
 gr-fec/swig/fec_swig.i                             |  4 +++
 10 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/gr-fec/include/gnuradio/fec/fec_mtrx.h 
b/gr-fec/include/gnuradio/fec/fec_mtrx.h
index fa991d3..37f336e 100644
--- a/gr-fec/include/gnuradio/fec/fec_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/fec_mtrx.h
@@ -47,12 +47,17 @@ namespace gr {
         // GSL matrix structure for the parity check matrix
         gsl_matrix *d_H_ptr;
         // Read the matrix from a file in alist format
-        void read_matrix_from_file(const std::string filename,
-                                   gsl_matrix *);
+        gsl_matrix *read_matrix_from_file(const std::string filename);
+        // Constructor
+        fec_mtrx();
         
       public:
         // Returns the parity check matrix H (needed by decoder)
-        virtual const gsl_matrix *H();
+        const gsl_matrix *H();
+        // Get the codeword length n
+        unsigned int n();
+        // Get the information word length k
+        unsigned int k();
 
         ///////////////////////////////////
         // TODO add a boolean for whether or not parity part comes first
diff --git a/gr-fec/include/gnuradio/fec/generator_mtrx.h 
b/gr-fec/include/gnuradio/fec/generator_mtrx.h
index 05286cc..4ee37b6 100644
--- a/gr-fec/include/gnuradio/fec/generator_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/generator_mtrx.h
@@ -41,15 +41,11 @@ namespace gr {
         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
+        // Get the generator matrix (used during encoding)
         const gsl_matrix *G();
 
         // Destructor
-        ~generator_mtrx();
+        virtual ~generator_mtrx();
       };
     }
   }
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 06a2b60..a671d6d 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
@@ -47,10 +47,6 @@ namespace gr {
         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 *A();
         const gsl_matrix *B();
@@ -59,7 +55,7 @@ namespace gr {
         const gsl_matrix *T();
         const gsl_matrix *phi_inverse();
         // Destructor
-        ~ldpc_R_U_mtrx();
+        virtual ~ldpc_R_U_mtrx();
       };
     }
   }
diff --git a/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h 
b/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
index 05d47fc..73f45d6 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
@@ -24,7 +24,7 @@
 
 #include <gnuradio/fec/api.h>
 #include <gnuradio/fec/generic_decoder.h>
-#include <gnuradio/fec/ldpc_R_U_mtrx.h>
+#include <gnuradio/fec/fec_mtrx.h>
 
 namespace gr {
   namespace fec {
@@ -63,8 +63,10 @@ namespace gr {
          * \param n Number of bits in each transmitted codeword, 
          *        usually denoted "n" in the literature.
          */
-        static generic_decoder::sptr make(ldpc_R_U_mtrx *H_obj,
+
+        static generic_decoder::sptr make(fec_mtrx *mtrx_obj,
                                           unsigned int max_iter=100);
+
         /*!
          * Sets the uncoded frame size to \p frame_size. If \p
          * frame_size is greater than the value given to the
diff --git a/gr-fec/lib/fec_mtrx.cc b/gr-fec/lib/fec_mtrx.cc
index 087cdc3..458c269 100644
--- a/gr-fec/lib/fec_mtrx.cc
+++ b/gr-fec/lib/fec_mtrx.cc
@@ -32,9 +32,13 @@ namespace gr {
   namespace fec {
     namespace code {
 
-      void
-      fec_mtrx::read_matrix_from_file(const std::string filename,
-                                      gsl_matrix *given_matrix)
+      fec_mtrx::fec_mtrx()
+      {
+        // nothing for the default constructor to do
+      }
+
+      gsl_matrix*
+      fec_mtrx::read_matrix_from_file(const std::string filename)
       {
         /* This function reads in an alist file and creates the
            corresponding matrix. The format of alist files is 
@@ -55,8 +59,9 @@ namespace gr {
         inputFile >> d_num_cols >> d_num_rows; 
 
         // Now we can allocate memory for the GSL matrix
-        given_matrix = gsl_matrix_alloc(d_num_rows, d_num_cols);
-        gsl_matrix_set_zero(given_matrix);
+        gsl_matrix *temp_matrix = gsl_matrix_alloc(d_num_rows,
+                                                   d_num_cols);
+        gsl_matrix_set_zero(temp_matrix);
 
         // The next few lines in the file are not necessary in
         // constructing the matrix.
@@ -80,7 +85,7 @@ namespace gr {
             // alist files index starting from 1, not 0, so decrement
             row_i--;
             // set the corresponding matrix element to 1
-            gsl_matrix_set(given_matrix,row_i,column_count,1);
+            gsl_matrix_set(temp_matrix,row_i,column_count,1);
           }
           column_count++;
         }
@@ -92,6 +97,7 @@ namespace gr {
         // Close the alist file
         inputFile.close();
 
+        return temp_matrix;
       }
 
       const gsl_matrix*
@@ -101,6 +107,18 @@ namespace gr {
         return H_ptr; 
       }
 
+      unsigned int
+      fec_mtrx::n()
+      {
+        return d_n;
+      }
+
+      unsigned int
+      fec_mtrx::k()
+      {
+        return d_k;
+      }
+
       gsl_matrix*
       fec_mtrx::add_matrices_mod2(const gsl_matrix *matrix1, const gsl_matrix 
*matrix2)
       {
diff --git a/gr-fec/lib/generator_mtrx.cc b/gr-fec/lib/generator_mtrx.cc
index 97aef5e..28fd368 100644
--- a/gr-fec/lib/generator_mtrx.cc
+++ b/gr-fec/lib/generator_mtrx.cc
@@ -35,7 +35,7 @@ namespace gr {
       generator_mtrx::generator_mtrx(const std::string filename) 
       {
         // Read the matrix from a file in alist format
-        read_matrix_from_file(filename, d_G_ptr);
+        d_G_ptr = read_matrix_from_file(filename);
 
         // The alist file should have provided a generator matrix G
         // in systematic form, G = [I P], where I is a k x k identity
@@ -110,19 +110,7 @@ namespace gr {
                   << " 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()
       {
diff --git a/gr-fec/lib/ldpc_R_U_mtrx.cc b/gr-fec/lib/ldpc_R_U_mtrx.cc
index 1d80825..f43cedd 100644
--- a/gr-fec/lib/ldpc_R_U_mtrx.cc
+++ b/gr-fec/lib/ldpc_R_U_mtrx.cc
@@ -34,13 +34,15 @@ namespace gr {
 
       ldpc_R_U_mtrx::ldpc_R_U_mtrx(const std::string filename, unsigned int 
gap) 
       {
-        read_matrix_from_file(filename, d_H_ptr);
+        d_H_ptr = read_matrix_from_file(filename);
         d_gap = gap;
 
         // Length of codeword = # of columns
         d_n = d_num_cols;
+
         // Length of information word = (# of columns) - (# of rows)
         d_k = d_num_cols - d_num_rows;
+
         set_parameters_for_encoding();
 
       } // Constructor
@@ -54,18 +56,6 @@ namespace gr {
         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::A()
       {
@@ -114,9 +104,9 @@ namespace gr {
 
         // This function defines all of the submatrices that will be
         // needed during encoding. 
-        
-        unsigned int t = d_num_rows - d_gap; 
 
+        unsigned int t = d_num_rows - d_gap; 
+        
         // T submatrix
         d_T_view = gsl_matrix_submatrix(d_H_ptr, 0, 0, t, t);
 
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc 
b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
index effc9ad..77e3e95 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
@@ -35,21 +35,22 @@ namespace gr {
     namespace code {
 
       generic_decoder::sptr
-      ldpc_bit_flip_decoder::make(ldpc_R_U_mtrx *H_obj,
+      ldpc_bit_flip_decoder::make(fec_mtrx *mtrx_obj,
                                   unsigned int max_iter)
       {
         return generic_decoder::sptr
-          (new ldpc_bit_flip_decoder_impl(H_obj, max_iter));
+          (new ldpc_bit_flip_decoder_impl(mtrx_obj, max_iter));
       }
 
-      ldpc_bit_flip_decoder_impl::ldpc_bit_flip_decoder_impl(ldpc_R_U_mtrx 
*H_obj, unsigned int max_iter)
+      ldpc_bit_flip_decoder_impl::ldpc_bit_flip_decoder_impl(fec_mtrx 
*mtrx_obj, unsigned int max_iter)
         : generic_decoder("ldpc_bit_flip_decoder")
       {
-        // LDPC parity check matrix to use for decoding
-        d_H = H_obj;
+        // FEC matrix object to use for decoding
+        d_mtrx = mtrx_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_H->k());
+        set_frame_size(d_mtrx->k());
         // Maximum number of iterations in the decoding algorithm
         d_max_iterations = max_iter;
       }
@@ -67,7 +68,7 @@ namespace gr {
       int
       ldpc_bit_flip_decoder_impl::get_input_size()
       {
-        return int(d_H->n());
+        return int(d_mtrx->n());
       }
 
       bool
@@ -86,7 +87,7 @@ namespace gr {
       double
       ldpc_bit_flip_decoder_impl::rate()
       {
-        return static_cast<double>(d_frame_size)/(d_H->n());
+        return static_cast<double>(d_frame_size)/(d_mtrx->n());
       }
 
 
@@ -98,7 +99,7 @@ namespace gr {
         // Populate the information word
         const float *in = (const float*)inbuffer;
 
-        unsigned int index, n = d_H->n();
+        unsigned int index, n = d_mtrx->n();
         gsl_matrix *x = gsl_matrix_alloc(n, 1);
         for (index = 0; index < n; index++) {
           double value = in[index] > 0 ? 1.0 : 0.0;
@@ -109,7 +110,7 @@ namespace gr {
         unsigned int count = 0;
 
         // Calculate syndrome
-        gsl_matrix *syndrome = d_H->mult_matrices_mod2(d_H->H(),x);
+        gsl_matrix *syndrome = d_mtrx->mult_matrices_mod2(d_mtrx->H(),x);
 
         // Flag for finding a valid codeword
         bool found_word = false;
@@ -138,12 +139,12 @@ namespace gr {
           // Second, for each bit, determine how many of the
           // unsatisfied parity checks involve this bit and store
           // the count.
-          unsigned int i, col_num, n = d_H->n();
+          unsigned int i, col_num, n = d_mtrx->n();
           std::vector<int> counts(n,0);
           for (i = 0; i < rows_of_interest_in_H.size(); i++) {
             unsigned int row_num = rows_of_interest_in_H[i];
             for (col_num = 0; col_num < n; col_num++) {
-              double value = gsl_matrix_get(d_H->H(),
+              double value = gsl_matrix_get(d_mtrx->H(),
                                             row_num,
                                             col_num);
               if (value > 0) {
@@ -170,7 +171,7 @@ namespace gr {
           }
 
           // Check the syndrome; see if valid codeword has been found
-          syndrome = d_H->mult_matrices_mod2(d_H->H(), x);
+          syndrome = d_mtrx->mult_matrices_mod2(d_mtrx->H(), x);
           if (gsl_matrix_isnull(syndrome)) {
             found_word = true;
             break;
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h 
b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
index bbb4620..e745963 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
@@ -22,7 +22,6 @@
 #define INCLUDED_FEC_LDPC_BIT_FLIP_DECODER_IMPL_H
 
 #include <gnuradio/fec/ldpc_bit_flip_decoder.h>
-#include <gnuradio/fec/ldpc_R_U_mtrx.h>
 
 namespace gr {
   namespace fec {
@@ -35,14 +34,15 @@ namespace gr {
         int get_input_size();   // n, # of bits in the received block
         int get_output_size();  // k, # of bits in the info word
         unsigned int d_frame_size;
+           
+        // FEC matrix object to use for decoding
+        fec_mtrx *d_mtrx;
 
-        // LDPC parity check matrix object to use for decoding
-        ldpc_R_U_mtrx *d_H;
         // Maximum number of iterations to do in decoding algorithm
         unsigned int d_max_iterations;
 
       public:
-        ldpc_bit_flip_decoder_impl(ldpc_R_U_mtrx *H_obj,
+        ldpc_bit_flip_decoder_impl(fec_mtrx *mtrx_obj,
                                    unsigned int max_iter=100);
         ~ldpc_bit_flip_decoder_impl();
 
diff --git a/gr-fec/swig/fec_swig.i b/gr-fec/swig/fec_swig.i
index 64e6fa4..8b5ce5f 100644
--- a/gr-fec/swig/fec_swig.i
+++ b/gr-fec/swig/fec_swig.i
@@ -69,6 +69,8 @@
 #include "gnuradio/fec/polar_decoder_common.h"
 #include "gnuradio/fec/ldpc_par_chk_mtrx.h"
 #include "gnuradio/fec/ldpc_R_U_mtrx.h"
+#include "gnuradio/fec/fec_mtrx.h"
+#include "gnuradio/fec/generator_mtrx.h"
 #include "gnuradio/fec/ldpc_bit_flip_decoder.h"
 #include "gnuradio/fec/ldpc_R_U_encoder.h"
 %}
@@ -101,6 +103,8 @@
 %include "gnuradio/fec/tpc_decoder.h"
 %include "gnuradio/fec/ldpc_par_chk_mtrx.h"
 %include "gnuradio/fec/ldpc_R_U_mtrx.h"
+%include "gnuradio/fec/generator_mtrx.h"
+%include "gnuradio/fec/fec_mtrx.h"
 %include "gnuradio/fec/ldpc_bit_flip_decoder.h"
 %include "gnuradio/fec/ldpc_R_U_encoder.h"
 



reply via email to

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