-
Notifications
You must be signed in to change notification settings - Fork 4
/
Eval_delay.m
56 lines (52 loc) · 1.68 KB
/
Eval_delay.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [FAR,MAR,EDD] = Eval_delay(normal_data, faulty_data, x_trip, delay_on, delay_off, alm_deadband, alm_type)
% compute Expected Detection Delay (EDD) for delay-timers
%
if nargin < 6
alm_deadband = 0;
end
if nargin < 7
alm_type = 'HI';
end
n = delay_on;
m = delay_off;
switch alm_type
case 'HI'
% probability of ALM
p1 = 1-ksdensity(normal_data, x_trip, 'function', 'cdf');
q2 = 1-ksdensity(faulty_data, x_trip, 'function', 'cdf');
% probability of NA
p2 = ksdensity(normal_data, x_trip-alm_deadband, 'function', 'cdf');
q1 = ksdensity(faulty_data, x_trip-alm_deadband, 'function', 'cdf');
case 'LO'
% probability of ALM
p2 = 1-ksdensity(normal_data, x_trip+alm_deadband, 'function', 'cdf');
q1 = 1-ksdensity(faulty_data, x_trip+alm_deadband, 'function', 'cdf');
% probability of NA
p1 = ksdensity(normal_data, x_trip, 'function', 'cdf');
q2 = ksdensity(faulty_data, x_trip, 'function', 'cdf');
end
p2_sum = zeros(size(x_trip));
for i=1:m
p2_sum = p2_sum + p2.^(i-1);
end
p1_sum = zeros(size(x_trip));
for i=1:n
p1_sum = p1_sum + p1.^(i-1);
end
FAR = (p1.^n).*p2_sum./((p1.^n).*p2_sum + (p2.^m).*p1_sum);
q1_sum = zeros(size(x_trip));
for i=1:m
q1_sum = q1_sum + q1.^(i-1);
end
q2_sum = zeros(size(x_trip));
for i=1:n
q2_sum = q2_sum + q2.^(i-1);
end
MAR = (q1.^m).*q2_sum./((q1.^m).*q2_sum + (q2.^n).*q1_sum);
pq_sum = zeros(size(x_trip));
for j=0:n-1
for k=0:n-j-1
pq_sum = pq_sum + (p1.^j) .* (q2.^k);
end
end
EDD = p2.^(m-1).*(p1.^n .* q1.*q2_sum + p2.*(pq_sum - q2.^n .* p1_sum))./(q2.^n .* (p2.^m .* p1_sum + p1.^n .* p2_sum));