summaryrefslogtreecommitdiff
path: root/2048/DEPENDENCIES/delc2d.sci
blob: c038b64b2771e6854a81c152c968b1f20ce0f1be (plain)
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
// Discretizing a tf with delay
// Exact solution
// Applicable for a 1st order system

// Ref.: pg.287,Digital Control,Prof.Kannan Moudgalya

// D: Delay
// TF:  e^(-Ds)       OR       e^(-Ds)
//    ------------          ------------  (gen.)
//     tau*s + 1              tau*s + a            

//D = kTs + D' (gen.) 
// G: TF with delay component
// G1: TF with zero delay 
// Required because G cannot be directly used in Scilab
// Coefficients are returned for ascending powers of z^-1

function [B,A,k1] = delc2d(G,G1,Ts)
D = G.iodelay;
d = coeff(G1('den'));
  if d(1) == 1
  tau = d(2);
  mu = 1;
  else
  tau = d(2)/d(1);
  mu = 1/d(1);
  end;
  
k = floor(D/Ts);
Dpri = D - k*Ts;
Dis = ((%z*(1 - (exp(-(Ts - Dpri)/tau)) ) )+ (exp(-(Ts - Dpri)/tau) - exp(-Ts/tau) ))/ ((%z^(k+1))*(%z - exp(-Ts/tau))) 
Dis1 = Dis*mu;
disp('Warning: Exact discretization of first order system only');
k1 = degree(Dis1('den')) - degree(Dis1('num'));
B = coeff(Dis1('num'));
A = coeff(Dis1('den'));
B = flip(B);
A = flip(A);
endfunction;