Fixed-Point Blockset | ![]() ![]() |
Optimize for a fixed-point function, the x values, or breakpoints, that are generated for a lookup table
Syntax
[xdata,ydata,errworst]=fixpt_look1_func_approx('funcstr',...xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax)
[xdata,ydata,errworst]=fixpt_look1_func_approx('funcstr',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax)
[xdata,ydata,errworst]=fixpt_look1_func_approx('funcstr',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,nptsmax)
[xdata,ydata,errworst]=fixpt_look1_func_approx('funcstr',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,nptsmax,spacing)
Description
fixpt_look1_func_approx('funcstr',xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax)
optimizes the breakpoints of a lookup table over a specified range. The lookup table satisfies the maximum acceptable error, maximum number of points, and spacing requirements given by the optional parameters. The breakpoints refer to the x values of the lookup table. The command
[xdata,ydata,errworst]=fixpt_look1_func_approx('funcstr',...
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax)
returns the X and Y coordinates of the lookup table as vectors xdata
and ydata
, respectively. It also returns the maximum absolute error of the lookup table as a variable errworst
.
The fixed-point approximation is found by interpolating between the lookup table data points. The required input parameters are as follows.
xmin
and xmax
specify the range over which the breakpoints are approximated.
xdt
, xscale
, ydt
, yscale
, and rndmeth
follow conventions used by the Fixed-Point Blockset.
rndmeth
has a default value listed in the input table.
In addition to the required parameters, there are three optional inputs, as follows.
Input |
Value |
errmax |
Maximum acceptable error |
nptsmax |
Maximum number of points |
errworst |
Spacing: 'even' , 'pow2' (even power of 2), 'unrestricted' (default value) |
Of these, you must use at least one of the parameters errmax
and nptsmax
. If you omit one of these, use brackets, []
, in place of the omitted parameter. The function will then ignore that requirement for the lookup table.
The outputs of the function are as follows.
Criteria For Optimizing the Breakpoints: errmax, nptsmax, and spacing
The approximation produced from the lookup table must satisfy the requirements for the maximum acceptable error, errmax
, the maximum number of points, nptsmax
, and the spacing, spacing
. The requirements are
errmax
.
nptsmax
.
Modes for errmax and nptsmax
errmax
parameter is given priority, and nptsmax
is ignored, if both criteria cannot be met with the specified spacing.
Modes for Spacing
If no spacing is specified, and more than one spacing method meets the requirements given by errmax
and nptsmax
, power of 2 spacing is chosen over even spacing, which in turn is chosen over uneven spacing. This case occurs when the errmax
and nptsmax
are both specified, but typically does not occur when only one is specified:
unrestricted
is entered, the function chooses the spacing that provides the best optimization.
even
is entered, the function chooses an evenly spaced set of points, including the pow2
spacing.
pow2
spacing is entered, the function chooses an even power of 2 spaced set of points.
Note The global optimum may not be found. The worst case error can depend on fixed-point calculations, which are highly nonlinear. Furthermore, the optimization approach is heuristic. |
The spacing you choose depends on the parameters you want to optimize: execution speed, function approximation error, ROM usage, and RAM usage:
When the lookup table has even power of two spacing, division is replaced by a bit shift. As a result, the execution speed is faster than for evenly spaced data.
Using the Approximation Function
eval('funcstr');
command to view the function before creating the lookup table.
fixpt_look1_func_approx
function.
fixpt_look1_func_plot
function to plot the function from the selected breakpoints, and to calculate the error and the number of points used.
Calculating the Output Function
To calculate the function, use the returned breakpoints with
eval
function
fixpt_look1_func_approx
function, and the y values can be supplied using the eval
function.
See Tutorial: Producing Lookup Table Data for a tutorial on using fixpt_look1_func_approx
.
The following table summarizes the effect of spacing on the execution speed, error, and memory used.
Examples
This example produces a lookup table for a sine function. The inputs for the example are as follows:
funcstr = 'sin(2*pi*x)';
xmin = 0;
xmax = 0.25;
xdt = ufix(16);
xscale = 2^-16;
ydt = sfix(16);
yscale = 2^-14;
rndmeth = 'Floor';
errmax = 2^-10;
spacing = 'pow2';
To create the lookup table, type
[xdata, ydata, errWorst]=fixpt_look1_func_approx(funcstr,
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,errmax,[],spacing);
The brackets [ ] are a place holder for the nptsmax
parameter, which is not used in this example.
You can then plot the ideal function, the approximation, and the errors by typing
The fixpt_look1_func_plot
function produces a plot of the fixed-point sine function, using these breakpoints, and a plot of the error between the ideal function and the fixed-point function. The maximum absolute error and the number of points required are listed with the plot. The error drops to zero at a breakpoint, and increases between breakpoints due to the difference in curvature of the ideal function and the line drawn between breakpoints.
The resulting plots are shown below.
The lookup table requires 33 points to achieve a maximum absolute error of 2^-11.3922.
See Also
![]() | fixpt_interp1 | fixpt_look1_func_plot | ![]() |