comnum.Constellation#
- class comnum.Constellation(kind, m)#
A constellation with Gray labels: point
icarries the bits ofi, MSB first.The points and their labels are those of OptiCommPy (
GrayMapping): square QAM as the product of two PAM listed row by row from the top in a “snake” order, PSK one^{j2πk/M}, PAM on-(M-1), …, -1, 1, …, M-1, OOK on{0, 1}; thei-th point of the construction order gets the Gray labeli ^ (i >> 1). The grids keep their integer spacing; callnormalized()for unit mean energy.- Parameters:
- Raises:
ValueError – for an invalid parameter (the message names it).
Examples
>>> import comnum, numpy as np >>> c = comnum.Constellation("qam", 16).normalized() >>> round(c.energy, 12) 1.0 >>> bits = np.array([0, 0, 0, 0, 1, 1, 1, 1], dtype=np.uint8) >>> c.demap_bits(c.map_bits(bits)).tolist() [0, 0, 0, 0, 1, 1, 1, 1]
- static from_name(name)#
A constellation from the name the specifications use (
"16-QAM","QPSK","8PSK","4-PAM","OOK"; case, dashes and spaces are ignored), with its integer grid (callnormalized()for unit energy).- Parameters:
name (str) – the name.
- Returns:
the constellation.
- Return type:
- Raises:
ValueError – for an unknown family or an invalid order.
Examples
>>> import comnum >>> c = comnum.Constellation.from_name("16-QAM") >>> c.kind, c.order ('qam', 16)
- static from_points(points)#
A custom constellation from its points, labelled by their index.
- Parameters:
points (array_like) – the
Mpoints (complex),Ma power of two.- Returns:
the constellation (kind
"custom").- Return type:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
Examples
>>> import comnum >>> comnum.Constellation.from_points([1, -1]).order 2
- static set_partitioning(kind, m)#
The points of
Constellation(kind, m)with a set-partitioning labelling (Ungerboeck): natural labels for PSK, Fig. 2(a) of Caire, Taricco & Biglieri (1998) for 16-QAM.- Parameters:
- Returns:
the constellation (kind
"custom").- Return type:
- Raises:
ValueError – for an invalid parameter (the message names it).
Examples
>>> import comnum >>> comnum.Constellation.set_partitioning("qam", 16).points[0b1001] np.complex128(-3+3j)
- decide(z)#
Index of the nearest point of every sample (minimum-distance decisions).
- Parameters:
z (array_like) – received samples.
- Returns:
the indices (int64).
- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
- demap_bits(z)#
Hard-decision bits of every sample (OptiCommPy
demodulateGray).- Parameters:
z (array_like) – received samples.
- Returns:
log2 Mbits per sample (uint8).- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
- energy_with(px)#
Mean energy of the points under the probabilities
px.- Parameters:
px (array_like) – the probabilities of the points.
- Returns:
Σ p_i |s_i|².- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
- indices(bits)#
Symbol indices of a bit sequence (
log2 Mbits per symbol, MSB first).- Parameters:
bits (array_like) – the bits, a multiple of
log2 M.- Returns:
the indices (int64).
- Return type:
- Raises:
ValueError – if the length is not a multiple of
log2 M.
- llr(z, noise_var, *, px=None, max_log=False)#
Bit log-likelihood ratios
ln p(b=0|y) - ln p(b=1|y),log2 Mper sample.The likelihood of point
sisexp(-|y - s|²/σ²)(OptiCommPycalcLLR).- Parameters:
- Returns:
log2 MLLRs per sample, MSB first (float64).- Return type:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
Examples
>>> import comnum >>> c = comnum.Constellation("qam", 4).normalized() >>> llr = c.llr(c.map_bits([0, 1]), 0.1) >>> bool(llr[0] > 0 and llr[1] < 0) True
- map_bits(bits)#
Symbols of a bit sequence (OptiCommPy
modulateGray).- Parameters:
bits (array_like) – the bits, a multiple of
log2 M.- Returns:
one symbol per
log2 Mbits (complex128).- Return type:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
- normalized()#
The same constellation scaled to unit mean energy.
- Returns:
the normalised constellation.
- Return type:
- project(z)#
The nearest point of every sample.
- Parameters:
z (array_like) – received samples.
- Returns:
the points (complex128).
- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
- scaled(s)#
The same constellation with every point multiplied by
s.- Parameters:
s (float) – the scale.
- Returns:
the scaled constellation.
- Return type:
- symbols(indices)#
Symbols of an index sequence.
- Parameters:
indices (array_like) – the indices, below
M.- Returns:
the points (complex128).
- Return type:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
- points#
The points, in label order (a copy, complex128).
- Type: