JS8Call-Improved master
Loading...
Searching...
No Matches
ldpc_feedback.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <QDebug>
16#include <QLoggingCategory>
17#include <QtGlobal>
18
19#include <algorithm>
20#include <array>
21#include <cmath>
22#include <cstdint>
23#include <cstdlib>
24#include <optional>
25
26Q_DECLARE_LOGGING_CATEGORY(decoder_js8);
27
28namespace js8 {
38constexpr float LLR_ERASURE_THRESHOLD_DEFAULT = 0.0f;
39
41inline float llrGlobalScale() {
42 if (auto const env = std::getenv("JS8_LLR_SCALE"); env) {
43 char *end = nullptr;
44 float const value = std::strtof(env, &end);
45 if (end != env && *end == '\0' && std::isfinite(value) && value > 0.0f)
46 return value;
47 }
48 return 2.0f;
49}
50
51constexpr float LLR_FEEDBACK_CONFIDENT_MIN = 3.0f;
53constexpr float LLR_FEEDBACK_UNCERTAIN_MAX = 1.0f;
55constexpr float LLR_FEEDBACK_CONFIDENT_BOOST = 1.2f;
57constexpr float LLR_FEEDBACK_UNCERTAIN_SHRINK = 0.5f;
59constexpr float LLR_FEEDBACK_MAX_MAG = 6.0f;
62
74inline float llrErasureThreshold() {
75 float threshold = LLR_ERASURE_THRESHOLD_DEFAULT;
76
77 if (auto const env = std::getenv("JS8_LLR_ERASURE_THRESH"); env) {
78 char *end = nullptr;
79 float val = std::strtof(env, &end);
80
81 if (end != env && std::isfinite(val)) {
82 threshold = val;
83 }
84 }
85
86 if (threshold <= 0.0f || !std::isfinite(threshold) ||
87 std::getenv("JS8_DISABLE_ERASURE_THRESHOLDING")) {
88 return 0.0f;
89 }
90
91 return threshold;
92}
93
103inline bool ldpcFeedbackEnabled() {
104 bool ok = false;
105 int value = qEnvironmentVariableIntValue("JS8_LDPC_FEEDBACK", &ok);
106 return ok ? value != 0 : true;
107}
108
119 bool ok = false;
120 int value = qEnvironmentVariableIntValue("JS8_LDPC_MAX_PASSES", &ok);
121
122 if (!ok)
124
125 return std::clamp(value, 1, LDPC_FEEDBACK_MAX_PASSES_DEFAULT);
126}
127
155template <std::size_t N>
156void refineLlrsWithLdpcFeedback(std::array<float, N> const &llrIn,
157 std::array<int8_t, N> const &cw,
158 float erasureThreshold,
159 std::array<float, N> &llrOut,
160 int &confidentCount, int &uncertainCount) {
161 llrOut = llrIn;
162 confidentCount = 0;
163 uncertainCount = 0;
164
165 for (std::size_t i = 0; i < llrOut.size(); ++i) {
166 float &value = llrOut[i];
167
168 if (!std::isfinite(value)) {
169 value = 0.0f;
170 ++uncertainCount;
171 continue;
172 }
173
174 bool const bitOne = cw[i] != 0;
175 float const mag = std::abs(value);
176 bool const signMatch = (value >= 0.0f) == bitOne;
177
178 if (signMatch && mag >= LLR_FEEDBACK_CONFIDENT_MIN) {
179 ++confidentCount;
180 float boosted = mag * LLR_FEEDBACK_CONFIDENT_BOOST;
181 boosted = std::clamp(boosted, 0.0f, LLR_FEEDBACK_MAX_MAG);
182 value = bitOne ? boosted : -boosted;
183 } else if (!signMatch || mag <= LLR_FEEDBACK_UNCERTAIN_MAX) {
184 ++uncertainCount;
185 float shrunk = mag * LLR_FEEDBACK_UNCERTAIN_SHRINK;
186
187 if (erasureThreshold > 0.0f && shrunk < erasureThreshold) {
188 value = 0.0f;
189 } else {
190 value = bitOne ? shrunk : -shrunk;
191 }
192 }
193 }
194}
195} // namespace js8
JS8 namespace for Kalman filter-based trackers.
Definition bp_math.h:12
constexpr float LLR_ERASURE_THRESHOLD_DEFAULT
LDPC erasure threshold config and feedback refinement helpers.
Definition ldpc_feedback.h:38
constexpr float LLR_FEEDBACK_MAX_MAG
Definition ldpc_feedback.h:59
constexpr float LLR_FEEDBACK_UNCERTAIN_MAX
Definition ldpc_feedback.h:53
float llrGlobalScale()
Definition ldpc_feedback.h:41
constexpr int LDPC_FEEDBACK_MAX_PASSES_DEFAULT
Definition ldpc_feedback.h:61
constexpr float LLR_FEEDBACK_CONFIDENT_MIN
Definition ldpc_feedback.h:51
constexpr float LLR_FEEDBACK_UNCERTAIN_SHRINK
Definition ldpc_feedback.h:57
void refineLlrsWithLdpcFeedback(std::array< float, N > const &llrIn, std::array< int8_t, N > const &cw, float erasureThreshold, std::array< float, N > &llrOut, int &confidentCount, int &uncertainCount)
Refine LLRs using a decoded LDPC codeword as feedback.
Definition ldpc_feedback.h:156
int ldpcFeedbackMaxPasses()
Maximum LDPC feedback passes to attempt.
Definition ldpc_feedback.h:118
bool ldpcFeedbackEnabled()
Whether LDPC feedback is enabled.
Definition ldpc_feedback.h:103
float llrErasureThreshold()
Read configured LLR erasure threshold.
Definition ldpc_feedback.h:74
constexpr float LLR_FEEDBACK_CONFIDENT_BOOST
Definition ldpc_feedback.h:55