[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 04/16: fec: code clean-up for block 'ber_bf
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 04/16: fec: code clean-up for block 'ber_bf'. |
Date: |
Tue, 21 Jul 2015 19:27:51 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch master
in repository gnuradio.
commit ac11b4db0094b865eac75be5b5f61e4856466cee
Author: Johannes Demel <address@hidden>
Date: Mon Jul 20 11:35:35 2015 +0200
fec: code clean-up for block 'ber_bf'.
---
gr-fec/lib/ber_bf_impl.cc | 60 ++++++++++++++++++++++--------------------
gr-fec/lib/ber_bf_impl.h | 3 +++
gr-fec/python/fec/qa_ber_bf.py | 36 ++++++++++++++++++++++---
3 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/gr-fec/lib/ber_bf_impl.cc b/gr-fec/lib/ber_bf_impl.cc
index 375844b..6e3dc85 100644
--- a/gr-fec/lib/ber_bf_impl.cc
+++ b/gr-fec/lib/ber_bf_impl.cc
@@ -48,6 +48,23 @@ namespace gr {
{
}
+ inline float
+ ber_bf_impl::calculate_log_ber() const
+ {
+ return log10(((double) d_total_errors) / (d_total * 8.0));
+ }
+
+ inline void
+ ber_bf_impl::update_counters(const int items, const unsigned char
*inbuffer0, const unsigned char *inbuffer1)
+ {
+ uint32_t ret;
+ for(int i = 0; i < items; i++) {
+ volk_32u_popcnt(&ret, static_cast<uint32_t>(inbuffer0[i] ^
inbuffer1[i]));
+ d_total_errors += ret;
+ }
+ d_total += items;
+ }
+
ber_bf_impl::~ber_bf_impl()
{
}
@@ -63,54 +80,41 @@ namespace gr {
int items = ninput_items[0] <= ninput_items[1] ? ninput_items[0] :
ninput_items[1];
- if(d_test_mode) {
- if(d_total_errors >= d_berminerrors) {
- return -1;
+ if(d_test_mode){
+ if(d_total_errors >= d_berminerrors){
+ return WORK_DONE;
}
- else {
- if(items > 0) {
- uint32_t ret;
- for(int i = 0; i < items; i++) {
- volk_32u_popcnt(&ret, static_cast<uint32_t>(inbuffer0[i] ^
inbuffer1[i]));
- d_total_errors += ret;
- }
- d_total += items;
+ else{
+ if(items > 0){
+ update_counters(items, inbuffer0, inbuffer1);
}
consume_each(items);
- if(d_total_errors >= d_berminerrors) {
- outbuffer[0] = log10(((double) d_total_errors) / (d_total * 8.0));
+ if(d_total_errors >= d_berminerrors){
+ outbuffer[0] = calculate_log_ber();
GR_LOG_INFO(d_logger, boost::format(" %1% over %2% --> %3%")
% d_total_errors % (d_total * 8) % outbuffer[0]);
return 1;
}
- else if(log10(((double) d_berminerrors) / (d_total * 8.0)) <
d_ber_limit) {
+ else if(calculate_log_ber() < d_ber_limit){
GR_LOG_INFO(d_logger, " Min. BER limit reached");
outbuffer[0] = d_ber_limit;
d_total_errors = d_berminerrors + 1;
return 1;
}
- else {
+ else{
return 0;
}
}
}
- else { // streaming mode
- if(items > 0) {
- uint32_t ret;
- for(int i = 0; i < items; i++) {
- volk_32u_popcnt(&ret, static_cast<uint32_t>(inbuffer0[i] ^
inbuffer1[i]));
- d_total_errors += ret;
- }
-
- d_total += items;
- outbuffer[0] = log10(((double) d_total_errors) / (d_total * 8.0));
-
+ else{ // streaming mode
+ if(items > 0){
+ update_counters(items, inbuffer0, inbuffer1);
+ outbuffer[0] = calculate_log_ber();
consume_each(items);
return 1;
}
- else {
- consume_each(0);
+ else{
return 0;
}
}
diff --git a/gr-fec/lib/ber_bf_impl.h b/gr-fec/lib/ber_bf_impl.h
index f1a7bfc..15c747f 100644
--- a/gr-fec/lib/ber_bf_impl.h
+++ b/gr-fec/lib/ber_bf_impl.h
@@ -37,6 +37,9 @@ namespace gr {
int d_berminerrors;
float d_ber_limit;
+ inline float calculate_log_ber() const;
+ inline void update_counters(const int items, const unsigned char
*inbuffer0, const unsigned char *inbuffer1);
+
public:
ber_bf_impl(bool d_test_mode = false, int berminerrors=100, float
ber_limit=-7.0);
~ber_bf_impl();
diff --git a/gr-fec/python/fec/qa_ber_bf.py b/gr-fec/python/fec/qa_ber_bf.py
index 3e7919e..5d1734d 100644
--- a/gr-fec/python/fec/qa_ber_bf.py
+++ b/gr-fec/python/fec/qa_ber_bf.py
@@ -54,7 +54,7 @@ class test_ber_bf(gr_unittest.TestCase):
self.tb.run()
data = dst.data()
- expected_result = [numpy.log10(1.0 / (8.0 * N)), ]
+ expected_result = self.log_ber(1., N) # [numpy.log10(1.0 / (8.0 * N)),
]
self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
@@ -79,7 +79,7 @@ class test_ber_bf(gr_unittest.TestCase):
self.tb.run()
data = dst.data()
- expected_result = [numpy.log10(1.0 / (8.0 * N)), ]
+ expected_result = self.log_ber(1., N)
self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
@@ -104,7 +104,7 @@ class test_ber_bf(gr_unittest.TestCase):
self.tb.run()
data = dst.data()
- expected_result = [numpy.log10(8.0 / (8.0 * N)), ]
+ expected_result = self.log_ber(8., N)
self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
@@ -137,6 +137,36 @@ class test_ber_bf(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
+ def test_004(self):
+ # Cause 16 consecutive bit errors out of 8*N bits
+ # make sure bytes are only read once.
+ # using streaming mode
+
+ mode = False
+ N = 10000
+ data0 = numpy.random.randint(0, 256, N).tolist()
+ data1 = copy.deepcopy(data0)
+ data1[0] ^= 0xFF
+ data1[1] ^= 0xFF
+
+ src0 = blocks.vector_source_b(data0)
+ src1 = blocks.vector_source_b(data1)
+ op = fec.ber_bf(mode)
+ dst = blocks.vector_sink_f()
+
+ self.tb.connect(src0, (op, 0))
+ self.tb.connect(src1, (op, 1))
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ data = dst.data()
+ expected_result = self.log_ber(16, N)
+
+ self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
+
+ def log_ber(self, n_errors, N):
+ return numpy.log10(1. * n_errors / (8.0 * N)),
+
if __name__ == '__main__':
gr_unittest.run(test_ber_bf, "test_ber_bf.xml")
- [Commit-gnuradio] [gnuradio] branch master updated (55d8f48 -> cc973de), git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 05/16: fec: extended encoder now appends unpack_k_bits(8) block after encoder to satisfy get_output_conversion() = unpack behaviour, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 02/16: fec: some initial refactoring for ber_bf, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 03/16: fec: fixed QA for ber_bf., git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 04/16: fec: code clean-up for block 'ber_bf'.,
git <=
- [Commit-gnuradio] [gnuradio] 08/16: fec: added tests for extended_encoder input/output conversion., git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 15/16: Merge remote-tracking branch 'fewu/crc32_unpack', git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 01/16: updates to waterfall for suchsamples, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 10/16: Merge remote-tracking branch 'namccart/master' into master_waterfall_pdu, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 07/16: digital: added an option to the crc32_bb block that adds the unpacked CRC to the bit stream, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 12/16: qtgui: protect PDU handling waterfall port for wrong data type., git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 09/16: Merge remote-tracking branch 'jdemel/fec/fix-extended_encoder', git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 16/16: Merge branch 'maint', git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 11/16: qtgui: waterfall PDU handling, git, 2015/07/21
- [Commit-gnuradio] [gnuradio] 13/16: qtgui: pdu handler for float waterfall plot., git, 2015/07/21