-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTstats.cpp
executable file
·119 lines (110 loc) · 2.89 KB
/
Tstats.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/////////////////////////////////////////////////////////////////////////
// Program : tstats.cpp
// Coded by : Prof. Gang-Gyoo Jin, Korea Maritime University
// Coded on : 12/12/2003
#include <math.h>
#include "rmatrix.h"
/////////////////////////////////////////////////////////////////////////
// TStats computes performance from the output response of a system and
// returns overshoot(Mp), peak time(tp), rise time(tr), steady-state error(ess)
// and settling time(ts) (opts=0: 2% ts, otherwise: 5% ts)
void ms_TStats(REAL t[],REAL y[],REAL yr,int n,REAL &mp,REAL &tp,REAL &tr,REAL &ts,REAL &ess, int opts)
{
int i, i10= 0, i90= 0, iess= 0, pass= 0;
REAL ymax, t0, t1, y0, y1, t10, t90, per;
REAL ms_VMax(REAL v[], int n, int &iv);
ymax= ms_VMax(y, n, i);
mp= (ymax >= yr) ? 100.0*(ymax-yr)/yr : 0.0;
tp= (ymax >= yr) ? t[i] : 0.0;
ess= fabs(yr-y[n-1]);
per= (opts == 0) ? 0.02:0.05;
for(i=0; i<n; i++)
{
if(pass == 0)
if(y[i] <= 0.1*yr)
i10= i;
else
pass= 1;
else if(pass == 1)
if(y[i] <= 0.9*yr)
i90= i;
else
pass= 2;
if(fabs(yr-y[i]) > per) // 2% or 5% ts
iess= i;
}
if(pass == 2)
{
t0= t[i90]; y0= y[i90];
t1= t[i90+1]; y1= y[i90+1];
t90= t1-(t1-t0)*(y1-0.9*yr)/(y1-y0);
t0= t[i10]; y0= y[i10];
t1= t[i10+1]; y1= y[i10+1];
t10= t1-(t1-t0)*(y1-0.1*yr)/(y1-y0);
tr= t90-t10;
}
else
tr= t[n-1];
if(iess == n-1)
ts= t[n-1];
else
{
t0= t[iess];
t1= t[iess+1];
ts= (t0+t1)/2.0;
}
return;
}
/////////////////////////////////////////////////////////////////////////
// TStats computes performance from the output response of a system and
// returns overshoot(Mp), peak time(tp), rise time(tr), steady-state error(ess)
// and settling time(ts) (opts=0: 2% ts, otherwise: 5% ts)
void ms_TStats(const RVECTOR &t,const RVECTOR &y,REAL yr,REAL &mp,REAL &tp,REAL &tr,REAL &ts,REAL &ess, int opts)
{
int i, i10= 0, i90= 0, iess= 0, pass= 0, n=t.num;
REAL ymax, t0, t1, y0, y1, t10, t90, per;
REAL ms_VMax(const RVECTOR &v, int &iv);
if(t.num!=y.num)
ErrorMsg("Error in 'TStats': Check the sizes of t and y");
ymax= ms_VMax(y, i);
mp= (ymax >= yr) ? 100.0*(ymax-yr)/yr : 0.0;
tp= (ymax >= yr) ? t(i) : 0.0;
ess= fabs(yr-y(n-1));
per= (opts == 0) ? 0.02:0.05;
for(i=0; i<n; i++)
{
if(pass == 0)
if(y(i) <= 0.1*yr)
i10= i;
else
pass= 1;
else if(pass == 1)
if(y(i) <= 0.9*yr)
i90= i;
else
pass= 2;
if(fabs(yr-y(i)) > per) // 2% or 5% ts
iess= i;
}
if(pass == 2)
{
t0= t(i90); y0= y(i90);
t1= t(i90+1); y1= y(i90+1);
t90= t1-(t1-t0)*(y1-0.9*yr)/(y1-y0);
t0= t(i10); y0= y(i10);
t1= t(i10+1); y1= y(i10+1);
t10= t1-(t1-t0)*(y1-0.1*yr)/(y1-y0);
tr= t90-t10;
}
else
tr= t(n-1);
if(iess == n-1)
ts= t(n-1);
else
{
t0= t(iess);
t1= t(iess+1);
ts= (t0+t1)/2.0;
}
return;
}