Scalar Quantizer Encoder
Encode each input value by associating it with index value of quantization region
Library
Quantizers
dspquant2
Description
The Scalar Quantizer Encoder block maps each input value to a quantization region by comparing the input value to the quantizer boundary points defined in the Boundary points parameter. The block outputs the zerobased index of the associated region.
You can select how you want to enter the Boundary points using
the Source of quantizer parameters. When you select
Specify via dialog
, type the boundary points into the
block parameters dialog box. When you select Input port
, port
B appears on the block. The block uses the input to port B as the Boundary
points parameter.
Use the Boundary points parameter to specify the boundary points for your quantizer. These values are used to break up the set of input numbers into regions. Each region is specified by an index number.
Let N
be the number of quantization regions. When the codebook is
defined as [c1 c2 c3 ... cN]
, and the Boundary
points parameter is defined as [p0 p1 p2 p3 ... pN]
,
then p0<c1<p1<c2 ... p(N1)<cN<pN
for a regular
quantizer. When your quantizer is bounded, from the
Partitioning list, select Bounded
. You
need to specify N+1 boundary points, or [p0 p1 p2 p3 ... pN]
. When
your quantizer is unbounded, from the Partitioning list,
select Unbounded
. You need to specify N1 boundary points,
or[p1 p2 p3 ... p(N1)]
; the block sets p0
equal to inf
and pN
equal to
inf
.
The block uses the Partitioning parameter to interpret the
boundary points you enter. For instance, to create a bounded quantizer, from the
Partitioning list, select
Bounded
and enter the following boundary points:
[0 0.5 3.7 5.8 6.0 11]
The block assigns any input values between 0 and 0.5 to index 0, input values between 0.5 and 3.7 to index 1, and so on. The block assigns any values that are less than 0 to index 0, the lowest index value. The block assigns any values that are greater than 11 to index 4, the highest index value.
To create an unbounded quantizer, from the Partitioning
list, select Unbounded
and enter the following boundary
points:
[0 0.5 3.7 5.8 6.0 11]
The block assigns any input values between 0 and 0.5 to index 1, input values between 0.5 and 3.7 to index 2, and so on. The block assigns any input values less than 0 to index 0 and any values greater than 11 to index 6.
The Searching method parameter determines how the appropriate
quantizer index is found. When you select Linear
, the Scalar
Quantizer Encoder block compares the input value to the first region defined by the
first two boundary points. When the input value does not fall within this region, the
block then compares the input value to the next region. This process continues until the
input value is determined to be within a region and is associated with the appropriate
index value. The computational cost of this process is of the order P, where P is the
number of boundary points.
When you select Binary
for the Searching
method, the block compares the input value to the middle value of the
boundary points vector. When the input value is larger than this boundary point, the
block discards the boundary points that are lower than this middle value. The block then
compares the input value to the middle boundary point of the new range, defined by the
remaining boundary points. This process continues until the input value is associated
with the appropriate index value. The computational cost of this process is of the order log_{2}P, where P is the number of boundary points. In most
cases, the Binary
option is faster than the
Linear
option.
When an input value is the same as a boundary point, the Tiebreaking
rule parameter determines the region to which the value is assigned. When
you want the input value to be assigned to the lower indexed region, select
Choose the lower index
. To assign the input value with
the higher indexed region, select Choose the higher
index
.
Select the Output codeword check box to output the codeword values that correspond to each index value at port Q(U).
Select the Output the quantization error check box to output the quantization error for each input value from the Err port on this block. The quantization error is the difference between the input value and the quantized output value.
When you select either the Output codeword check box or the
Output quantization error check box, you must also enter your
codebook values. If, from the Source of quantizer parameters
list, you choose Specify via dialog
, use the
Codebook parameter to enter a vector of quantized output values
that correspond to each region. If, from the Source of quantizer
parameters list, you choose Input port
, use
input port C to specify your codebook values.
If, for the Partitioning parameter, you select
Bounded
, the Output clipping status
check box and the Action for out of range input parameter appear.
When you select the Output clipping status check box, port S
appears on the block. Any time an input value is outside the range defined by the
Boundary points parameter, the block outputs a 1 at the S port.
When the value is inside the range, the blocks outputs a 0.
You can use the Action for out of range input parameter to
determine the block's behavior when an input value is outside the range defined by the
Boundary points parameter. Suppose the boundary points for a
bounded quantizer are defined as [p0 p1 p2 p3 ... pN]
and the
possible index values are defined as [i0 i1 i2 ... i(N1)]
, where
i0=0
and i0<i1<i2<...<i(N1)
. When
you want any input value less than p0
to be assigned to index value
i0
and any input values greater than pN
to be
assigned to index value i(N1)
, select Clip
. When
you want to be warned when clipping occurs, select Clip and
warn
. When you want the simulation to stop and the block to display an
error when the index values are out of range, select
Error
.
The Scalar Quantizer Encoder block accepts real floatingpoint and fixedpoint inputs. For more information on the data types accepted by each port, see Data Type Support or Supported Data Types.
Data Type Support
The input data values, boundary points, and codebook values can be input to the
block at ports U, B, and C, respectively. The data type of the inputs can be
double
, single
, or
Fixedpoint.
The outputs of the block can be the index values, the quantized output values, the
quantization error, and the clipping status. Use the Index output data
type parameter to specify the data type of the index output from the
block at port I. You can choose int8
,
uint8
, int16
,
uint16
, int32
, or
uint32
. The data type of the quantized output and the
quantization error can be double
,
single
, or Fixedpoint. The clipping status values
output at port S are Boolean values.
Note
The input data, boundary points, codebook values, quantized output values, and the quantization error must have the same data type whenever they are present.
Dialog Box
Main Tab
 Source of quantizer parameters
