qam_modulate
Builtin index · Signal processing
result = qam_modulate(bits, order)
Input: bits, order · Output: result
What it is
bits: a bit vector whose length is a multiple of log2(order); order (number): the constellation size, a power of two with an even exponent (4, 16, 64, 256, ...). Maps each group of log2(order) bits to one point of the standard Gray-coded square constellation — the first half of the group labels the in-phase level, the second half the quadrature one. Points sit on the unnormalized odd-integer grid (±1, ±3 for 16-QAM), the same convention MATLAB's qammod uses by default, so the mapping is exact in floating point. Cross constellations (32, 128) are a different geometry and are rejected rather than approximated by a rectangle.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = qam_modulate(bits, order) | bits vectorbits: a bit vector whose length is a multiple of log2(order).order numberorder (number): the constellation size, a power of two with an even exponent (4, 16, 64, 256, ...). | result CVec | Returns a CVec, one symbol per group. (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
qam_modulate(bits, order) — bits is a vector of 0/1, MSB-first, whose length is a multiple of log2(order). Returns a CVec of one symbol per log2(order) bits on the unnormalized odd-integer square grid. order must be a power of two with an even exponent (4, 16, 64, 256, ...); order 4 is QPSK.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.