フィルターのクリア

Get max, min and precision of a fi

19 ビュー (過去 30 日間)
Justin
Justin 2019 年 3 月 27 日
編集済み: Harry 2021 年 7 月 30 日
What is the easiest way to find the maximum or minimum value that a fi can take?
What is the easiest way to find the precision of a fi?

採用された回答

Jan
Jan 2019 年 3 月 27 日
編集済み: Jan 2019 年 3 月 28 日
a = fi(pi, true, 16, 12);
xi = intmax(a)
This is code taken from https://www.mathworks.com/help/fixedpoint/ref/intmax.html , which I found as first link by asking an internet search engine for "Matlab fi maximum value".
a = fi(pi, true, 16, 12);
xd = realmax(a)
  3 件のコメント
Jan
Jan 2019 年 3 月 28 日
I cannot test this, because I do not have the FI toolbox. But what about realmax?
Justin
Justin 2019 年 3 月 28 日
Yes, that looks good. found everything I need here:https://uk.mathworks.com/help/fixedpoint/data-type-operators-and-tools.html
upperbound and lowerbound (or range) and realmin get me what I want. Thanks for your help navigating the documentation!

サインインしてコメントする。

その他の回答 (2 件)

Justin
Justin 2019 年 3 月 27 日
I have answered my own question by creating the following function:
function info = fiInfo(inFi)
if inFi.Signed
info.max = (2^(inFi.WordLength - 1) - 1) / 2^inFi.FractionLength;
info.min = -2^((inFi.WordLength - 1) - inFi.FractionLength);
info.precision = 2^-inFi.FractionLength;
else
info.max = (2^inFi.WordLength - 1) / 2^inFi.FractionLength;
info.min = 0;
info.precision = 2^-inFi.FractionLength;
end
end
resulting in
>> a = fi(pi, true, 16, 12);
>> fiInfo(a)
ans =
struct with fields:
max: 7.9998
min: -8
precision: 2.4414e-04
or
>> a = fi(pi, false, 16, 12);
>> fiInfo(a)
ans =
struct with fields:
max: 15.9998
min: 0
precision: 2.4414e-04
This seems to be a lot of faffing to get at some basic info. Surely there is a better way?

Harry
Harry 2021 年 7 月 30 日
編集済み: Harry 2021 年 7 月 30 日
% A fixed-point object with no value, 18-bit word length, and 16-bit fraction length
a = fi([],1,18, 16)
a = [] DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16
% The easiest way to find the maximum or minimum value that a fi can represent is
range(a)
ans =
-2.0000 2.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16
% The easiest way to find the precision of a fi is
eps(a)
ans =
1.5259e-05 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16

カテゴリ

Help Center および File ExchangeFixed-Point Designer についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by