Code covered by the BSD License

# Benchmark Problem 02 - Matlab Code

### Yogananda Jeppu (view profile)

21 May 2013 (Updated )

This is the Matlab code for the model Benchmark Problem 02.

Original.m
```warning off
%%
% This is a code that is written to match the Simulink model Bench_02. This
% is a MTech Thesis contribution by M Surya Karthik entitled "DO-331 Compliant
% Model Based Automated Optimized Test Case Generation". This work is done
% under the Guidance of Atit Mishra, Yogananda Jeppu, Moog India Technology
% Control Engineering, Manipal Institute of Technology, Manipal, Karnataka,
% India. We used a Taguchi DOE methodology to design test cases and
% compared them with the test case generated using Simulated Annealing.
%
%%
% This runs the Simulink Model. You can use this script to load test case
% data if required and inject the waveform into the Simulink model. W
run_bench_02
%
%We apologize for the choice of variables. A1, A2 ... A21 are the array that
% input data with respect to variable time.
%
Z1 = [A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A20 A21]; % Store the input in case required
%%
NN11=0;NN22=0; % These two variables store the error histogram.
%
% Error histograms have the X axis as the abs(error between the model
% and code) and the Y axis is the number of such points. This will help in
% case you want to fix some automated pass fail thresholds. 0.0002 is a good
% number based on the data. NN11 store the difference and NN22 stores the
% percentage difference.
%
DT = single(0.02); % Sampling time
%
% These are the inputs that actually go to the Simulink model and are
% tapped out as logsout data.
%
AA1 = logsout.Bench_02.A_1_1.data;
AA2 = logsout.Bench_02.A_2_1.data;
AA3 = logsout.Bench_02.A_3_1.data;
AA4 = logsout.Bench_02.A_4_1.data;
AA5 = logsout.Bench_02.A_5_1.data;
AA6 = logsout.Bench_02.A_6_1.data;
AA7 = logsout.Bench_02.A_7_1.data;
AA8 = logsout.Bench_02.A_8_1.data;
AA9 = logsout.Bench_02.A_9_1.data;
AA10 = logsout.Bench_02.A_10_1.data;
AA11 = logsout.Bench_02.A_11_1.data;
AA12 = logsout.Bench_02.A_12_1.data;
AA13 = logsout.Bench_02.A_13_1.data;
AA14 = logsout.Bench_02.A_14_1.data;
AA15 = logsout.Bench_02.A_15_1.data;
AA16 = logsout.Bench_02.A_16_1.data;
AA17 = logsout.Bench_02.A_17_1.data;
AA18 = logsout.Bench_02.A_18_1.data;
AA19 = logsout.Bench_02.A_19_1.data;
AA20 = logsout.Bench_02.A_20_1.data;
AA21 = logsout.Bench_02.A_21_1.data;
Z = [AA1 AA2 AA3 AA4 AA5 AA6 AA7 AA8 AA9 AA10 AA11 AA12 AA13 AA14 AA15 AA16 AA17 AA18 AA19 AA20 AA21];
plot(Z);shg
pause(1)
%
% Initialization
RLFF = 1;
poutRL = 0;
RL1FF = 1;
poutRL1 = 0;
ud1 = 1;
ud3 = 1;
S1 = 0;
S2 = 0;
S3 = 0;
pLO3 = 0; count = 0; outper = 0; initper = 1;
pinp19 = 0; count1 = 0; outper1 = 0; initper1 = 1;
limitmax=single(1);
limitmin=single(0);
initinteg = 1; pintegout = 0;
pTFSout1 = 0;initTFS = 1;
pinp16 = 0;
pLFout = 0; pLFInp = 1; LFInp = 1;
pLF1out = 0; pLF1Inp = 0; LF1Inp = 1;
pLF2out = 0; pLF2Inp = 0; LF2Inp = 1;
pinp4 = 0;
out_2 = 0; out_1 = 0; out_7 = 0; out_3 = 0; out_4 = 0;
pOR1 = 0;
pinp20 = 0;
pAnd3 = 0;
pLO4 = 0;
pinp11 = 0;
pinp10 = 0;
F2 = 0; SOP2 = 0;  init2 = 0;% parameters for TFS2
F1 = 0; SOP1 = 0;  init1 = 0;% parameters for TFS1
F7 = 0; SOP7 = 0;  init7 = 0;% parameters for TFS7
F3 = 0; SOP3 = 0;  init3 = 0;% parameters for TFS3
F4 = 0; SOP4 = 0;  init4 = 0;% parameters for TFS4
OUT=zeros(length(time),8);
TAPOUT=zeros(length(time),54); % This variable taps out 54 internal variables basically the block outputs
%%
% Start the simulation loop for the code
for ii = 1:length(time)
inp1 = AA1(ii);
inp2 = AA2(ii);
inp3 = AA3(ii);
inp4 = AA4(ii);
inp5 = AA5(ii);
inp6 = AA6(ii);
inp7 = AA7(ii);
inp8 = AA8(ii);
inp9 = AA9(ii);
inp10 = AA10(ii);
inp11 = AA11(ii);
inp12 = AA12(ii);
inp13 = AA13(ii);
inp14 = AA14(ii);
inp15 = AA15(ii);
inp16 = AA16(ii);
inp17 = AA17(ii);
inp18 = AA18(ii);
inp19 = AA19(ii);
inp20 = AA20(ii);
inp21 = AA21(ii);
% We have used mutants to check the efficacy of testing. The two words
% below are a key used by the mutant generator to mutate lines below this.
%START HERE
% Data that can be mutated below this
DtOn1 = 50;
DtOff1 = 200;
DtOn = 150;
DtOff = 150;
ftime2 = 2.5;
ftime1 = 2.5;
ftime7 = 2;
ftime3 = 1.5;
ftime4 = 2.5;
a1 = single(-49); a0 = single(51);
sn1 = single(10.0); sn0 = single(1.0);
up = single(10.0); lo = single(-10.0);
% Table lookup data(ONEDTable1)
XT1 = [0 1 5 10 20 25 30];
YT1 = [0 0 1.5 1.9 1.4 1.2 0];
% Table lookup data(ONEDTable)
XT = [0 7.234 10.234 21.984 25.484 30];
YT = [0 3.5 8 7.5 6.2 0];
% Table lookup data(ONEDTable2)
XT2 = [-80 -50 -5 0 10 20 50];
YT2 = [2.5 3.5 8.0 7.5 6.2 5 3];
% Table lookup data(ONEDTable3)
XT3 = [0 1 5 10 20 25 30];
YT3 = [2.5 3.5 8.0 7.5 6.2 5 3];
%Logical Operator3
LO3 = and(and(inp1,inp8),inp2);
TAPOUT(ii,1) = LO3;
% Rate Limiter
I1toRL = inp5;
ul = (single(11) * DT) + poutRL;
ll = poutRL - (single(10.0) * DT) ;
if RLFF == 1
RLFF = 0;
outRL = I1toRL;
poutRL = outRL;
else
itemp = I1toRL;
if itemp >= ul
outRL = ul;
elseif itemp <= ll
outRL = ll;
else
outRL = itemp;
end
poutRL = outRL;
end
TAPOUT(ii,2) = outRL;
% Switch1
if ud1 == 1
ud1 = 0;
ySwitch1 = single(-10.0);
else
ySwitch1 = S1;
end
if(LO3)
S1 = outRL;
else
S1 = ySwitch1;
end
TAPOUT(ii,3) = S1;
% Rate Limiter 1(at input 6)
I1toRL1 = inp6;
ul = (single(11) * DT) + poutRL1;
ll = poutRL1 - (single(10.0) * DT);
if RL1FF == 1
RL1FF = 0;
outRL1 = I1toRL1;
poutRL1 = outRL1;
else
itemp = I1toRL1;
if itemp >= ul
outRL1 = ul;
elseif itemp <= ll
outRL1 = ll;
else
outRL1 = itemp;
end
poutRL1 = outRL1;
end
TAPOUT(ii,4) = outRL1;
% Switch3
if ud3 == 1
ud3 = 0;
ySwitch3 = single(12.4);
else
ySwitch3 = S3;
end
if(LO3)
S3 = inp3;
else
S3 = ySwitch3;
end
TAPOUT(ii,5) = S3;
% Persistence
if (LO3)
dtx = DtOn;
else
dtx = DtOff;
end
if LO3 ~= pLO3
count = 0;
end
count = count + 1;
if count > dtx
outper = LO3;
end
if initper == 1
outper = 0;
count = 1;
initper = 0;
end
pLO3 = LO3;
TAPOUT(ii,6) = outper;
% Logical Operator
LO = and(not(inp7),outper);
TAPOUT(ii,7) = LO;
%Logical Operator2
LO2 = not(LO);
TAPOUT(ii,8) = LO2;
% Output5
out5 = LO2;
% Interpolation1(ONEDTable1)
tempinp=outRL1;
if tempinp > XT1(end)
tempinp=XT1(end);
elseif tempinp < XT1(1)
tempinp=XT1(1);
end
ONEDTable1out = interp1(XT1,YT1,tempinp);
TAPOUT(ii,9) = ONEDTable1out;
% Switch2
if(inp10)
S2 = ONEDTable1out;
else
S2 = single(0);
end
TAPOUT(ii,10) = S2;
% Sum2
Sum2 = S1 + S2 - S3;
TAPOUT(ii,11) = Sum2;
% Product2
Product2 = Sum2 * single(0.39);
TAPOUT(ii,12) = Product2;
% Limit1
if (Product2 < limitmin)
y1 = limitmin;
elseif (Product2 > limitmax)
y1 = limitmax;
else
y1 = Product2;
end
TAPOUT(ii,13) = y1;
% Sum3
Sum3 = single(1) - y1;
TAPOUT(ii,14) = Sum3;
% Transient free switch2
delt = single(DT)/single(ftime2);
if (inp11 > 0)
INP2 = single(1);
else
INP2 = Sum3;
end
if (abs(inp11 - pinp11) > 0)
F2 = 1.0;
SOP2 = out_2;
end
pinp11 = inp11;
F2 = F2 - delt;
if F2 < 0
F2 = 0;
end
if (init2 > 0)
out_2 = INP2;
else
out_2 = F2*SOP2 + (1-F2)*INP2;
end
TFSout2 = out_2;
TAPOUT(ii,15) = TFSout2;
% Limit2
if (TFSout2 < limitmin)
y2 = limitmin;
elseif (TFSout2 > limitmax)
y2 = limitmax;
else
y2 = TFSout2;
end
TAPOUT(ii,16) = y2;
% Output1
out1 = TFSout2;
% Lag Filter
% output of lag filter is LFout
if LFInp ~= 0
LFInp = 0;
LFout = inp4;
else
LFPro = inp4 * 1;
LFPro1 = pinp4 * 1;
LFSum = LFPro + LFPro1;
LFPro3 = a1 * pLFout;
LFSum2 = LFSum - LFPro3;
LFDiv1 = LFSum2 / a0;
LFout = LFDiv1;
end
pLFout = LFout;
TAPOUT(ii,17) = LFout;
pinp4=inp4;
% Interpolation(ONEDTable)
tempinp=LFout;
if tempinp > XT(end)
tempinp=XT(end);
elseif tempinp < XT(1)
tempinp=XT(1);
end
ONEDTableout = interp1(XT,YT,tempinp);
TAPOUT(ii,18) = ONEDTableout;
% Transient free switch1
delt = single(DT)/single(ftime1);
if (inp10 > 0)
INP1 = ONEDTableout;
else
INP1 = 0;
end
if (abs(inp10 - pinp10) > 0)
F1 = 1.0;
SOP1 = out_1;
end
pinp10 = inp10;
F1 = F1 - delt;
if F1 < 0
F1 = 0;
end
if (init1 > 0)
out_1 = INP1;
else
out_1 = F1*SOP1 + (1-F1)*INP1;
end
TFSout1 = out_1;
TAPOUT(ii,19) = TFSout1;
% Product1
Product1 = y2 * TFSout1;
TAPOUT(ii,20) = Product1;
% Output2
out2 = Product1;
% Sum5
Sum5 = inp21 - pintegout;
TAPOUT(ii,21) = Sum5;
% Gain3
Gain3 = 10.0 * Sum5;
TAPOUT(ii,22) = Gain3;
% Integrator
% output of integrator is integout
if initinteg > 0
initinteg = single(0);
sw1 = 0;
integout = 0;
else
sw1 = (Gain3 * DT) + pintegout;
if sw1 >= up
integout = up;
elseif sw1 <= lo
integout = lo;
else
integout = sw1;
end
end
pintegout = integout;
TAPOUT(ii,23) = integout;
% Output8
out8 = integout;
% Lag Filter1
% output of Lag Filter is LF1out
if LF1Inp ~= 0
LF1Inp = 0;
LF1out = inp16;
else
LF1Pro = inp16 * 1;
LF1Pro1 = pinp16 * 1;
LF1Sum = LF1Pro + LF1Pro1;
LF1Pro3 = a1 * pLF1out;
LF1Sum2 = LF1Sum - LF1Pro3;
LF1Div1 = LF1Sum2 / a0;
LF1out = LF1Div1;
end
pLF1out = LF1out;
TAPOUT(ii,24) = LF1out;
pinp16=inp16;
% Interpolation2(ONEDTable2)
tempinp=LF1out;
if tempinp > XT2(end)
tempinp=XT2(end);
elseif tempinp < XT2(1)
tempinp=XT2(1);
end
ONEDTableout2 = interp1(XT2,YT2,tempinp);
TAPOUT(ii,25) = ONEDTableout2;
% Sum2
Sum2 = inp15 + ONEDTableout2 + inp13;
TAPOUT(ii,26) = Sum2;
% Relational Operator(A>=B)
ROout = inp17 >= single(3.5);
TAPOUT(ii,27) = ROout;
% Not3
Not3 = not(inp18);
TAPOUT(ii,28) = Not3;
% OR1
OR1 = or(ROout,Not3);
TAPOUT(ii,29) = OR1;
% Product4
Product4 = inp12 * single(1.32);
TAPOUT(ii,30) = Product4;
% Transient Free Switch7
delt = single(DT)/single(ftime7);
if (OR1 > 0)
INP7 = Product4;
else
INP7 = single(1.56);
end
if (abs(OR1 - pOR1) > 0)
F7 = 1.0;
SOP7 = out_7;
end
pOR1 = OR1;
F7 = F7 - delt;
if F7 < 0
F7 = 0;
end
if (init7 > 0)
out_7 = INP7;
else
out_7 = F7*SOP7 + (1-F7)*INP7;
end
TFSout7 = out_7;
TAPOUT(ii,31) = TFSout7;
% Lag Filter2
% output of Lag Filter2 is LF2out
if LF2Inp ~= 0
LF2Inp = 0;
LF2out = inp20;
else
LF2Pro = inp20 * 1;
LF2Pro1 = pinp20 * 1;
LF2Sum = LF2Pro + LF2Pro1;
LF2Pro3 = a1 * pLF2out;
LF2Sum2 = LF2Sum - LF2Pro3;
LF2Div1 = LF2Sum2 / a0;
LF2out = LF2Div1;
end
pLF2out = LF2out;
TAPOUT(ii,32) = LF2out;
pinp20=inp20;
% Interpolation3(ONEDTable3)
tempinp=LF2out;
if tempinp > XT3(end)
tempinp=XT3(end);
elseif tempinp < XT3(1)
tempinp=XT3(1);
end
ONEDTableout3 = interp1(XT3,YT3,tempinp);
TAPOUT(ii,33) = ONEDTableout3;
% Sum4
Sum4 = inp13 + ONEDTableout3 + inp15;
TAPOUT(ii,34) = Sum4;
% Product3
Product3 = Sum2 * inp14;
TAPOUT(ii,35) = Product3;
% Product5
Product5 = inp14 * Sum4;
TAPOUT(ii,36) = Product5;
% Relational Operator1(A<=B)
RO1out = inp17 <= single(3.25);
TAPOUT(ii,37) = RO1out;
% OR2
OR2 = or(Not3,RO1out);
TAPOUT(ii,38) = OR2;
% Persistence1
if (inp19)
dtx1 = DtOn1;
else
dtx1 = DtOff1;
end
if inp19 ~= pinp19
count1 = 0;
end
count1 = count1 + 1;
if count1 > dtx1
outper1 = inp19;
end
if initper1 == 1
outper1 = 0;
count1 = 1;
initper1 = 0;
end
pinp19 = inp19;
TAPOUT(ii,39) = outper1;
% Not4
Not4 = not(outper1);
TAPOUT(ii,40) = Not4;
% And3
And3 = and(OR2,Not4);
TAPOUT(ii,41) = And3;
% Transient Free Switch3
delt = single(DT)/single(ftime3);
if (And3 > 0)
INP3 = single(10);
else
INP3 = single(0);
end
if (abs(And3 - pAnd3) > 0)
F3 = 1.0;
SOP3 = out_3;
end
pAnd3 = And3;
F3 = F3 - delt;
if F3 < 0
F3 = 0;
end
if (init3 > 0)
out_3 = INP3;
else
out_3 = F3*SOP3 + (1-F3)*INP3;
end
TFSout3 = out_3;
TAPOUT(ii,42) = TFSout3;
% Sumxx
Sumxx = integout + Product3 + TFSout3;
TAPOUT(ii,43) = Sumxx;
% Sum5
Sum5 = integout + Product5 + TFSout3;
TAPOUT(ii,44) = Sum5;
% Limit4
if (Sumxx < single(-5.0))
y4 = -5;
elseif (Sumxx > TFSout7)
y4 = TFSout7;
else
y4 = Sumxx;
end
TAPOUT(ii,45) = y4;
% Output6
out6 = y4;
% Limit5
if (Sum5 < single(-5.0))
y5 = single(-5);
elseif (Sum5 > TFSout7)
y5 = TFSout7;
else
y5 = Sum5;
end
TAPOUT(ii,46) = y5;
% Output7
out7 = y5;
% Logical Operator5
LO5 = not(outper);
TAPOUT(ii,47) = LO5;
% Logical Operator4
LO4 = or(LO5,inp7);
TAPOUT(ii,48) = LO4;
% Sumx1
Sumx1 = integout + S3 - S1;
TAPOUT(ii,49) = Sumx1;
% Gain 0.45
Gain = Sumx1 * 0.45;
TAPOUT(ii,50) = Gain;
% Limit3
if (Gain < limitmin)
y3 = limitmin;
elseif (Gain > limitmax)
y3 = limitmax;
else
y3 = Gain;
end
TAPOUT(ii,51) = y3;
% Transient Free Switch4
delt = single(DT)/single(ftime4);
if (LO4 > 0)
INP4 = single(1);
else
INP4 = y3;
end
if (abs(LO4 - pLO4) > 0)
F4 = 1.0;
SOP4 = out_4;
end
pLO4 = LO4;
F4 = F4 - delt;
if F4 < 0
F4 = 0;
end
if (init4 > 0)
out_4 = INP4;
else
out_4 = F4*SOP4 + (1-F4)*INP4;
end
TFSout4 = out_4;
TAPOUT(ii,52) = TFSout4;
% Limit6
if (TFSout4 < limitmin)
y6 = limitmin;
elseif (TFSout4 > limitmax)
y6 = limitmax;
else
y6 = TFSout4;
end
TAPOUT(ii,53) = y6;
% Output3
out3 = y6;
% Logical Operator7
LO7 = or(LO2,inp9);
TAPOUT(ii,54) = LO7;
% Output4
out4 = LO7;
%END HERE
% The above two words indicate that the mutations end here and code below
% should not be mutated.
% Tapping out all outputs
OUT(ii,:) = [out1 out2 out3 out4 out5 out6 out7 out8];
end
% These tap out the Simulink internal signals corresponding to the Matlab
% code points.
TAPOUTSIM = [logsout.Bench_02.Logical_Operator3_1.data' %1
logsout.Bench_02.RATEL_1.data' %2
logsout.Bench_02.Switch1_1.data' %3
logsout.Bench_02.RATEL1_1.data' %4
logsout.Bench_02.Switch3_1.data' %5
logsout.Bench_02.Persistance_1.data' %6
logsout.Bench_02.Logical_Operator_1.data' %7
logsout.Bench_02.Logical_Operator2_1.data' %8
logsout.Bench_02.ONEDTable1_1.data' %9
logsout.Bench_02.Switch2_1.data' %10
logsout.Bench_02.Sum2x_1.data' %11
logsout.Bench_02.Product2_1.data' %12
logsout.Bench_02.Limit1_1.data' %13
logsout.Bench_02.Sum3_1.data' %14
logsout.Bench_02.TFS2_1.data' %15
logsout.Bench_02.Limit2_1.data' %16
logsout.Bench_02.LagFilter_1.data' %17
logsout.Bench_02.ONEDTable_1.data' %18
logsout.Bench_02.TFS1_1.data' %19
logsout.Bench_02.Product1_1.data' %20
logsout.Bench_02.Sum5_1.data' %21
logsout.Bench_02.Gain3_1.data' %22
logsout.Bench_02.INTEG_1.data' %23
logsout.Bench_02.Lag1.data' %24
logsout.Bench_02.ONEDTable2_1.data' %25
logsout.Bench_02.Sum2_1.data' %26
logsout.Bench_02.Relational_Operator_1.data' %27
logsout.Bench_02.NOT3_1.data' %28
logsout.Bench_02.OR1_1.data' %29
logsout.Bench_02.Product4_1.data' %30
logsout.Bench_02.TFS7_1.data' %31
logsout.Bench_02.Lag2.data' %32
logsout.Bench_02.ONEDTable3_1.data' %33
logsout.Bench_02.Sum4_1.data' %34
logsout.Bench_02.Product3_1.data' %35
logsout.Bench_02.Product5_1.data' %36
logsout.Bench_02.Relational_Operator1_1.data' %37
logsout.Bench_02.OR2_1.data' %38
logsout.Bench_02.Persistance1_1.data' %39
logsout.Bench_02.NOT4_1.data' %40
logsout.Bench_02.AND3_1.data' %41
logsout.Bench_02.TFS3_1.data' %42
logsout.Bench_02.Sumxx_1.data' %43
logsout.Bench_02.Sum5x_1.data' %44
logsout.Bench_02.Limit4_1.data' %45
logsout.Bench_02.Limit5_1.data' %46
logsout.Bench_02.Logical_Operator5_1.data' %47
logsout.Bench_02.Logical_Operator4_1.data' %48
logsout.Bench_02.Sumx1_1.data' %49
logsout.Bench_02.Gain_1.data' %50
logsout.Bench_02.Limit3_1.data' %51
logsout.Bench_02.TFS4_1.data' %52
logsout.Bench_02.Limit6_1.data' %53
logsout.Bench_02.Logical_Operator7_1.data']'; %54

% Block outputs comparison. The lines below plot each tapout point and can
% be used for debug.

% plot([TAPOUTSIM(:,1)-TAPOUT(:,1)]);title('1');shg;%pause;
% plot([TAPOUTSIM(:,2)-TAPOUT(:,2)]);title('2');shg;%pause;
% plot([TAPOUTSIM(:,3)-TAPOUT(:,3)]);title('3');shg;%pause;
% plot([TAPOUTSIM(:,4)-TAPOUT(:,4)]);title('4');shg;%pause;
% plot([TAPOUTSIM(:,5)-TAPOUT(:,5)]);title('5');shg;%pause;
% plot([TAPOUTSIM(:,6)-TAPOUT(:,6)]);title('6');shg;%pause;
% plot([TAPOUTSIM(:,7)-TAPOUT(:,7)]);title('7');shg;%pause;
% plot([TAPOUTSIM(:,8)-TAPOUT(:,8)]);title('8');shg;%pause;
% plot([TAPOUTSIM(:,9)-TAPOUT(:,9)]);title('9');shg;%pause;
% plot([TAPOUTSIM(:,10)-TAPOUT(:,10)]);title('10');shg;%pause;
% plot([TAPOUTSIM(:,11)-TAPOUT(:,11)]);title('11');shg;%pause;
% plot([TAPOUTSIM(:,12)-TAPOUT(:,12)]);title('12');shg;%pause;
% plot([TAPOUTSIM(:,13)-TAPOUT(:,13)]);title('13');shg;%pause;
% plot([TAPOUTSIM(:,14)-TAPOUT(:,14)]);title('14');shg;%pause;
% plot([TAPOUTSIM(:,15)-TAPOUT(:,15)]);title('15');shg;%pause;
% plot([TAPOUTSIM(:,16)-TAPOUT(:,16)]);title('16');shg;%pause;
% plot([TAPOUTSIM(:,17)-TAPOUT(:,17)]);title('17');shg;%pause;
% plot([TAPOUTSIM(:,18)-TAPOUT(:,18)]);title('18');shg;%pause;
% plot([TAPOUTSIM(:,19)-TAPOUT(:,19)]);title('19');shg;%pause;
% plot([TAPOUTSIM(:,20)-TAPOUT(:,20)]);title('20');shg;%pause;
% plot([TAPOUTSIM(:,21)-TAPOUT(:,21)]);title('21');shg;%pause;
% plot([TAPOUTSIM(:,22)-TAPOUT(:,22)]);title('22');shg;%pause;
% plot([TAPOUTSIM(:,23)-TAPOUT(:,23)]);title('23');shg;%pause;
% plot([TAPOUTSIM(:,24)-TAPOUT(:,24)]);title('24');shg;%pause;
% plot([TAPOUTSIM(:,25)-TAPOUT(:,25)]);title('25');shg;%pause;
% plot([TAPOUTSIM(:,26)-TAPOUT(:,26)]);title('26');shg;%pause;
% plot([TAPOUTSIM(:,27)-TAPOUT(:,27)]);title('27');shg;%pause;
% plot([TAPOUTSIM(:,28)-TAPOUT(:,28)]);title('28');shg;%pause;
% plot([TAPOUTSIM(:,29)-TAPOUT(:,29)]);title('29');shg;%pause;
% plot([TAPOUTSIM(:,30)-TAPOUT(:,30)]);title('30');shg;%pause;
% plot([TAPOUTSIM(:,31)-TAPOUT(:,31)]);title('31');shg;%pause;
% plot([TAPOUTSIM(:,32)-TAPOUT(:,32)]);title('32');shg;%pause;
% plot([TAPOUTSIM(:,33)-TAPOUT(:,33)]);title('33');shg;%pause;
% plot([TAPOUTSIM(:,34)-TAPOUT(:,34)]);title('34');shg;%pause;
% plot([TAPOUTSIM(:,35)-TAPOUT(:,35)]);title('35');shg;%pause;
% plot([TAPOUTSIM(:,36)-TAPOUT(:,36)]);title('36');shg;%pause;
% plot([TAPOUTSIM(:,37)-TAPOUT(:,37)]);title('37');shg;%pause;
% plot([TAPOUTSIM(:,38)-TAPOUT(:,38)]);title('38');shg;%pause;
% plot([TAPOUTSIM(:,39)-TAPOUT(:,39)]);title('39');shg;%pause;
% plot([TAPOUTSIM(:,40)-TAPOUT(:,40)]);title('40');shg;%pause;
% plot([TAPOUTSIM(:,41)-TAPOUT(:,41)]);title('41');shg;%pause;
% plot([TAPOUTSIM(:,42)-TAPOUT(:,42)]);title('42');shg;%pause;
% plot([TAPOUTSIM(:,43)-TAPOUT(:,43)]);title('43');shg;%pause;
% plot([TAPOUTSIM(:,44)-TAPOUT(:,44)]);title('44');shg;%pause;
% plot([TAPOUTSIM(:,45)-TAPOUT(:,45)]);title('45');shg;%pause;
% plot([TAPOUTSIM(:,46)-TAPOUT(:,46)]);title('46');shg;%pause;
% plot([TAPOUTSIM(:,47)-TAPOUT(:,47)]);title('47');shg;%pause;
% plot([TAPOUTSIM(:,48)-TAPOUT(:,48)]);title('48');shg;%pause;
% plot([T[APOUTSIM(:,49)-TAPOUT(:,49]));title('49');shg;%pause;
% plot([TAPOUTSIM(:,50)-TAPOUT(:,50)]);title('50');shg;%pause;
% plot([TAPOUTSIM(:,51)-TAPOUT(:,51)]);title('51');shg;%pause;
% plot([TAPOUTSIM(:,52)-TAPOUT(:,52)]);title('52');shg;%pause;
% plot([TAPOUTSIM(:,53)-TAPOUT(:,53)]);title('53');shg;%pause;
% plot([TAPOUTSIM(:,54)-TAPOUT(:,54)]);title('54');shg;%pause;

% Compute the simple difference as an error
err1=abs(TAPOUTSIM-TAPOUT);
X=logspace(-8,-2,100); % generate the X axis for the histogram
[N1] = hist(err1(:),X); % Compute historgram
NN11=NN11+N1; % Add to the store

% This is the percentage computation. If the signal is greater than 1 then
% compute percentage else keep the error.
indxgt1 = find(abs(TAPOUT) > 1);
if ~isempty(indxgt1)
err1(indxgt1)=err1(indxgt1)./abs(TAPOUT(indxgt1));
end
[N2] = hist(err1(:),X); % Compute Histogram
NN22=NN22+N2; % Store
maxerr = max(max(abs(err1))); % Compute max error and display
disp([r maxerr]);
if maxerr > 3e-4
% eval(['save err_file' num2str(r) ' Z Z1 TAPOUT TAPOUTSIM'])  % You can
% use this to save the error data for later debug is the threshold is
% greater than 3e-4.
disp(['Max error in test ' num2str(r) ' is ' num2str(maxerr)]);
end
%%
% If you are making mutants it would be advisable not to store the
% histogram data as the histogram data is for a match between the Model and
% code. Comment the save dataruns below
r=r+1;
save temp r
save dataruns NN11 NN22
% if mod(r,500)==0
% !restart.bat  % Sometimes you may want to restart matlab. Use a windows
% batch to restart the matlab program
% end
```