Wrap/Saturate on overflow

32 views (last 30 days)
Giuseppe Galioto
Giuseppe Galioto on 21 Dec 2019
Commented: Walter Roberson on 13 Jan 2020
Hi there,
I'm trying to simulate a control algorithm with the fixed point tool. When I apply the fixed point data types and try to simulate the model, I get many wrap/saturate on overflow warnings. What's the right method to avoid overflows and fix them?
Thanks in advance
  1 Comment
Walter Roberson
Walter Roberson on 21 Dec 2019
Edited: Walter Roberson on 3 Jan 2020
Typically there are two ways to approach this:
  1. Increase the permitted range for your fixed point objects, so that they do not overflow; Or
  2. Re-examine the mathematics of your equations to figure out why you are getting overflows, and repair the algorithm
It is not uncommon that you need to do both of those -- not uncommon that when you examine your code in detail that you find some mistake in it, but that you also find some reason why it is reasonable for the control values to need to go outside the range you have permitted.

Sign in to comment.

Answers (1)

MathWorks Fixed Point Team
I think it’s important to understand if these overflows are a concern in the context of the numerical behavior of your control algorithm i.e. Is the fixed point response within a reasonable tolerance compared to the floating point response?
If the answer is no, you can try two quick things:
  1. Increase the word length choice in the Fixed-Point Tool to check if greater precision improves the numerical behavior or
  2. Specify a larger safety margin that will accommodate for a larger operating range as Walter suggested (see image below)
It might help to check out these how to videos on Fixed-Point Tool:
Walter Roberson
Walter Roberson on 13 Jan 2020
Thanks, Evangelos, that is useful.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!