# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# dsp.ScalarQuantizerEncoder System object

Package: dsp

Associate input value with index value of quantization region

## Description

The `ScalarQuantizerEncoder` object encodes each input value by associating that value with the index value of the quantization region. Then, the object outputs the index of the associated region.

To encode an input value by associating it with an index value of the quantization region:

1. Define and set up your scalar quantizer encoder. See Construction.

2. Call `step` to encode the input value according to the properties of `dsp.ScalarQuantizerEncoder`. The behavior of `step` is specific to each object in the toolbox.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`sqenc = dsp.ScalarQuantizerEncoder` returns a scalar quantizer encoder System object, `sqenc`. This object maps each input value to a quantization region by comparing the input value to the user-specified boundary points.

`sqenc = dsp.ScalarQuantizerEncoder('PropertyName',PropertyValue,...)` returns a scalar quantizer encoder object, `sqenc`, with each specified property set to the specified value.

## Properties

 `BoundaryPointsSource` Source of boundary points Specify how to determine the boundary points and codebook values as `Property` or `Input port`. The default is `Property`. `Partitioning` Quantizer is bounded or unbounded Specify the quantizer as `Bounded` or `Unbounded`. The default is `Bounded`. `BoundaryPoints` Boundary points of quantizer regions Specify the boundary points of quantizer regions as a vector. The vector values must be in ascending order. Let ```[p0 p1 p2 p3 ... pN]``` denote the boundary points property in the quantizer. If the quantizer is bounded, the object uses this property to specify `[p0 p1 p2 p3 ... pN]`. If the quantizer is unbounded, the object uses this property to specify ```[p1 p2 p3 ... p(N-1)]``` and sets `p0 = -Inf` and ```pN = +Inf```. This property applies when you set the `BoundaryPointsSource` property to `Property`. The default is `1:10`. This property is tunable. `SearchMethod` Find quantizer index by linear or binary search Specify whether to find the appropriate quantizer index using a linear search or a binary search as one of `Linear` or `Binary`. The computational cost of the linear search method is of the order P and the computational cost of the binary search method is of the order `${\text{log}}_{\text{2}}\text{(P)}$`where P is the number of boundary points. The default is `Linear`. `TiebreakerRule` Behavior when input equals boundary point Specify whether the input value is assigned to the lower indexed region or higher indexed region when the input value equals boundary point by selecting `Choose the lower index` or `Choose the higher index`. The default is ```Choose the lower index```. `CodewordOutputPort` Enable output of codeword value Set this property to `true` to output the codeword values that correspond to each index value. The default is `false`. `QuantizationErrorOutputPort` Enable output of quantization error Set this property to `true` to output the quantization error for each input value. The quantization error is the difference between the input value and the quantized output value. The default is `false`. `Codebook` Codebook Specify the codebook as a vector of quantized output values that correspond to each region. If the `Partitioning` property is `Bounded` and the boundary points vector has length N, you must set this property to a vector of length N-1. If the `Partitioning` property is `Unbounded` and the boundary points vector has length N, you must set this property to a vector of length N+1. This property applies when you set the `BoundaryPointsSource` property to `Property` and either the `CodewordOutputPort` property or the `QuantizationErrorOutputPort` property is `true`. The default is `1.5:9.5`. This property is tunable. `ClippingStatusOutputPort` Enable output of clipping status Set this property to `true` to output the clipping status. The output is a 1 when an input value is outside the range defined by the `BoundaryPoints` property. When the value is inside the range, the exception output is a 0. This property applies when you set the `Partitioning` property to `Bounded`. The default is `false`. `OutputIndexDataType` Data type of the index output Specify the data type of the index output from the object as: `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`. The default is `int32`.

## Methods

 step Encode using scalar quantization
Common to All System Objects
`clone`

Create System object with same property values

`getNumInputs`

Expected number of inputs to a System object

`getNumOutputs`

Expected number of outputs of a System object

`isLocked`

Check locked states of a System object (logical)

`release`

Allow System object property value changes

## 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).

Quantize the varying fractional inputs between zero and five to the closest integers, and then plot the results.

```sqenc = dsp.ScalarQuantizerEncoder; sqenc.BoundaryPoints = [-.001 .499 1.499 ... 2.499 3.499 4.499 5.001]; sqenc.CodewordOutputPort = true; sqenc.Codebook = [0 1 2 3 4 5]; input = (0:0.02:5)'; [index, quantizedValue] = sqenc(input); plot(1:length(input), [input quantizedValue]); ```

## Algorithms

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