Main Content

quantize

Quantize fi values using fixed.Quantizer object

quantize and fixed.Quantizer are not recommended. Use cast, zeros, ones, eye, or subsasgn instead. For more information, see Compatibility Considerations.

Description

example

y = quantize(q,x) uses the fixed.Quantizer object q to quantize x. x can be any fixed-point fi number except a Boolean value.

  • If x is a scaled double, the data of the output y will be the same as the data of the input x. Only the fixed-point settings of y will change.

  • When x is a double or single, then y = x. This functionality allows you to share the same code for both floating-point data types and fixed-point fi data types when quantizers are present.

Examples

collapse all

Use fixed.Quantizer to reduce the word length that results from adding two fixed-point numbers.

q = fixed.Quantizer
x1 = fi(0.1,1,16,15);
x2 = fi(0.8,1,16,15);
y  = quantize(q,x1+x2)
q = 

  fixed.Quantizer with properties:

                   Signed: 1
               WordLength: 16
    SlopeAdjustmentFactor: 1
            FixedExponent: -15
                     Bias: 0
               Signedness: 'Signed'
                    Slope: 3.0518e-05
           FractionLength: 15
           RoundingMethod: 'Floor'
           OverflowAction: 'Wrap'


y = 

    0.9000

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 15

Use a fixed.Quantizer object to change a binary-point scaled fixed-point fi to a slope-bias scaled fixed-point fi.

x = fi(pi,1,16,13)
q = fixed.Quantizer(numerictype(1,7,1.6,0.2),'Round','Saturate')
y = quantize(q,x)
x = 

    3.1416

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13

q = 

  fixed.Quantizer with properties:

                   Signed: 1
               WordLength: 7
    SlopeAdjustmentFactor: 1.6000
            FixedExponent: 0
                     Bias: 0.2000
               Signedness: 'Signed'
                    Slope: 1.6000
           FractionLength: 0
           RoundingMethod: 'Round'
           OverflowAction: 'Saturate'


y = 

    3.4000

          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 7
                 Slope: 1.6
                  Bias: 0.2

Input Arguments

collapse all

Data type properties to use for quantization, specified as a fixed.Quantizer object.

Data to quantize, specified as a fi object.

Data Types: fi

Compatibility Considerations

expand all

Not recommended starting in R2013a

Introduced in R2011b