Fixed-Point Blockset    
fixpt_look1_func_approx

Optimize for a fixed-point function, the x values, or breakpoints, that are generated for a lookup table

Syntax

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

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.

Input
Value
'funcstr'
Function of x funcstr is the function for which breakpoints are approximated.
xmin
Minimum value of x
xmax
Maximum value of x
xdt
Data type of x
xscale
Scaling for the x values
ydt
Data type of y
yscale
Scaling for the y values
rndmeth
Rounding mode supported by the Fixed-Point Blockset: 'Toward Zero', 'Nearest', 'Floor' (default value), 'Ceiling'

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.

Output
Value
xdata
The breakpoints for the lookup table
ydata
The ideal function applied to the breakpoints
errworst
The worst case error, which is the maximum absolute error between the ideal function and the approximation given by the lookup table

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

Modes for errmax and nptsmax

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:

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

  1. Choose a function and use the eval('funcstr'); command to view the function before creating the lookup table.
  2. Define the remaining inputs.
  3. Run the fixpt_look1_func_approx function.
  4. Use the fixpt_look1_func_plot function to plot the function from the selected breakpoints, and to calculate the error and the number of points used.
  5. Vary the inputs to produce sets of breakpoints that generate functions with varying number of points required and worst case error.
  6. Compare the number of points required and worst case error from various runs to choose the best set of breakpoints.

Calculating the Output Function

To calculate the function, use the returned breakpoints with

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.

Table 8-1: Comparison of the Spacing Options
Parameter
Even Power of Two Spaced Data
Evenly Spaced Data
Unevenly Spaced Data
Execution Speed
The execution speed is the fastest. The position search and interpolation are the same as for evenly spaced data. However, to increase the speed more, the position search is replaced by a bit shift, and the interpolation is replaced with a bit mask.
The execution speed is faster then that for unevenly spaced data because the position search is faster and the interpolation requires a simple division.
The execution speed is the slowest of the different spacings because the position search is slower, and the interpolation requires more operations.
Error
The error can be larger than that for unevenly spaced data because approximating a function with nonuniform curvature requires more points to achieve the same accuracy.
The error can be larger than that for unevenly spaced data because approximating a function with nonuniform curvature requires more points to achieve the same accuracy.
The error can be smaller because approximating a function with nonuniform curvature requires fewer points to achieve the same accuracy.
ROM Usage
Uses less command ROM, but more data ROM.
Uses less command ROM, but more data ROM.
Uses more command ROM, and less data ROM.
RAM Usage
Not significant.
Not significant.
Not significant.

Examples

This example produces a lookup table for a sine function. The inputs for the example are as follows:

To create the lookup table, type

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_look1_func_plot


  fixpt_interp1 fixpt_look1_func_plot