image thumbnail
from Safety Critical Control Elements Examples by Chethan C U
The files contained have the examples for safety critical control elements.

x=GenRandomTestBool(NoOfTransitions,EndTime,DT)
% Safety Critical Control Design.
% Control element Simulation and testing Examples.
% Based on requirements available at
% http://www.mathworks.in/matlabcentral/fileexchange/39047-testing-of-safet
% y-critical-control-systems
%
% Copyright Chethan CU - chethan.cu@gmail.com 
% Jan 2013

function x=GenRandomTestBool(NoOfTransitions,EndTime,DT)
% This function is used to generate Random Boolean Signals. The signal x
% changes at random instants on time between 0 to EndTime. NoOfTransitions
% is the count of desired number of transitions.

dt=DT;


a=rand(NoOfTransitions,1)*EndTime;
b=sort(ceil(a/dt)*dt);


t=0:dt:EndTime;
%x=zeros(length(t),1);


IC=rand();
if(IC>0.5)
    flag=0;
else
    flag=1;
end

rand_index=1;
for n=1:EndTime*1/dt+1
    if(rand_index~=NoOfTransitions)
        if(t(n)>=b(rand_index))
            flag=~flag;
            rand_index=rand_index+1;
        end
    end
    x(n)=flag;
end
x=[  x' ];


%plot(t,x)
%shg;

Contact us