Documentation

fixpt_look1_func_plot

Plot fixed-point approximation function for lookup table

Syntax

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)

Description

fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
plots a lookup table approximation function and the error from the ideal function.

errworst= fixpt_look1_func_plot(xdata,ydata,'func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
plots a lookup table approximation function and the error from the ideal function. The outputerrworstis the maximum absolute error.

You can usefixpt_look1_func_approxto generatexdataydata,分别为查找表的断点和表数据。fixpt_look1_func_approxapplies the ideal function to the breakpoints inxdatato produceydata. While this method is the easiest way to generateydata, you can choose other values forydataas input forfixpt_look1_func_plot. Choosing different values forydatacan, in some cases, produce a lookup table with a smaller maximum absolute error.

Input Arguments

xdata

Vector of breakpoints for the lookup table.

ydata

Vector of values from applying the ideal function to the breakpoints.

func

功能x为此近似断点。将此表达式包装在单引号中'sin(2*pi*x)'.

xmin

Minimum value ofx.

xmax

Maximum value ofx.

xdt

Data type ofx.

xscale

Scaling for thexvalues.

ydt

Data type ofy.

yscale

Scaling for theyvalues.

rndmeth

Rounding mode supported by fixed-point Simulink®块:

'Ceiling'

Round to the nearest representable number in the direction of positive infinity.

'Floor'(default)

Round to the nearest representable number in the direction of negative infinity.

'Nearest'

Round to the nearest representable number.

'Toward Zero'

在零方向上圆形到最近的代表数。

Examples

Plot a fixed-point approximation of the sine function using data points generated byfixpt_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_plotplots the fixed-point sine function, using generated data points, and plots the error between the ideal function and the fixed-point function. The maximum absolute error and the number of points required appear on the plot. The error drops to zero at a breakpoint, but increases between breakpoints due to curvature differences between the ideal function and the line drawn between breakpoints.

The lookup table requires 33 points to achieve a maximum absolute error of2^-11.3922.

在R2006a之前引入

Was this topic helpful?