summaryrefslogtreecommitdiff
path: root/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc')
-rw-r--r--gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc73
1 files changed, 36 insertions, 37 deletions
diff --git a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
index 59a3bb2438..6fe1c8982c 100644
--- a/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
+++ b/gr-fec/lib/ldpc_gen_mtrx_encoder_impl.cc
@@ -1,17 +1,17 @@
/* -*- c++ -*- */
-/*
+/*
* Copyright 2015 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
+ * 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,
@@ -28,21 +28,25 @@
namespace gr {
namespace fec {
namespace code {
+
generic_encoder::sptr
- ldpc_gen_mtrx_encoder::make(const ldpc_HorG_mtrx *M_obj)
+ ldpc_gen_mtrx_encoder::make(const ldpc_G_matrix::sptr G_obj)
{
return generic_encoder::sptr
- (new ldpc_gen_mtrx_encoder_impl(M_obj));
+ (new ldpc_gen_mtrx_encoder_impl(G_obj));
}
- ldpc_gen_mtrx_encoder_impl::ldpc_gen_mtrx_encoder_impl(const ldpc_HorG_mtrx *M_obj)
+ ldpc_gen_mtrx_encoder_impl::ldpc_gen_mtrx_encoder_impl(const ldpc_G_matrix::sptr G_obj)
: generic_encoder("ldpc_gen_mtrx_encoder")
{
// Generator matrix to use for encoding
- d_M = M_obj;
+ d_G = G_obj;
+
+ d_rate = static_cast<double>(d_G->n())/static_cast<double>(d_G->k());
+
// 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_M->k());
+ set_frame_size(d_G->k());
}
ldpc_gen_mtrx_encoder_impl::~ldpc_gen_mtrx_encoder_impl()
@@ -52,7 +56,7 @@ namespace gr {
int
ldpc_gen_mtrx_encoder_impl::get_output_size()
{
- return d_M->n();
+ return d_output_size;
}
int
@@ -65,18 +69,26 @@ namespace gr {
ldpc_gen_mtrx_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.
+
+ if(frame_size % d_G->k() != 0) {
+ GR_LOG_ERROR(d_logger, boost::format("Frame size (%1% bits) must be a "
+ "multiple of the information word "
+ "size of the LDPC matrix (%2%).") \
+ % frame_size % (d_G->k()));
+ throw std::runtime_error("ldpc_gen_mtrx_encoder: cannot use frame size.");
+ }
+
d_frame_size = frame_size;
- return ret;
+ d_output_size = static_cast<int>(d_rate * d_frame_size);
+
+ return ret;
}
double
ldpc_gen_mtrx_encoder_impl::rate()
{
- return (d_M->n())/static_cast<double>(d_frame_size);
+ return d_rate;
}
void
@@ -85,28 +97,15 @@ namespace gr {
{
// Populate the information word
const unsigned char *in = (const unsigned char *)inbuffer;
- unsigned int index, k = d_M->k(), n = d_M->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_M->mult_matrices_mod2(d_M->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);
-
+ int j = 0;
+ for(int i = 0; i < get_input_size(); i+=d_G->k()) {
+ d_G->encode(&out[j], &in[i]);
+ j += d_G->n();
+ }
}
+
} /* namespace code */
} /* namespace fec */
-} /* namespace gr */ \ No newline at end of file
+} /* namespace gr */