Main Content

coder.float2fixed.skip

Exclude functions from fixed-point conversion

Since R2024b

    Description

    coder.float2fixed.skip({'fcn'}) excludes the function fcn from fixed-point conversion when you use the -float2fixed option with codegen or fiaccel (Fixed-Point Designer), or the HDL Coder™ Workflow Advisor.

    Use coder.float2fixed.skip for designs that contain functions that do not support fixed-point inputs, or that contain custom floating-point or fixed-point functions that do not need to be converted to fixed point.

    example

    Examples

    collapse all

    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.

    fixptcfg = coder.config("fixpt");

    Specify a test bench. The test bench used in this example is skipFcn_tb.

    fixptcfg.TestBenchName = 'skipFcn_tb';

    Generate fixed-point code.

    codegen -float2fixed fixptcfg skipFcn
    ===================================================
    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.

    The Code Generation Report Viewer displays the generated code. The function output of skipFcn is highlighted, showing that the input to localFcn is converted to double precision. The output of localFcn is then converted to fi inside of skipFcn.

    Input Arguments

    collapse all

    Name of the function to exclude from fixed-point conversion, specified as a cell array. You can specify multiple functions.

    Example: coder.float2fixed.skip({'fcn1','fcn2'})

    Data Types: cell

    Version History

    Introduced in R2024b