Solution 8.8.8.a
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 p2zid1
topm = size(p2zid1)
top = topm(1,1)
t=p2zid1(1:top,1);;
y=p2zid1(1:top,2);;
%
%
asum = 0.0;;
plot(t,y)
print -deps sr888a.a.ep
t=t+0.004
y=y(78:top);;
t=t(78:top);;
t(1)=0;;
y(1) = 0
plot(t,y)
print -deps sr888a.b.eps
topm = size(y)
top = topm(1,1)
%
%
k0 = y(top)
%
f0 = k0-y;;
%
%Reset counter
%
k=2;;
%
%Integrate f0 = k0 - y(t). and form the function y1(t).
%
while ( k <= top)
1
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)
l= k-1;;
asum = asum + ( ( (f1(k)+f1(l))/2 ) *( t(k) - t(l) ) );;
y2(k) = asum;;
k=k+1;;
2
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
%
%SetK3 equal to maximum value of y3(t).
%
k3 = asum
A=[k0,0,-1;;k1,-k0,0;;k2,-k1,0]
3
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 sr888a.c.eps
The MATLAB statements
load p2zid1
topm = size(p2zid1)
top = topm(1,1)
t=p2zid1(1:top,1);;
y=p2zid1(1:top,2);;
%
%
asum = 0.0;;
plot(t,y)
print -deps sr888a.a.ep
t=t+0.004
y=y(78:top);;
t=t(78:top);;
t(1)=0;;
y(1) = 0
plot(t,y)
print -deps sr888a.b.eps
topm = size(y)
top = topm(1,1)
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
4
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
0.5
1
1.5
2
2.5
3
Figure 1: Unadjusted step response
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0.5
1
1.5
2
2.5
3
Figure 2: Adjusted step response
5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.5
1
1.5
2
2.5
3
Figure 3: Comparison of measured response to model response
For this problem the alogrithm gives the answer
G(s)=
78:6152(s+1:718)
(s +15:33)(s+9:274)
:
The step response of the model is compared to the actual recorded step
response in Figure 3 The matchisprettygood.
6