Main Content

Use CDFX-Files with Simulink

This example shows how to use calibration data from a CDFX-file as inputs to a Simulink model.

Import Data

Import the calibration data using thecdfxfunction.

cdfxObj = cdfx("CDFXExampleFile.cdfx")
cdfxObj = CDFX with properties: Name: "CDFXExampleFile.cdfx" Path: "/tmp/Bdoc22a_1891349_156950/tp07074cff/vnt-ex88524458/CDFXExampleFile.cdfx" Version: "CDF20"

Instantiate Local Variables

UsegetValueto extract the desired parameters into the MATLAB workspace.

gainParam = getValue(cdfxObj,"ASAM.C.SCALAR.GAIN")
gainParam = 3
mapParam = getValue(cdfxObj,"ASAM.C.MAP")
mapParam =struct with fields:PhysicalValue: [5x5 double] Axis1: [1x1 struct] Axis2: [1x1 struct]

Lookup-Gain Model

open_system("CDFXSimulinkModel.slx"); cdfxMdl = gcs
cdfxMdl = 'CDFXSimulinkModel'

This model contains:

  • 2-D Lookup Table block to represent theASAM.C.MAPparameter from the CDFX-file. The "Table data" field represents the physical value of the instance, and the "Breakpoint" fields represent the physical values of the axes.

  • Gain block to represent theASAM.C.SCALAR.GAINparameter from the CDFX-file.

  • To Workspace block to log the simulation data.

Indexing Logic Subsystem

The Indexing Logic subsystem uses the physical values of the axes of theASAM.C.MAPparameter, along with signal routing blocks and a triggered subsystem, to produce all valid combinations of lookup indices. This configuration can be useful if you need to test across the full range of possible input values of a calibration parameter.

Log Output Data in MATLAB

The output of the simulation is sent to MATLAB by the To Workspace block, where it is stored as a timeseries object calledmapData. This data can now be inspected and visualized in the MATLAB workspace.

sim(cdfxMdl); plot(mapData) title("Simulation Output for ASAM.C.MAP")

Figure contains an axes object. The axes object with title Simulation Output for ASAM.C.MAP contains an object of type stair.

%Copyright 2018-2021 The MathWorks, Inc.