Products & Services Solutions Academia Support User Community Company

Learn more about Fixed-Point Toolbox   

fi - Construct fixed-point numeric object

Syntax

a = fi
a = fi(v)
a = fi(v,s)
a = fi(v,s,w)
a = fi(v,s,w,f)
a = fi(v,s,w,slope,bias)
a = fi(v,s,w,slopeadjustmentfactor,fixedexponent,bias)
a = fi(v,T)
a = fi(v,F)
b = fi(a,F)
a = fi(v,T,F)
a = fi(v,s,F)
a = fi(v,s,w,F)
a = fi(v,s,w,f,F)
a = fi(v,s,w,slope,bias,F)
a = fi(v,s,w,slopeadjustmentfactor,fixedexponent,bias,F)
a = fi(...'PropertyName',PropertyValue...)
a = fi('PropertyName',PropertyValue...)

Description

You can use the fi constructor function in the following ways:

The fi object has the following three general types of properties:

Data Properties

The data properties of a fi object are always writable.

These properties are described in detail in fi Object Properties.

fimath Properties

When you create a fi object and specify fimath object properties in the fi constructor, a fimath object is created as a property of the fi object. If you do not specify any fimath properties in the fi constructor, the resulting fi object associates itself with the global fimath. See Working with the Global fimath for more information.

The following fimath properties are, by transitivity, also properties of a fi object. The properties of the fimath object listed below are always writable.

These properties are described in detail in fimath Object Properties.

numerictype Properties

When you create a fi object, a numerictype object is also automatically created as a property of the fi object.

numerictype — Object containing all the data type information of a fi object, Simulink® signal or model parameter

The following numerictype properties are, by transitivity, also properties of a fi object. The properties of the numerictype object become read only after you create the fi object. However, you can create a copy of a fi object with new values specified for the numerictype properties.

For further details on these properties, see numerictype Object Properties.

Examples

Example 1

For example, the following creates a signed fi object with a value of pi, a word length of 8 bits, and a fraction length of 3 bits:

a = fi(pi, 1, 8, 3) 

a =
 
    3.1250

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 3

Example 2

The value v can also be an array:

a = fi((magic(3)/10), 1, 16, 12) 

a =
 
    0.8000    0.1001    0.6001
    0.3000    0.5000    0.7000
    0.3999    0.8999    0.2000

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

Example 3

If you omit the argument f, it is set automatically to the best precision possible:

 a = fi(pi, 1, 8) 

a =
 
    3.1563

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 5

Example 4

If you omit w and f, they are set automatically to 16 bits and the best precision possible, respectively:

a = fi(pi, 1) 

a =
 
    3.1416

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

Example 5

You can use property name/property value pairs to set fi properties when you create the object:

a = fi(pi, 'roundmode', 'floor', 'overflowmode', 'wrap') 

a =
    3.1415

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

             RoundMode: floor
          OverflowMode: wrap
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128
         CastBeforeSum: true

Example 6

You can remove an attached fimath object from a fi object at any time using the following syntax:

a = fi(pi, 'roundmode', 'floor', 'overflowmode', 'wrap')
a.fimath = []

a =
    3.1415

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

             RoundMode: floor
          OverflowMode: wrap
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128
         CastBeforeSum: true
a =
    3.1415

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

fi object a is now associated with the global fimath. To reassign it its own fimath object, use dot notation:

a.ProductMode = 'KeepLSB'

a =
    3.1415

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

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: KeepLSB
     ProductWordLength: 32
               SumMode: FullPrecision
      MaxSumWordLength: 128
         CastBeforeSum: true

fi object a now has its own attached fimath object with a ProductMode of KeepLSB. The values of the remaining fimath object properties are inherited from the current global fimath.

See Also

fimath, fipref, isfimathlocal, numerictype, quantizer, sfi, ufi

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS