Solution 8.8.8.b
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 p2zid2
topm = size(p2zid2);;
top = topm(1,1)
%
%Initialize counter.
%
asum = 0.0;;
%
%Put data into arrays
%
t=p2zid2(1:top,1);;
y=p2zid2(1:top,2);;
plot(t,y)
print -deps sr888b.a.eps
t=t+0.06;;
t=t(78:top);;
y=y(78:top);;
t(1) = 0;;
y(1)= 0;;
plot(t,y)
print -deps sr888b.b.eps
%
%
%
topm = size(y);;
top = topm(1,1)
k0 = y(top)
%
f0 = k0-y;;
%
%Reset counter
%
1
k=2;;
%
%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)
%
2
while ( k <= top)
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 sr888b.c.eps
The MATLAB statements
load p2zid2
topm = size(p2zid2);;
top = topm(1,1)
%
%Initialize counter.
%
asum = 0.0;;
%
%Put data into arrays
%
t=p2zid2(1:top,1);;
y=p2zid2(1:top,2);;
plot(t,y)
print -deps sr888b.a.eps
t=t+0.06;;
t=t(78:top);;
y=y(78:top);;
t(1) = 0;;
4
-2 0 2 4 6 8 10
-0.5
0
0.5
1
1.5
2
2.5
Figure 1: Unadjusted step response
y(1)= 0;;
plot(t,y)
print -deps sr888b.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)=
4:7344(s+0:4954)
(s +2:044)(s+0:4683)
:
The step response of the model is compared to the actual recorded step
response in Figure 3 The matchisprettygood.
5
0 1 2 3 4 5 6 7 8 9
0.5
1
1.5
2
2.5
Figure 2: Adjusted step response
6
0 1 2 3 4 5 6 7 8 9
0.5
1
1.5
2
2.5
Figure 3: Comparison of measured response to model response
7