lf fsk demod: do not fabricate a bit from a leading run

aggregate_bits sized each run of like waves in bits and then forced a zero to
one. That is right mid-stream, where a run rounding to nothing would drop a bit
the tag did send. On the leading run it is wrong: a single subcarrier wave is
about fchigh samples against a bit period of clk, so it rounds to no bits and
was made into one anyway - a bit the tag never sent, shifting every bit after it
and dragging startIdx back by most of a bit period.

Skip a leading run that rounds to nothing and let the next transition be first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Matthew CarrollandClaude Opus 5 committed 2026-09-10 14:57:14 -07:00
1 parent 1ebcf225f1
commit e206d748a2
2 files changed
+8

No files matched your search

+7
View File
@@ -2051,6 +2051,13 @@ static size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t in
// 0->1 crossing
n = (n * fchigh + hclk) / clk;
// A leading run that rounds to no bits is lead-in, not data. Forcing it to one fabricates
// a bit and shifts the word; mid-stream a zero would lose a bit the tag did send.
if (n == 0 && numBits == 0) {
lastval = dest[i];
continue;
}
if (n == 0)
n = 1;