Main Content

fixpt_look1_func_approx

Optimize fixed-point approximation of nonlinear function by interpolating lookup table data points

Syntax

[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,nptsmax)
[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,[])
[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax)
[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydtydt,yscale,rndmeth,errmax,nptsmax,spacing)

描述

[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,nptsmax)
returns the optimal breakpoints of a lookup table, an ideal function applied to the breakpoints, and the worst-case approximation error. The lookup table satisfies the maximum acceptable error and maximum number of points that you specify.

[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,[])
returns the optimal breakpoints of a lookup table, an ideal function applied to the breakpoints, and the worst-case approximation error. The lookup table satisfies the maximum acceptable error that you specify.

[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax)
returns the optimal breakpoints of a lookup table, an ideal function applied to the breakpoints, and the worst-case approximation error. The lookup table satisfies the maximum number of points that you specify.

[xdata,ydata,errworst] = fixpt_look1_func_approx('func',...
xmin,xmax,xdt,xscale,ydtydt,yscale,rndmeth,errmax,nptsmax,spacing)
returns the optimal breakpoints of a lookup table, an ideal function applied to the breakpoints, and the worst-case approximation error. The lookup table satisfies the maximum acceptable error, maximum number of points, and breakpoint spacing that you specify.

In each case,fixpt_look1_func_approxinterpolates between lookup table data points to optimize the fixed-point approximation. The inputsxminandxmaxspecify the range over which to approximate the breakpoints. The inputsxdt,xscale,ydt,yscale, andrndmethfollow conventions used by fixed-point Simulink®blocks.

The inputserrmax,nptsmax, andspacingare optional. Of these inputs, you must specify at leasterrmaxornptsmax. If you omit one of those two inputs, you must use brackets,[], in place of the omitted input.fixpt_look1_func_approxignores that requirement for the lookup table.

If you do not specify spacing, and more than one spacing satisfieserrmaxandnptsmax,fixpt_look1_func_approxchooses in this order: power-of-2 spacing, even spacing, uneven spacing. This behavior applies when you specify botherrmaxandnptsmax, but not when you specify just one of the two.

Input Arguments

func

Function ofxfor which to approximate breakpoints. Enclose this expression in single quotes, for example,'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 blocks:

'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'

Round to the nearest representable number in the direction of zero.

errmax

Maximum acceptable error between the ideal function and the approximation given by the lookup table.

nptsmax

Maximum number of points for the lookup table.

spacing

Spacing of breakpoints for the lookup table:

'even' Even spacing
'pow2' Even, power-of-2 spacing
'unrestricted'(default) Uneven spacing
If you specify... The breakpoints of the lookup table...

errmaxandnptsmax

Meet both criteria, if possible.

Theerrmaxrequirement has higher priority thannptsmax. If the breakpoints cannot meet both criteria with the specified spacing,nptsmaxdoes not apply.

errmaxonly

Meet the error criteria, andfixpt_look1_func_approxreturns the fewest number of points.

nptsmaxonly

Meet the points criteria, andfixpt_look1_func_approxreturns the smallest worst-case error.

Output Arguments

xdata

Vector of breakpoints for the lookup table.

ydata

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

errworst

Worst-case error, which is the maximum absolute error between the ideal function and the approximation given by the lookup table.

Examples

Approximate a fixed-point sine function using a lookup table:

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'; % Create the lookup table [xdata,ydata,errworst] = fixpt_look1_func_approx(func,... xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,[],spacing);
Introduced before R2006a