Main Content

unitquantizer

Create unitquantizer object

Description

The unitquantizer object describes data type properties to use for quantization. After you create a unitquantizer object, use quantize to quantize double-precision data. A unitquantizer object is the same as a quantizer object except that its quantize method quantizes numbers within eps(q) of +1 to exactly +1. You can use the unitquantizer object to simulate custom floating-point data types with arbitrary word length and exponent length.

Creation

Description

q = unitquantizer creates a unitquantizer object with properties set to their default values. To use this object to quantize values, use quantize.

q = unitquantizer(Name,Value) sets named properties using name-value arguments. You can specify multiple name-value arguments. Enclose each property name in single quotes.

example

q = unitquantizer(Value1,Value2) sets properties using property values. Property values are unique, so you can set property names by specifying just the property values in the command. When two values conflict, unitquantizer sets the last property value in the list.

q = unitquantizer(s) sets properties named in each field name with the values contained in the structure s.

q = unitquantizer(pn,pv) sets the named properties specified in the cell array of character vectors pn to the corresponding values in the cell array pv.

You can use a combination of name-value string arguments, structures, and name-value cell array arguments to set property values when creating a unitquantizer object.

Properties

expand all

Type of arithmetic used in quantization, specified as one of these values:

  • 'fixed' — Signed fixed-point mode.

  • 'ufixed' — Unsigned fixed-point mode.

  • 'float' — Custom-precision floating-point mode.

  • 'single' — Single-precision mode. This mode overrides all other property settings.

  • 'double' — Double-precision mode. This mode overrides all other property settings.

Data Types: char | struct | cell

Rounding method to use, specified as one of these values:

  • 'ceil' — Round up to the next allowable quantized value.

  • 'convergent' — Round to the nearest allowable quantized value. Numbers that are exactly halfway between the two nearest allowable quantized values are rounded up only if the least significant bit after rounding would be set to 0.

  • 'fix' — Round negative numbers up and positive numbers down to the next allowable quantized value.

  • 'floor' — Round down to the next allowable quantized value.

  • 'nearest' — Round to the nearest allowable quantized value. Numbers that are halfway between the two nearest allowable quantized values are rounded up.

  • 'round' — Round to the nearest allowable quantized value. Numbers that are halfway between the two nearest allowable quantized values are rounded up in absolute value.

Data Types: char | struct | cell

Action to take on overflow, specified as one of these values:

  • 'saturate' — Overflows saturate.

    When the values of data to be quantized lie outside the range of the largest and smallest representable numbers as specified by the data format properties, these values are quantized to the value of either the largest or smallest representable value, depending on which is closest.

  • 'wrap' — Overflows wrap to the range of representable values.

    When the values of data to be quantized lie outside the range of the largest and smallest representable numbers as specified by the data format properties, these values are wrapped back into that range using modular arithmetic relative to the smallest representable number.

This property only applies to fixed-point data type modes. This property becomes a read-only property when you set the DataMode property to float, double, or single.

Note

Floating-point numbers that extend beyond the dynamic range overflow to ±Inf.

Data Types: char | struct | cell

Data format of unitquantizer object. The interpretation of this property value depends on the value of the DataMode property.

DataMode Property ValueInterpreting the Format Property Values
fixed or ufixed

[wordlength fractionlength]

Specify the Format property value as a two-element row vector where the first element is the number of bits for the quantizer object word length and the second element is the number of bits for the quantizer object fraction length.

The word length can range from 2 to the limits of memory on your PC. The fraction length can range from 0 to one less than the word length.

float

[wordlength exponenetlength]

Specify the Format property value as a two-element row vector where the first element is the number of bits for the unitquantizer object word length and the second element is the number of bits for the unitquantizer object exponent length.

The word length can range from 2 to the limits of memory on your PC. The fraction length can range from 0 to 11.

double

[64 11]

The read-only Format property value automatically specifies the word length and exponent length.

single

[32 8]

The read-only Format property value automatically specifies the word length and exponent length.

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

Read-Only unitquantizer Object States

Read-only unitquantizer object states are updated when quantize is called. To reset these states, use reset.

Maximum value before quantization during a call to quantize(q,…) for unitquantizer object q, specified as a scalar. This value is the maximum value recorded over successive calls to quantize.

Example: max(q)

Example: q.max

Minimum value before quantization during a call to quantize(q,…) for unitquantizer object q, specified as a scalar. This value is the minimum value recorded over successive calls to quantize.

Example: min(q)

Example: q.min

Number of overflows during a call to quantize(q,…) for unitquantizer object q, specified as a scalar. This value accumulates over successive calls to quantize. An overflow is defined as a value that when quantized is outside the range of q.

Example: noverflows(q)

Example: q.noverflows

Number of underflows during a call to quantize(q,…) for unitquantizer object q. This value accumulates over successive calls to quantize. An underflow is defined as a number that is nonzero before it is quantized and zero after it is quantized.

Example: nunderflows(q)

Example: q.nunderflows

Number of quantization operations during a call to quantize(q,…) for unitquantizer object q. This value accumulates over successive calls to quantize.

Example: noperations(q)

Example: q.noperations

Object Functions

Examples

collapse all

Quantize a vector x using the unitquantizer object q.

x = (0.8:.1:1.2)';
q = unitquantizer([4 3]);
y = quantize(q,x);
z = [x y]
e = eps(q)
z =

    0.8000    0.7500
    0.9000    1.0000
    1.0000    1.0000
    1.1000    1.0000
    1.2000    1.0000


e =

    0.1250

quantize quantizes the elements of x except for numbers within eps of +1.

Version History

Introduced in R2008a