Tune Lookup Table Data Using Planar Approximations
Lookup tables are commonly used blocks that serve to approximate the behavior of functions. This example shows how to tune lookup table data by using planar approximations with Simulink® Design Verifier™. To tune lookup table values, perform this two-step process:
1. Transform the instances of 1-D and 2-D lookup table into a representation that uses planar computation (1-D or 2-D) where you can configure the parameters of the plane for tunability.
2. Analyze the corresponding lookup tables data from the generated planar parameters.
You can use Simulink® Coverage™ to determine the coverage for lookup tables by verifying whether all the grid points in the plane, which are specified by the breakpoints, are addressed during the analysis.
Open Original Model
This example uses two preconfigured models: sldvexTableParamTune
is the original model and sldvexTableParamTuneReplace
is the model that uses planar approximations.
Open the sldvexTableParamTune
model.
open_system('sldvexTableParamTune');
This model contains a 2-D lookup table block with an output that is always 0.
Analyze Original Model
The values in the 2-D lookup table prevent some test cases from completing successfully during test generation analysis.
To perform test generation analysis, follow these steps:
1. On the Apps tab, under Model Verification, Validation, and Test, click Design Verifier.
2. On the Design Verifier tab, click Generate Tests. Alternatively, use the sldvrun
function to run the analysis.
sldvrun('sldvexTableParamTune');
06-Sep-2024 05:11:52 Checking compatibility for test generation: model 'sldvexTableParamTune' Compiling model...done Building model representation...done 06-Sep-2024 05:11:56 'sldvexTableParamTune' is compatible for test generation with Simulink Design Verifier. Generating tests using model representation from 06-Sep-2024 05:11:56... Generating output files: 06-Sep-2024 05:12:07 Results generation completed. Data file: /tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex32482295/sldv_output/sldvexTableParamTune/sldvexTableParamTune_sldvdata.mat
sldvloadresults('sldvexTableParamTune')
ans = logical
1
Once the analysis is complete, the results summary window shows four unsatisfied
objectives.
Close the model.
bdclose('all');
Open Transformed Model with Planar Table Replacements
Open the sldvexTableParamTuneReplace
model. The model uses a simple linear equation instead of a lookup table and you can tune its parameters using Simulink Design Verifier.
open_system("sldvexTableParamTuneReplace");
In the sldvexTableParamTuneReplace
model, the planarApprox
block replaces the 2-D Lookup Table block in the sldvexTableParamTune
model.
Open the planarApprox
block. The block contains three scalar parameters that you can generate using Simulink Design Verifier analysis: tableParam_k1
, tableParam_k2
, and tableParam_off.
open_system("sldvexTableParamTuneReplace/planarApprox");
To view these parameters, in the Configuration Parameters window, navigate to Parameters and Variants > Parameter table.
Analyze Transformed Model
To perform test generation analysis on the transformed model, on the Design Verifier tab, click Generate Tests. Alternatively, use the sldvrun
function.
[status, fileNames] = sldvrun("sldvexTableParamTuneReplace");
06-Sep-2024 05:12:13 Checking compatibility for test generation: model 'sldvexTableParamTuneReplace' Compiling model...done Building model representation...done 06-Sep-2024 05:12:16 'sldvexTableParamTuneReplace' is compatible for test generation with Simulink Design Verifier. Generating tests using model representation from 06-Sep-2024 05:12:16... Generating output files: 06-Sep-2024 05:12:26 Results generation completed. Data file: /tmp/Bdoc24b_2725827_13574/tpa7db8267/sldv-ex32482295/sldv_output/sldvexTableParamTuneReplace/sldvexTableParamTuneReplace_sldvdata.mat
The test generation analysis completes normally and produces the input and parameter values that satisfy all test conditions. The results summary window shows that all objectives are satisfied.
Each test case contains the values of the linear parameters of the planar approximation block.
load(fileNames.DataFile) sldvData.TestCases(1).paramValues(1)
ans = struct with fields:
name: 'tableParam_k1'
value: -3.3210
noEffect: 0
type: 'Parameter'
sourceType: 'base workspace'
source: 'base workspace'
sldvData.TestCases(1).paramValues(2)
ans = struct with fields:
name: 'tableParam_k2'
value: 5.9365
noEffect: 0
type: 'Parameter'
sourceType: 'base workspace'
source: 'base workspace'
sldvData.TestCases(1).paramValues(3)
ans = struct with fields:
name: 'tableParam_off'
value: -6.4012
noEffect: 0
type: 'Parameter'
sourceType: 'base workspace'
source: 'base workspace'
Compute Lookup Table Values from Planar Parameters
Simulink Design Verifier generates parameter values for each test case, and each set of parameter values is a plane that you can visualize in a 3-D plot (x, y, and z axes) of the linear equation
,
where z is the result of the lookup table.
Generate the equivalent matrix of table outputs by substituting parameters value with the table breakpoint arrays using the planar parameters generated by Simulink Design Verifier.
tableParam_k1 = sldvData.TestCases(1).paramValues(1).value; tableParam_k2 = sldvData.TestCases(1).paramValues(2).value; tableParam_off = sldvData.TestCases(1).paramValues(3).value; u1Break = [0:500:3000]; u2Break = [0:0.1:1.1]; tableParam = (tableParam_k1 * u1Break' * ones(1,12)) + (tableParam_k2 * ones(7,1) * u2Break) + tableParam_off
tableParam = 7×12
103 ×
-0.0064 -0.0058 -0.0052 -0.0046 -0.0040 -0.0034 -0.0028 -0.0022 -0.0017 -0.0011 -0.0005 0.0001
-1.6669 -1.6663 -1.6657 -1.6651 -1.6645 -1.6639 -1.6633 -1.6627 -1.6622 -1.6616 -1.6610 -1.6604
-3.3274 -3.3268 -3.3262 -3.3256 -3.3250 -3.3244 -3.3238 -3.3232 -3.3227 -3.3221 -3.3215 -3.3209
-4.9879 -4.9873 -4.9867 -4.9861 -4.9855 -4.9849 -4.9843 -4.9837 -4.9832 -4.9826 -4.9820 -4.9814
-6.6484 -6.6478 -6.6472 -6.6466 -6.6460 -6.6454 -6.6448 -6.6442 -6.6437 -6.6431 -6.6425 -6.6419
-8.3089 -8.3083 -8.3077 -8.3071 -8.3065 -8.3059 -8.3053 -8.3047 -8.3042 -8.3036 -8.3030 -8.3024
-9.9694 -9.9688 -9.9682 -9.9676 -9.9670 -9.9664 -9.9658 -9.9652 -9.9647 -9.9641 -9.9635 -9.9629
This example includes the function file expand_planar_table_params.m
. You can embed this computation data and it transforms the Simulink Design Verifier output data.
Package Inferred Data
Edit the expand_planar_table_params.m
function file to include the information about the breakpoints for the table parameters. Save the result in newSldvData.
tableInfo.VarName = 'tableParam'; tableInfo.Breakpoints = {[0:500:3000], [0:0.1:1.1]}; newSldvData = expand_planar_table_params(sldvData, tableInfo); sldvData = newSldvData; save('table_param_tune_inferdata.mat','sldvData');
Close all the models.
bdclose('all');
Run Test Cases with Lookup Table Values on Original Model
Perform test generation analysis on the sldvexTableParamTune
model by running the test cases with the lookup table values.
open_system('sldvexTableParamTune') opts = sldvruntestopts; opts.coverageEnabled = true; opts.fastRestart = false; assignin('base','opts',opts); [out,covData] = evalin('base','sldvruntest(''sldvexTableParamTune'',''table_param_tune_inferdata.mat'', opts)')
out = 1x2 Simulink.SimulationOutput array
covData = ... cvdata version: (R2024b) id: 0 type: DERIVED_DATA test: [] rootID: 1856 checksum: [1x1 struct] modelinfo: [1x1 struct] startTime: 06-Sep-2024 05:12:31 stopTime: 06-Sep-2024 05:12:32 intervalStartTime: intervalStopTime: filter: simMode: Normal
Verify Coverage
Generate a coverage report from the result to confirm full coverage.
cvhtml('table_param_tune_alltests.html',covData);
The report summary indicates full decision coverage for the sldvexTableParamTune
model.