MATLAB: Does fixed-point signal multiplication give different output depending on the datatype

accuracyfixedfixed-pointmultiplicationpointprecisionresultsimulink

I have a Simulink model where a constant value of "-500" (stored as a "fixdt(1,16,0.1,-400)" ) is multiplied by "-1" via a product block in 3 different ways:
  1. By a constant value of "-1" stored as a fixed-point integer "fixdt(1,16,0.1,-400)".
  2. By a constant value of "-1" stored as an int8.
  3. By a constant value of "-1" stored as a single.
For each of these 3 cases I obtain a slightly different precision in the result.
Why does the datatype of "-1" affect the result of the product block?

Best Answer

The designed behavior for product and other operations applied to* fixed-point signals *with non-zero bias is to do a conversion to a more "operation friendly" type to do the operation. This results in more efficient code (generally), but as a side effect it could also lead to less accurate results.
The developers are working on improving the behavior of non-zero bias multiplications in future releases.
For the time being, please consider a few tips to obtain more accurate results:
  • Ensure that the slope of the fixed-point datatype can be represented as a power of 2 (e.g. 0.125=2^(-3)).
  • Try to use a bias equal to 0 in the fixed-point datatype.