Fixed-Point Blockset    

3. Automatic Scaling

Using the automatic scaling procedure, you can easily maximize the precision of the output data type while spanning the full simulation range. For a complex model, the absence of such a procedure can make achieving this goal tedious and time consuming.

Perform automatic scaling for the Controller block. This block is a subsystem representing software running on the target, and requires optimization.

  1. Turn off the data type override by setting Data type override in the Fixed-Point Settings interface to Use local settings. Each subsystem in the model now follows its own independent setting for this parameter.

  1. Select the Controller subsystem in the Select current system parameter of the interface.
  2. Set the Safety margin parameter in the interface to 20. This sets the scaling so that the largest simulation value seen is at least 20% smaller than the maximum value allowed. The Safety margin parameter value multiplies the "raw" simulation values by a factor of 1.2. Setting this parameter to a value greater than 1 decreases the likelihood that an overflow will occur when fixed-point data types are being used.
  1. Due to the nonlinear effects of quantization, a fixed-point simulation will produce results that are different from an idealized, doubles-based simulation. Signals in a fixed-point simulation may cover a larger or smaller range than in a doubles-based simulation. If the range increases enough, overflows or saturations could occur. A safety margin decreases the likelihood of this happening, but it may also decrease the precision of the simulation.

  1. Run the autofixexp M-file script by clicking the Autoscale Blocks button. This script automatically changes the scaling on all fixed-point blocks that do not have their scaling locked, and that have their output data type specified as a generalized fixed-point number. This script uses the minimum and maximum data logged from the previous simulation to change each block's scaling such that the precision is maximized while the full range of simulation values is spanned for each block.
  2. Run the simulation by clicking the Run button. This simulation will use the new scaling set in Step 4.
  3. Launch the Plot System interface and plot the plant output signal. The resulting plot is shown below.

You can produce a close-up of a portion of the plot by clicking at the upper left of the region you want to expand, and dragging the pointer to the lower right while pressing the mouse button. When you then release the mouse button, you produce the plot below.

Note that a steady state has been achieved, but a small limit cycle is present in the steady state due to poor A/D design.


  2. Data Type Override Tutorial: Producing Lookup Table Data