Matlab Fixed Point - Suggesting Fraction length larger than Word Length?
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 14 Okt. 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.
Rick Rosson
am 14 Okt. 2011
That is not correct. Please see my answer below.
Akzeptierte Antwort
Weitere Antworten (3)
Tom Bryan
am 15 Okt. 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 Kommentare
Walter Roberson
am 15 Okt. 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
am 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.
Rick Rosson
am 15 Okt. 2011
1 Stimme
Hi Walter,
Please check the following links:
- http://www.mathworks.com/help/toolbox/simulink/slref/fixdt.html
- http://www.mathworks.com/help/toolbox/fixedpoint/ref/f20333.html
HTH
Rick
2 Kommentare
Walter Roberson
am 15 Okt. 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
am 16 Okt. 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?
Riccardo
am 10 Dez. 2025
0 Stimmen
I found this function that works well:
Kategorien
Mehr zu Quantization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!