Solution 8.8.8.d
The full MATLAB program used to nd the transfer function is:
%
%Find the length of the array y(t) Note:this the step response. It has to be
%pulled into Matlab before this program is run.
%
load p2zid4
y=p2zid4
%t = linspace(0,10,800);;
%g = zpk([],[-4 -8 -20],640)
%[y,t] = step(g,t);;
topm = size(y);;
top = topm(1,1)
%
t=p2zid4(1:top,1);;
y=p2zid4(1:top,2);;
plot(t,y)
print -deps sr888d.a.eps
%
%
%
t=t+0.036;;
t=t(72:top);;
y=y(72:top);;
t(1) = 0;;
y(1)= 0;;
plot(t,y)
print -deps sr888d.b.eps
topm = size(y);;
top = topm(1,1)
k0 = y(top)
%
f0 = k0-y;;
%
%Reset counter
%
asum = 0.0;;
k=2;;
1
%
%Integrate f0 = k0 - y(t). and form the function y1(t).
%
while ( k <= top)
l=k-1;;
asum = asum + ( ( (f0(k)+f0(l))/2 ) *( t(k) - t(l) ) );;
y1(k) = asum;;
k=k+1;;
end
%
%Save data for plotting.
%
save time.dat t -ascii
save y.dat y -ascii
save y1.dat y1 -ascii
save f0.dat f0 -ascii
%
%SetK1 = to max(y1(t)), that is its final steady state value.
%
k1 = asum
%
%form function:f1 = k1 - y1(t).
%
f1 = k1-y1;;
%
%Save function for later plotting
%
save f1.dat f1 -ascii
%
%reset summer
%
asum = 0.0;;
%
%Reset counter
%
k=2;;
%
%Integrate f1(k) = k1 - y1(t) to get y2(t)
%
while ( k <= top)
2
l= k-1;;
asum = asum + ( ( (f1(k)+f1(l))/2 ) *( t(k) - t(l) ) );;
y2(k) = asum;;
k=k+1;;
end
%
%Setk2 equal to maximum value of y2(t).
%
k2 = asum
%
%Save function y2(t) for later plotting.
%
save y2.data y2 -ascii
%
%
%form function: f2 = k2 - y2(t).
%
f2 = k2-y2;;
%
%Save function for later plotting
%
save f2.data f2 -ascii
%
%reset summer
%
asum = 0.0;;
%
%Reset counter
%
k=2;;
%
%Integrate f2 = k2 - y2(t) to get y3(t)
%
while ( k <= top)
l= k-1;;
asum = asum + ( ( (f2(k)+f2(l))/2 ) *( t(k) - t(l) ) );;
y3(k) = asum;;
k=k+1;;
end
%
3
%SetK3 equal to maximum value of y3(t).
%
k3 = asum
A=[k0,0,-1;;k1,-k0,0;;k2,-k1,0]
b=[k1;;k2;;k3]
x=inv(A)*b
a1 = x(1)
a2 = x(2)
b1 = x(3)
polyd=[a2 a1 1]
p=roots(polyd)
Kplant = b1/a2
z=-k0/b1
T=linspace(0,1,200);;
g=zpk([z],[p(1) p(2)],Kplant)
[yhat,T] = step(g,T);;
plot(t,y,'k-',T,yhat,'k--')
print -deps sr888d.c.eps
The MATLAB statements
load p2zid4
y=p2zid4
%t = linspace(0,10,800);;
%g = zpk([],[-4 -8 -20],640)
%[y,t] = step(g,t);;
topm = size(y);;
top = topm(1,1)
%
t=p2zid4(1:top,1);;
y=p2zid4(1:top,2);;
plot(t,y)
print -deps sr888d.a.eps
%
%
%
t=t+0.036;;
t=t(72:top);;
y=y(72:top);;
t(1) = 0;;
4
-0.5 0 0.5 1 1.5 2
-0.5
0
0.5
1
1.5
2
2.5
Figure 1: Unadjusted step response
y(1)= 0;;
plot(t,y)
print -deps sr888d.b.eps
adjust the data so that the response begins at zero for t =0. The rest of
the program is the integration routine. The rawdataisshown in Figure 1
The adjusted data is shown in Figure 2
For this problem the alogrithm gives the answer
G(s)=
20:3562(s+1:995)
(s +9:14)(s+2:025)
:
The step response of the model is compared to the actual recorded step
response in Figure 3 The matchisprettygood.
5
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
0.5
1
1.5
2
2.5
Figure 2: Adjusted step response
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
0.5
1
1.5
2
2.5
Figure 3: Comparison of measured response to model response
6