model engine using n-d adaptive lookup table
objectives
in this example, you learn how to capture the time-varying behavior of an engine using an n-d adaptive lookup table. you accomplish the following tasks using the simulink® software:
configure an adaptive lookup table block to model your system.
simulate the model to update the lookup table values dynamically.
export the adapted lookup table values to the matlab® workspace.
lock a specific cell in the table during adaptation.
disable the adaptation process and use the adaptive lookup table as a static lookup table.
about the data
in this example, you use the data in vedata.mat
which contains the
following variables measured from an engine:
x
— 10 input breakpoints for intake manifold pressure in the range [10,100]y
— 36 input breakpoints for engine speed in the range [0,7000]z
— 10x36 matrix of table data for engine volumetric efficiencyto learn more about breakpoints and table data, see .
the output volumetric efficiency of the engine is time varying, and a function of two inputs—intake manifold pressure and engine speed. the data in the mat-file is used to generate the time-varying input and output (i/o) data for the engine.
in next section, you open a preconfigured simulink model.
engine data model
load the engine data.
load vedata.mat
open the preconfigured model.
open_system('enginetable1_data')
building a model using adaptive lookup table blocks
in this portion of the tutorial, you learn how to build a model of an engine using an adaptive lookup table block.
the experimental data subsystem in the simulink model generates time-varying i/o data during simulation.
this command also loads the variables
x
,y
andz
into the matlab workspace. to learn more about this data, see about the data.add an adaptive lookup table block to the simulink model.
open the simulink library browser.
at the matlab prompt, enter
sllibrarybrowser
.open the simulink design optimization™ library.
in the libraries pane, expand the simulink design optimization node.
in the simulink design optimization library tree, click adaptive lookup tables.
drag and drop the adaptive lookup table (nd stair-fit) block from the adaptive lookup tables library to the simulink model window.
double-click the adaptive lookup table (nd stair-fit) block to open the function block parameters: adaptive lookup table (nd stair-fit) dialog box.
in the function block parameters dialog box:
specify the following block parameters:
table breakpoints (cell array) — enter
{[x; 110], [y; 7200]}
to specify the range of input breakpoints.table data (initial) — enter
rand(10,36)
to specify random numbers as the initial table values for the volumetric efficiency.table numbering data — enter
reshape(1:360,10,36)
to specify a numbering scheme for the table cells.
verify that
sample mean (with forgetting)
is selected in the adaptation method drop-down list.enter
0.98
in the adaptation gain (0 to 1) field to specify the forgetting factor for thesample mean (with forgetting)
adaptation algorithm.an adaptation gain close to 1 indicates high robustness of the lookup table values to input noise. to learn more about the adaptation gain, see in .
select the make adapted table an output check box.
this action adds a new port named
tout
to the adaptive lookup table block. you use this port to plot the table values as they are being adapted.select the add adaptation enable/disable/reset port check box.
this action adds a new port named
enable
to the adaptive lookup table block. you use this port to enable or disable the adaptation process.select the add cell lock enable/disable port check box.
this action adds a new port named
lock
to the adaptive lookup table block. you use this port to lock a cell during the adaptation process.verify that
ignore
is selected in the action for out-of-range drop-down list.this selection specifies that the software ignores any time-varying inputs outside the range of input breakpoints during adaptation.
tip
to learn more, see block reference page.
after you configure the parameters, the block parameters dialog box looks like the following figure.
click ok to close the function block parameters dialog box.
the simulink model now looks similar to the following figure.
assign the input and output data to the engine model by connecting the
u
andy
ports of the experimental data block to theu
andy
ports of the adaptive lookup table block, respectively.design a logic using simulink blocks to enable or disable the adaptation process. connect the logic to the adaptive lookup table block, as shown in the following figure.
this logic outputs an initial value of 1 which enables the adaptation process.
design a logic to lock a cell during adaptation. connect the logic to the adaptive lookup table block, as shown in the following figure.
in the simulink library browser, select the simulink > sinks library, and drag display blocks to the model window. connect the blocks, as shown in the following figure.
during simulation, the display blocks show the following:
display
block — shows the value of the current cell being adapted.display1
block — shows the number of the current cell being adapted.
write a matlab function to plot the lookup table values as they adapt during simulation.
alternatively, type
enginetable
at the matlab prompt to open a preconfigured simulink model. theefficiency surface
subsystem contains a function to plot the lookup table values, as shown in the next figure.connect a to workspace block to export the adapted table values:
in the simulink library browser, select the simulink > sinks library, and drag the to workspace block to the model window.
to learn more about this block, see the block reference page in the simulink documentation.
double-click the to workspace block to open the sink block parameters dialog box, and type
tout
in the variable name field.click ok.
connect the to workspace block to the adaptive lookup table output signal
tout
, as shown in the next figure.
you have now built the model for updating and viewing the adaptive lookup table values. you must now simulate the model to start the adaptation, as described in adapting the lookup table values using time-varying i/o data.
adapting the lookup table values using time-varying i/o data
in this portion of the tutorial, you learn how to update the lookup table values to adapt to the time-varying input and output values.
you must have already built the simulink model, as described building a model using adaptive lookup table blocks.
to perform the adaptation:
in the simulink editor, specify the simulation time as
inf
.the simulation time of infinity specifies that the adaptation process continues as long as the input and output values of the engine change.
in the simulink editor, click run under simulation to start the adaptation process.
a figure window opens that shows the volumetric efficiency of the engine as a function of the intake manifold pressure and engine speed:
the left plot shows the measured volumetric efficiency as a function of intake manifold pressure and engine speed.
the right plot shows the volumetric efficiency as it adapts with the time-varying intake manifold pressure and engine speed.
during simulation, the lookup table values displayed on the right plot adapt to the variations in the i/o data. the left and the right plots resemble each other after a few seconds, as shown in the next figure.
tip
during simulation, the
cell number
andadaptive table outputs
blocks in the simulink model display the cell number, and the adapted lookup table value in the cell, respectively.pause the simulation by clicking pause under simulation.
this action also exports the adapted table values
tout
to the matlab workspace.note
after you pause the simulation, the adapted table values are stored in the adaptive lookup table block.
examine that the left and the right plots match. this resemblance indicates that the table values have adapted to the time-varying i/o data.
lock a table cell so that only one cell adapts. you may find this feature useful if a portion of the data is highly erratic or otherwise difficult for the algorithm to handle.
click run under simulation to restart the simulation.
double-click the
lock
block. this action toggles the switch and feeds the output of theon
block to thelock
input port of theadaptive lookup table(nd stair-fit)
block.you can view the number of the locked cell in the
cell number
block in the simulink model.
after the table values adapt to the time-varying i/o data, you can continue to use the adaptive lookup table block as a static lookup table:
in the simulink model window, double-click the
enable
block. this action toggles the switch, and disables the adaptation.click run under simulation to restart the simulation, if it is not already running.
during simulation, the adaptive lookup table block works like a static lookup table, and continues to estimate the output values as the input values change. you can see the current lookup table value in the
adaptive table outputs
block in the simulink model window.
note
after you disable the adaptation, the adaptive lookup table block does not update the stored table values, and the figure that displays the table values does not update.