| DSP Blockset | ![]() |
Start the Scalar Quantizer Design Tool (SQDTool) to design a scalar quantizer using the Lloyd algorithm
Library
Description
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.
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. If 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. If 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.
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. If 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. If 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. If 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. If 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 point to the boundary points. Select Linear search and SQDTool begins by comparing the training point to the first quantization region defined by -inf and the first finite-valued boundary point. If the training point does not fall within this region, the block then compares the training point to the next region. This process continues until the training point is associated with the appropriate region.
Select Binary search for the Searching methods parameter and the block compares the training point to the middle value of the boundary points vector. If 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 Scalar Quantizer 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. In the Block name field, enter a name for the block. If you have a Scalar Quantizer block in your destination model with the same name, select the Overwrite target block check box to replace the block's parameters with the current parameters. If this check box is not selected, a new Scalar Quantizer block is created in your destination model.
Click Realize Block. SQDTool uses the parameters it calculated to set the parameters of the Scalar Quantizer block.
Dialog Box
1e6.
Auto-generate to have the block choose the initial codebook values. Select User defined to enter your own initial codebook values.
.
User defined in order to activate this parameter.
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.
-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.
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.
Maximum iteration in order to activate this parameter.
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.
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.
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.
References
Gersho, A. and R. Gray. Vector Quantization and Signal Compression. Boston: Kluwer Academic Publishers, 1992.
Supported Data Types
To learn how to convert your data types to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.
See Also
| Quantizer |
Simulink |
| Scalar Quantizer |
DSP Blockset |
| Uniform Encoder |
DSP Blockset |
| Uniform Decoder |
DSP Blockset |
| Scalar Quantizer | Short-Time FFT | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |