Digital Control Systemoo Khimani
Digital Control Systemoo Khimani
Solutions provided by
Prof Deepti Khimani
Instrumentation Engineering
Mumbai/ V.E.S. Institute of Technology
2
12 Determine stability of a given system by using Lyapunov
stability analysis. 49
3
List of Experiments
4
List of Figures
1.1 Lab01 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2 Lab01 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1 Lab02 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Lab02 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1 Lab03 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1 Lab04 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Lab04 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.1 Lab05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.2 Lab05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.1 Lab06 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6.2 Lab06 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
9.1 Lab09 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.2 Lab09 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
10.1 Lab10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
10.2 Lab10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
11.1 Lab11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
13.1 Lab13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
13.2 Lab13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5
Experiment: 1
1 // Lab01 : (A) R e p r e s e n t t h e g i v e n d i s c r e t e −t i m e (
s a m p l e d d a t a ) sytem u s i n g
2 // p u l s e t r a n s f e r f u n c t i o n and s t a t e
space forms .
3 // (B) O b s e r v e t h e r e s p o n s e s o f c o n t i n u o u s −
t i m e and s a m p l e d d a t a s y s t e m .
4
5 // scilab − 5.5.1
6 // O p e r a t i n g System : Windows 7 , 32− b i t
7 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
8 // C l e a n t h e e n v i r o n m e n t
9 close ;
10 clear ;
6
11 clc ;
12 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
13 //A . R e p r e s e n t a t i o n o f d i s c r e t e −t i m e m o d e l s
14 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
15
16 // S t a t e s p a c e r e p r e s e n t a t i o n
17 A =[0 1; -0.2 -0.1];
18 B =[0 1] ’;
19 C =[1 0];
20 D =0;
21 sysd = syslin ( ’ d ’ ,A ,B ,C , D ) ;
22
23 // P u l s e t r a n s f e r f u n c t i o n r e p r e s e n t a t i o n
24 Num =1;
25 Den = poly ([0.2 0.1 1] , ’ z ’ , ’ c o e f f ’ ) ;
26 Gz1 = syslin ( ’ d ’ ,Num , Den )
27
28 // P u l s e t r a n s f e r f u n c t i o n from s s model
29 Gz2 = ss2tf ( sysd )
30
31 // R e s p o n s e o f t h e s y s t e m w i t h s a m p l i n g t i m e Ts =0.5
sec .
32
33 // s a m p l i n g Time
34 Ts =0.5;
35 t =0: Ts :10;
36 u = ones (1 , length ( t ) ) ;
37
38 y = flts (u , sysd ) ;
39 plot2d2 (t ,y ,2)
40 zoom_rect ([0 0 10 1.2])
41 xgrid (35)
42 title ( ’ R e s p o n s e o f d i s c r e t e t i m e s y s t e m ’ , ’ f o n t s i z e ’
,3)
7
43 xlabel ( ’ kT ’ , ’ f o n t s i z e ’ ,2)
44 ylabel ( ’ y ( kT ) ’ , ’ f o n t s i z e ’ ,2)
45
46 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
47 // (B) R e s p o n s e s o f t h e c o n t i n u o u s −t i m e and d i s c r e t e
−t i m e model o f t h e g i v e n
48 // system .
49 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
50
51 // p o l e s o f c o n t i u o u s t i m e s y s t e m a r e a t −1 , −2 and
−3;
52 den = poly ([ -1 , -2 , -3] , ” s ” , ’ r o o t s ’ ) ;
53 num =1;
54 g = num ./ den
55 g = syslin ( ’ c ’ ,g )
56 tc =0:0.2:10;
57 yc = csim ( ” s t e p ” ,tc , g )
58
59 // D i s c r e t e −t i m e r e s p r e s e n t a t i o n w i t h Ts = 0 . 5 ;
60 sysz = dscr (g , Ts ) ;
61 gz = ss2tf ( sysz )
62 yd = flts (u , sysz ) ;
63
64 // R e s p o n s e s
65 figure ,
66 plot ( tc , yc , ’ b l u e ’ ) // c o n t i n u o u s t i m e s y s t e m
67 plot2d2 (t , yd ,5) // D i s c r e t e t i m e s y s t e m
68 title ( ’ R e s p o n s e s o f c o n t i n u o u s and d i s c r e t e t i m e
s y s t e m ’ , ’ f o n t s i z e ’ ,3)
69 xlabel ( ’ t ’ , ’ f o n t s i z e ’ ,2)
70 ylabel ( ’ y ( t ) , ( y ( kT ) ’ , ’ f o n t s i z e ’ ,2)
71 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e handle
72 f . background =8
73 xgrid (36)
8
Figure 1.1: Lab01
74 h = legend ( ’ y ( t ) ’ , ’ y ( kT ) ’ )
75 h . legend_location = ” i n l o w e r r i g h t ”
9
Figure 1.2: Lab01
10
Experiment: 2
1 // Lab02 : D i s c r e t i z e t h e g i v e n c o n t i n u o u s −t i m e
s i g n a l u s i n g Z e r o Order Hold
2 // and F i r s t Order Hold t e c h n i q u e s .
3
4 // scilab − 5.5.1
5 // O p e r a t i n g System : Windows 7 , 32− b i t
6 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
7 // C l e a n t h e e n v i r o n m e n t
8 close ;
9 clear ;
10 clc ;
11
12 // ramp g e n e r a t o r d u r i n g s a m p l i n g p e r i o d
11
Figure 2.1: Lab02
12
Figure 2.2: Lab02
13
Experiment: 3
1 // Lab03 : D i s c r e t i z e t h e g i v e n c o n t i n u o u s −t i m e
system
2 // using B i l i n e a r Transformation .
3
4 // scilab − 5.5.1
5 // O p e r a t i n g System : Windows 7 , 32− b i t
6 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
7 // C l e a n t h e e n v i r o n m e n t
8 close ;
9 clear ;
10 clc ;
11
12 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
14
13 // S t a t e s p a c e r e p r e s e n t a t i o n o f c o n t i n u o u s t i m e
system
14 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
15 //
16 A =[0 1; -6 -5];
17 B =[0 1] ’;
18 C =[1 0];
19 D =0;
20 sysc = syslin ( ’ c ’ ,A ,B ,C , D ) ;
21 // t r a n s f e r f u n c t i o n
22 Gs = ss2tf ( sysc )
23 disp ( ’ Gs= ’ )
24 disp ( Gs )
25 // R e s p o n s e o f t h e s y s t e m
26 tc =0:0.1:10;
27 yc = csim ( ” s t e p ” ,tc , sysc ) ;
28
29 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
30 // D i s c r e t i z a t i o n o f t h e s y s t e m u s i n g b i l i n e a r
transformation at
31 // s a m p l i n g t i m e Ts =0.5 s e c
32 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
33 Ts =0.5;
34 sysd = cls2dls ( sysc , Ts ) ;
35 // P u l s e t r a n s f e r f u n c t i o n
36 Gz = ss2tf ( sysd )
37 disp ( ’ Gz= ’ )
38 disp ( ’ Gz= ’ , Gz )
39 // R e s p o n s e o f t h e d i s c r e t e s y s t e m
40 td =0: Ts :10;
41 ud = ones (1 , length ( td ) ) ;
42 yd = flts ( ud , sysd ) ;
15
43
44 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
45 // P l o t i n g t h e r e s p o n s e s
46 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
47 plot2d ( tc , yc ,5) // c o n t i n u o u s t i m e
48 plot2d2 ( td , yd ,2) // D i s c r e t e t i m e
49 xgrid (35)
50 title ( ’ R e s p o n s e s o f c o n t i n o u s and T u s t i n t r a n s f o r m e d
d i s c r e t e t i m e s y s t e m ’ , ’ f o n t s i z e ’ ,3)
51 xlabel ( ’ kT ’ , ’ f o n t s i z e ’ ,2)
52 ylabel ( ’ y ( kT ) ’ , ’ f o n t s i z e ’ ,2)
53 h = legend ( ’ y ( t ) ’ , ’ y ( kT ) ’ )
54 h . legend_location = ” i n l o w e r r i g h t ” ;
16
Figure 3.1: Lab03
17
Experiment: 4
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // // System model
12 s = poly (0 , ’ s ’ ) ;
13 Ts =0.2;
14 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
18
15 // S−p l a n e p o l e −z e r o map f o r t h e c o n t i n u o u s t i m e
system
16 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
32 //Z−p l a n e p o l e −z e r o map f o r t h e s a m p l e d a t a s y s t e m
33 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
34 figure ;
35 for sigma =[ -1 1]
36 for w =0:0.2:16
37 num =1;
38 den = poly ([ - sigma + %i *w , - sigma - %i * w ] , ’ s ’ ) ;
39 g = syslin ( ’ c ’ , num ./ den ) ;
40 gz = dscr (g , Ts )
41 plzr ( gz ) ;
42 end
43 end
44 zgrid () ;
19
Figure 4.1: Lab04
45 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
46 f . background =8
47 title ( ’ Z−p l a n e p o l e −z e r o map f o r t h e c o n s t a n t
a t t e n u a t i o n l o c i ’ , ’ f o n t s i z e ’ ,3)
48
49 // Zoom a x e s f o r c l a r i t y
50 zoom_rect ([ -1.5 -1.5 1.5 1.5])
20
Figure 4.2: Lab04
21
Experiment: 5
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // System model
12 s = poly (0 , ’ s ’ ) ;
13 Ts =0.2;
14 w =1.5;
15
16 //
22
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
17 // S−p l a n e p o l e −z e r o map f o r t h e c o n t i n u o u s t i m e
system
18 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
32 //Z−p l a n e p o l e −z e r o map f o r t h e s a m p l e d a t a s y s t e m
33 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
34 figure ;
35 for sigma = -1.1:0.2:20
36 num =1;
37 den = poly ([ - sigma + %i *w , - sigma - %i * w ] , ’ s ’ ) ;
38 g = syslin ( ’ c ’ , num ./ den ) ;
39 gz = dscr (g , Ts )
40 plzr ( gz ) ;
41 end
42 zgrid ()
43 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
44 f . background =8
23
Figure 5.1: Lab05
24
Figure 5.2: Lab05
25
Experiment: 6
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // System model
12 s = poly (0 , ’ s ’ ) ;
13 Ts =0.2;
14 //
26
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
15 // S−p l a n e p o l e −z e r o map f o r t h e c o n t i n u o u s t i m e
system
16 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
17 for w =0:0.2:19
18 sigma = w ;
19 num =1;
20 den = poly ([ - sigma + %i *w , - sigma - %i * w ] , ’ s ’ ) ;
21 g = syslin ( ’ c ’ , num ./ den ) ;
22 plzr ( g )
23 end
24 sgrid ()
25 title ( ’ S−p l a n e p o l e −z e r o map f o r t h e c o n s t a n t
damping r a t i o l o c i ’ , ’ f o n t s i z e ’ ,3)
26
27 // Zoom a x e s f o r c l a r i t y
28
29 zoom_rect ([ -20 -22 20 22])
30
31 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
32 //Z−p l a n e p o l e −z e r o map f o r t h e s a m p l e d a t a s y s t e m
33 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
34 figure ;
35 for w =0:0.2:19
36 sigma = w ;
37 num =1;
38 den = poly ([ - sigma + %i *w , - sigma - %i * w ] , ’ s ’ ) ;
39 g = syslin ( ’ c ’ , num ./ den ) ;
40 gz = dscr (g , Ts )
41 plzr ( gz ) ;
42 end
27
Figure 6.1: Lab06
43 zgrid () ;
44 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
45 f . background =8
46 title ( ’ Z−p l a n e p o l e −z e r o map f o r t h e c o n s t a n t
damping r a t i o l o c i ’ , ’ f o n t s i z e ’ ,3)
47
48 // Zoom a x e s f o r c l a r i t y
49 zoom_rect ([ -1.2 -1.2 1.2 1.2])
28
Figure 6.2: Lab06
29
Experiment: 7
1 // Lab . 0 7 : T r a n s f o r m t h e d i s c r e t e −t i m e s t a t e model
i n t o c a n o n i c a l forms .
2
3 // scilab − 5.5.1
4 // O p e r a t i n g System : Windows 7 , 32− b i t
5 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // S t a t e s p a c e model
12 A =[0 -0.4; 1 -1.3];
13 B =[0;1];
14 C =[0 1];
30
15 D =0;
16
17 sys = syslin ( ’ d ’ ,A ,B ,C , D )
18 mprintf ( ’ S t a t e s p a c e r e p r e s e n t a t i o n of the given
d i s c r e t e system i s ’ )
19 disp ( sys )
20
21 // T r a n s f e r f u n c t i o n model
22 systf = ss2tf ( sys )
23 mprintf ( ’ T r a n s f e r f u n c t i o n o f t h e g i v e n d i s c r e t e
system i s ’ )
24 disp ( systf )
25
26
27 // E i g e n v a l u e s o f s y s t e m m a t r i x
28 eig_val = spec ( A )
29 mprintf ( ’ E i g e n v a l u e s o f t h e s y s t e m m a t r i x a r e ’ )
30 disp ( eig_val )
31
32 // C o n t r o l l a b l e c a n o n i c a l form
33 [ Phi , Gamma , T ]= canon (A , B )
34 T = flipdim (T ,2) ;
35 Phi = T \ A * T ;
36 Gamma = T \ B ;
37 C=C*T;
38 D=D;
39 sysd = syslin ( ’ d ’ ,Phi , Gamma ,C , D )
40 mprintf ( ’ S t a t e s p a c e r e p r e s e n t a t i o n o f t h e g i v e n
d i s c r e t e system ’ )
41 disp ( ’ i n c o n t r o l l a b l e c a n o n i c a l form i s ’ )
42 disp ( sysd )
43
44 // D i a g o n a l form
45 [ Phid M ]= bdiag ( A ) ;
46 Gammad = M \ B ;
47 Cd = C * M ;
48 Dd = D ;
49 sysd = syslin ( ’ d ’ , Phid , Gammad , Cd , Dd )
31
50 mprintf ( ’ S t a t e s p a c e r e p r e s e n t a t i o n o f t h e g i v e n ’ )
51 disp ( ’ d i s c r e t e s y s t e m i n d i a g o n a l form i s ’ )
52 disp ( sysd )
32
Experiment: 8
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // S t a t e s p a c e r e p r e s e n t a t i o n
12 A =[ -0.2 0;0 -0.8];
13 B =[1 1] ’;
14 C =[4/3 -1/3];
15 D =0;
16 sys = syslin ( ’ d ’ ,A ,B ,C , D )
33
17
18 // C o n t r o l l a b i l i t y t e s t
19
20 n = cont_mat ( sys )
21 mprintf ( ’ C o n t r o l l a b i l i t y m a t r i x i s ’ )
22 disp ( n )
23
24 if rank ( n ) ==2 then
25 disp ( ’ Rank o f c o n t r o l l a b i l i t y m a t r i x i s f u l l , ’ )
26 disp ( ’ t h e r e f o r e s y s t e m i s c o n t r o l l a b l e ’ )
27 else
28 disp ( ’ Rank o f c o n t r o l l a b i l i t y m a t r i x i s n o t f u l l ,
’)
29 disp ( ’ t h e r e f o r e s y s t e m i s u n c o n t r o l l a b l e ’ )
30 end
31
32 disp ( ’ ’ )
33
34 // O b s e r v a b i l i t y t e s t
35 m = obsv_mat ( sys )
36 mprintf ( ’ O b s e r v a b i l i t y m a t r i x i s ’ )
37 disp ( m )
38
39 if rank ( m ) ==2 then
40 disp ( ’ Rank o f o b s e r v a b i l i t y m a t r i x i s f u l l , ’ )
41 disp ( ’ t h e r e f o r e s y s t e m i s o b s e r v a b l e ’ )
42 else
43 disp ( ’ Rank o f o b s e r v a b i l i t y m a t r i x i s n o t f u l l , ’
)
44 disp ( ’ t h e r e f o r e s y s t e m i s u n o b s e r v a b l e ’ )
45 end
34
Experiment: 9
1 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 // Lab . 0 9 : D e s i g n s t a t e f e e d b a c k c o n t r o l l e r f o r a
g i v e n s y s t e m t o a c h i e v e d e s i r e d dynamic
characteristics .
3 // scilab − 5.5.1
4 // O p e r a t i n g System : Windows 7 , 32− b i t
5 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
35
Figure 9.1: Lab09
36
Figure 9.2: Lab09
37
8 clear ;
9 clc ;
10
11 // S t a t e s p a c e r e p r e s e n t a t i o n
12 A =[0 1; -0.16 -1.5];
13 B =[0 1] ’;
14 C =[0 1];
15 D =0;
16
17 sys1 = syslin ( ’ d ’ ,A ,B ,C , D )
18
19 // D e s i r e d p o l e s
20 Pd =[0.5+0.5* %i 0.5 -0.5* %i ];
21
22 // S t a t e f e e d b a c k g a i n m a t r i x
23 K = ppol (A ,B , Pd )
24 mprintf ( ’ S t a t e f e e d b a c k g a i n m a t r i x i s K= ’ )
25 disp ( K )
26
27 // C l o s e d l o o p s y s t e m
28 sys = syslin ( ’ d ’ ,A - B *K ,B ,C , D )
29
30 // S a m p l i n g Time
31 Ts =0.5;
32 t =0: Ts :14;
33 u = ones (1 , length ( t ) ) ;
34
35 // R e s p o n s e o f open l o o p s y s t e m
36 y1 = flts (u , sys1 ) ;
37 plot2d2 (t , y1 ,2)
38 xgrid (35)
39 title ( ’ R e s p o n s e o f open l o o p s y s t e m ’ , ’ f o n t s i z e ’ ,3)
40 xlabel ( ’ kT ’ , ’ f o n t s i z e ’ ,2)
41 ylabel ( ’ y ( kT ) ’ , ’ f o n t s i z e ’ ,2)
42
43 // R e s p o n s e o f c l o s e d l o o p s y s t e m
44 y = flts (u , sys ) ;
45 figure ,
38
46 plot2d2 (t ,y ,2)
47 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
48 f . background =8
49 xgrid (36)
50 title ( ’ R e s p o n s e o f c l o s e d l o o p s y s t e m ’ , ’ f o n t s i z e ’ ,3)
51 xlabel ( ’ kT ’ , ’ f o n t s i z e ’ ,2)
52 ylabel ( ’ y ( kT ) ’ , ’ f o n t s i z e ’ ,2)
39
Experiment: 10
1 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 // Lab . 1 0 : D e s i g n dead b e a t c o n t r o l l e r f o r a g i v e n
system .
3 // scilab − 5.5.1
4 // O p e r a t i n g System : Windows 7 , 32− b i t
5 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
40
Figure 10.1: Lab10
41
Figure 10.2: Lab10
42
11 // S a m p l i n g t i m e
12 Ts =0.5;
13
14 // S t a t e s p a c e r e p r e s e n t a t i o n o f the continuous time
system
15 A =[0 1;0 0];
16 B =[0 1] ’;
17 C =[1 0];
18 D =0;
19
20 sys1 = syslin ( ’ c ’ ,A ,B ,C , D )
21
22 // D i s c r e t e model o f t h e s y s t e m
23
24 sys = dscr ( sys1 , Ts )
25 mprintf ( ’ D i s c r e t e model o f t h e s y s t e m i s s y s= ’ )
26 disp ( sys )
27
28 // D e s i r e d p o l e s
29 Pd =[0 0];
30
31 // S t a t e f e e d b a c k g a i n m a t r i x
32 K = ppol ( sys .A , sys .B , Pd )
33 mprintf ( ’ S t a t e f e e d b a c k g a i n m a t r i x i s K= ’ )
34 disp ( K )
35
36 // R e s p o n s e s
37 t =0: Ts :10;
38 u = ones (1 , length ( t ) ) ;
39
40 // R e s p o n s e o f open l o o p s y s t e m
41 y1 = flts (u , sys ) ;
42 plot2d2 (t , y1 ,2)
43 xgrid (35)
44 title ( ’ R e s p o n s e o f t h e open l o o p s y s t e m ’ , ’ f o n t s i z e ’
,3)
45 xlabel ( ’ k t ’ , ’ f o n t s i z e ’ ,2)
46 ylabel ( ’ y ( k ) ’ , ’ f o n t s i z e ’ ,2)
43
47
48
49 // R e s p o n s e o f c l o s e d l o o p s y s t e m
50 syscl = syslin ( ’ d ’ , sys .A - sys . B *K , sys .B , sys .C ,0)
51 y = flts (u , syscl ) ;
52 figure ,
53 plot2d2 (t ,y ,2)
54 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
55 f . background =8
56 xgrid (36)
57 title ( ’ R e s p o n s e o f t h e c l o s e d l o o p s y s t e m w i t h dead
b e a t c o n t r o l l e r ’ , ’ f o n t s i z e ’ ,3)
58 xlabel ( ’ k t ’ , ’ f o n t s i z e ’ ,2)
59 ylabel ( ’ y ( k ) ’ , ’ f o n t s i z e ’ ,2)
44
Experiment: 11
1 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 // Lab . 1 1 : D e s i g n a f u l l s t a t e o b s e r v e r f o r t h e
system .
3 // scilab − 5.5.1
4 // O p e r a t i n g System : Windows 7 , 32− b i t
5 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // S t a t e s p a c e model
12 A =[0 1 0; 0 0 1; 0.6 0.7 0.2 ];
13 B =[0 0 1] ’;
14 C =[1 0 0];
45
15 D =0;
16
17 // S t a b i l i z e r d e s i g n
18 // D e s i r e d p o l e s
19 Pd =[0.2 , -0.5+0.5* %i , -0.5 -0.5* %i ];
20
21 // S t a t e f e e d b a c k g a i n m a t r i x
22 K = ppol (A ,B , Pd )
23
24 // Computation o f g a i n f o r dead b e a t o b s e r v e r
response
25 obsr_pol =[0 0 0];
26 L = ppol (A ’ ,C ’ , obsr_pol ) ’
27
28 // Augmented s y s t e m
29 temp = size ( A ) ;
30 Aa =[ A - B * K B * K ; zeros ( temp (1) , temp (2) ) A-L*C
];
31 temp = size ( Aa ) ;
32 Ba = zeros ( temp (1) ,1) ;
33 Ca = eye (6 ,6) ;
34 sys = syslin ( ’ d ’ ,Aa , Ba , Ca , zeros (6 ,1) )
35
36 // O b s e r v e r e r r o r
37 t =0:0.2:4.5;
38 u = zeros (1 , length ( t ) ) ;
39 // y= f l t s ( u , s y s ) ;
40 x = ltitr ( Aa , Ba ,u ,[0.1 0.1 0.1 -0.5 -0.5 -0.5] ’)
41
42 temp = size ( Aa ) ;
43 temp = temp (1 ,1) /2;
44
45 col =[1 2 5]; // s p e c i f y i n g p l o t c o l o r s
46 for i =1: temp
47 subplot (2 ,1 ,1) , plot2d2 (t , x (i ,:) , col (1 , i ) )
48 if i == temp then
49 title ( ’ S t a t e s o f t h e s y s t e m ’ , ’ f o n t s i z e ’ ,2) ;
50 xlabel ( ’ $ t $ ’ , ’ f o n t s i z e ’ ,2) ;
46
51 ylabel ( ’ $x ( kT ) $ ’ , ’ f o n t s i z e ’ ,2) ;
52 h1 = legend ( ’ $ x 1 ( kT ) $ ’ , ’ $ x 2 ( kT ) $ ’ , ’ $ x 3 ( kT ) $
’ );
53 h1 . legend_location = ” i n l o w e r r i g h t ” ;
54 xgrid (35)
55 end
56 subplot (2 ,1 ,2) , plot2d2 (t , x ( i +3 ,:) , col (1 , i ) )
57 if i == temp then
58 title ( ’ O b s e r v e r e r r o r ’ , ’ f o n t s i z e ’ ,2)
59 xlabel ( ’ $ t $ ’ , ’ f o n t s i z e ’ ,2)
60 ylabel ( ’ $ e ( kT )=x ( kT ) −\ h a t x ( kT ) $ ’ , ’ f o n t s i z e ’
,2)
61 h2 = legend ( ’ $ e 1 ( kT ) $ ’ , ’ $ e 2 ( kT ) $ ’ , ’ $ e 3 ( kT ) $
’)
62 h2 . legend_location = ” i n l o w e r r i g h t ”
63 xgrid (35)
64 end
65 end
47
Figure 11.1: Lab11
48
Experiment: 12
1 // Lab . 1 2 : D e t e r m i n e s t a b i l i t y o f a g i v e n s y s t e m by
u s i n g Lyapunov s t a b i l i t y a n a l y s i s
2 // scilab − 5.5.1
3 // O p e r a t i n g System : Windows 7 , 32− b i t
4 //
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
5 // C l e a n t h e e n v i r o n m e n t
6 close ;
7 clear ;
8 clc ;
9
10 // System m a t r i x
11 a =[0 1; -0.5 -1];
12 q = - eye (2 ,2) ;
13 p = lyap (a ,q , ’ d ’ ) ;
14
49
15 // For a s t a b l e s y s t e m m a t r i x , p s h o u l d be p o s i t i v e
definite for
16 // which a l l t h e p r i n c i p l e m i n o r s o r a l l e i g e n v a l u e s
of the matrix p
17 // s h o u l d be p o s i t i v e
18
19 eig_val = spec ( p ) ;
20 m = length ( eig_val ) ;
21 stable =0;
22 for i =1: m ;
23 if real ( eig_val ( i ) ) >0 then
24 stable = stable +1;
25 end
26 end
27 if stable == m then
28 disp ( ’ The s y s t e m i s a s y m p t o t i c a l l y s t a b l e ’ )
29 else
30 disp ( ’ The s y s t e m i s u n s t a b l e o r c r i t i c a l l y
stable ’)
31 end
50
Experiment: 13
6 // C l e a n t h e e n v i r o n m e n t
7 close ;
8 clear ;
9 clc ;
10
11 // S a m p l i n g t i m e
12 Ts =0.4;
13
14 // System t r a n s f e r f u n c t i o n .
51
15 s = poly (0 , ’ s ’ ) ;
16 g =1/( s *( s +1) ) ;
17 g = syslin ( ’ c ’ ,g ) ;
18 gz = dscr (g , Ts ) // d i s c r e t e model
19
20 // Root l o c u s f o r t h e d i s c r e t e s y s t e m
21 evans ( gz ,100)
22 title ( ’ Root l o c u s o f t h e d i s c r e t e −t i m e s y s t e m ’ )
23 zgrid (0:0.1:0.5)
24 zoom_rect ([ -1.2 -1.5 1.2 1.5])
25 figure
26
27 // Bode p l o t f o r t h e d i s c r e t e s y s t e m
28 bode ( gz )
29 f = get ( ” c u r r e n t f i g u r e ” ) // C u r r e n t f i g u r e h a n d l e
30 f . background =8
31 title ( ’ Bode p l o t o f d i s c r e t e −t i m e s y s t e m ’ )
52
Figure 13.1: Lab13
53
Figure 13.2: Lab13
54