% continuous process dynamics

a = -2;
b = -1.3;
V = 5;

A = [a 0 0; 1 0 0; 0 -V 0];
B = [b; 0; 0];
C = [0 0 1];
Gp = ss(A,B,C,0);

% sampled process

h = 0.2;
Hp = c2d(Gp,h);
[Phi,Gam] = ssdata(Hp);

% state feedback design

wc = 1;                    % speed of state feedback
pc = wc*roots([1 2 2 1]);  % control poles in continuous time
pcd = exp(pc*h);           % control poles in discrete time

L = place(Phi,Gam,pcd);

% observer design (predictor version with one sample delay)

wo = 2;                    % speed of observer
po = wo*roots([1 2 2 1]);  % observer poles in continuous time
pod = exp(po*h);           % observer poles in discrete time

K = place(Phi',C',pod)';

% naive reference handling

Hcl = ss(Phi-Gam*L,Gam,C,0,h);
lc = 1/dcgain(Hcl);

% reference generator

wm = 2;                    % speed of model
pm = wm*roots([1 3 3 1]);  % model poles in continuous time
pmd = exp(pm*h);           % model poles in discrete time

Lm = place(Phi,Gam,pmd);

Hm = ss(Phi-Gam*Lm,Gam,C,0,h);
lcm = 1/dcgain(Hm);

% form the controller

refgen = ss(Phi-Gam*Lm,Gam*lcm,[-Lm; eye(3)],[lcm; zeros(3,1)],h)
observer = ss(Phi-K*C,[Gam K],eye(3),zeros(3,2),h);
