summaryrefslogtreecommitdiff
path: root/3432/CH4/EX4.8/Ex4_8.sce
blob: 5f5e37109e58f8fafb916d47338aacc2662fca34 (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
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
//Example 4.8
//Equivalent discrete controller for DC motor speed control.
//------------------------------------------------------------------
//NOTE THAT-- The system response (continuous) to sampled control 
//input depends on 
//the sampling time set for continuous signal in SIMULATION.
//In this example we consider sampling period of 0.009 sec 
//to represent continuous time signal.
//------------------------------------------------------------------

xdel(winsid())//close all graphics Windows
clear;
clc;
//------------------------------------------------------------------
// Continuous time system and controller
// System transfer function
s=%s; 
num=[45 0];
den=[45 14 1]
Nms=poly(num,'s','coeff');
Dns=poly(den,'s','coeff');
Gp=syslin('c',Nms/Dns); //system transfer function

// Controller

numDa=[6 1];
denDa=[0 1]
Nms=poly(numDa,'s','coeff');
Dns=poly(denDa,'s','coeff');
sysD=syslin('c',1.4*Nms/Dns); //controller transfer function

//Closed loop responses

num=[1 0];
den=[1 0];
Nms=poly(num,'s','coeff');
Dns=poly(den,'s','coeff');
H=syslin('c',Nms/Dns)

sysDa=Gp*sysD/.H;

//step response and control input
t=0:0.009:5;
yt=csim('step',t,sysDa); //step response
figure(0)
plot2d(t,yt,1)
Gu=sysD/(1+Gp*sysD);
ut=csim('step',t,Gu); //control input
figure(1)
plot2d(t,ut,1)
//------------------------------------------------------------------

sys=tf2ss(Gp); //state space model of the system
con=tf2ss(sysD); //controller state space model

// discrete-time time system and controller

//Discretize the system and control with sampling time Ts=0.07
// using Bilinear Transform
Ts=0.07;
sysDd=cls2dls(sys,Ts); // discrete-time system state space model
conDd=cls2dls(con,Ts); // discrete-time controller state space model

//Pulse transfer function of system
Gpz=ss2tf(sysDd);
//Pulse transfer function of controller
Gcz=ss2tf(conDd);
//Closed loop response
Gz=Gpz*Gcz/(1+Gpz*Gcz)
//Control input pulse transfer function
Guz=Gcz/(1+Gpz*Gcz)
T=0:Ts:5;
r=ones(1,length(T));
yd=flts(r,Gz);............//Discrete respnse to discrete input
ud=flts(r,Guz);           //Discrete Control input
//continuous response for digital input
t=0:0.009:5;
k=0;

for i=1:length(yd)
    for j=1:8
       if (k+j)>length(t) then
          break
          else
          YD(1,k+j)=yd(i);
       end
       end
    k=k+j;
end

yt=csim(1-YD,t,Gp*sysD);
scf(0)
plot2d(t,yt,5);
scf(1)
plot2d2(T,ud,5);
//------------------------------------------------------------------
//Discretize the system and control with sampling time Ts=0.035
// using Bilinear Transform
Ts=0.035;
sysDd=cls2dls(sys,Ts); // discrete-time system state space model
conDd=cls2dls(con,Ts); // discrete-time controller state space model

Gpz=ss2tf(sysDd);      //Pulse transfer function of system
Gcz=ss2tf(conDd);     //Pulse transfer function of controller

//Closed loop response
Gz=Gpz*Gcz/(1+Gpz*Gcz)
//Control input pulse transfer function
Guz=Gcz/(1+Gpz*Gcz)
T=0:Ts:5;
r=ones(1,length(T));
yd=flts(r,Gz);............//Discrete respnse to discrete input
ud=flts(r,Guz);           //Discrete Control input
t=0:0.009:5;
k=0;

for i=1:length(yd)
    for j=1:4
       if (k+j)>length(t) then
          break
          else
          YD(1,k+j)=yd(i);
       end
       end
    k=k+j;
end

yt=csim(1-YD,t,Gp*sysD);
scf(0)
plot2d(t,yt,2);
scf(1)
plot2d2(T,ud,2);

scf(0)
//Title, labels and grid to the figure
exec .\fig_settings.sci; //custom script to set the figure properties
title('Comparision plots of Speed-control system with continuous...
 and discrete controllers','fontsize',3)
xlabel('Time t (sec.)','fontsize',2)
hl=legend(['Continuous time','Discrete-time, Ts=0.07 s'...
,'Discrete-time, Ts=0.035 s'],4);
scf(1)
//Title, labels and grid to the figure
exec .\fig_settings.sci; //custom script to set the figure properties
title('Comparision plots of Speed-control system with continuous...
 and discrete controllers','fontsize',3)
xlabel('Time t (sec.)','fontsize',2)
hl=legend(['Continuous time','Discrete-time, Ts=0.07 s',...
'Discrete-time, Ts=0.035 s']);
//------------------------------------------------------------------