From 809ab3690be0a38041c39b1bb7e95796496b599e Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Tue, 9 Jun 2020 14:36:19 +0200 Subject: [PATCH] return -1 if unsure --- short_bch_code_decoder.hh | 16 +++++++++++++++- tests/soft_bch_regression_test.cc | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/short_bch_code_decoder.hh b/short_bch_code_decoder.hh index fa292fc..775f25d 100644 --- a/short_bch_code_decoder.hh +++ b/short_bch_code_decoder.hh @@ -62,15 +62,20 @@ public: { // maximum likelihood if (0) { - int word = 0, best = 0; + int word = 0, best = -1, next = -1; for (int msg = 0; msg < W; ++msg) { int enc = (msg << P) | par[msg]; int met = metric(code, enc); if (met > best) { + next = best; best = met; word = enc; + } else if (met > next) { + next = met; } } + if (best == next) + return -1; return word; } int cw = 0; @@ -82,6 +87,7 @@ public: return word; // metric of hard decision int best = metric(code, word); + int next = -1; // flip each bit and see .. if (0) { for (int j = 0; j < N; ++j) { @@ -89,8 +95,11 @@ public: int dec = (*this)(cw ^ tmp); int met = metric(code, dec); if (met > best) { + next = best; best = met; word = dec; + } else if (word != dec && met > next) { + next = met; } } } @@ -122,11 +131,16 @@ public: int dec = (*this)(cw ^ tmp); int met = metric(code, dec); if (met > best) { + next = best; best = met; word = dec; + } else if (word != dec && met > next) { + next = met; } } } + if (best == next) + return -1; return word; } }; diff --git a/tests/soft_bch_regression_test.cc b/tests/soft_bch_regression_test.cc index f47b8ee..e291b6e 100644 --- a/tests/soft_bch_regression_test.cc +++ b/tests/soft_bch_regression_test.cc @@ -91,8 +91,8 @@ int main() awgn_errors += noisy[i] * orig[i] < 0; for (int i = 0; i < CODE_LEN; ++i) quantization_erasures += !noisy[i]; - uncorrected_errors += popcnt(enc^dec); - for (int i = 0; i < CODE_LEN; ++i) + uncorrected_errors += dec < 0 ? CODE_LEN : popcnt(enc^dec); + for (int i = 0; dec >= 0 && i < CODE_LEN; ++i) decoder_errors += ((enc^dec)&(1< 0; } float bit_error_rate = (float)uncorrected_errors / (float)(CODE_LEN * LOOPS);