Main Content

addApproximation

Replace floating-point function with lookup table during fixed-point conversion

Syntax

addApproximation(approximationObject)

Description

addApproximation(approximationObject) specifies a lookup table replacement in a coder.FixptConfig object. During floating-point to fixed-point conversion, the conversion process generates a lookup table approximation for the function specified in the approximationObject.

Input Arguments

expand all

Function replacement configuration object that specifies how to create an approximation for a MATLAB® function. Use the coder.FixptConfig configuration object addApproximation method to associate this configuration object with a coder.FixptConfig object. Then use the fiaccel function -float2fixed option with coder.FixptConfig to convert floating-point MATLAB code to fixed-point MATLAB code.

Examples

expand all

Create a function replacement configuration object that specifies to replace the log function with an optimized lookup table.

logAppx = coder.approximation('Function','log','OptimizeLUTSize',...
          true,'InputRange',[0.1,1000],'InterpolationDegree',1,...
          'ErrorThreshold',1e-3,...	 
          'FunctionNamePrefix','log_optim_','OptimizeIterations',25);	 

Create a fixed-point configuration object and associate the function replacement configuration object with it.

fixptcfg = coder.config('fixpt');
fixptcfg.addApproximation(logAppx);

You can now generate fixed-point code using the fiaccel function.