%% SPLS/2e MATLAB
% Chapter 6
clear; close all;
%% Ex. 6.4
num = [2 0 5]; den = [1 3 2];
[r, p, k] = residue(num,den)
num = [2 7 4]; den = [conv([1 1],conv([1 2],[1 2]))];
[r, p, k] = residue(num,den)
num = [8 21 19]; den = [conv([1 2],[1 1 7])];
[r, p, k]= residue(num,den)
ang = angle(r), mag = abs(r)
%% Ex. 6.5
syms a b t; x_a = sin(a*t)+cos(b*t);
X_a = laplace(x_a)
X_a = collect(X_a)
syms a b s; X_b = (a*s^2)/(s^2+b^2);
x_b = ilaplace(X_b)
%% Ex. 6.21
H = tf(1,1); K = 7; G = tf([0 0 K],[1 8 0]); Ha = feedback(G,H)
H = tf(1,1); K = 16; G = tf([0 0 K],[1 8 0]); Hb = feedback(G,H)
H = tf(1,1); K = 80; G = tf([0 0 K],[1 8 0]); Hc = feedback(G,H)
%% Ex. 6.26, Fig. 6.37
H = tf(1,1); K = 7; G = tf([K],conv([1 0],[1 8])); Ha = feedback(G,H);
H = tf(1,1); K = 16; G = tf([K],conv([1 0],[1 8])); Hb = feedback(G,H);
H = tf(1,1); K = 80; G = tf([K],conv([1 0],[1 8])); Hc = feedback(G,H);
clf; step(Ha,'k-',Hb,'k--',Hc,'k-.');
legend('K = 7','K = 16','K = 80','Location','best');
%% Ex. 6.26, Fig. 6.38
t = 0:.001:1.5; Hd = series(Hc,tf([1],[1 0])); 
step(Hd,'k-',t); title('Unit Ramp Response');
%% Ex. 6.27
num = [0 0 0 1]; 
den = conv(conv([1 0],[1 2]),[1 4]);
H = tf(num,den); rlocusplot(H,'k-');
