Matlab Fixed Point - Suggesting Fraction length larger than Word Length?

22 views (last 30 days)
I am confused by how matlab is suggesting a Fixed point number of sfix32_En44. This means it has a word length of 32bits but a fraction length of 44. With standard Binary Point this is impossible. The fraction length is always less than the word length.
Is matlab trying to tell me my word size is not big enough?
  2 Comments
Walter Roberson
Walter Roberson on 14 Oct 2011
It is a _suggestion_ so you could override it (and take the precision hits involved). But yeah, I think my interpretation would be the same as yours, that it thinks you need a wider word.
I'm going by principles and documentation here, not experience.

Sign in to comment.

Accepted Answer

Rick Rosson
Rick Rosson on 14 Oct 2011
The fraction length does not have to be shorter than the word length if you allow for (implicit) leading zeros. So if it is suggesting a 32 bit word length with 44 bits fraction length, then that implies that with one bit for the sign, all 31 of the remaining bits are fraction; and in addition, there must be 13 leading zeros to the right of the binary point prior to the 31 significant binary digits.
So the word consists of 1 sign bit followed by the 31 significant binary digits, and 13 implicit leading zeros (or ones if the sign bit is negative) between the binary point and the first significant binary digit.
HTH.
Rick
  1 Comment
Walter Roberson
Walter Roberson on 14 Oct 2011
Rick, this is a point I cannot seem to find hinted at in the documentation. There appears to be no reference page for fixdt(), just the user guide. I cannot seem to find anything in the user guide that hints that the binary point might be to the "left" of the word completely.
I can see how the usage you have given would have some good uses, but one has to read the documentation fairly perversely to see that it doesn't actually forbid this situation.
As an analogy, this would be like noticing that an obscure page in the (non-normative!) user-guide talks about indexing without explicitly forbidding using negative numbers as indices, and extrapolating a whole range of behaviors from that.
What's with the Simulink Fixed-Point Reference pages showing only 4 functions, only one of which has anything at all to do with the construction or usage of fixed point numbers?
http://www.mathworks.com/help/toolbox/fixpoint/ref/brxj5qn.html

Sign in to comment.

More Answers (2)

Tom Bryan
Tom Bryan on 15 Oct 2011
Rick Rosson is right. Here is an example.
FractionLength defines the scaling of the StoredInteger value and relates to the RealWorldValue like this:
RealWorldValue = StoredInteger * 2 ^ -FractionLength
It is the binary equivalent of scientific notation. The WordLength limits the values the StoredInteger can attain, but does not limit the values FractionLength can attain.
For example, let
WordLength = 8
Signed = true (Signed)
FractionLength = 10
StoredInteger = 5
Then
RealWorldValue = 5 * 2 ^ -10 = 0.0048828125
In other words:
0.0048828125 (decimal) = x.xx00000101 (binary)
where "x" is a placeholder for implicit zeros.
You can experiment with fixed-point definitions using the fi object. The above example defined as a fi object is:
a = fi(0.0048828125, true, 8, 10)
Which returns
a =
0.0048828125
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 10
To see the stored integer value, do
a.int
Which returns
ans =
5
To see the binary representation of the StoredInteger, do
a.bin
Which returns
ans =
00000101
The fixed-point definitions are described in the documentation here:
Simulink Fixed-Point > User's Guide > Data Types and Scaling > Fixed-Point Numbers http://www.mathworks.com/help/toolbox/fixpoint/ug/f20705.html
  2 Comments
Walter Roberson
Walter Roberson on 15 Oct 2011
That is a User's Guide, not a reference guide; and I have not been able to find anything in there that hints that the binary point might be to the left of the stored bits. It is not forbidden by the table of values, but it is a surprise facility.
I do not see anything in that User Guide that would forbid fl from being negative in a fixdt() call. Is negative fl allowed?
satheesh appukuttan
satheesh appukuttan on 26 Feb 2020
http://www.mathworks.com/help/toolbox/fixpoint/ug/f20705.html This link doesnt exist. Can you please help me to find this page ? I am trying to understand how FL can be more than WL in fixed point representation.

Sign in to comment.


Rick Rosson
Rick Rosson on 15 Oct 2011
  2 Comments
Walter Roberson
Walter Roberson on 15 Oct 2011
Thank you.
If you google site:mathworks.com fixdt
then the first of those links does not appear within the first 20 pages of results. It does, however, I see now, appear as the first hit if one searches the documentation directly on mathworks.com
The reference page describes, for the format fixdt(Signed, WordLength, FractionLength), the permitted values for the Signed parameters, but does not discuss the type or permitted range for WordLength or FractionLength .
I still have not found anything in the documentation that indicates that implicit leading 0 bits are permitted, other than the fact that the chart in the User's Guide does not specifically forbid them. On the other hand, the chart in the User's Guide also does not specifically forbid the values from being negative or having fractional values -- e.g., log2(123) as a fraction length would appear to be as valid as using a fraction length larger than the word length.
To be clear: I am not at all saying that the toolbox is not implemented as Rick and Tom have indicated: I am pointing out that the documentation appears to say nothing about this. Users would have no more reason to expect this than they would to expect that log2(123) would be a valid fraction length.
Rick Rosson
Rick Rosson on 16 Oct 2011
If you opened a text book and came across a formula containing the expression a*2^x, would you have any reason to assume that x must be a positive number?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!