dsp.VectorQuantizerEncoder

Vector quantization encoding

Description

The VectorQuantizerEncoder object performs vector quantization encoding. The object finds the nearest codeword by computing a distortion based on Euclidean or weighted Euclidean distance.

To perform vector quantization encoding:

  1. Create the dsp.VectorQuantizerEncoder object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Description

vqenc = dsp.VectorQuantizerEncoder returns a vector quantizer encoder System object™, vqenc. This object finds a zero-based index of the nearest codeword for each given input column vector.

example

vqenc = dsp.VectorQuantizerEncoder(Name,Value) returns a vector quantizer encoder System object, vqenc, with each specified property set to the specified value.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Specify how to determine the codebook values as Property or Input port.

Specify the codebook to which the input column vector or matrix is compared, as a k-by-N matrix. Each column of the codebook matrix is a codeword, and each codeword corresponds to an index value. The codeword vectors must have the same number of rows as the input. 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 default is:

[1.5 13.3 136.4 6.82.5 14.3 137.4 7.83.5 15.3 138.4 8.8]

Tunable: Yes

Dependencies

This property applies when you set the CodebookSource property to Property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify how to calculate the distortion as Squared error or Weighted squared error. If you set this property to Squared error, the object calculates the distortion by evaluating the Euclidean distance between the input column vector and each codeword in the codebook. If you set this property to Weighted squared error, the object calculates the distortion by evaluating a weighted Euclidean distance using a weighting factor to emphasize or deemphasize certain input values.

Specify how to determine weighting factor as Property or Input port.

Dependencies

This property applies when you set the DistortionMeasure property to Weighted squared error.

Specify the weighting factor as a vector of length equal to the number of rows of the input.

Tunable: Yes

Dependencies

This property applies when you set the DistortionMeasure property to Weighted squared error and WeightsSource property is Property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify whether to represent the input column vector by the lower index valued codeword or higher indexed valued codeword when an input column vector is equidistant from two codewords. You can set this property to Choose the lower index or Choose the higher index.

Set this property to true to output the codeword vectors nearest to the input column vectors.

Set this property to true to output the quantization error value that results when the object represents the input column vector by the nearest codeword.

Specify the data type of the index output as: int8, uint8, int16, uint16, int32, uint32.

Fixed-Point Properties

Specify the rounding method as Ceiling, Convergent, Floor, Nearest, Round, Simplest or Zero.

Specify the overflow action as Wrap or Saturate.

Specify the product fixed-point data type as Same as input or Custom.

Specify the product fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies when you set the ProductDataType property to Custom.

Specify the accumulator fixed-point data type as Same as product, Same as input, or Custom.

Specify the accumulator fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies when you set the AccumulatorDataType property to Custom.

Usage

Description

Index = vqenc(Input) returns Index, a scalar or column vector representing the quantization region(s) to which Input belongs.

Index = vqenc(Input,Codebook) uses the codebook given in input Codebook, a k-by-N matrix with N codewords each of length k. This option is available when the CodebookSource property is Input port.

Index = vqenc(___,Weights) uses the input vector Weights to emphasize or de-emphasize certain input values when calculating the distortion measure. Weights must be a vector of length equal to the number of rows of Input. This option is available when the DistortionMeasure property is Weighted squared error and the WeightsSource property is Input port.

[Index,Codeword] = vqenc(___) outputs the Codeword values that correspond to each index value when the CodewordOutputPort property is true. This syntax can be used with any of the previous input syntaxes.

example

[Index,Qerr] = vqenc(___) outputs the quantization error Qerr for each input value when the QuantizationErrorOutputPort property is true.

Input Arguments

expand all

Data input, specified as a column vector of size k-by-1 or a matrix of size k-by-M, where k is the length of each codeword in the codebook.

The number of rows in the data input, the length of the Weights vector, and the length of the codeword vector must all be the same value. All inputs to the object must have the same data type.

Data Types: single | double | int8 | int16 | int32 | int64 | fi

Codebook values, specified as a column vector of size k-by-1 or a matrix of size k-by-N, where k is the length of each codeword and N is the number of codewords.

The length of the codeword vector, the number of rows in the data input, and the length of the Weights vector must all be the same value. All inputs to the object must have the same data type.

Dependencies

This input applies when the CodebookSource property is Input port.

Data Types: single | double | int8 | int16 | int32 | int64 | fi

The object uses the Weights vector to emphasize or de-emphasize certain input values when calculating the distortion measure.

The length of the Weights vector must equal the number of rows in the data input and the length of the codeword. All inputs to the object must have the same data type.

Dependencies

This input applies when the DistortionMeasure property is Weighted squared error and the WeightsSource property is Input port.

Data Types: single | double | int8 | int16 | int32 | int64 | fi

Output Arguments

expand all

Indices of the nearest codeword vectors, returned as a scalar or a row vector. The object compares each input column vector to the codeword vectors in the codebook matrix. Each column of this codebook matrix is a codeword. The object finds the codeword vector nearest to the input column vector and returns its zero-based index. When the input is a matrix, the indices of the nearest codeword vectors are horizontally concatenated.

The object finds the nearest codeword by calculating the distortion using the method specified in DistortionMeasure property.

Data Types: int32

Codeword values that correspond to each index value, returned as a column vector or a matrix. When the input is a matrix, the corresponding codeword vectors are horizontally concatenated into a matrix.

Dependencies

This output is enabled when the CodewordOutputPort property is set to true.

Data Types: single | double | int8 | int16 | int32 | int64 | fi

Quantization error, returned as a scalar or a row vector. The quantization error results when the object represents the input column vector by its nearest codeword. When the input is a matrix, the quantization error values are horizontally concatenated.

Dependencies

This output is enabled when the QuantizationErrorOutputPort property is set to true.

Data Types: single | double | int8 | int16 | int32 | int64 | fi

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).

Find the indices of nearest codewords based on Euclidean distances.

vqenc = dsp.VectorQuantizerEncoder(...
    'Codebook', [-1 -1 1 1;1 -1 -1 1], ...
    'CodewordOutputPort', true, ...
    'QuantizationErrorOutputPort', true, ...
    'OutputIndexDataType', 'uint8');

Generate an input signal with some additive noise

x = sign(rand(2,40)-0.5) + 0.1*randn(2,40);
[ind, cw, err] = vqenc(x);
plot(cw(1,:), cw(2,:), 'rO', x(1,:), x(2,:), 'g.');
legend('Quantized', 'Inputs', 'location', 'best');

Algorithms

This object implements the algorithm, inputs, and outputs described on the Vector Quantizer Encoder block reference page. The object properties correspond to the block parameters.

Extended Capabilities

Introduced in R2012a