|
Calling Sequence
|
|
Quantize( signal, codebook, options )
Quantize( signal, coderange, numcodes, options )
Quantize( signal, quantizer, bound, numcodes, options )
|
|
Parameters
|
|
signal
|
-
|
rtable or list of real-valued data
|
codebook
|
-
|
1-D rtable or list of two or more strictly increasing real values for the quantization codes
|
coderange
|
-
|
range of the form , where and are numeric values for, respectively, the smallest and largest quantization codes
|
numcodes
|
-
|
positive integer larger than 1 for the number of quantization codes
|
quantizer
|
-
|
keyword midriser or midtread
|
bound
|
-
|
positive real value for the bound on the absolute values of quantization codes
|
|
|
|
|
Options
|
|
•
|
inplace: Keyword true or false. Specifies whether the quantization is to be performed in-place. The default is false.
|
•
|
timerange: Range of the form , where and are numeric values. Specifies the time range for the plot and Vector of times. The default is 1..numelems(signal).
|
•
|
truncation: Keyword above, below, or nearest. Specifies how matches in a custom codebook are determined. The default is nearest.
|
•
|
threshold: Numeric value larger than 0.0 and smaller than 1.0. Specifies, for the custom codebook with truncation=nearest, the distance ratio at which the quantized value above is considered closer than the one below. The default is 0.5.
|
•
|
uniform: Keyword true or false. When true and a custom codebook is passed, Maple assumes the codes are evenly spaced and skips the check for uniformity. The default is false.
|
•
|
emphasizecodes: Keyword true or false. Specifies whether the quantization codes should be emphasized in the plot using horizontal lines. The default is false.
|
•
|
originalsignalplotoptions: List for additional plot options to be passed when creating the plot of the original signal. The default is [].
|
•
|
quantizedsignalplotoptions: List for additional plot options to be passed when creating the plot of the quantized signal. The default is [].
|
•
|
codebookplotoptions: List for additional plot options to be passed when creating the plot of the codebook. The default is [].
|
•
|
plotoptions: List for additional plot options to be passed when creating the combined plot. The default is [].
|
•
|
output: The type of output. The supported options are:
|
–
|
codebook: Returns a Vector, of float[8] datatype, with the quantization values.
|
–
|
distortion: Returns the numeric value for the distortion between the original and quantized signals.
|
–
|
indices: Returns an rtable, of integer[4] datatype, with the indices of the codebook that give the respective values in the quantized signal.
|
–
|
originalsignal: Returns an rtable, of float[8] datatype, with the original signal.
|
–
|
plot: Returns a plot of the original and quantized signals.
|
–
|
quantizedsignal: Returns an rtable, of float[8] datatype, with the quantized signal.
|
–
|
sqnr: Returns the numeric value for the signal-to-quantized noise ratio.
|
–
|
times: Returns an rtable, of float[8] datatype, with the time values determined by timerange.
|
–
|
record: Returns a record with the previous options.
|
–
|
list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order. The default is quantizedsignal.
|
|
|
Description
|
|
•
|
The Quantize command takes a signal with real data and computes the associated quantized values for each element based on a codebook.
|
•
|
For the quantizer with a custom codebook, suppose data value satisfies and for some index , where is the codebook. If truncation=below, then the quantized value is . Similarly, if truncation=above, then . When truncation=nearest, then is when and otherwise, where is the threshold which satisfies and . For the boundary cases, if then , and if then .
|
•
|
When the codebook is specified as a range and number of codes, a codebook with uniformly spaced codes is constructed internally.
|
•
|
For the midriser and midtread quantizers, a step size of
|
|
is used, where is bound and is numcodes, and the codebook is of the form
|
|
where and , which are specified below, depend on the type of quantizer and whether the size of the codebook is even or odd. Before applying the quantizer, each data value is lowered or raised so that it satisfies the bounds, that is, is replaced with , where:
|
•
|
When the quantizer is midriser, the data value is quantized as follows:
|
|
The offset term acts as a vertical translation so that there is a jump in quantized value from to when a data value passes from negative to positive, hence the name. Consequently, there is no value of 0 in the codebook. For the bounds:
|
•
|
When the quantizer is midtread, the data value is quantized as follows:
|
|
The offset term acts as a horizontal translation so that a quantized value is zero when a data value passes from negative to positive, hence the name. Consequently, the value of 0 is in the codebook. For the bounds:
|
•
|
The quantized signal , indices , and codebook satisfy Q=C[K].
|
•
|
The distortion is computed as the root mean square (RMS) error between the original and quantized signals.
|
•
|
The signal-to-quantization noise ratio (SQNR) is computed as
|
|
where is the size of the codebook.
|
•
|
The bound is also known as the half-scale range. Another convention is to use the full-scale range, which is twice the bound.
|
•
|
The signal and codebook rtables cannot have an indexing function and must use Fortran ordering and rectangular storage.
|
•
|
The outputs indices, quantizedsignal, and times will have the same dimensions as signal. Internally, these containers are all treated as Vectors, with Fortran ordering determining the order of elements in the respective Vector versions. The plot will display the Vector versions of originalsignal and quantizedsignal.
|
•
|
Maple attempts to coerce signal and codebook to an rtable of float[8] datatype, and an error is thrown if this is not possible. For this reason, it is most efficient for the passed containers to be rtables of this datatype.
|
•
|
The Quantize command is not thread safe.
|
|
|
Examples
|
|
|
Example 1
|
|
•
|
Quantization can be performed in-place:
|
|
|
Example 2
|
|
|
|
Example 3
|
|
|
|
Example 4
|
|
•
|
Three different truncation methods are available for custom codebooks:
|
|
|
Example 5
|
|
•
|
The different outputs can be collected and returned as a single record:
|
|
|
Example 6
|
|
•
|
Multi-dimensional rtables are also supported:
|
|
|
Example 7
|
|
•
|
A uniform codebook can be specified by the range and number of codes:
|
|
|
Example 8
|
|
•
|
Consider the following grayscale image:
|
•
|
By using a codebook with only two values, 0 and 1, we can convert the image to black and white:
|
•
|
The threshold can control which values are lowered to 0 and which values are raised to 1:
|
|
|
|
Compatibility
|
|
•
|
The SignalProcessing[Quantize] command was introduced in Maple 2023.
|
|
|
|