Main Content

Vector Quantizer Encoder

Index of nearest codeword based on Euclidean or weighted Euclidean distance measure

  • Vector Quantizer Encoder block

Libraries:
DSP System Toolbox / Quantizers

Description

The Vector Quantizer Encoder block compares each input column vector to the codeword vectors in the codebook matrix. Each column of this codebook matrix is a codeword. The block finds the codeword vector nearest to the input column vector and returns its zero-based index. This block supports real floating-point and fixed-point signals on all input ports.

The Vector Quantizer Encoder block accepts real floating-point and fixed-point inputs. For more information, see the Ports section.

Ports

Input

expand all

Specify the input data values as a vector or a matrix.

The data, codebook values, and weighting factor inputs must have the same data type whenever they are present.

If the input is fixed point, it must be a signed integer or a signed fixed point value with a power-of-two slope and zero bias.

Data Types: single | double | int8 | int16 | int32 | fixed point

Specify the codebook values as a k-by-N matrix, where k ≥ 1 and N ≥ 1. Each input column vector is compared to this codebook. Each column of the codebook matrix is a codeword, and each codeword has an index value. The first codeword vector corresponds to an index value of 0, the second codeword vector corresponds to an index value of 1, and so on.

The input data, codebook values, and weighting factor must be of the same data type.

If the codebook values are fixed-point, they must be signed values only.

Dependencies

To enable this port, set the Source of codebook parameter to Input port.

Data Types: single | double | int8 | int16 | int32 | fixed point

Use the Weighting factor parameter to emphasize or deemphasize certain input values when calculating the distortion measure. For more information, see Weighting factor.

The input data, codebook values, and weighting factor must be of the same data type.

If the weighting factor is fixed-point, it must be signed values only.

Dependencies

To enable this port, set the Distortion measure parameter to Weighted squared error and the Source of weighting factor parameter to Input port.

Data Types: single | double | int8 | int16 | int32 | fixed point

Output

expand all

Index values of the nearest codeword based on Euclidean or weighted Euclidean distance measure, returned as a scalar or a row vector.

Data Types: int8 | int16 | int32 | uint8 | uint16 | uint32

Output codeword, returned as a vector or a matrix.

The block assigns the data type of the output codewords based on the data type of the input data. If the output codeword is fixed-point, it must be signed values only.

Data Types: single | double | int8 | int16 | int32 | fixed point

Quantization error, returned as a scalar or a row vector.

The block assigns the data type of the quantization error based on the data type of the input data. If the quantization error is fixed-point, it must be signed values only.

Data Types: single | double | int8 | int16 | int32 | fixed point

Parameters

expand all

Main Tab

Specify the source of codebook as one of these options:

  • Specify via dialog –– Specify codebook values in the Codebook parameter.

  • Input port –– Specify codebook values through the input port C.

Specify the codebook values as a k-by-N matrix, where k ≥ 1 and N ≥ 1. Each input column vector is compared to this codebook. Each column of the codebook matrix is a codeword, and each codeword has an index value. The first codeword vector corresponds to an index value of 0, the second codeword vector corresponds to an index value of 1, and so on. The codeword vectors must have the same number of rows as the input, U.

Dependencies

To enable this parameter, set the Source of codebook parameter to Specify via dialog.

Specify the measure of distortion as one of these:

  • Squared error –– Block calculates the distortion by evaluating the Euclidean distance between the input column vector and each codeword in the codebook.

  • Weighted squared error –– Block calculates the distortion by evaluating a weighted Euclidean distance using a weighting factor to emphasize or deemphasize certain input values.

Specify the source of weighting factor as one of these options:

  • Specify via dialog –– Specify the weighting factor in the Weighting factor parameter of the block dialog box.

  • Input port –– Specify the weighting factor through the input port W.

Dependencies

To enable this parameter, set the Distortion measure parameter to Weighted squared error.

Specify weighting factor as a vector of values. The length of this vector must equal the number of rows of the input, U.

