Also lets say if i place output min and max in the signal attribute would that control the product multiplication output?
Data Type Conversion in simulink
9 views (last 30 days)
Show older comments
I have a question about Data Type conversion used in simulink. What is the impact of settings
- output data type fixdt(1,16,4) and,
- integer rounding mode : simplest
on my simulation in simulink and if I convert it to C code using coder for Arm Cortex.
Answers (2)
Benjamin Thompson
on 28 Jun 2022
Type "doc fixedt" in MATLAB to get a detailed explanation of the fixed point data types. If I right click on the data type conversion block in Simulink and choose the Help, I can find this explanation for the "simplest" rounding method:
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Andy Bartlett
on 29 Jun 2022
To explore the impact of
- output data type specification
- rounding mode specification
- integer overflow handling specification
open the model
fxpdemo_dbl2fix
simulate the model and look at the Scope that compares the input in double data type to the output in the specified types.
The input goes from -10 to 10.
So if the specified data type has maximum representable value less than 10 or minimum representable value greater than -10, then overflows will occur. On the block dialog if you open data type assistant and then also click the link "Fixed Point Details" the min and max representable values of the type will be shown.
Run two simulations back to back, one with saturation on and one with saturation off to see how overflow are handled. The handling of overflows will be dramatically different.
If the scaling is coarse enough you'll also see a staircase shape in the output plot. The greater the fraction lenght the finer the staircase will be. The smaller fraction length the higher the tread height of each step will be.
Depending on rounding mode, the staircase will be below, above, or "in the middle" of the double input's plot.
Simulation and code generation are design to be in very, very close agreement in behavior. If all the signals in an operation are fixed-point, then there should be bit true agreement between simulation and code generation. If floating-point is involved idividual operations may see some eps of difference, but Simulink and Coders seek to avoid that difference as much as possible and often get bit true agreement there too.
Choice of data type, rounding mode, and saturation affect the size and speed of generated C code. I suggest you do some experiments to see the impact. Simplest rounding is designed to give the leanest code of all the rounding choices.
HTH
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!