Main Content

fixpt_look1_func_plot

ルックアップ テーブルの固定小数点近似関数をプロットする

構文

fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
errworst = fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)

説明

fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
は、ルックアップ テーブルの近似関数と理想関数からの誤差をプロットします。

errworst = fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
は、ルックアップ テーブルの近似関数と理想関数からの誤差をプロットします。出力 errworst は最大絶対誤差です。

fixpt_look1_func_approx を使って xdataydata、つまり、ルックアップ テーブルのブレークポイントとテーブル データを生成できます。fixpt_look1_func_approx は理想関数を xdata のブレークポイントに適用して ydata を生成します。この方法が最も簡単な ydata の生成方法ですが、fixpt_look1_func_plot への入力として ydata には別の値を選択できます。ydata 用に異なる値を選択すると、場合によっては、最大絶対誤差が小さいルックアップ テーブルを作成することができます。

入力引数

xdata

ルックアップ テーブルのブレークポイントのベクトル。

ydata

ブレークポイントに理想関数を適用して得た値のベクトル。

func

ブレークポイントの近似に使用する x の関数。この式は一重引用符で囲みます。たとえば、'sin(2*pi*x)'

xmin

x の最小値。

xmax

x の最大値。

xdt

x のデータ型。

xscale

x 値のスケーリング。

ydt

y のデータ型。

yscale

y 値のスケーリング。

rndmeth

固定小数点の Simulink® ブロックでサポートされる丸め処理モード。

'Ceiling'

正の無限大方向の最も近い表記可能な数値に丸めます。

'Floor' (既定の設定)

負の無限大方向の最も近い表記可能な数値に丸めます。

'Nearest'

最も近くの表記可能な数値に丸めます。

'Toward Zero'

ゼロに近づく方向の最も近い表記可能な数値に丸めます。

fixpt_look1_func_approx によって生成されたデータ点を使用して、正弦関数の固定小数点近似をプロットします。

func = 'sin(2*pi*x)';
% Define the range over which to optimize breakpoints
xmin = 0;
xmax = 0.25;
% Define the data type and scaling for the inputs
xdt = ufix(16);
xscale = 2^-16;
% Define the data type and scaling for the outputs
ydt = sfix(16);
yscale = 2^-14;
% Specify the rounding method
rndmeth = 'Floor';
% Define the maximum acceptable error
errmax = 2^-10;
% Choose even, power-of-2 spacing for breakpoints
spacing = 'pow2';
% Generate data points for the lookup table
[xdata,ydata,errworst]=fixpt_look1_func_approx(func,...
 xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,[],spacing);
% Plot the sine function (ideal and fixed-point) & errors
fixpt_look1_func_plot(xdata,ydata,func,xmin,xmax,...
 xdt,xscale,ydt,yscale,rndmeth);

fixpt_look1_func_plot は生成されたデータ点を使って固定小数点正弦関数をプロットし、さらに、理想関数と固定小数点関数との間の誤差をプロットします。グラフには、最大絶対誤差と必要なデータ点の数も表示されます。ブレークポイントの位置では誤差がゼロになり、ブレークポイント間では、理想関数の曲線とブレークポイント間に引いた線との違いのために曲率の誤差が大きくなります。

このルックアップ テーブルでは、2^-11.3922 の最大絶対誤差を実現するためには 33 個のポイントが必要です。

バージョン履歴

R2006a より前に導入