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 Carroll
2026-09-10 14:57:14 -07:00
co-authored by Claude Opus 5
parent 1ebcf225f1
commit e206d748a2
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
## [unreleased][unreleased]
- Fixed `lf t55xx detect` - PSK1 now detects at every bit rate and subcarrier. (@iceman1001)
- Fixed `lf t55xx detect` - FSK was skipped entirely when the field-clock pair measured as neither legal pair, losing FSK1 at RF/32 and RF/40 and every variant at RF/16 (@iceman1001)
- Fixed `lf fsk demod` - a leading run too short to be a bit was forced to one, fabricating a bit and shifting the word (@mfcarroll)
- Fixed `lf nrz demod` - the samples before the first level change were counted as bits, rotating the word whenever that edge moved (@mfcarroll)
- Fixed `lf t55xx dump/read` - blocks were extracted at a bit offset cached from the last `detect` The offset is now anchored in graph samples (@iceman1001)
- Fixed `lf t55xx write --verify` - a successful write could be reported as a validation failure, both from the rotated read above and from the pre-write config decoding the post-write signal into garbage (@iceman1001)
+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;