-
Notifications
You must be signed in to change notification settings - Fork 4
/
sigma.sci
141 lines (118 loc) · 4.93 KB
/
sigma.sci
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function [output,w]=sigma(varargin)
//Calling Sequence
// sigma(sys)
// sigma(sys,{Wmin,Wmax})
// sigma(sys,W)
// sigma(sys1,sys2,sys3,sys4,...,W)
// [V,W]=sigma(sys)
//
//Parameters
// sys - dynamic system
// Wmin - Minimum frequency in radians/unit from which the singular values of the system are to be calculated.
// Wmax - Maximum frequency in radians/unit upto which the singular values of the system are to be calculated.
// W - Range of frequencies in which the singular values of the system has to be calculated.
// V - Singular values of the systems in the range of frequency W.
//
//Description
// Sigma function plots or calculates Singular values of dynamic systems.
// When frequency range is not specified, it is chosen automatically.
//
//Examples
// s=%s;
// sys=syslin('c',1/(1+s));
// sigma(sys)
// sigma(sys,sys^2)
// sigma(sys,20:40)
//
//See also
// sigmaplot,bode.
//
//Authors
// Paresh Yeole
// email-id:- [email protected]
[lhs,rhs]=argn(0);
x=logspace(-3,3);
//________________if freq vector or freqfinal is given//__________________//________________//
if rhs > 1 then
if typeof(varargin($)) == 'constant' then
if ~isreal(varargin($)) then
error("sigma:The freq values must be real and positive")
end
if size(varargin($)) == [1 2] then
if varargin($) <= 0 then
error(msprintf(gettext("%s: The final time value must be a positive real number.\n"),"sigma"))
end
if(varargin($)(1)>=varargin($)(2)) then
error("sigma:The frequency interval must be specified as {WMIN,WMAX} where WMIN and WMAX are positive frequencies satisfying WMIN<WMAX.");
end
x=varargin($)(1):0.01:varargin($)(2);
elseif (isequal(size(varargin($)),[1 2]) == %f & size(varargin($),'*')<>1) then
x=varargin($);
elseif (size(varargin($),'*')==1) then
error("sigma:The frequency interval must be specified as {WMIN,WMAX} where WMIN and WMAX are positive frequencies satisfying WMIN<WMAX.");
end
end
end
//______________________________________________________________//
CIindex=1;
//____________PLOTS__________________________________//
if lhs==1 then
for i=1:rhs
CIindex=CIindex+1;
if or(typeof(varargin(i))==['string','boolean']) then
continue;
end
//__________________SiSo system & MIMO systems__________________________//
if(or(typeof(varargin(i))==['rational','state-space']) & (i==rhs | typeof(varargin(i+1))<>'boolean' )) then
y=svplot(varargin(i),x);
y=20*log10(y);
if (i<>rhs & typeof(varargin(i+1))=='string') then
plot(x,y,varargin(i+1));
else
plot(x,y);
hh=gce();
hh.children.foreground=CIindex;
end
//______________.siso arrays.__________________________//
elseif(or(typeof(varargin(i))==['rational','state-space']) & (typeof(varargin(i+1))=='boolean' )) then
if(varargin(i+1)<>%T) then
error("Sigma: Siso array must be followed with boolean input %T");
end
xx=size(varargin(i),'r');
yy=size(varargin(i),'c');
zz=size(varargin(i),3);
for ii=1:xx
for j=1:yy
for k=1:zz
y=svplot(varargin(i)(ii,j,k),x);
y=20*log10(y);
if (i<>rhs-1 & typeof(varargin(i+2))=='string') then
plot(x,y,varargin(i+2));
else
plot(x,y);
hh=gce();
hh.children.foreground=CIindex;
end
end
end
end
end
end;
xtitle("singular values","Frequency(rad/s)","Singular Values(dB)");
end
output="Singular-Value Plot";
//_________________No plots only values______________________________//
//___________________when output arguments_________________________//
if lhs>1 then
if(rhs>2 | (rhs==2 & typeof(varargin(2))<>'constant')) then
error("sigma:command operates on a single model when used with output arguments.");
end
y=svplot(varargin(1));
output=y;
w=x;
end
// y=svplot(varargin(1));
// y=20*log10(y);
//
// plot(x,y);
endfunction