Worst-Case Error for a Lookup Table
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, 0.25, and 1, then in a perfect implementation of the lookup table, the worst-case error is 1/8 = 0.125, which occurs at the point 1/16 = 0.0625. In practice, the error could be greater, depending on the fixed-point quantization and other factors.
The section that follows shows how to use the function
fixpt_look1_func_plot to find the worst-case error of a lookup table for the
square root function.
Approximate the 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, 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, 0.5, and 1.
To use the function
fixpt_look1_func_plot , you need to define its parameters first. 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 breakpoints xmin = 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
To get the worst-case error of the lookup table and a plot of the error, type:
errworst = fixpt_look1_func_plot(xdata,ydata,funcstr, ... xmin,xmax,xdt,xscale,ydt,yscale,rndmeth)
errworst = 0.1250
The upper box (Outputs) displays a plot of the square root function with 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 0.0625. The error at the breakpoints is 0.