fix: correct DSC decoder check-bit formula, add de-interleaving and 1… - #243
Open
blackwellj wants to merge 1 commit into
Open
fix: correct DSC decoder check-bit formula, add de-interleaving and 1…#243blackwellj wants to merge 1 commit into
blackwellj wants to merge 1 commit into
Conversation
…-bit error tolerance ## Summary The DSC decoder had several critical bugs that prevented correct decoding of DSC (Digital Selective Calling) messages per ITU-R M.493-16: ### Bug fixes 1. **Wrong check-bit formula** — used even parity (total 1s must be even) instead of the correct ITU-R M.493-16 algorithm: 3 check bits encode the count of B-elements (binary 0) among the 7 info bits as a 3-bit number (MSB first). This caused valid symbols to be rejected and invalid symbols to pass. 2. **Missing de-interleaving** — DSC transmits every symbol twice (DX + RX copies ~5 positions apart). Without de-interleaving, duplicated symbols corrupted field boundaries. Added format-specifier anchor detection that takes every 2nd symbol to recover the original data. 3. **Format code mappings reversed** — 102 was ALL_SHIPS (should be GEOGRAPHICAL_AREA), 112 was INDIVIDUAL (should be DISTRESS), 114 was INDIVIDUAL_ACK (should be GROUP), 116 was GROUP (should be ALL_SHIPS), 120 was DISTRESS (should be INDIVIDUAL), 123 was ALL_SHIPS_URGENCY_SAFETY (should be AUTOMATIC_SERVICE). Fixed all per ITU-R M.493-16. 4. **Missing format specifiers** — added 100 (SELECTIVE_CALL), 113 (INDIVIDUAL_ACK), 115 (SHIP_POSITION), 118 (DISTRESS_RELAY), 121 (MEDICAL_TRANSPORT). 5. **Wrong position encoding** — treated position symbols as 2-digit BCD values instead of single digits 0-9 per ITU-R M.493-11. Quadrant values were also wrong (0-3 instead of 10/11/00/01). 6. **Wrong distress nature codes** — used value+100 (100-110) instead of the correct 0-31 range (lower 5 bits of symbol value). 7. **Wrong phasing symbol stripping** — stripped symbols 120-126 unconditionally instead of using de-interleaving. ### Improvements - 1-bit error tolerant symbol decoding: corrects single-bit errors during symbol-to-value conversion, dramatically improving decode rate on noisy signals. - De-interleaving with format-specifier anchor detection: handles the DX/RX duplication pattern in transmitted DSC messages. - Reusable symbol encoding/decoding utilities at module level (encode_symbol, bits_to_symbol, decode_mmsi, decode_position). - Updated all tests to match correct ITU-R M.493-16 specifications. ### How to verify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…-bit error tolerance
Summary
The DSC decoder had several critical bugs that prevented correct decoding of DSC (Digital Selective Calling) messages per ITU-R M.493-16:
Bug fixes
Wrong check-bit formula — used even parity (total 1s must be even) instead of the correct ITU-R M.493-16 algorithm: 3 check bits encode the count of B-elements (binary 0) among the 7 info bits as a 3-bit number (MSB first). This caused valid symbols to be rejected and invalid symbols to pass.
Missing de-interleaving — DSC transmits every symbol twice (DX + RX copies ~5 positions apart). Without de-interleaving, duplicated symbols corrupted field boundaries. Added format-specifier anchor detection that takes every 2nd symbol to recover the original data.
Format code mappings reversed — 102 was ALL_SHIPS (should be GEOGRAPHICAL_AREA), 112 was INDIVIDUAL (should be DISTRESS), 114 was INDIVIDUAL_ACK (should be GROUP), 116 was GROUP (should be ALL_SHIPS), 120 was DISTRESS (should be INDIVIDUAL), 123 was ALL_SHIPS_URGENCY_SAFETY (should be AUTOMATIC_SERVICE). Fixed all per ITU-R M.493-16.
Missing format specifiers — added 100 (SELECTIVE_CALL), 113 (INDIVIDUAL_ACK), 115 (SHIP_POSITION), 118 (DISTRESS_RELAY), 121 (MEDICAL_TRANSPORT).
Wrong position encoding — treated position symbols as 2-digit BCD values instead of single digits 0-9 per ITU-R M.493-11. Quadrant values were also wrong (0-3 instead of 10/11/00/01).
Wrong distress nature codes — used value+100 (100-110) instead of the correct 0-31 range (lower 5 bits of symbol value).
Wrong phasing symbol stripping — stripped symbols 120-126 unconditionally instead of using de-interleaving.
Improvements
How to verify