Fixed-Point Blockset | ![]() ![]() |
Example 2: Using nptsmax with Unrestricted Spacing
The next example shows how to create a lookup table that minimizes the worst case error for a specified maximum number of data points, with unrestricted spacing. Before starting the example, enter the same parameter values given in the section Setting Function Parameters for the Lookup Table, if you have not already done so in this MATLAB session.
Setting the Number of Breakpoints
You specify the number of breakpoints in the lookup table by typing
Creating the Lookup Table
[xdata,ydata,errworst]= fixpt_look1_func_approx(funcstr, xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax);
The empty brackets, []
, tell the function to ignore the parameter errmax
, which is not used in this example. Omitting errmax
causes the function fixpt_look1_func_approx
to return a lookup table of size specified by nptsmax
, with the smallest worst case error.
The function returns a vector xdata
, with 21 points. You can find the maximum error for this set of points is given by typing errworst
at the MATLAB prompt. This returns
Plotting the Results
To plot the lookup table along with the errors, type
The resulting plots are shown below.
Restricting the Spacing
In the previous two examples, the function fixpt_look1_func_approx
creates lookup tables with unrestricted spacing between the breakpoints. You can restrict the spacing to improve the computational efficiency of the lookup table, using the spacing parameter.
'unrestricted'
- The default.
'even'
- The distance between any two adjacent breakpoints is the same.
'pow2'
- The distance between any two adjacent breakpoints is the same and is a power of two.
Both power of two and even spacing increase the computational speed of the lookup table and use less command read-only memory (ROM). However, specifying either of the spacing restrictions along with errmax
usually requires more data points in the lookup table than does unrestricted spacing, in order to achieve the same degree of accuracy. The section Effect of Spacing on Speed, Error, and Memory Usage discusses the tradeoffs between different spacing options.
![]() | Example 1: Using errmax with Unrestricted Spacing | Example 3: Using errmax with Even Spacing | ![]() |