Keep sustained off-SF traffic out of the background noise estimate

Hardware captures show that a median and lower quartile can follow the interferer while the 12.5th percentile retains the quiet floor. Use that estimate with existing weighting and bounded rise recovery. Wait for settling after every RX re-arm and allow thirty seconds for a complete idle-sample block.

Add captured-sample, low-tail limitation, and real CLI setter regressions. Preserve RXPS intent when parsing an off command with trailing whitespace. All 162 native cases and 24 Python regressions pass.
This commit is contained in:
mikecarper committed 2026-09-10 13:52:21 -07:00
1 parent 238cca759a
commit 9c3b57eaa2
7 files changed
+180 -31

No files matched your search

+1 -1
View File
@@ -3550,7 +3550,7 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
// Remember the intent so the timings can auto-retune when SF/BW change.
_prefs->rx_ps_level = level;
_prefs->rx_ps_preamble = preamble_overridden ? preamble : 0; // 0 = auto (derive from SF)
} else if (strcmp(value, "off") != 0) {
} else if (parsed.mode != RxPowerSavingArgumentMode::Off) {
// manual <rx_us> <sleep_us> timings are fixed, not level-derived
// (the named profiles set level_requested and are handled above)
_prefs->rx_ps_level = 0;
+14 -9
View File
@@ -3,13 +3,14 @@
#include <stdint.h>
#include <math.h>
// PR #2933's spaced median and bounded rise hold, retaining Cascade's
// fractional dBm and 25% previous / 75% new weighting. No radio or clock I/O.
// Spaced idle RSSI sampling with a low-percentile estimate and bounded rise hold.
// Retains Cascade's fractional dBm and 25% previous / 75% new weighting.
// No radio or clock I/O.
class NoiseFloorEstimator {
public:
static constexpr uint16_t SAMPLE_COUNT = 64;
static constexpr uint32_t SAMPLE_INTERVAL_MS = 50;
static constexpr uint32_t WINDOW_TIMEOUT_MS = 10000;
static constexpr uint32_t WINDOW_TIMEOUT_MS = 30000;
static constexpr uint8_t MAX_HELD_BLOCKS = 3;
static constexpr int32_t MAX_RISE_CENTI_DB = 1500;
@@ -54,18 +55,22 @@ public:
}
_samples[j] = key;
}
int32_t median = (int32_t(_samples[SAMPLE_COUNT / 2 - 1])
+ _samples[SAMPLE_COUNT / 2]) / 2;
if (median < -12000) median = -12000;
if (previous_valid && median > floor_centi_dbm + MAX_RISE_CENTI_DB) {
// Off-SF traffic can dominate the accepted samples. The median (and even
// the lower quartile) followed that traffic in hardware captures. The
// 12.5th percentile retained the quiet background while rejecting sparse
// low outliers. It still requires enough clean, settled samples per block.
const uint16_t upper = SAMPLE_COUNT / 8;
int32_t candidate = (int32_t(_samples[upper - 1]) + _samples[upper]) / 2;
if (candidate < -12000) candidate = -12000;
if (previous_valid && candidate > floor_centi_dbm + MAX_RISE_CENTI_DB) {
if (++_held_blocks < MAX_HELD_BLOCKS) return false;
}
_held_blocks = 0;
if (previous_valid) {
const int32_t weighted = floor_centi_dbm + 3 * median;
const int32_t weighted = floor_centi_dbm + 3 * candidate;
floor_centi_dbm = (weighted - 2) / 4;
} else {
floor_centi_dbm = median;
floor_centi_dbm = candidate;
}
return true;
}
@@ -544,6 +544,9 @@ void RadioLibWrapper::startRecv() {
noInterrupts();
state = (state & STATE_INT_READY) | STATE_RX;
interrupts();
// RSSI is unsettled after every RX entry, including CAD/TX completion.
// Keep the partial block, but wait for the frontend before its next sample.
_nf_sample_from = millis() + NF_CALIB_SETTLE_MS;
_startrx_fails = 0;
if (_rx_ps_armed) {
// (re)base the duty-cycle watchdog on the freshly armed cycle