Fix sign convention in SBAS message timestamp correction

The symbol alignment term of compute_message_timestamp() used the
opposite sign convention to the sample alignment term. In both
aligners, true means the non-shifted hypothesis won (no correction)
and false means the shifted one won (-1 unit), so the symbol term
must be (symbol_aligned ? 0 : -1).

Two of the unit tests added along with that function were failing as
a result, which is what broke the check step of the CI on all three
platforms.

Also express the correction bound in whole code periods rather than
comparing doubles at an exact boundary: the worst case is 3 code
periods (1 from the sample-pairing ambiguity plus 2 from the
symbol-pairing one), not 2, and the floating-point comparison was
fragile at that boundary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
kalmancitoandClaude Opus 5 authored and kalmancito committed 2026-08-04 23:05:33 +02:00
1 parent f129a4af8e
commit 68bac23bcb
2 files changed
+12 -6

No files matched your search

@@ -129,7 +129,7 @@ double sbas_l1_telemetry_decoder_gs::compute_message_timestamp(double first_bit_
// Residual sub-bit correction: which of the two possible sample/symbol
// alignments was chosen shifts the true message start by a few samples
// with respect to the first bit's own timestamp.
const int32_t offset_samples = (sample_aligned ? 0 : -1) + D_SAMPLES_PER_SYMBOL * (symbol_aligned ? -1 : 0);
const int32_t offset_samples = (sample_aligned ? 0 : -1) + D_SAMPLES_PER_SYMBOL * (symbol_aligned ? 0 : -1);
return first_bit_stamp_s + static_cast<double>(offset_samples) * SBAS_L1_CODE_PERIOD_S;
}
@@ -18,6 +18,8 @@
#include "SBAS_L1.h"
#include "sbas_l1_telemetry_decoder_gs.h"
#include <gtest/gtest.h>
#include <cmath>
#include <cstdint>
TEST(SbasL1TelemetryDecoderTest, TimestampMatchesFirstBitWhenFullyAligned)
{
@@ -32,18 +34,22 @@ TEST(SbasL1TelemetryDecoderTest, TimestampMatchesFirstBitWhenFullyAligned)
TEST(SbasL1TelemetryDecoderTest, TimestampCorrectionIsBoundedBySymbolPeriod)
{
// The residual sample/symbol alignment correction must never exceed one
// encoded symbol period: it only resolves a small, sub-bit ambiguity, not
// the block-level offset that used to cause ~1 s errors.
// The correction is always a whole number of code periods, and spans at
// most one code period (sample-pairing ambiguity) plus one symbol, i.e.
// two code periods (bit-pairing ambiguity). It only resolves a small
// sub-bit ambiguity, not the block-level offset that used to cause ~1 s
// errors.
const double first_bit_stamp_s = 1000.0;
const double max_correction_s = 2.0 * SBAS_L1_CODE_PERIOD_S; // 1 symbol = 2 code periods
const int64_t max_correction_code_periods = 3;
for (const bool sample_aligned : {false, true})
{
for (const bool symbol_aligned : {false, true})
{
const double message_stamp_s = sbas_l1_telemetry_decoder_gs::compute_message_timestamp(first_bit_stamp_s, sample_aligned, symbol_aligned);
EXPECT_NEAR(first_bit_stamp_s, message_stamp_s, max_correction_s);
const int64_t correction_code_periods = std::llround((first_bit_stamp_s - message_stamp_s) / SBAS_L1_CODE_PERIOD_S);
EXPECT_GE(correction_code_periods, 0);
EXPECT_LE(correction_code_periods, max_correction_code_periods);
}
}
}