Main Content

coder.FixptConfig class

Package: coder

Floating-point to fixed-point conversion configuration object

Description

A coder.FixptConfig object contains the configuration parameters that the HDL codegen function requires to convert floating-point MATLAB® code to fixed-point MATLAB code during HDL code generation. Use the -float2fixed option to pass this object to the codegen function.

Construction

fixptcfg = coder.config('fixpt') creates a coder.FixptConfig object for floating-point to fixed-point conversion.

Properties

ComputeDerivedRanges

Enable derived range analysis.

Values: true|false (default)

ComputeSimulationRanges

Enable collection and reporting of simulation range data. 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.

Values: true (default)|false

DefaultFractionLength

Default fixed-point fraction length.

Values: 4 (default) | positive integer

DefaultSignedness

Default signedness of variables in the generated code.

Values: 'Automatic' (default) | 'Signed' | 'Unsigned'

DefaultWordLength

Default fixed-point word length.

Values: 14 (default) | positive integer

DetectFixptOverflows

Enable detection of overflows using scaled doubles.

Values: true| false (default)

fimath

fimath properties to use for conversion.

Values: fimath('RoundingMethod', 'Floor', 'OverflowAction', 'Wrap', 'ProductMode', 'FullPrecision', 'SumMode', 'FullPrecision') (default) | string

FixPtFileNameSuffix

Suffix for fixed-point file names.

Values: '_fixpt' | string

LaunchNumericTypesReport

View the numeric types report after the software has proposed fixed-point types.

Values: true (default) | false

LogIOForComparisonPlotting

Enable simulation data logging to plot the data differences introduced by fixed-point conversion.

Values: true (default) | false

OptimizeWholeNumber

Optimize the word lengths of variables whose simulation min/max logs indicate that they are always whole numbers.

Values: true (default) | false

PlotFunction

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.

Values: '' (default) | string

PlotWithSimulationDataInspector

Use Simulation Data Inspector for comparison plots.

LogIOForComparisonPlotting must be set to true to enable comparison plotting. The PlotFunction option takes precedence over PlotWithSimulationDataInspector.

Values: true| false (default)

ProposeFractionLengthsForDefaultWordLength

Propose fixed-point types based on DefaultWordLength.

Values: true (default) | false

ProposeTargetContainerTypes

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.

Values: true| false (default)

ProposeWordLengthsForDefaultFractionLength

Propose fixed-point types based on DefaultFractionLength.

Values: false (default) | true

ProposeTypesUsing

Propose data types based on simulation range data, derived ranges, or both.

Values: 'BothSimulationAndDerivedRanges' (default) | 'SimulationRanges'|'DerivedRanges'

SafetyMargin

Safety margin percentage by which to increase the simulation range when proposing fixed-point types. The specified safety margin must be a real number greater than -100.

Values: 0 (default) | double

StaticAnalysisQuickMode

Perform faster static analysis.

Values: true | false (default)

StaticAnalysisTimeoutMinutes

Abort analysis if timeout is reached.

Values: '' (default) | positive integer

TestBenchName

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.

Values: '' (default) | string | cell array of strings

TestNumerics

Enable numerics testing.

Values: true| false (default)

Methods

addDesignRangeSpecificationAdd design range specification to parameter
addFunctionReplacementReplace floating-point function with fixed-point function during fixed-point conversion
clearDesignRangeSpecificationsClear all design range specifications
getDesignRangeSpecificationGet design range specifications for parameter
hasDesignRangeSpecificationDetermine whether parameter has design range
removeDesignRangeSpecificationRemove design range specification from parameter

Examples

collapse all

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 mlhdlc_dti_tb.

fixptcfg.TestBenchName = 'mlhdlc_dti_tb';

Create a coder.HdlConfig object, hdlcfg, with default settings.

hdlcfg = coder.config('hdl');

Convert your floating-point MATLAB design to fixed-point, and generate HDL code. In this example, the MATLAB design function name is mlhdlc_dti.

codegen -float2fixed fixptcfg -config hdlcfg mlhdlc_dti

Alternatives

You can also generate HDL code from MATLAB code using the HDL Workflow Advisor. For more information, see Basic HDL Code Generation and FPGA Synthesis from MATLAB.