commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 17/39: fec: LDPC: updates to the 3 LDPC-rel


From: git
Subject: [Commit-gnuradio] [gnuradio] 17/39: fec: LDPC: updates to the 3 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 be63a9a754de6f98d72c8463df27280aa43ca238
Author: tracierenea <address@hidden>
Date:   Tue Feb 17 16:15:29 2015 -0600

    fec: LDPC: updates to the 3 LDPC-related matrix classes.
    
    Updates to fec_mtrx, LDPC_R_U_mtrx, & generator_mtrx classes. These
    updates are not yet reflected in the associated GRC files.
---
 gr-fec/include/gnuradio/fec/fec_mtrx.h       |  9 ++--
 gr-fec/include/gnuradio/fec/generator_mtrx.h |  2 -
 gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h  |  6 ---
 gr-fec/lib/fec_mtrx.cc                       | 28 ++++------
 gr-fec/lib/generator_mtrx.cc                 | 79 +++++++++++++++++++++++-----
 gr-fec/lib/ldpc_R_U_mtrx.cc                  | 15 +++---
 6 files changed, 90 insertions(+), 49 deletions(-)

diff --git a/gr-fec/include/gnuradio/fec/fec_mtrx.h 
b/gr-fec/include/gnuradio/fec/fec_mtrx.h
index f90898b..fa991d3 100644
--- a/gr-fec/include/gnuradio/fec/fec_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/fec_mtrx.h
@@ -36,18 +36,19 @@ namespace gr {
       class FEC_API fec_mtrx
       {
       protected:
-        // Codeword length n (also the number of columns in the H
-        // matrix)
+        // Codeword length n
         unsigned int d_n;
         // Information word length k
         unsigned int d_k;
         // Number of rows in the matrix read in from alist file
         unsigned int d_num_rows;
+        // Number of columns in the matrix read in from alist file
+        unsigned int d_num_cols;
         // 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);
-
+        void read_matrix_from_file(const std::string filename,
+                                   gsl_matrix *);
         
       public:
         // Returns the parity check matrix H (needed by decoder)
diff --git a/gr-fec/include/gnuradio/fec/generator_mtrx.h 
b/gr-fec/include/gnuradio/fec/generator_mtrx.h
index 50e1853..05286cc 100644
--- a/gr-fec/include/gnuradio/fec/generator_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/generator_mtrx.h
@@ -47,8 +47,6 @@ namespace gr {
         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();
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 bdde870..06a2b60 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_R_U_mtrx.h
@@ -21,11 +21,6 @@
 #ifndef INCLUDED_ldpc_R_U_mtrx_H
 #define INCLUDED_ldpc_R_U_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 {
@@ -57,7 +52,6 @@ namespace gr {
         // 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();
diff --git a/gr-fec/lib/fec_mtrx.cc b/gr-fec/lib/fec_mtrx.cc
index 9c4439e..087cdc3 100644
--- a/gr-fec/lib/fec_mtrx.cc
+++ b/gr-fec/lib/fec_mtrx.cc
@@ -33,11 +33,12 @@ namespace gr {
     namespace code {
 
       void
-      fec_mtrx::read_matrix_from_file(const std::string filename)
+      fec_mtrx::read_matrix_from_file(const std::string filename,
+                                      gsl_matrix *given_matrix)
       {
         /* This function reads in an alist file and creates the
-           corresponding parity check matrix. The format of alist
-           files is described at:
+           corresponding matrix. The format of alist files is 
+           described at:
            http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
         */
         std::ifstream inputFile;
@@ -51,14 +52,11 @@ namespace gr {
         }
 
         // First line of file is matrix size: # columns, # rows
-        inputFile >> d_n >> d_num_rows; 
+        inputFile >> d_num_cols >> 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);
+        given_matrix = gsl_matrix_alloc(d_num_rows, d_num_cols);
+        gsl_matrix_set_zero(given_matrix);
 
         // The next few lines in the file are not necessary in
         // constructing the matrix.
@@ -73,7 +71,7 @@ namespace gr {
         unsigned int column_count = 0;
         std::string row_number;
 
-        while (column_count < d_n) {
+        while (column_count < d_num_cols) {
           getline(inputFile,tempBuffer);
           std::stringstream ss(tempBuffer);
 
@@ -82,7 +80,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(d_H_ptr,row_i,column_count,1);
+            gsl_matrix_set(given_matrix,row_i,column_count,1);
           }
           column_count++;
         }
@@ -94,16 +92,13 @@ namespace gr {
         // Close the alist file
         inputFile.close();
 
-        // Length of information word = (# of columns) - (# of rows)
-        d_k = d_n - d_num_rows;
       }
 
       const gsl_matrix*
       fec_mtrx::H()
       {
-
-        ////// Compiler will throw warning as long as nothing is returned here
- 
+        const gsl_matrix *H_ptr = d_H_ptr;
+        return H_ptr; 
       }
 
       gsl_matrix*
@@ -279,7 +274,6 @@ namespace gr {
         return matrix_inverse;
       }
 
-
       fec_mtrx::~fec_mtrx()
       {
 
diff --git a/gr-fec/lib/generator_mtrx.cc b/gr-fec/lib/generator_mtrx.cc
index fd94cac..97aef5e 100644
--- a/gr-fec/lib/generator_mtrx.cc
+++ b/gr-fec/lib/generator_mtrx.cc
@@ -35,7 +35,70 @@ namespace gr {
       generator_mtrx::generator_mtrx(const std::string filename) 
       {
         // Read the matrix from a file in alist format
-        read_matrix_from_file(filename);
+        read_matrix_from_file(filename, d_G_ptr);
+
+        // The alist file should have provided a generator matrix G
+        // in systematic form, G = [I P], where I is a k x k identity
+        // matrix and P is the parity submatrix. So start by checking
+        // that the left side k x k submatrix is I.
+
+        gsl_matrix *I_test   = gsl_matrix_alloc(d_k,d_k);
+        gsl_matrix *identity = gsl_matrix_alloc(d_k,d_k);
+        gsl_matrix_set_identity(identity);
+
+        unsigned int row_index, col_index;
+        for (row_index = 0; row_index < d_k; row_index++) {
+          for (col_index = 0; col_index < d_k; col_index++) {
+            int value = gsl_matrix_get(d_G_ptr, row_index,col_index);
+            gsl_matrix_set(I_test, row_index, col_index, value);
+          }
+        }
+
+        int test_if_equal = gsl_matrix_equal(identity,I_test);
+        if (!test_if_equal) {
+          throw "Error in generator_mtrx constructor. It appears that the 
given alist file did not contain a valid generator matrix of the form G = [I 
P].\n";
+        }
+
+        // Length of codeword = # of columns of generator matrix
+        d_n = d_num_cols;
+        // Length of information word = # of rows of generator matrix
+        d_k = d_num_rows;
+
+        // Grab P matrix
+        gsl_matrix *P = gsl_matrix_alloc(d_k,d_n-d_k);
+        for (row_index = 0; row_index < d_k; row_index++) {
+          for (col_index = 0; col_index < d_n-d_k; col_index++) {
+            int value = gsl_matrix_get(d_G_ptr, row_index,col_index);
+            gsl_matrix_set(P, row_index, col_index, value);
+          }
+        }
+
+        // Calculate P transpose
+        gsl_matrix *P_transpose = gsl_matrix_alloc(d_n-d_k, d_k);
+        gsl_matrix_transpose_memcpy(P_transpose, P);
+
+        // Set H matrix. H = [-P' I] but since we are doing mod 2,
+        // -P = P, so H = [P' I]
+        d_H_ptr = gsl_matrix_alloc(d_n-d_k, d_k);
+        gsl_matrix_set_zero(d_H_ptr);
+        for (row_index = 0; row_index < d_k; row_index++) {
+          for (col_index = 0; col_index < d_n-d_k; col_index++) {
+            int value = gsl_matrix_get(P_transpose,
+                                       row_index,
+                                       col_index);
+            gsl_matrix_set(d_H_ptr, row_index, col_index, value);
+          }
+        }
+        for (row_index = 0; row_index < d_k; row_index++) {
+          col_index = row_index + d_k;
+          gsl_matrix_set(d_H_ptr, row_index, col_index, 1);
+        }
+
+        // Free memory
+        gsl_matrix_free(P);
+        gsl_matrix_free(P_transpose);
+        gsl_matrix_free(identity);
+        gsl_matrix_free(I_test);
 
       } // Constructor
 
@@ -67,19 +130,11 @@ namespace gr {
         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.
-        ///////////////////////////////////
-
+        // Call the gsl_matrix_free function to free memory.
+        gsl_matrix_free(d_H_ptr);
+        gsl_matrix_free(d_G_ptr);
       }
     } /* namespace code */
   } /* namespace fec */
diff --git a/gr-fec/lib/ldpc_R_U_mtrx.cc b/gr-fec/lib/ldpc_R_U_mtrx.cc
index f3d48ec..1d80825 100644
--- a/gr-fec/lib/ldpc_R_U_mtrx.cc
+++ b/gr-fec/lib/ldpc_R_U_mtrx.cc
@@ -34,9 +34,15 @@ namespace gr {
 
       ldpc_R_U_mtrx::ldpc_R_U_mtrx(const std::string filename, unsigned int 
gap) 
       {
-        read_matrix_from_file(filename);
+        read_matrix_from_file(filename, d_H_ptr);
         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
 
       // Default constructor, should not be used
@@ -61,13 +67,6 @@ namespace gr {
       }
 
       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;



reply via email to

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