Main Content

Uniform Encoder

Quantize and encode floating-point input into integer output

  • Uniform Encoder block

Libraries:
DSP System Toolbox / Quantizers

Description

The Uniform Encoder block performs the following two operations on each floating-point sample in the input vector or matrix:

  1. Quantizes the value using the same precision

  2. Encodes the quantized floating-point value to an integer value

For more information on how the block computes the output, see Algorithms.

The Uniform Encoder block operations adhere to the definition for uniform encoding specified in ITU-T Recommendation G.701.

Examples

expand all

Open the ex_uniform_encoder model.

Double-click the Uniform Encoder block and set these parameters in the block dialog box:

  • Peak = 2

  • Bits = 3

  • Output type = Unsigned

The following figure illustrates uniform encoding.

The real and complex components of each input (horizontal axis) are independently quantized to one of $2^3$ distinct levels in the range [-2,1.5]. These components are then mapped to one of $2^3$ integer values in the range [0,7].

  • -2.0 is mapped to 0

  • -1.5 is mapped to 1

  • -1.0 is mapped to 2

  • -0.5 is mapped to 3

  • 0.0 is mapped to 4

  • 0.5 is mapped to 5

  • 1.0 is mapped to 6

  • 1.5 is mapped to 7

This shows the results for a few particular inputs.

  • Input = 1.6, Quantized Input = 1.5+0.0i, Output = 7+4i

  • Input = -0.4, Quantized Input = -0.5+0.0i, Output = 3+4i

  • Input = -3.2, Quantized Input = -2.0+0.0i, Output = 4i, Saturation (real)

  • Input = 0.4-1.2i, Quantized Input = 0.0-1.5i, Output = 4+i

  • Input = 0.4-6.0i, Quantized Input = 0.0-2.0i, Output = 4, Saturation (imaginary)

  • Input = -4.2+3.5i, Quantized Input = -2.0+2.0i, Output = 7i, Saturation (real and imaginary)

The output data type is automatically set to uint8, the most efficient format for this input range.

Ports

Input

expand all

Specify the floating-point input signal as a vector or a matrix. Inputs greater than (1−21−B)V or less than −V saturate at those respective values. The real and imaginary components of complex inputs saturate independently.

Data Types: single | double
Complex Number Support: Yes

Output

expand all

Encoder output, returned as a vector or a matrix. The block quantizes each sample in the floating-point input and encodes the quantized floating-point value to an integer value. For more information on how the block computes the output, see Algorithms.

Data Types: int8 | int16 | int32 | uint8 | uint16 | uint32
Complex Number Support: Yes

Parameters

expand all

Specify the largest input amplitude to be encoded V as a nonnegative scalar. Real or imaginary input values greater than (1−21−B)V or less than −V saturate (independently for complex inputs) at those limits.

Specify the number of bits B needed to represent the integer output. The number of bits B can be any integer value between 2 and 32, inclusive. The number of levels at which the block quantizes the floating-point input is 2B.

Specify the data type of the block output as one of these:

  • Unsigned integer –– The smallest quantized floating-point value −V is mapped to the integer 0 and the largest quantized floating-point value (1−21−B)V is mapped to the integer 2B−1. Intermediate quantized floating-point values are linearly (uniformly) mapped to the intermediate integers in the range [0, 2B−1]. For efficiency, the block automatically selects an unsigned output data type (uint8, uint16, or uint32) with the minimum number of bits equal to or greater than B.

  • Signed integer –– The smallest quantized floating-point value −V is mapped to the integer −2B−1, and the largest quantized floating-point value (1−21−B)V is mapped to the integer 2B−1−1. Intermediate quantized floating-point values are linearly mapped to the intermediate integers in the range [−2B−1, 2B−1−1]. The block automatically selects a signed output data type (int8, int16, or int32) with the minimum number of bits equal to or greater than B.

The output data types that the block uses are shown in the table below.

BitsUnsigned IntegerSigned Integer

2 to 8

uint8

int8

9 to 16

uint16

int16

17 to 32

uint32

int32

Block Characteristics

Data Types

double | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Algorithms

The Uniform Encoder block performs the following two operations on each floating-point sample in the input.

  1. Quantizes the value using the same precision

  2. Encodes the quantized floating-point value to an integer value

In the first step, the block quantizes an input value to one of 2B uniformly spaced levels in the range [−V, (1−21−B)V], where you specify B in the Bits parameter and you specify V in the Peak parameter. The quantization process rounds both positive and negative inputs downward to the nearest quantization level, with the exception of those that fall exactly on a quantization boundary. The real and imaginary components of complex inputs are quantized independently.

In the second step, the quantized floating-point value is uniquely mapped (encoded) to one of 2B integer values. When the Output type is set to Unsigned integer, the smallest quantized floating-point value −V is mapped to the integer 0 and the largest quantized floating-point value (1−21−B)V is mapped to the integer 2B−1. Intermediate quantized floating-point values are linearly (uniformly) mapped to the intermediate integers in the range [0, 2B−1]. For efficiency, the block automatically selects an unsigned output data type (uint8, uint16, or uint32) with the minimum number of bits equal to or greater than B.

When the Output type is set to Signed integer, the smallest quantized floating-point value −V is mapped to the integer −2B−1, and the largest quantized floating-point value (1−21−B)V is mapped to the integer 2B−1−1. Intermediate quantized floating-point values are linearly mapped to the intermediate integers in the range [−2B−1, 2B−1−1]. The block automatically selects a signed output data type (int8, int16, or int32) with the minimum number of bits equal to or greater than B.

References

[1] General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms, International Telecommunication Union, ITU-T Recommendation G.701, March, 1993.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a

See Also

Functions

Blocks