komm.ScalarQuantizer
General scalar quantizer. It is defined by a list of levels, $v_0, v_1, \ldots, v_{L-1}$, and a list of thresholds, $t_0, t_1, \ldots, t_L$, satisfying $$ -\infty = t_0 < v_0 < t_1 < v_1 < \cdots < t_{L - 1} < v_{L - 1} < t_L = +\infty. $$ Given an input $x \in \mathbb{R}$, the output of the quantizer is given by $y = v_i$ if and only if $t_i \leq x < t_{i+1}$, where $i \in [0:L)$. For more details, see Say06, Ch. 9.
Attributes:
-
levels
(NDArray[floating]
) –The quantizer levels $v_0, v_1, \ldots, v_{L-1}$. It should be a list floats of length $L$.
-
thresholds
(NDArray[floating]
) –The quantizer finite thresholds $t_1, t_2, \ldots, t_{L-1}$. It should be a list of floats of length $L - 1$.
Examples:
The $5$-level scalar quantizer whose characteristic (input × output) curve is depicted in the figure below has levels $$ v_0 = -2, ~ v_1 = -1, ~ v_2 = 0, ~ v_3 = 1, ~ v_4 = 2, $$ and thresholds $$ t_0 = -\infty, ~ t_1 = -1.5, ~ t_2 = -0.3, ~ t_3 = 0.8, ~ t_4 = 1.4, ~ t_5 = \infty. $$
>>> quantizer = komm.ScalarQuantizer(
... levels=[-2.0, -1.0, 0.0, 1.0, 2.0],
... thresholds=[-1.5, -0.3, 0.8, 1.4],
... )
levels
NDArray[floating]
cached
property
The quantizer levels $v_0, v_1, \ldots, v_{L-1}$.
Examples:
>>> quantizer = komm.ScalarQuantizer(
... levels=[-2.0, -1.0, 0.0, 1.0, 2.0],
... thresholds=[-1.5, -0.3, 0.8, 1.4],
... )
>>> quantizer.levels
array([-2., -1., 0., 1., 2.])
thresholds
NDArray[floating]
cached
property
The quantizer finite thresholds $t_1, t_2, \ldots, t_{L-1}$.
Examples:
>>> quantizer = komm.ScalarQuantizer(
... levels=[-2.0, -1.0, 0.0, 1.0, 2.0],
... thresholds=[-1.5, -0.3, 0.8, 1.4],
... )
>>> quantizer.thresholds
array([-1.5, -0.3, 0.8, 1.4])
digitize()
Returns the quantization indices for the input signal.
Parameters:
-
input
(ArrayLike
) –The input signal $x$ to be digitized.
Returns:
-
output
(NDArray[integer]
) –The integer indices of the quantization levels for each input sample.
Examples:
>>> quantizer = komm.ScalarQuantizer(
... levels=[-2.0, -1.0, 0.0, 1.0, 2.0],
... thresholds=[-1.5, -0.3, 0.8, 1.4],
... )
>>> quantizer.digitize([-2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5])
array([0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4])
quantize()
Quantizes the input signal.
Parameters:
-
input
(ArrayLike
) –The input signal $x$ to be quantized.
Returns:
-
output
(NDArray[floating]
) –The quantized signal $y$.
Examples:
>>> quantizer = komm.ScalarQuantizer(
... levels=[-2.0, -1.0, 0.0, 1.0, 2.0],
... thresholds=[-1.5, -0.3, 0.8, 1.4],
... )
>>> quantizer.quantize([-2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5])
array([-2., -2., -1., -1., -1., 0., 0., 1., 2., 2., 2.])