Choose
Specify via dialog
to enter the boundary points and codebook values using the block parameters dialog box. SelectInput port
to specify the parameters using the block's input ports. Input the boundary points and codebook values using ports B and C, respectively. Partitioning
When your quantizer is bounded, select
Bounded
. When your quantizer is unbounded, selectUnbounded
. Boundary points
Enter a vector of values that represent the boundary points of the quantizer regions. This parameter is visible when you select
Specify via dialog
from the Source of quantizer parameters list. Tunable (Simulink). Searching method
When you select
Linear
, the block finds the region in which the input value is located using a linear search. When you selectBinary
, the block finds the region in which the input value is located using a binary search. Tiebreaking rule
Set this parameter to determine the behavior of the block when the input value is the same as the boundary point. When you select
Choose the lower index
, the input value is assigned to lower indexed region. When you selectChoose the higher index
, the value is assigned to the higher indexed region. Output codeword
Select this check box to output the codeword values that correspond to each index value at port Q(U).
 Output quantization error
Select this check box to output the quantization error for each input value at port Err.
 Codebook
Enter a vector of quantized output values that correspond to each index value. If, for the Partitioning parameter, you select
Bounded
and your boundary points vector has length N, then you must specify a codebook of length N1. If, for the Partitioning parameter, you selectUnbounded
and your boundary points vector has length N, then you must specify a codebook of length N+1.This parameter is visible when you select
Specify via dialog
from the Source of quantizer parameters list and you select either the Output codeword or Output quantization error check box. Tunable (Simulink). Output clipping status
When you select this check box, port S appears on the block. Any time an input value is outside the range defined by the Boundary points parameter, the block outputs a 1 at this port. When the value is inside the range, the block outputs a 0. This parameter is visible when you select
Bounded
from the Partitioning list. Action for out of range input
Use this parameter to determine the behavior of the block when an input value is outside the range defined by the Boundary points parameter. Suppose the boundary points are defined as
[p0 p1 p2 p3 ... pN]
and the index values are defined as[i0 i1 i2 ... i(N1)]
. When you want any input value less thanp0
to be assigned to index valuei0
and any input values greater thanpN
to be assigned to index valuei(N1)
, selectClip
. When you want to be warned when clipping occurs, selectClip and warn
. When you want the simulation to stop and the block to display an error when the index values are out of range, selectError
. This parameter is visible when you selectBounded
from the Partitioning list. Index output data type
Specify the data type of the index output from the block at port I. You can choose
int8
,uint8
,int16
,uint16
,int32
,uint32
, orInherit via back propagation
.
Data Types Tab
 Rounding mode
Specify the rounding mode for fixedpoint operations as one of the following:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see rounding mode.
 Saturate on integer overflow
When you select this parameter, the block saturates the result of its fixedpoint operation. When you clear this parameter, the block wraps the result of its fixedpoint operation. For details on
saturate
andwrap
, see overflow mode for fixedpoint operations.
References
Gersho, A. and R. Gray. Vector Quantization and Signal Compression. Boston: Kluwer Academic Publishers, 1992.
Supported Data Types
Port  Supported Data Types 

U 

B 

C 

I 

Q(U) 

Err 

S 

For more information on what data types are supported for each quantizer mode, see Data Type Support.
See Also
Quantizer (Simulink)  Simulink 
Scalar Quantizer Decoder  DSP System Toolbox 
Uniform Encoder  DSP System Toolbox 
Uniform Decoder  DSP System Toolbox 
Extended Capabilities
Version History
Introduced before R2006a