-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetRiseTime.m
64 lines (53 loc) · 1.63 KB
/
getRiseTime.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
57
58
59
60
61
62
63
64
%
% getRiseTime.m
%
% Calculate the rise time for a unit step input.
%
% Inputs: tData - simulation time values
% oData - corresponding response values
% finalVal - the reference value to rise to
% lVal - lower bound for rise time (default is 0.1)
% uVal - upper bound for rise time (default is 0.9)
% Output: the rise time
%
function riseTime = getRiseTime(tData, oData, finalVal, lVal, uVal);
badvals = 0;
if nargin == 5
if lVal < 0 | lVal > 1 | uVal < lVal | uVal > 1
disp('Rise time bounds are unacceptable. Using defaults.');
badvals = 1;
end
end
if nargin < 5 | badvals == 1
% Set defaults.
lVal = 0.1;
uVal = 0.9;
end
% Express bounds in response format.
lVal = lVal * finalVal;
uVal = uVal * finalVal;
% Find the time to reach upper limit.
indexUp = min(find(oData > uVal));
if ~isempty(indexUp)
% Linearly interpolate for greater accuracy.
if indexUp ~= 1
timeUp = tData(indexUp-1) + (tData(indexUp) - tData(indexUp-1)) * ...
(uVal - oData(indexUp-1)) / (oData(indexUp) - oData(indexUp-1));
else
timeUp = tData(indexUp);
end
% Find the time to reach the lower bound.
indexDown = min(find(oData > lVal));
% NB: This index will exist, if we passed the test for the upper bound.
if indexDown ~= 1
timeDown = tData(indexDown-1) + (tData(indexDown) - tData(indexDown-1)) * ...
(lVal - oData(indexDown-1)) / (oData(indexDown) - oData(indexDown-1));
else
timeDown = tData(indexDown);
end
% Calculate rise-time.
riseTime = timeUp - timeDown;
else
disp('Response failed to reach upper rise time bound.');
riseTime = Inf;
end