Main Content


Class: coder.FixPtConfig
Namespace: coder

Specify fixed-point data type for variable during fixed-point conversion




addTypeSpecification(fcnName,varName,numericType) specifies the data type to use for the variable, varName, in the function, fcnName. The fixed-point conversion process uses this information to determine the fixed-point data type to use in generated code.

Input Arguments

expand all

Function name, specified as a string.

Data Types: string | char

Variable name, specified as a string.

Data Types: string | char

Data type to assign to the specified variable, specified as a numerictype object.


expand 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 dti_test.

fixptcfg.TestBenchName = "dti_test";

In this example, the MATLAB® design function name is dti. Specify the numeric type to use in fixed-point conversion for the variable y in the design function.


Generate fixed-point code.

fiaccel -float2fixed fixptcfg dti;

Specify a fixed-point data type for a specialized function during fixed-point conversion. To learn more about function specialization, see Specializations (HDL Coder).

Open the function testFunc.



testFunc contains multiple calls to a subfunction tmpFunc with two different input types. Converting testFunc to fixed point creates fixed-point code with two specializations of tmpFunc. To generate fixed-point code for testFunc, create a fixed-point configuration object.

cfg = coder.config("fixpt");
cfg.TestBenchName = ["testFunc_tb.m"];

Generate fixed-point code.

fiaccel -float2fixed cfg testFunc;

Open the file testFunc_fixpt to view the generated fixed-point code. The two specializations of tmpFunc in testFunc_fixpt have distinct names, tmpFunc_s1 and tmpFunc_s2. The first specialization tmpFunc_s1 behaves differently between variables b and c, based on how the inputs are defined in tmpFunc.


To specify the data type assigned to only one specialization of tmpFunc, say tmpFunc_s2, add a data type to the fixed-point configuration object using addTypeSpecification.


Regenerate the fixed-point code.

fiaccel -float2fixed cfg testFunc;

Open testFunc_fixpt and observe the numeric type returned by the output of tmpFunc_s2.