Select a design for fixed-point conversion that contains unsupported constructs. This example uses a design called skipFcn
, shown below.
function out = skipFcn(inp)
out = localFcn(inp);
end
function y = localFcn(u)
y = 2*exp(u);
end
The skipFcn
design calls exp
, a MATLAB® function that does not support fixed-point data types. To exclude exp
from fixed-point conversion, add a call to coder.float2fixed.skip
. Specify localFcn
, which contains the call to exp
, as the function to exclude.
function out = skipFcn(inp)
coder.float2fixed.skip({'localFcn'});
out = localFcn(inp);
end
function y = localFcn(u)
y = 2*exp(u);
end
To generate fixed-point code, create a coder.FixPtConfig
object fixptcfg
with default settings.
Specify a test bench. The test bench used in this example is skipFcn_tb
.
Generate fixed-point code.
===================================================
Design Name: skipFcn
Test Bench Name: skipFcn_tb
===================================================
Input types not specified for design(s) 'skipFcn', inferring types by simulating the first test bench: 'skipFcn_tb' in the base workspace.
============= Step1: Analyze floating-point code ==============
Code generation successful.
============= Step1a: Verify Floating Point ==============
### Analyzing the design 'skipFcn'
### Analyzing the test bench(es) 'skipFcn_tb'
### Begin Floating Point Simulation (Instrumented)
### Floating Point Simulation Completed in 1.8153 sec(s)
### Elapsed Time: 2.6461 sec(s)
============= Step2: Propose Types based on Range Information ==============
============= Step3: Generate Fixed Point Code ==============
### Generating Fixed Point MATLAB Code skipFcn_fixpt using Proposed Types
### Generating Fixed Point MATLAB Design Wrapper skipFcn_wrapper_fixpt
### Generating Mex file for ' skipFcn_wrapper_fixpt '
Code generation successful: View report
### Generating Type Proposal Report for 'skipFcn' skipFcn_report.html
===================================================
Code generation successful.
Open the Code Generation Report Viewer by clicking View report
in the code generation output.
On the left side, under MATLAB Source, select skipFcn_fixpt
from the function list to view the generated fixed-point code. Point to localFcn
to view the expression information and note that the class is double. The function returns a fixed-point output by converting the output of localFcn
to fixed point.