| Simulink® | ![]() |
[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,[])
[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,spacing)
fixpt_look1_func_approx('funcstr',xmin,xmax,xdt,xscale,ydt,
yscale,rndmeth,errmax,nptsmax) 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.
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 fixed-point Simulink® blocks: 'Toward Zero', 'Nearest', 'Floor' (default value), 'Ceiling' |
xmin and xmax specify the range over which the breakpoints are approximated.
xdt, xscale, ydt, yscale, and rndmeth follow conventions used by fixed-point Simulink blocks.
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 |
spacing | 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, you must 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 |
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
The maximum absolute error is less than errmax.
The number of points required is less than nptsmax.
The spacing is specified as unrestricted, even or even power of 2.
If both errmax and nptsmax are specified
The returned breakpoints will meet both criteria if possible. The errmax parameter is given priority, and nptsmax is ignored, if both criteria cannot be met with the specified spacing.
If only errmax is specified
The breakpoints that meet the error criteria, and have the least number of points are returned
If only nptsmax is specified
The breakpoints that require nptsmax or fewer, and give the smallest worst case error are returned
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:
If unrestricted is entered, the function chooses the spacing that provides the best optimization.
If even is entered, the function chooses an evenly spaced set of points, including the pow2 spacing.
If pow2 spacing is entered, the function chooses an even power of 2 spaced set of points.
The spacing you choose depends on the parameters you want to optimize: execution speed, function approximation error, ROM usage, and RAM usage:
The execution speed depends on the bisection search, and the interpolation method.
The error depends on how accurately the method approximates the nonuniform curvature of the function.
The ROM usage depends on the amount of data and command ROM used.
The RAM usage depends on how much global and stack RAM is used.
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.
Choose a function and use the eval('funcstr'); command to view the function before creating the lookup table.
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.
Vary the inputs to produce sets of breakpoints that generate functions with varying number of points required and worst case error.
Compare the number of points required and worst case error from various runs to choose the best set of breakpoints.
To calculate the function, use the returned breakpoints with
The eval function
A function lookup table. The x values are the breakpoints from the fixpt_look1_func_approx function, and the y values can be supplied using the eval function.
See Tutorial: Producing Lookup Table Data in Simulink® Fixed Point™ User's Guide 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.
Parameter | Even Power of 2 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 than 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. |
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
fixpt_look1_func_plot(xdata,ydata,funcstr,xmin,xmax,xdt,... xscale,ydt,yscale,rndmeth);
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.

The lookup table requires 33 points to achieve a maximum absolute error of 2^-11.3922.
![]() | fixpt_interp1 | fixpt_look1_func_plot | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |