coder.FixPtConfig Class
Namespace: coder
Floating-point to fixed-point conversion configuration object
Description
A coder.FixptConfig
object contains the
configuration parameters that the MATLAB®
Coder™
codegen
function requires to convert floating-point MATLAB code to fixed-point MATLAB code during code generation. Use the -float2fixed
option to
pass this object to the codegen
function.
Creation
creates a
fixptcfg
= coder.config('fixpt')coder.FixPtConfig
object for floating-point to fixed-point
conversion.
Properties
ComputeDerivedRanges
— Enable derived range analysis
false
(default) | true
Enable derived range analysis, specified as true
or
false
.
ComputeSimulationRanges
— Enable collection and reporting of simulation range data
true
(default) | false
Enable collection and reporting of simulation range data, specified as
true
or false
. If you need to run a long
simulation to cover the complete dynamic range of your design, consider disabling
simulation range collection and running derived range analysis instead.
DefaultFractionLength
— Default fixed-point fraction length
4
(default) | positive integer
Default fixed-point fraction length, specified as a positive integer.
DefaultSignedness
— Default signedness of variables in the generated code
'Automatic'
(default) | 'Signed'
| 'Unsigned'
Default signedness of variables in the generated code, specified as
'Automatic'
, 'Signed'
, or
'Unsigned'
.
DefaultWordLength
— Default fixed-point word length
14
(default) | positive integer
Default fixed-point word length, specified as a positive integer.
DetectFixptOverflows
— Enable detection of overflows using scaled doubles
false
(default) | true
Enable detection of overflows using scaled doubles, specified as
true
or false
.
fimath
— fimath
properties to use for conversion
fimath('RoundingMethod','Floor','OverflowAction','Wrap','ProductMode','FullPrecision','SumMode','FullPrecision')
(default) | fimath
object
fimath
properties to use for conversion, specified as a fimath
(Fixed-Point Designer) object.
FixPtFileNameSuffix
— Suffix for fixed-point file names
'_fixpt'
(default) | string
Suffix for fixed-point file names, specified as a string.
LaunchNumericTypesReport
— View the numeric types report after the software has proposed fixed-point types
true
(default) | false
View the numeric types report after the software has proposed fixed-point types,
specified as true
or false
.
LogIOForComparisonPlotting
— Enable simulation data logging to plot the data differences introduced by fixed-point conversion
true
(default) | false
Enable simulation data logging to plot the data differences introduced by
fixed-point conversion, specified as true
or
false
.
OptimizeWholeNumber
— Optimize the word lengths of variables that are always whole numbers
true
(default) | false
Optimize the word lengths of variables whose simulation min/max logs indicate that
they are always whole numbers, specified as
true
or false
.
PlotFunction
— Name of function to use for comparison plots
''
(default) | string
Name of function to use for comparison plots.
LogIOForComparisonPlotting
must be set to true to enable
comparison plotting. This option takes precedence over
PlotWithSimulationDataInspector
.
The plot function should accept three inputs:
A structure that holds the name of the variable and the function that uses it.
A cell array to hold the logged floating-point values for the variable.
A cell array to hold the logged values for the variable after fixed-point conversion.
PlotWithSimulationDataInspector
— Use the Simulation Data Inspector for comparison plots
false
(default) | true
Use the Simulation Data Inspector for comparison plots, specified as
true
or false
.
LogIOForComparisonPlotting
must be set to true to enable
comparison plotting. The PlotFunction
option takes precedence over
PlotWithSimulationDataInspector
.
ProposeFractionLengthsForDefaultWordLength
— Propose fixed-point types based on DefaultWordLength
true
(default) | false
Propose fixed-point types based on DefaultWordLength
, specified
as true
or false
.
ProposeTargetContainerTypes
— Whether to propose target container types
false
(default) | true
By default (false
), propose data types with the minimum word
length needed to represent the value. When set to
true, propose data type with the smallest word length that can represent the range and
is suitable for C code generation ( 8, 16, 32, 64, … ). For example, for a variable with
range [0..7], propose a word length of 8 rather than 3.
ProposeWordLengthsForDefaultFractionLength
— Propose fixed-point types based on DefaultFractionLength
false
(default) | true
Propose fixed-point types based on DefaultFractionLength
,
specified as true
or false
.
ProposeTypesUsing
— Propose data types based on simulation range data, derived ranges, or both
'BothSimulationAndDerivedRanges'
(default) | 'SimulationRanges'
| 'DerivedRanges'
Propose data types based on simulation range data, derived ranges, or both,
specified as 'BothSimulationAndDerivedRanges'
,
'SimulationRanges'
, or 'DerivedRanges'
.
SafetyMargin
— Safety margin percentage by which to increase the simulation range when proposing fixed-point types
0
(default) | real number greater than -100
Safety margin percentage by which to increase the simulation range when proposing
fixed-point types, specified as a real number greater than
-100
.
Data Types: double
StaticAnalysisQuickMode
— Perform faster static analysis
false
(default) | true
Perform faster static analysis, specified as true
or
false
.
StaticAnalysisTimeoutMinutes
— Abort analysis if timeout is reached
''
(default) | positive integer
Abort analysis if timeout is reached, specified as a positive integer.
TestBenchName
— Test bench function name or names
''
(default) | string | cell array of strings
Test bench function name or names, specified as a string or cell array of strings. You must specify at least one test bench. If you do not explicitly specify input parameter data types, the conversion uses the first test bench function to infer these data types.
Data Types: string
| cell
TestNumerics
— Enable numerics testing
false
(default) | true
Enable numerics testing, specified as true
or
false
.
Methods
Public Methods
addApproximation (Fixed-Point Designer) | Replace floating-point function with lookup table during fixed-point conversion |
addDesignRangeSpecification (Fixed-Point Designer) | Add design range specification to parameter |
addFunctionReplacement (Fixed-Point Designer) | Replace floating-point function with fixed-point function during fixed-point conversion |
addTypeSpecification (Fixed-Point Designer) | Specify fixed-point data type for a variable during fixed-point conversion |
clearDesignRangeSpecifications (Fixed-Point Designer) | Clear all design range specifications |
getDesignRangeSpecification (Fixed-Point Designer) | Get design range specifications for parameter |
hasDesignRangeSpecification (Fixed-Point Designer) | Determine whether parameter has design range |
removeDesignRangeSpecification (Fixed-Point Designer) | Remove design range specification from parameter |
Examples
Generate Fixed-Point C Code from Floating-Point MATLAB Code
This example shows how to convert a floating-point MATLAB function to fixed-point C code.
Create a coder.FixPtConfig
object, fixptcfg
, with default settings.
fixptcfg = coder.config('fixpt');
Set the test bench name. In this example, the test bench function name is dti_test
.
fixptcfg.TestBenchName = 'dti_test';
Create a code generation configuration object to generate a standalone C static library.
cfg = coder.config('lib');
Convert a floating-point MATLAB function to fixed-point C code. In this example, the MATLAB function name is dti
.
codegen -float2fixed fixptcfg -config cfg dti
Convert Floating-Point MATLAB Code to Fixed Point Based on Derived Ranges
This example shows how to convert a floating-point MATLAB function to fixed-point MATLAB code.
Create a coder.FixPtConfig
object, fixptcfg
, with default settings.
fixptcfg = coder.config('fixpt');
Set the name of the test bench to use to infer input data types. In this example, the test bench function name is dti_test
. The conversion process uses the test bench to infer input data types.
fixptcfg.TestBenchName = 'dti_test';
Select to propose data types based on derived ranges.
fixptcfg.ProposeTypesUsing = 'DerivedRanges';
fixptcfg.ComputeDerivedRanges = true;
Add design ranges. In this example, the dti
function has one scalar double input, u_in
. Set the design minimum value for u_in
to -1
and the design maximum to 1
.
fixptcfg.addDesignRangeSpecification('dti','u_in',-1.0,1.0);
Convert the floating-point MATLAB function, dti
, to fixed-point MATLAB code.
codegen -float2fixed fixptcfg dti
Enable Overflow Detection
When you select to detect potential overflows, codegen
generates a scaled double version of the generated fixed-point MEX function. Scaled doubles store their data in double-precision floating-point, so they carry out arithmetic in full range. They also retain their fixed-point settings, so they are able to report when a computation goes out of the range of the fixed-point type.
Create a coder.FixPtConfig
object, fixptcfg
, with default settings.
fixptcfg = coder.config('fixpt');
Set the test bench name. In this example, the test bench function name is dti_test
.
fixptcfg.TestBenchName = 'dti_test';
Enable numerics testing with overflow detection.
fixptcfg.TestNumerics = true; fixptcfg.DetectFixptOverflows = true;
Create a code generation configuration object to generate a standalone C static library.
cfg = coder.config('lib');
Convert a floating-point MATLAB function to fixed-point C code. In this example, the MATLAB function name is dti
.
codegen -float2fixed fixptcfg -config cfg dti
Alternatives
You can convert floating-point MATLAB code to fixed-point code using the MATLAB Coder app. Open the app using one of these methods:
On the Apps tab, in the Code Generation section, select MATLAB Coder.
Use the
coder
command.
Version History
Introduced in R2014b
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)