Start Scalar Quantizer Design Tool (SQDTool) to design scalar quantizer using Lloyd algorithm
Quantizers
dspquant2
Double-click on the Scalar Quantizer Design block to start SQDTool, a GUI that allows you to design and implement a scalar quantizer. Based on your input values, SQDTool iteratively calculates the codebook values that minimize the mean squared error until the stopping criteria for the design process is satisfied. The block uses the resulting quantizer codebook values and boundary points to implement your scalar quantizer encoder and/or decoder.
For the Training Set parameter, enter a
set of observations, or samples, of the signal you want to quantize.
This data can be any variable defined in the MATLAB^{®} workspace
including a variable created using a MATLAB function, such as
the default value randn(10000,1)
.
You have two choices for the Source of initial codebook parameter.
Select Auto-generate
to have the block
choose the values of the initial codebook vector. In this case, the
minimum training set value becomes the first codeword, and the maximum
training set value becomes the last codeword. Then, the remaining
initial codewords are equally spaced between these two values to form
a codebook vector of length N, where N is the Number of
levels parameter. When you select User defined
,
enter the initial codebook values in the Initial codebook field.
Then, set the Source of initial boundary points parameter.
You can select Mid-points
to locate the
boundary points at the midpoint between the codewords. To calculate
the mid-points, the block internally arranges the initial codebook
values in ascending order. You can also choose User defined
and
enter your own boundary points in the Initial boundary points
(unbounded) field. Only one boundary point can be located
between two codewords. When you select User defined
for
the Source of initial boundary points parameter,
the values you enter in the Initial codebook and Initial
boundary points (unbounded) fields must be arranged in
ascending order.
Note
This block assumes that you are designing an unbounded quantizer.
Therefore, the first and last boundary points are always |
After you have specified the quantization parameters, the block performs an iterative process to design the optimal scalar quantizer. Each step of the design process involves using the Lloyd algorithm to calculate codebook values and quantizer boundary points. Then, the block calculates the squared quantization error and checks whether the stopping criteria has been satisfied.
The two possible options for the Stopping criteria parameter
are Relative threshold
and Maximum
iteration
. When you want the design process to stop
when the fractional drop in the squared quantization error is below
a certain value, select Relative threshold
.
Then, for Relative threshold, type the maximum
acceptable fractional drop. When you want the design process to stop
after a certain number of iterations, choose Maximum
iteration
. Then, enter the maximum number of iterations
you want the block to perform in the Maximum iteration field.
For Stopping criteria, you can also choose Whichever
comes first
and enter a Relative threshold and Maximum
iteration value. The block stops iterating as soon as one
of these conditions is satisfied.
With each iteration, the block quantizes the training set values
based on the newly calculated codebook values and boundary points.
When the training point lies on a boundary point, the algorithm uses
the Tie-breaking rules parameter to determine
which region the value is associated with. When you want the training
point to be assigned to the lower indexed region, select Lower
indexed codeword
. To assign the training point with
the higher indexed region, select Higher indexed codeword
.
The Searching methods parameter determines
how the block compares the training points to the boundary points.
Select Linear search
and SQDTool compares
each training point to each quantization region sequentially. This
process continues until all the training points are associated with
the appropriate regions.
Select Binary search
for the Searching
methods parameter and the block compares the training point
to the middle value of the boundary points vector. When the training
point is larger than this boundary point, the block discards the lower
boundary points. The block then compares the training point to the
middle boundary point of the new range, defined by the remaining boundary
points. This process continues until the training point is associated
with the appropriate region.
Click Design and Plot to design the quantizer with the parameter values specified on the left side of the GUI. The performance curve and the staircase character of the quantizer are updated and displayed in the figures on the right side of the GUI.
Note You must click Design and Plot to apply any changes you make to the parameter values in the SQDTool dialog box. |
SQDTool can export parameter values that correspond to the figures displayed in the GUI. Click the Export Outputs button, or press Ctrl+E, to export the Final Codebook, Final Boundary Points, and Error values to the workspace, a text file, or a MAT-file. The Error values represent the mean squared error for each iteration.
In the Model section of the GUI,
specify the destination of the block that will contain the parameters
of your quantizer. For Destination, select Current
model
to create a block with your parameters in the
model you most recently selected. Type gcs
in the MATLAB Command
Window to display the name of your current model. Select New
model
to create a block in a new model file.
From the Block type list, select Encoder
to
design a Scalar Quantizer Encoder block. Select Decoder
to
design a Scalar Quantizer Decoder block. Select Both
to
design a Scalar Quantizer Encoder block and a Scalar Quantizer Decoder
block.
In the Encoder block name field, enter a name for the Scalar Quantizer Encoder block. In the Decoder block name field, enter a name for the Scalar Quantizer Decoder block. When you have a Scalar Quantizer Encoder and/or Decoder block in your destination model with the same name, select the Overwrite target block(s) check box to replace the block's parameters with the current parameters. When you do not select this check box, a new Scalar Quantizer Encoder and/or Decoder block is created in your destination model.
Click Generate Model. SQDTool uses the parameters that correspond to the current plots to set the parameters of the Scalar Quantizer Encoder and/or Decoder blocks.
Enter the samples of the signal you would like to quantize.
This data set can be a MATLAB function or a variable defined
in the MATLAB workspace. The typical length of this data vector
is 1e6
.
Select Auto-generate
to have the
block choose the initial codebook values. Select User
defined
to enter your own initial codebook values.
Enter the length of the codebook vector. For a b-bit quantizer, the length should be N = 2^{b}.
Enter your initial codebook values. From the Source
of initial codebook list, select User defined
in
order to activate this parameter.
Select Mid-points
to locate the boundary
points at the midpoint between the codebook values. Choose User
defined
to enter your own boundary points. From the Source
of initial codebook list, select User defined
in
order to activate this parameter.
Enter your initial boundary points. This block assumes that
you are designing an unbounded quantizer. Therefore, the first and
last boundary point are -inf
and inf
,
regardless of any other boundary point values you might enter. From
the Source of initial boundary points list,
select User defined
in order to activate
this parameter.
Choose Relative threshold
to enter
the maximum acceptable fractional drop in the squared quantization
error. Choose Maximum iteration
to specify
the number of iterations at which to stop. Choose Whichever
comes first
and the block stops the iteration process
as soon as the relative threshold or maximum iteration value is attained.
Type the value that is the maximum acceptable fractional drop in the squared quantization error.
Enter the maximum number of iterations you want the block to
perform. From the Stopping criteria list,
select Maximum iteration
in order to activate
this parameter.
Choose Linear search
to use a linear
search method when comparing the training points to the boundary points.
Choose Binary search
to use a binary search
method when comparing the training points to the boundary points.
When a training point lies on a boundary point, choose Lower
indexed codeword
to assign the training point to the
lower indexed quantization region. Choose Higher indexed
codeword
to assign the training point to the higher
indexed region.
Click this button to display the performance curve and the staircase character of the quantizer in the figures on the right side of the GUI. These plots are based on the current parameter settings.
You must click Design and Plot to apply any changes you make to the parameter values in the SQDTool GUI.
Click this button, or press Ctrl+E, to export the Final Codebook, Final Boundary Points, and Error values to the workspace, a text file, or a MAT-file.
Choose Current model
to create a
Scalar Quantizer block in the model you most recently selected. Type gcs
in
the MATLAB Command Window to display the name of your current
model. Choose New model
to create a block
in a new model file.
Select Encoder
to design a Scalar
Quantizer Encoder block. Select Decoder
to
design a Scalar Quantizer Decoder block. Select Both
to
design a Scalar Quantizer Encoder block and a Scalar Quantizer Decoder
block.
Enter a name for the Scalar Quantizer Encoder block.
Enter a name for the Scalar Quantizer Decoder block.
When you do not select this check box and a Scalar Quantizer Encoder and/or Decoder block with the same block name exists in the destination model, a new Scalar Quantizer Encoder and/or Decoder block is created in the destination model. When you select this check box and a Scalar Quantizer Encoder and/or Decoder block with the same block name exists in the destination model, the parameters of these blocks are overwritten by new parameters.
Click this button and SQDTool uses the parameters that correspond to the current plots to set the parameters of the Scalar Quantizer Encoder and/or Decoder blocks.
Gersho, A. and R. Gray. Vector Quantization and Signal Compression. Boston: Kluwer Academic Publishers, 1992.
Double-precision floating point
Quantizer | Simulink |
Scalar Quantizer Decoder | DSP System Toolbox |
Scalar Quantizer Encoder | DSP System Toolbox |
Uniform Encoder | DSP System Toolbox |
Uniform Decoder | DSP System Toolbox |