-
Notifications
You must be signed in to change notification settings - Fork 4
/
bandwidth.sci
249 lines (222 loc) · 6.56 KB
/
bandwidth.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
function[fw]=bandwidth(sys,varargin)
//
//Calling Sequence
// fw=bandwidth(sys) ----for SISO transfer function CT,DT and state space --dbdrop=-3db
// fw=bandwidth(sys,dbdrop) --computes bandwidth at given dbdrop
// fw=bandwidth(sys,[],1) --for SISO array --dbdrop=-3db
// fw=bandwidth(sys,dbdrop,1) ---for SISO array at given dbdrop
//Parameters
// sys- SISO system which can be continuous as well as Discrete time . It can either be in transfer function form or state-space form.
// dbdrop - It is the desired drop at which the bandwidth has to be calculated.
//Description
// function is to find bandwidth of CT system,DT system,SS system for SISO type of systems only.
// [fw]=bandwidth(sys,dbdrop) determines the bandwidth of the system at the given dbdrop.
// if array of siso system is to be passed then call as:-fw=bandwidth(sys,dbdrop,1)
// Note:-"dbdrop must be negative value".
//Examples
// 1.a1=ssrand(1,1,2);
// y=bandwidth(a1);
// 2.s=poly(0,'s');
// sys=syslin('c',(s+2)/(s^4+3*s+12));
// y2=bandwidth(sys);
//See also
// horner,dcgain.
//Authors
// Rutuja Moharil & Paresh Yeole
//Bibliography
// 1. https://en.wikipedia.org/wiki/Bandwidth
[lhs rhs]=argn(0);
if rhs<1 then
error("bandwidth:input parameter as a dynamic system is expected");
end
n=length(varargin);
if((n>=1 & ( varargin(1)==%nan | varargin(1)>0) ) ) then
if(n==2 & varargin(1)==[]) then
else
error(msprintf(_("dbdrop must be real and negative:bandwidth")));
end
end
if(n==0 | (n==2 & varargin(1)==[])) then
dbdrop=0.7079;
//if(varargin(1)==[]) then
//dbdrop=0.7079;
elseif(n==1 | n==2) then
dbdrop=10^(varargin(1)/20);
end
select typeof(sys)
case "rational" then
if(n==2 & varargin(2)==1) then
o=0;
else
o=1;
end
case "state-space" then
sys=ss2tf(sys)
o=1;
case "constant" then
fw=0;
return;
else
msprintf("\n")
error(97,1),
end;
//bandwidth is defined for only SISO systems.
if (or(size(sys)<>[1 1]) & o==1) then
// if ~(typeof(sum(sys)) == "rational") then
error(msprintf(_("\n %s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"bandwidth",1))
///end
end
//[p, m] = size (sys);
// if (p*m <> 1) then
//if (typeof(sum(sys)) == "rational") then
// error(msprintf(_("\n %s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"bandwidth",1))
//end
// end
w=poly(0,'w');
el=1e-7;
//niw=((real(horner(sys.num,%i*w)))^2)+((abs(imag(horner(sys.num,%i*w))))^2);
//diw=((real(horner(sys.den,%i*w)))^2)+((abs(imag(horner(sys.den,%i*w))))^2);
if(sys.dt=='c') then
//t=horner(sys,0);
if(o==1) then
try
t=horner(sys,0);
catch
fw=%nan;
return;
end
// if(isinf(t)) then
// fw=NaN;
//elseif (t==0) then
// fw= Inf;
// else
niw=(((horner(sys.num,%i*w))))*(conj(horner(sys.num,%i*w)));
diw=(((horner(sys.den,%i*w))))*(conj(horner(sys.den,%i*w)));
p=(roots(niw-((t*dbdrop)^2)*diw));
fw=real(p(find((abs(imag(p))<el)&real(p)>0)));
//end
else
// aa=size(sys);
y=ndims(sys);
//if(y>2)then
if(y==3) then
for i=1:size(sys,'r')
for j=1:size(sys,'c')
for k=1:size(sys,3)
try
t=horner(sys(i,j,k),0);
catch
fw(i,j,k)=%nan;
continue;
end
// if(isinf(t)) then
// fw=NaN;
//elseif (t==0) then
// fw= Inf;
//
//else
niw=(((horner(sys(i,j,k).num,%i*w))))*(conj(horner(sys(i,j,k).num,%i*w)));
diw=(((horner(sys(i,j,k).den,%i*w))))*(conj(horner(sys(i,j,k).den,%i*w)));
p=(roots(niw-((t*dbdrop)^2)*diw));
k1=real(p(find((abs(imag(p))<el)&real(p)>0)));
if(k1==[]) then
fw(i,j,k)=%inf;
else
fw(i,j,k)=k1;
end
//end
end
end
end
//end
else
for i=1:size(sys,'r')
for j=1:size(sys,'c')
//for k=1:size(sys,3)
try
t=horner(sys(i,j),0);
catch
fw(i,j)=%nan;
continue;
end
//if(isinf(t)) then
// fw=NaN;
//elseif (t==0) then
// fw= Inf;
//
// else
niw=(((horner(sys(i,j).num,%i*w))))*(conj(horner(sys(i,j).num,%i*w)));
diw=(((horner(sys(i,j).den,%i*w))))*(conj(horner(sys(i,j).den,%i*w)));
p=(roots(niw-((t*dbdrop)^2)*diw));
k1=real(p(find((abs(imag(p))<el)&real(p)>0)));
if(k1==[]) then
fw(i,j)=%inf;
else
fw(i,j)=k1;
end
end
end
end
end
//end
else
if(sys.dt=='d') then
q=1;
else
q=sys.dt
end
if(o==1) then
try
t=horner(sys,1);
catch
fw=%nan;
end;
//else
//z=%e^((%i*w)*q);
//g=horner(sys.num,z)*horner(sys.num,1/z);
//f=horner(sys.den,z)*horner(sys.den,1/z);
//u=roots(((gain*t)^2)*f-g);
//fw=real(u(find((abs(imag(u))<el)&real(u)>0)));
z=poly(0,varn(sys.den));
sm=simp_mode();
simp_mode(%f);
hh=sys*horner(sys,1/z)-(t*dbdrop)^2;
simp_mode(sm);
//find the numerator roots
z=roots(hh.num,"e");
z(abs(abs(z)-1)>el)=[];// retain only roots with modulus equal to 1
w=log(z)/(%i*q);
ws=real(w(abs(imag(w))<el&real(w)>0)); //frequency points with unitary modulus
fw = ws;
else
for i=1:size(sys,'r')
for j=1:size(sys,'c')
for k=1:size(sys,3)
try
t=horner(sys(i,j,k),1);
catch
fw(i,j,k)=%nan;
continue;
end
z=poly(0,varn(sys(i,j,k).den));
sm=simp_mode();
simp_mode(%f);
hh=sys(i,j,k)*horner(sys(i,j,k),1/z)-(t*dbdrop)^2;
simp_mode(sm);
//find the numerator roots
z=roots(hh.num,"e");
z(abs(abs(z)-1)>el)=[];// retain only roots with modulus equal to 1
w=log(z)/(%i*q);
ws=real(w(abs(imag(w))<el&real(w)>0)); //frequency points with unitary modulus
fw(i,j,k) = ws;
end
end
end
end
//if fw=[] then it means either the bandwidth is finite or band
//end
end
if(fw==[]) then
fw=%inf;
end;
endfunction