hamming74_decode
Builtin index · Signal processing
result = hamming74_decode(codeword)
Input: codeword · Output: result
What it is
codeword: a bit vector whose length is a multiple of 7. Computes each block's syndrome, flips the bit it names, and recovers the data. Corrects any single bit flip per codeword; the code's minimum distance is 3, so a double flip is mis-corrected — that is the code's limit, not the implementation's.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = hamming74_decode(codeword) | codeword vectornot documented yet | data —the recovered bits, 4 per codewordcorrected —a Bool, true when any codeword needed fixingpositions —per codeword, the 1-indexed bit flipped back, or 0 for a clean one | Returns a Record with fields data (the recovered bits, 4 per codeword), corrected (a Bool, true when any codeword needed fixing) and positions (per codeword, the 1-indexed bit flipped back, or 0 for a clean one). (Added in v0.3.0.) |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
bits = [0, 1, 1, 0, 1, 0, 0, 1]
syms = qam_modulate(bits, 16) # 2 symbols on the odd-integer grid
print(qam_demodulate(syms, 16)) # back to the same 8 bits
print(hamming74_encode([1, 0, 1, 1])) # [0, 1, 1, 0, 0, 1, 1]
r = hamming74_decode([0, 1, 1, 0, 1, 1, 1]) # bit 5 flipped in transit
print("{r.data} corrected={r.corrected} at {r.positions}")
m = [1, 1, 0, 1]
print(crc(m, 11)) # [0, 0, 1] -- x^3 + x + 1
print(crc_check([1, 1, 0, 1, 0, 0, 1], 11)) # true
[0, 1, 1, 0, 1, 0, 0, 1] [0, 1, 1, 0, 0, 1, 1] [1, 0, 1, 1] corrected=true at [5] [0, 0, 1] true
from signal-processing
How it works
hamming74_decode(codeword) — corrects one bit flip per 7-bit codeword. Returns a Record, the same multi-return convention huffman_encode uses: data (the recovered bits), corrected (a Bool, true when any codeword needed fixing) and positions (per codeword, the 1-indexed bit that was flipped back, or 0 for a clean one).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.