Main Content

Data Type Override Preferences Using fipref

Overriding the Data Type of fi Objects

Use the fipref DataTypeOverride property to override fi objects with singles, doubles, or scaled doubles. Data type override only occurs when the fi constructor function is called. Objects that are created while data type override is on have the overridden data type. They maintain that data type when data type override is later turned off. To obtain an object with a data type that is not the override data type, you must create an object when data type override is off:

p = fipref('DataTypeOverride', 'TrueDoubles')
 
p =
 
         NumberDisplay: 'RealWorldValue'
    NumericTypeDisplay: 'full'
         FimathDisplay: 'full'
           LoggingMode: 'Off'
      DataTypeOverride: 'TrueDoubles'

a = fi(pi)
 
a =
 
    3.1416

          DataTypeMode: Double

p = fipref('DataTypeOverride', 'ForceOff')
 
p =
 
         NumberDisplay: 'RealWorldValue'
    NumericTypeDisplay: 'full'
         FimathDisplay: 'full'
           LoggingMode: 'Off'
      DataTypeOverride: 'ForceOff'

a
 
a =
 
    3.1416

          DataTypeMode: Double

b = fi(pi)
 
b =
 
    3.1416

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

Tip

To reset the fipref object to its default values use reset(fipref) or reset(p), where p is a fipref object. This is useful to ensure that data type override and logging are off.

Data Type Override for Fixed-Point Scaling

Choosing the scaling for the fixed-point variables in your algorithms can be difficult. In Fixed-Point Designer™ software, you can use a combination of data type override and min/max logging to help you discover the numerical ranges that your fixed-point data types need to cover. These ranges dictate the appropriate scalings for your fixed-point data types. In general, the procedure is

  1. Implement your algorithm using fixed-point fi objects, using initial “best guesses” for word lengths and scalings.

  2. Set the fipref DataTypeOverride property to ScaledDoubles, TrueSingles, or TrueDoubles.

  3. Set the fipref LoggingMode property to on.

  4. Use the maxlog and minlog functions to log the maximum and minimum values achieved by the variables in your algorithm in floating-point mode.

  5. Set the fipref DataTypeOverride property to ForceOff.

  6. Use the information obtained in step 4 to set the fixed-point scaling for each variable in your algorithm such that the full numerical range of each variable is representable by its data type and scaling.

A detailed example of this process is shown in the Fixed-Point Designer Set Data Types Using Min/Max Instrumentation example.