Real World Value Vs Stored Integer In Simulink ( Fixed Point Number Debunked )

Relationship Between Stored Integer Value and Real-World Value

The binary encoding of variables is only an approximation of an arbitrarily precise real-world value. Therefore, the limitations of the binary representation automatically introduce limitations on the precision of the value.
In BinaryPoint scaling, the relationship between the stored integer value and the real-world value is
There is also SlopeBias scaling, which has the relationship
where
and





https://blogs.mathworks.com/simulink/2008/12/14/representing-numbers-integers-and-fixed-point/

Fixed-Point Numbers: Binary Point
Fixed-point numbers use the same integer representations, but they assign a different meaning to the bits.  We can introduce the idea of fractional bits and a binary point.  With integers, your smallest spacing between numbers is 1.  If we decide to let a bit represent ½ we now have closer spacing in our system.  The number of bits to the right of the binary point is the fraction length.  Using our toy three-bit system, we can assign a fixed binary point after the first bit.    This is then a three-bit system with a fraction length of two.  The values of the bits are now 1, ½, and ¼.  A number 0.10 equals ½.  This three-bit fixed-point system can represent the following range of numbers:
20
2-1
2-2
Value
0
0
0
= 0
0
0
1
= ¼
0
1
0
= ½
0
1
1
= ¾
1
0
0
= 1
1
0
1
= 1 ¼
1
1
0
= 1 ½
1
1
1
= 1 ¾

This allows more precision over a smaller range of numbers.  The location of the binary point determines the range of the numbers and the spacing between them.
What if we wanted to move the binary point to be after the 5th bit in our three-bit system?  In this case, the fraction length would be -2.  Instead of fractional bits, the least significant bit equal to 4.  In a system like this, the bits would be 16, 8, and 4.
24
23
22
Value
0
0
0
= 0
0
0
1
= 4
0
1
0
= 8
0
1
1
= 12
1
0
0
= 16
1
0
1
= 20
1
1
0
= 24
1
1
1
= 28

This representation gives us a larger range, but greater spacing between bits.  Imagine an engine controller that has to represent values between 0 and 10,000 RPMs.  Unsigned eight-bit integers have a maximum value of 255.  A sixteen-bit unsigned int can hold values over the range 0 to 65535.  If we choose an eight-bit number with fraction length of -6, we could store these numbers using only 8 bits.  The range of such a system is 0 to 16320 with a spacing of 64.
Fixed-Point Number: Slope and Bias
A fixed-point number system can also encode the real-world value using an arbitrary slope and bias.  Regular integers have a slope of 1 and a bias of 0.  When using slope and bias, the binary representation stores an integer that is used to calculate the real-world value.  The calculation is the ever familiar line equation, y = m ∙ x + b.  This representation shifts the range and scaling of the numbers represented.  Using our toy three-bit integers, we can define a slope of 1.25 and a bias of 20. The bits still represent 4, 2, and 1, but the value computed is 1.25 ∙ x + 20.
22
21
20
Integer
Real World Value
0
0
0
= 0
1.25 ∙ 0 + 20 = 20
0
0
1
= 1
1.25 ∙ 1 + 20 = 21.25
0
1
0
= 2
1.25 ∙ 2 + 20 = 22.50
0
1
1
= 3
1.25 ∙ 3 + 20 = 23.75
1
0
0
= 4
1.25 ∙ 4 + 20 = 25.00
1
0
1
= 5
1.25 ∙ 5 + 20 = 26.25
1
1
0
= 6
1.25 ∙ 6 + 20 = 27.50
1
1
1
= 7
1.25 ∙ 7 + 20 = 27.75

There are more intricacies to fixed-point representations, and the Simulink Fixed-Point documentation gives a great overview.
Challenges of Working in Fixed-Point
The challenges of using fixed-point add complexity to embedded system development.  You have to make sure you have the correct scaling and bias for your application in order to avoid overflow or underflow.



https://www.embedded.com/discussion/other/4024639/Fixed-point-math-in-C


Comments

Popular posts from this blog

What is .TLC (Target Language Compiler) and MEX file in Matlab Simulink

Simulink & Matlab Interview Question and Answers For Automotive , Aerospace etc.