hamming74_encode
Builtin index · Signal processing
result = hamming74_encode(d)
Input: d · Output: result
What it is
d: a bit vector whose length is a multiple of 4. Hamming(7,4) systematic encoder, 7 bits out per 4 in, laid out [p1, p2, d1, p4, d2, d3, d4] with the parity bits at the power-of-two positions — the layout that makes a nonzero syndrome read out directly as the 1-indexed position of the corrupted bit. Not to be confused with hamming(n), the window function.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = hamming74_encode(d) | d vectornot documented yet | result Vec | Returns a Vec of 0/1. (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_encode(d) — d is a vector of 0/1 whose length is a multiple of 4. Returns 7 bits per 4 data bits, laid out [p1, p2, d1, p4, d2, d3, d4].
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.