%ERROR STEP RESPONSE WITH ADDED POLE
% Develop output time response and 
%  linear phase plane by ordinary matrix procedure

% Compare to Fig. 6.14
% alpha = 1, zeta = 0.5, Wn = 1
% rn: ratio of natural frequency to added pole

% Generate vector of computation times
inc = .05; %sampling period
ending = 10; % Student Matlab, v 3.5, limits ending/inc to 1024 max
last = 1 + ending/inc; % index of last data points
t = linspace(0,ending,last); % linear sequence of times

u = ones(1,last); % unit step input

rn = 0
while(rn>=0)
	NUM = [0 0 1 1   % first row is output (phase)
        0 1 1 0]; % second row is derivative of output (frequency)
	DEN = [rn 1 1 1];
	[a,b,c,d] = tf2ss(NUM,DEN); % elements of dynamic matrix equation
	[Phi, Gamma] = C2D(a,b,inc); % values for use in solution eqaution
 x = ltitr(Phi,Gamma,u'); % solutions for each value of t
	y = c*x'+d*u; % outputs
 
 clg;
 er = u - y(1,:);
	subplot(211), plot(t,er,'g') 
	grid
	title('Time Response, Error (linear)')
	xlabel('seconds')
	ylabel('radians')
	subplot(212), plot(y(1,:),y(2,:),'r')
	grid
	title('Phase Plane, Output (linear)')
	xlabel('phase (radians)')
	ylabel('freq (rad/sec)')

rn = input('enter ratio of Wn to added pole (negative to quit)')
end %while
		
		
