commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 23/39: fec: LDPC: Finishing encoder's work(


From: git
Subject: [Commit-gnuradio] [gnuradio] 23/39: fec: LDPC: Finishing encoder's work() function and updating matrix class.
Date: Thu, 15 Oct 2015 21:21:31 +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 4ab46d31cb4868e1cd7304f3aaeee12d81c11cfb
Author: tracierenea <address@hidden>
Date:   Sat Feb 28 16:25:48 2015 -0600

    fec: LDPC: Finishing encoder's work() function and updating matrix
    class.
---
 gr-fec/include/gnuradio/fec/ldpc_gen_mtrx.h |  6 +++---
 gr-fec/lib/ldpc_gen_mtrx.cc                 | 33 +++++++++++++++++------------
 gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc    | 18 ++++++++++++++++
 3 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/gr-fec/include/gnuradio/fec/ldpc_gen_mtrx.h 
b/gr-fec/include/gnuradio/fec/ldpc_gen_mtrx.h
index 66ee32e..56b171d 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_gen_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_gen_mtrx.h
@@ -34,8 +34,8 @@ namespace gr {
       class FEC_API ldpc_gen_mtrx : public fec_mtrx
       {
       private:
-        // GSL matrix structure for the generator matrix (encode)
-        gsl_matrix *d_G_ptr;
+        // GSL matrix structure for transpose of G
+        gsl_matrix *d_G_transp_ptr;
         // Swig needs the scope resolution operator here
         gr::fec::code::fec_mtrx *d_base_ptr;
         
@@ -44,7 +44,7 @@ namespace gr {
         // Default constructor, should not be used
         ldpc_gen_mtrx();
         // Get the generator matrix (used during encoding)
-        const gsl_matrix *G();
+        const gsl_matrix *G_transpose() const;
         // A pointer to make swig work for the ldpc_bit_flip_decoder
         // GRC block
         gr::fec::code::fec_mtrx *get_base_ptr();
diff --git a/gr-fec/lib/ldpc_gen_mtrx.cc b/gr-fec/lib/ldpc_gen_mtrx.cc
index 3c5df4d..f2af63c 100644
--- a/gr-fec/lib/ldpc_gen_mtrx.cc
+++ b/gr-fec/lib/ldpc_gen_mtrx.cc
@@ -35,7 +35,11 @@ namespace gr {
       ldpc_gen_mtrx::ldpc_gen_mtrx(const std::string filename) 
       {
         // Read the matrix from a file in alist format
-        d_G_ptr = read_matrix_from_file(filename);
+        gsl_matrix *d_G_ptr = read_matrix_from_file(filename);
+        // 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;
 
         // The alist file should have provided a generator matrix G
         // in systematic form, G = [I P], where I is a k x k identity
@@ -59,16 +63,13 @@ namespace gr {
           throw "Error in ldpc_gen_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);
+            int value = gsl_matrix_get(d_G_ptr,
+                                       row_index,
+                                       col_index + d_k);
             gsl_matrix_set(P, row_index, col_index, value);
           }
         }
@@ -79,7 +80,7 @@ namespace gr {
 
         // 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);
+        d_H_ptr = gsl_matrix_alloc(d_n-d_k, d_n);
         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++) {
@@ -89,16 +90,22 @@ namespace gr {
             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);
         }
 
+        // Calculate G transpose (used for encoding)
+        d_G_transp_ptr = gsl_matrix_alloc(d_n, d_k);
+        gsl_matrix_transpose_memcpy(d_G_transp_ptr, d_G_ptr);
+
         // Free memory
         gsl_matrix_free(P);
         gsl_matrix_free(P_transpose);
         gsl_matrix_free(identity);
         gsl_matrix_free(I_test);
+        gsl_matrix_free(d_G_ptr);
 
         // For info about this see get_base_ptr() function
         d_base_ptr = this;
@@ -113,12 +120,12 @@ namespace gr {
                   << " generator matrix. \n\n";
         exit(1);
       } // Default constructor
-    
+
       const gsl_matrix*
-      ldpc_gen_mtrx::G()
+      ldpc_gen_mtrx::G_transpose() const
       {
-        const gsl_matrix *G_ptr = d_G_ptr;
-        return G_ptr; 
+        const gsl_matrix *G_trans_ptr = d_G_transp_ptr;
+        return G_trans_ptr;
       }
 
       gr::fec::code::fec_mtrx*
@@ -136,7 +143,7 @@ namespace gr {
       {
         // Call the gsl_matrix_free function to free memory.
         gsl_matrix_free(d_H_ptr);
-        gsl_matrix_free(d_G_ptr);
+        gsl_matrix_free(d_G_transp_ptr);
       }
     } /* namespace code */
   } /* namespace fec */
diff --git a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc 
b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
index affacc8..1a6a55c 100644
--- a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
+++ b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
@@ -83,9 +83,27 @@ namespace gr {
       ldpc_gen_mtrx_encoder_impl::generic_work(void *inbuffer,
                                                void *outbuffer)
       {
+        // Populate the information word
+        const unsigned char *in = (const unsigned char *)inbuffer;
+        unsigned int index, k = d_G->k(), n = d_G->n();
+        gsl_matrix *s = gsl_matrix_alloc(k, 1);
+        for (index = 0; index < k; index++) {
+          double value = static_cast<double>(in[index]);
+          gsl_matrix_set(s, index, 0, value);
+        }
 
+        // Simple matrix multiplication to get codeword
+        gsl_matrix *codeword;
+        codeword = d_G->mult_matrices_mod2(d_G->G_transpose(), s);
+
+        // Output
+        unsigned char *out = (unsigned char*)outbuffer;
+        for (index = 0; index < n; index++) {
+          out[index] = gsl_matrix_get(codeword, index, 0);
+        }
 
         // Free memory
+        gsl_matrix_free(codeword);
 
 
       }



reply via email to

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