计算斜率和偏置
斜率偏置定标概述
使用斜率偏置定标时,您必须指定数字的斜率和偏置。斜率偏置定标数的真实值可以表示为:
计算斜率和偏置
从所需的端点、符号性和字长开始。
lower_bound = 999; upper_bound = 1000; is_signed = true; word_length = 16;
要查找具有指定字长和符号性的 fi
对象的范围,请使用 range
函数。
[Q_min, Q_max] = range(fi([], is_signed, word_length, 0));
要查找斜率和偏置,请求解方程组:
lower_bound = slope * Q_min + bias
upper_bound = slope * Q_max + bias
以矩阵形式重写这些方程。
求解斜率和偏置。
A = double ([Q_min, 1; Q_max, 1]); b = double ([lower_bound; upper_bound]); x = A\b; format long g
要查找斜率或精度,请调用斜率偏置向量 x
的第一个元素。
slope = x(1)
slope = 1.52590218966964e-05
要查找偏置,请调用向量 x
的第二个元素。
bias = x(2)
bias = 999.500007629511
创建一个具有斜率偏置定标的 numerictype
对象。
T = numerictype(is_signed, word_length, slope, bias)
T = DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 1.5259021896696368e-5 Bias: 999.500007629511
创建一个 numerictype
为 T
的 fi
对象。
a = fi(999.255, T)
a = 999.254993514916 DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 1.5259021896696368e-5 Bias: 999.500007629511
通过查找 a
的范围,验证您创建的 fi
对象是否具有正确的设定。
range(a)
ans = 999 1000 DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 1.5259021896696368e-5 Bias: 999.500007629511