komm.UniformQuantizer
Uniform scalar quantizer. It is a scalar quantizer in which the separation between levels is constant, $\Delta$, and the thresholds are the mid-point between adjacent levels. For more details, see Say06, Sec. 9.4.
Attributes:
-
num_levels
(int
) –The number of quantization levels $L$. It must be greater than $1$.
-
input_range
(tuple[float, float]
) –The range $(x_\mathrm{min}, x_\mathrm{max})$ of the input signal. Default is $(-1.0, 1.0)$.
-
choice
(Literal['mid-riser', 'mid-tread']
) –The choice for the uniform quantizer. Must be either
'mid-riser'
or'mid-tread'
. Default is'mid-riser'
.
Examples:
>>> quantizer = komm.UniformQuantizer(
... num_levels=4,
... input_range=(-1.0, 1.0),
... choice='mid-riser',
... )
>>> quantizer.levels
array([-0.75, -0.25, 0.25, 0.75])
>>> quantizer.thresholds
array([-0.5, 0. , 0.5])
>>> quantizer = komm.UniformQuantizer(
... num_levels=4,
... input_range=(-1.0, 1.0),
... choice='mid-tread',
... )
>>> quantizer.levels
array([-1. , -0.5, 0. , 0.5])
>>> quantizer.thresholds
array([-0.75, -0.25, 0.25])
>>> quantizer = komm.UniformQuantizer(
... num_levels=4,
... input_range=(0.0, 1.0),
... choice='mid-tread',
... )
>>> quantizer.levels
array([0. , 0.25, 0.5 , 0.75])
>>> quantizer.thresholds
array([0.125, 0.375, 0.625])
quantization_step
float
cached
property
The quantization step $\Delta$.
Examples:
>>> quantizer = komm.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> quantizer.quantization_step
2.0
levels
NDArray[floating]
cached
property
The quantizer levels $v_0, v_1, \ldots, v_{L-1}$.
Examples:
>>> quantizer = komm.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> quantizer.levels
array([-3., -1., 1., 3.])
thresholds
NDArray[floating]
cached
property
The quantizer finite thresholds $t_1, t_2, \ldots, t_{L-1}$.
Examples:
>>> quantizer = komm.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> quantizer.thresholds
array([-2., 0., 2.])
mean_squared_error()
Computes the mean squared (quantization) error (MSE) of the quantizer for a given input probability density function (pdf). It is defined as $$ \mse = \int_{-\infty}^{\infty} (x - y)^2 f_X(x) \, dx $$ where $y$ is the quantized signal and $f_X(x)$ is the pdf of the input signal.
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.
-
points_per_interval
(int
) –The number of points per interval for numerical integration (default: 4096).
Returns:
-
mse
(float
) –The mean square quantization error.
Examples:
>>> quantizer = komm.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> gaussian_pdf = lambda x: 1/np.sqrt(2*np.pi) * np.exp(-x**2/2)
>>> quantizer.mean_squared_error(
... input_pdf=gaussian_pdf,
... input_range=(-5, 5),
... )
0.3363025489037716
>>> uniform_pdf = lambda x: 1/8 * (np.abs(x) <= 4)
>>> quantizer.mean_squared_error(
... input_pdf=uniform_pdf,
... input_range=(-4, 4),
... )
0.3333333730891729
>>> quantizer.quantization_step**2 / 12
0.3333333333333333
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.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> quantizer.digitize([-2.4, 0.8, 3.2])
array([0, 2, 3])
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.UniformQuantizer(num_levels=4, input_range=(-4, 4))
>>> quantizer.quantize([-2.4, 0.8, 3.2])
array([-3., 1., 3.])