Use the Weighting factor parameter to emphasize or deemphasize certain input values when calculating the distortion measure. For example, consider the p-th input column vector, Up=[u1pu2p...ukp]. When you want to neglect the effect of the first element of this vector, enter [0 1 1 ... 1] as the Weighting factor parameter. This weighting factor is used to calculate the weighted squared error using the equation:

D=j=1kwj(ajiujp)2

Because of the weighting factor used in this example, the weighted squared error is not affected by the first element of the input matrix. Therefore, the first element of the input column vector no longer impacts the choice of index value output by the Vector Quantizer Encoder block.

Dependencies

To enable this parameter, set the Source of weighting factor parameter to Specify via dialog.

Set this parameter to determine the behavior of the block when an input column vector is equidistant from two codewords. When you want the input column vector to be represented by the lower index valued codeword, select Choose the lower index. To represent the input column vector by the higher index valued codeword, select Choose the higher index.

Select the Output codeword check box to output at port Q(U) the codeword vectors that correspond to each index value. When the input is a matrix, the corresponding codeword vectors are horizontally concatenated into a matrix.

Select the Output quantization error check box to output at port D the quantization error that results when the block represents the input column vector by its nearest codeword. When the input is a matrix, the quantization error values are horizontally concatenated.

Specify the data type of the index output from the block at port I as one of the following:

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

To inherit the index output data type, select Inherit via back propagation.

Data Types Tab

Specify the rounding mode for fixed-point operations as one of the following:

  • Floor

  • Ceiling

  • Convergent

  • Nearest

  • Round

  • Simplest

  • Zero

For more details, see rounding mode.

When you select this parameter, the block saturates the result of its fixed-point operation. When you clear this parameter, the block wraps the result of its fixed-point operation. For details, see overflow mode for fixed-point operations.

As depicted above, the output of the multiplier is placed into the product output data type and scaling. Use this parameter to specify how you would like to designate this product output word and fraction lengths.

  • When you select Same as input, these characteristics match those of the input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the product output in bits.

Specify the product output word length as a positive integer in the range [2,128].

Dependencies

To enable this parameter, set the Product output parameter to Binary point scaling.

Specify the product output fraction length as an integer.

Dependencies

To enable this parameter, set the Product output parameter to Binary point scaling.

As depicted in this diagram, inputs to the accumulator are cast to the accumulator data type. The output of the adder remains in the accumulator data type as each element of the input is added to it. Use this parameter to specify how you would like to designate the accumulator word and fraction lengths.

  • When you select Same as product output, these characteristics match those of the product output.

  • When you select Same as input, these characteristics match those of the input to the block.

  • When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator in bits.

Specify the accumulator word length as a positive integer in the range [2,128].

Dependencies

To enable this parameter, set the Accumulator parameter to Binary point scaling.

Specify the accumulator fraction length as an integer.

Dependencies

To enable this parameter, set the Accumulator parameter to Binary point scaling.

Block Characteristics

Data Types

double | fixed point | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

More About

expand all

Algorithms

The block finds the nearest codeword by calculating the distortion. The block uses two methods for calculating distortion –– Euclidean squared error (unweighted) and weighted Euclidean squared error. Consider the codebook CB=[CW1CW2...CWN]. This codebook has N codewords and each codeword has k elements. The i-th codeword is defined as a column vector, CWi=[a1ia2i...aki]. The multichannel input has M columns and is defined as U=[U1U2...UM], where the p-th input column vector is Up=[u1pu2p...ukp].

The squared error (unweighted) is calculated using the equation

D=j=1k(ajiujp)2

The weighted squared error is calculated using the equation

D=j=1kwj(ajiujp)2

where the weighting factor is defined as W=[w1w2...wk]. The index of the codeword that is associated with the minimum distortion is assigned to the input column vector.

References

[1] Gersho, A. and R. Gray. Vector Quantization and Signal Compression. Boston: Kluwer Academic Publishers, 1992.

Extended Capabilities

Version History

Introduced before R2006a