Table Of Contents

quantencode

Version:
    Last Modified: March 15, 2017

    Uses quantization to convert floating-point inputs to integer outputs. Quantization transforms real floating-point numbers into integers. You can use quantencode to solve overflow problems.

    Syntax

    y = quantencode(x, n)
    y = quantencode(x, n, r)
    y = quantencode(x, n, r, s)
    Legacy name: uencode

    Inputs

    x

    Real numbers to encode. The elements of x must fall in the range [-r, r]. MathScript treats the elements outside of this range as overflows and saturates the overflows.

    n

    Level of quantization. n is a positive integer between 2 and 32. If n is in the range [2, 8], the output data type is int8/uint8. If n is in the range [9, 16], the output data type is int16/uint16. If n is in the range [17, 32], the output data type is int32/uint32.

    r

    Range of x. r is a positive number.

    Default: 1

    s

    Data type of the outputs. s accepts the following values.

    Name Description
    'signed'

    Directs MathScript to output signed integers with magnitudes in the range [-2^(n-1), 2^(n-1)-1].

    'unsigned'

    Directs MathScript to output unsigned integers with magnitudes in the range [0, 2^n-1].

    Default: 'unsigned'

    Outputs

    y

    Quantized integers.

    Complex Inputs

    quantencode does not accept complex inputs. To encode and decode a complex x, use quantencode and quantdecode separately on the real and imaginary parts of x and then combine the results, as shown in the following example:

    X = real (input) %get the real part of the input

    Y = imag (input) %get the imaginary part of the input

    X = quantencode (X, 4, 1, 'unsigned') %encode X

    Y = quantencode(Y, 4, 1, 'unsigned') %encode Y

    X = quantdecode (X, 4, 1, 'wrap') %decode X

    Y = quantdecode (Y, 4, 1, 'wrap') %decode Y

    output = complex (X, Y) %combine the real and imaginary parts

    X = -1:0.01:1;
    Y = quantencode(X, 4, 1, 'signed');
    X1 = quantdecode(Y, 4, 1);
    plot(X, X1)

    Where This Node Can Run:

    Desktop OS: Windows

    FPGA: This product does not support FPGA devices


    Recently Viewed Topics