komm.LloydMaxQuantizer
Lloyd–Max scalar quantizer. It is a scalar quantizer that minimizes the mean-squared error (MSE) between the input signal $X$ and its quantized version. For more details, see Say06, Sec. 9.6.1.
Parameters:
-
input_pdf
(Callable[[NDArray[float64]], NDArray[float64]]
) –The probability density function $f_X(x)$ of the input signal.
-
input_range
(tuple[float, float]
) –The range $(x_\mathrm{min}, x_\mathrm{max})$ of the input signal.
-
num_levels
(int
) –The number $L$ of quantization levels. It must be greater than $1$.
Examples:
>>> uniform_pdf = lambda x: 1/8 * (np.abs(x) <= 4)
>>> quantizer = komm.LloydMaxQuantizer(
... input_pdf=uniform_pdf,
... input_range=(-4, 4),
... num_levels=8,
... )
>>> quantizer.levels
array([-3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5])
>>> quantizer.thresholds
array([-3., -2., -1., 0., 1., 2., 3.])
>>> gaussian_pdf = lambda x: 1/np.sqrt(2*np.pi) * np.exp(-x**2/2)
>>> quantizer = komm.LloydMaxQuantizer(
... input_pdf=gaussian_pdf,
... input_range=(-5, 5),
... num_levels=8,
... )
>>> quantizer.levels.round(3)
array([-2.152, -1.344, -0.756, -0.245, 0.245, 0.756, 1.344, 2.152])
>>> quantizer.thresholds.round(3)
array([-1.748, -1.05 , -0.501, -0. , 0.501, 1.05 , 1.748])