Clear Filters
Clear Filters

Overflows when I use Fixed-Point Tool

3 views (last 30 days)

Accepted Answer

Andy Bartlett
Andy Bartlett on 28 Mar 2023
Edited: Andy Bartlett on 28 Mar 2023
Two Kinds of Overflows
Fixed-Point Tool presents two types of overflows, Actual and Potential.
Actual Overflows
Actual overflows occurred during a PREVIOUS instrumentated simulation of the model.
These will be shown in the Result Details pane above the Histogram.
In your image, look on the right for the red triangle with the text "Overflows (# of wraps): 32353"
During the prior simulation, the selected block overflowed 32353 times.
Potential Overflows
Potential overflows compare collected range information to a potential NEW specified data type to be used in a FUTURE simulation.
This range information includes simulation minimum, simulation maximum, and counts in power of 2 histogram bins.
For a histogram bar, if the interval covered by that bar contains a value above the new specified data types maximum representable value, the bar will be painted red and marked as positive overflows. If the interval covered by that bar contains a value below the new specified data types minimum representable value, the bar will be painted red and marked as negative overflows.
Note, that the ranges were collected from a simulation that used the compiled data type. Potential overflows can only "appear" if the NEW specified data type has a representable max or min closer to zero than the compiled data type used in the previous simulations. From that it naturally follows that if the "NEW" specified data type is identical to the compiled data type, then every collected range value will be in range of the NEW data type, so the histogram will show NO potential overflows.
For your image, the compiled data type and the specified data type are the same, hence the histogram does not show any Potential Overflows.
"Heisenberg Uncertainty Principle" and Safety Margin
The presence or abscence of potential overflows does not fully predict what will happen if those types are specified on a model and the model is re-simulated. Think of it as being like the "Heisenberg Uncertainty Principle." Changing the data types is expected to change calculations at least slightly.
For example, suppose the previous simulation was in doubles and part of the model summed five signals each with value -25.5. So the sum will have value -127.5. If the new specified data type for the signals was int8, then Potential Overflows would not be shown. But in int8 if rounded toward floor, the signal values -25.5 become -26. Summing five of those gives a total of -130 which would overflow int8 even though potential overflows were not predicted.
To avoid this "Heisenberg Uncertainty Principle" issue, it is good to use a safety margin. This will cause a data type with a slightly bigger range to be used, such as fixdt(1,8,-1) which goes from -256 to +254 and would not overflow.
Suggestion Regarding Your Model
I'm guessing the block in your model showing Actual Overflows was a Sine. Naturally, a Sine can produce values from -1 to +1. But the compiled data type used for simulation, fixdt(0,16,16), can only represent values from 0 to slightly under +1. So during simulation, the angle input to the Sine should have produced an ideal output equal to +1 or negative around 32353 times. Since these ideal values overflow the compiled data type of fixdt(0,16,16) these cases drove the 32353 Actual Overflow counts. But the collected ranges are from the values in the compiled data type fixdt(0,16,16) which can only be from 0 to 0.999984741210938.
I suggest you rerun the simulation to collect ranges, but this time turn on Data Type Override to quickly force all data types to be double. This option can be found by right clicking the left Collect Ranges simulation button on the Fixed-Point Tool toolstrip. Based on the ranges collected in the doubles override simulation, you should see the potential overflows. Based on that NEW data types can be set to cover that range, plus a safety margin.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!