perform analogue-to-digital conversion on a signal
Quantize( signal, codebook, options )
Quantize( signal, coderange, numcodes, options )
Quantize( signal, quantizer, bound, numcodes, options )
rtable or list of real-valued data
1-D rtable or list of two or more strictly increasing real values for the quantization codes
range of the form c1..c2, where c1 and c2 are numeric values for, respectively, the smallest and largest quantization codes
positive integer larger than 1 for the number of quantization codes
keyword midriser or midtread
positive real value for the bound on the absolute values of quantization codes
inplace: Keyword true or false. Specifies whether the quantization is to be performed in-place. The default is false.
timerange: Range of the form t1..t2, where t1 and t2 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 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 datatype, with the indices of the codebook that give the respective values in the quantized signal.
originalsignal: Returns an rtable, of float datatype, with the original signal.
plot: Returns a plot of the original and quantized signals.
quantizedsignal: Returns an rtable, of float datatype, with the quantized signal.
sqnr: Returns the numeric value for the signal-to-quantized noise ratio.
times: Returns an rtable, of float 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.
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 x satisfies Ck≤x and x<Ck+1 for some index k, where C is the codebook. If truncation=below, then the quantized value is y=Ck. Similarly, if truncation=above, then y=Ck+1. When truncation=nearest, then y is Ck when y<Ck+φ⁢Ck+1−Ck and Ck+1 otherwise, where φ is the threshold which satisfies 0<φ and φ<1. For the boundary cases, if x≤C1 then y=C1, and if C−1≤x then y=C−1.
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 b is bound and m 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 x is lowered or raised so that it satisfies the bounds, that is, x is replaced with y, where:
When the quantizer is midriser, the data value y 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 y 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 Q, indices K, and codebook C 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 m 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 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.
X ≔ GenerateSignal⁡t,t=−1..1,25
b ≔ 1
c ≔ 5
X ≔ Array⁡1..10,0.01,0.04,0.09,0.16,0.25,0.36,0.49,0.64,0.81,1.00
C ≔ Array⁡1..4,0.00,0.50,0.75,1.00
Q ≔ Quantize⁡X,C,'truncation'='nearest'
Three different truncation methods are available for custom codebooks:
Signal ≔ GenerateSignal⁡2⁢cos⁡t,t=−Pi..Pi,50
Codebook ≔ Vector⁡seq⁡−2..2,0.5,'datatype'='float8'
The different outputs can be collected and returned as a single record:
expr ≔ 2.0⁢sin⁡t+0.5⁢cos⁡3⁢t
τ1 ≔ 0
τ2 ≔ 4⁢Pi
size ≔ 50
Data ≔ GenerateSignal⁡expr,t=τ1..τ2,size
bound ≔ 3.0
bits ≔ 3
codes ≔ 2bits
R1 ≔ Quantize⁡Data,'midriser',bound,codes,'timerange'=τ1..τ2,'output'='record':
R2 ≔ Quantize⁡Data,'midtread',bound,codes,'timerange'=τ1..τ2,'output'='record':
Quantization can be performed in-place:
U ≔ Vector'row'⁡2.95199901137063,2.65516788149002,−1.18441542906992,−0.612556403436018,−4.65553919497091,4.50222048838355,−1.82900519939139,1.94828622975817,3.23457828327293,−4.02868218764152,'datatype'='float8'
Multi-dimensional rtables are also supported:
X ≔ ArrayTools:-Reshape⁡GenerateSignal⁡cos⁡2⁢Pi⁢t2,t=0..2,300,150,2
C ≔ seq⁡−1..1,0.5
A uniform codebook can be specified by the range and number of codes:
X ≔ GenerateSignal⁡20⁢t2⁢ⅇ−t,t=0..10,25
Consider the following grayscale image:
A ≔ Array⁡RGBtoGray⁡SampleImage⁡5,'order'='Fortran_order':
By using a codebook with only two values, 0 and 1, we can convert the image to black and white:
B1 ≔ Quantize⁡A,0,1,'truncation'='nearest':
The threshold can control which values are lowered to 0 and which values are raised to 1:
B2 ≔ Quantize⁡A,0,1,'truncation'='nearest','threshold'=0.4:
B3 ≔ Quantize⁡A,0,1,'truncation'='nearest','threshold'=0.6:
The SignalProcessing[Quantize] command was introduced in Maple 2023.
For more information on Maple 2023 changes, see Updates in Maple 2023.
Download Help Document