0% found this document useful (0 votes)
89 views

Design and Simulation of Full Order Observer: Program

1. The document describes the design and simulation of a full order observer for a state space system using MATLAB. It generates the observer gain, adds the observer dynamics, and simulates the output of the original system and estimated states. 2. Discretization and conversion between continuous and discrete transfer functions are simulated using MATLAB. The effects of sampling period are demonstrated. 3. An inverted pendulum system is modeled and LQR control is designed and simulated in MATLAB. Different weight matrices are tested. Precompensation is also implemented and state estimation is added using an observer.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Design and Simulation of Full Order Observer: Program

1. The document describes the design and simulation of a full order observer for a state space system using MATLAB. It generates the observer gain, adds the observer dynamics, and simulates the output of the original system and estimated states. 2. Discretization and conversion between continuous and discrete transfer functions are simulated using MATLAB. The effects of sampling period are demonstrated. 3. An inverted pendulum system is modeled and LQR control is designed and simulated in MATLAB. Different weight matrices are tested. Precompensation is also implemented and state estimation is added using an observer.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

DESIGN AND SIMULATION OF FULL ORDER OBSERVER


PROGRAM:
A = [0 1;-4 -0.2];
B = [0 1]';
C = [1 0];
sys = ss(A,B,C,0);
Q = 3e4; R = 0.01;
[kest,L,P] = kalman(sys,Q,R,[]);
Aobs = A;
Bobs = B;
Cobs = C;
Anew = [A zeros(2);
L*C Aobs-L*Cobs];
Bnew = [B B
zeros(2,1) Bobs];
Cnew = [C zeros(1,2);
zeros(2,2) eye(2)];
sysNew = ss(Anew,Bnew,Cnew,0);
t = 0:1e-3:10;
u1 = 2*cos(5*2*pi*t')+2*cos(1*2*pi*t')+2*cos(.2*2*pi*t');
u2 = zeros(length(t),1);
y = lsim(sysNew,[u1 u2],t);
plot(t,y(:,1),t,y(:,2))
legend('plant output','observer output estimate')

OUTPUT:
2. SIMULATION OF DISCRETIZATION USING MATLAB
PROGRAM:
G = tf([1 -2],[1 3 20],'inputdelay',1);
Ts = 0.1;
Gd = c2d(G,Ts);
step(G,'b',Gd,'r')
legend('Continuous','Discretized')
Gc = d2c(Gd);
step(G,'b',Gd,'r',Gc,'g--')
legend('Original','Discretized','D2C Interpolant')
Ts = 1;
Hd = c2d(G,Ts);
Hc = d2c(Hd);
step(G,'b',Hd,'r',Hc,'g--',10)
legend('Original','Discretized','D2C Interpolant')
Gr = d2d(Gd,0.025);
step(G,'b',Gr,'r',c2d(G,0.025),'g--',4)
legend('Continuous','Resampled from 0.1 to 0.025','Discretized with
Ts=0.025')

OUTPUT:
3. LQR DESIGN AND SIMULATION USING MATLAB

PROGRAM:
M =
0.5;
m =
0.2;
b =
0.1;
I =
0.006;
g =
9.8;
l =
0.3;
p =
I*(M+m)+M*m*l^2;
A =
[0 1 0 0;
0 -(I+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 -(m*l*b)/p m*g*l*(M+m)/p 0];
B = [ 0;
(I+m*l^2)/p;
0;
m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'u'};
outputs = {'x'; 'phi'};
sys_ss =
ss(A,B,C,D,'statename',states,'inputname',inputs,'outputname',outputs);
pole = eig(A);
co = ctrb(sys_ss);
controllability = rank(co);
Q = C'*C;
R = 1;
K = lqr(A,B,Q,R);
Ac = (A-B*K);
Bc = B;
Cc = C;
Dc = D;
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_cl =
ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X3]=lsim(sys_cl,r,t);
[AX,h3,H7] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with LQR Control')
Q = C'*C;
Q(1,1) = 5000;
Q(3,3) = 100;
R = 1;
K = lqr(A,B,Q,R);
Ac = (A-B*K);
Bc = B;
Cc = C;
Dc = D;
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_cl =
ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X1]=lsim(sys_cl,r,t);
[AX,h1,H3] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with LQR Control')
Cn = [1 0 0 0];
sys_ss = ss(A,B,Cn,0);
Nbar = rscale(sys_ss,K);
sys_cl =
ss(Ac,Bc*Nbar,Cc,Dc,'statename',states,'inputname',inputs,'outputname',output
s);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,X]=lsim(sys_cl,r,t);
[AX,h,H] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with Precompensation and LQR Control')
ob = obsv(sys_ss);
observability = rank(ob);
poles = eig(Ac);
P = [-40 -41 -42 -43];
L = place(A',C',P);
Ace = [(A-B*K) (B*K);
zeros(size(A)) (A-L*C)];
Bce = [B*Nbar;
zeros(size(B))];
Cce = [Cc zeros(size(Cc))];
Dce = [0;0];
states = {'x' 'x_dot' 'phi' 'phi_dot' 'e1' 'e2' 'e3' 'e4'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_est_cl =
ss(Ace,Bce,Cce,Dce,'statename',states,'inputname',inputs,'outputname',outputs
);
t = 0:0.01:5;
r = 0.2*ones(size(t));
[y,t,x]=lsim(sys_est_cl,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with Observer-Based State-Feedback Control')
OUTPUT:

You might also like