Drop msb of fi object, producing a new fi object

조회 수: 3 (최근 30일)
Mike
Mike 2024년 1월 26일
답변: Shivansh 2024년 6월 22일
This seems to do what I want.
Is there anything to go wrong with this approach?
Seems like I have dropped the msb from the number, changing it from a 5.2 fi numbe to a 4.2 fi number
>> a = fi(3,1,5,2);
>> b = fi(a,1,4,2);
>> a.bin
ans =
01100
>> b.bin
ans =
0111

답변 (1개)

Shivansh
Shivansh 2024년 6월 22일
Hi Mike,
I think you have misinterpreted the 'fi' function and its application.
The 'fi' function is used to represent the numbers in fixed point by fixing the word length(or even fraction length) allowed for the number.
In the above mentioned example, fi(3,1,5,2) means you are storing 3 in a signed fixed point representation with a world length of 5 and fraction length of 2.
You can understand this better using the below code snippet:
a = fi(3,1,5,2)
a =
3 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 5 FractionLength: 2
Now, moving on the next example. You have reduced the word length for 'a' by keeping the same fraction length. Now, you can't represent 3 using 2 bits which will result in change in the value.
b = fi(a,1,4,2)
b =
1.7500 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 4 FractionLength: 2
The result stored in b is the maximum possible value for a world length of 4 with franction length of 2.
For the results using the 'bin' function, they represent the stored integer form of these fixed point numbers in the binary form. You can verify it by first evaluating them to base 10 integer and then dividing them by 2^fractionlength. This will get you the same number represented in the fixed point representation.
You can refer to the following documentation for more information on the 'fi' representation:
I hope it helps!

카테고리

Help CenterFile Exchange에서 Fixed Point에 대해 자세히 알아보기

제품


릴리스

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by