diff --git a/osd.hh b/osd.hh index 4b5e6d6..cc906b9 100644 --- a/osd.hh +++ b/osd.hh @@ -172,14 +172,16 @@ public: { for (int i = 0; i < N; ++i) perm[i] = i; - std::sort(perm, perm+N, [soft](int a, int b){ return std::abs(soft[a]) > std::abs(soft[b]); }); + for (int i = 0; i < N; ++i) + softperm[i] = std::abs(std::max(soft[i], -127)); + std::sort(perm, perm+N, [this](int a, int b){ return softperm[a] > softperm[b]; }); for (int j = 0; j < K; ++j) for (int i = 0; i < N; ++i) G[W*j+i] = genmat[N*j+perm[i]]; row_echelon(); systematic(); for (int i = 0; i < N; ++i) - softperm[i] = soft[perm[i]]; + softperm[i] = std::max(soft[perm[i]], -127); for (int i = N; i < W; ++i) softperm[i] = 0; for (int i = 0; i < K; ++i) diff --git a/tests/osd_regression_test.cc b/tests/osd_regression_test.cc index b564dbe..1a6eb40 100644 --- a/tests/osd_regression_test.cc +++ b/tests/osd_regression_test.cc @@ -111,7 +111,7 @@ int main() double DIST = 2; // BPSK double fact = DIST / (sigma_noise * sigma_noise); for (int i = 0; i < N; ++i) - noisy[i] = std::min(std::max(std::nearbyint(fact * symb[i]), -127), 127); + noisy[i] = std::min(std::max(std::nearbyint(fact * symb[i]), -128), 127); bool unique = osddec(decoded, noisy, genmat);