Fixed-Point Blockset | ![]() ![]() |
Worst Case Error for a Lookup Table
This section explains the worst case error of a lookup table, and how to find the worst case error using the function fixpt_look1_func_plot
. It gives a simple example of the worst case error of a lookup table for the square root function.
The error at any point of a function lookup table is the absolute value of the difference between the ideal function at the point and the corresponding Y value found by linearly interpolating between the adjacent breakpoints. The worst case error, or maximum absolute error, of a lookup table is the maximum absolute value of all errors in the interval containing the breakpoints.
For example, if the ideal function is the square root, and the breakpoints of the lookup table are 0, .25 and 1, then in a perfect implementation of the lookup table, the worst case error is 1/8 = .125, which occurs at the point 1/16 = .0625. In practice, the error could be greater, depending on the fixed point quantization and other factors.
Example: Square Root Function
This example shows how to use the function fixpt_look1_func_plot
to find the maximum absolute error for the simple lookup table whose breakpoints are 0, .25, and 1. The corresponding Y data points of the lookup table, which you find by taking the square roots of the breakpoints, are 0, .5 and 1.
To use the function fixpt_look1_func_plot
, you need to first define its parameters. To do so, type the following at the MATLAB prompt:
funcstr='sqrt(x)'; %Define the square root function xdata=[0;.25;1]; %Set the breakpoints ydata=sqrt(xdata); %Find the square root of the breakpointsxmin = 0; %Set the minimum breakpoint
xmax = 1; %Set the maximum breakpoint
xdt = ufix(16); %Set the x data type
xscale = 2^-16; %Set the x data scaling
ydt = sfix(16); %Set the y data type
yscale = 2^-14; %Set the y data scaling
rndmeth = 'Floor'; %Set the rounding method
This returns the worst case error of the lookup table as the variable errworst
:
It also generates the plots shown below. The upper box (Outputs) displays a plot of the square root function, and a plot of the fixed-point lookup approximation underneath. The approximation is found by linear interpolation between the breakpoints. The lower box (Absolute Error) displays the errors at all points in the interval from 0 to 1. Notice that the maximum absolute error occurs at .0625. The error at the breakpoints is 0.
![]() | Overview | Creating Lookup Tables for a Sine Function | ![]() |