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[floating]], NDArray[floating]]
) –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])
levels: npt.NDArray[np.floating]
property
The quantizer levels $v_0, v_1, \ldots, v_{L-1}$.
Examples:
>>> 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])
thresholds: npt.NDArray[np.floating]
property
The quantizer finite thresholds $t_1, t_2, \ldots, t_{L-1}$.
Examples:
>>> 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.thresholds.round(3)
array([-1.748, -1.05 , -0.501, -0. , 0.501, 1.05 , 1.748])
__call__
Quantizes the input signal.
Parameters:
-
input
(ArrayLike
) –The input signal $x$ to be quantized.
Returns:
-
output
(NDArray[floating]
) –The quantized signal $y$.
Examples:
>>> 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([0, 1, 2, 3, 4, 5, 6, 7]).round(3)
array([0.245, 0.756, 2.152, 2.152, 2.152, 2.152, 2.152, 2.152])