Está en la página 1de 7

%%Lab#6-7 IDENTIFICACION DE SISTEMAS

%%MATERIA: LABORATORIO DE DISEÑO DE SISTEMAS DE CONTROL


%% Aproximamos con un sistema de PRIMER ORDEN
%Tiempo de muestreo de la planta
clear all
Ts=0.5;
%La planta es :
tf([1],[1 5 6])
step(tf([1],[1 5 6]))
grid
hold on
%Desarrollo por el metodo de minimos cuadrados
N=9;%Numero de muestras
u_k=ones(N,1);%Entrada tipo escalon
%Valores tomados en planta:
Ruido=0.02*rand(N,1);%Ruido
y_ki=[0 0.057 0.115 0.15 0.16 0.163 0.165 0.166 0.1665]';%Muestras de
"tf"
y_k=Ruido+y_ki%Valores mas ruido
%Aproximamos con un sistema de primer orden
PHI_N=[[0;y_k(1:length(y_k)-1)],u_k,[0;u_k(1:length(u_k)-1)]]
A_N=PHI_N'*PHI_N;
B_N=PHI_N'*y_k;
Theta_N=((A_N)^-1)*B_N
%Del ultimo grafico hallamos los valores de Y_k aproximados para asi
poder calcular el
%error y la funcion de coste:
Y_k=PHI_N*Theta_N
sumE2=sum((y_k-Y_k).^2)
J=(1/(2*N))*sumE2
%La matriz fila Rho_N+1 sera:
Rho_N1=[y_k(9,1) u_k(N,1) u_k(N,1)];
%Añadimos la fila Rho_N+1 a la matriz PHI_N
PHI_N(10,:)=Rho_N1%Matriz de PHI_N+1
A_N1=A_N+((Rho_N1')*Rho_N1);
B_N1=B_N+((Rho_N1')*y_k(9,1));
Theta_N1=((A_N1)^-1)*B_N1
%La planta aproximada en el dominio discreto sera:
step(tf([Theta_N1(2,1) Theta_N1(3,1)],[1 -Theta_N1(1,1)],Ts))
%La funcion de transferencia aproximada en el dominio continuo sera:
G_z=tf([Theta_N1(2,1) Theta_N1(3,1)],[1 -Theta_N1(1,1)],Ts)
G_s=d2c(G_z)
step(G_s)
[nc,dc]=tfdata(G_s,'V')
Pause
ans =

1
-------------
s^2 + 5 s + 6

Continuous-time transfer function.

y_k =

0.0163
0.0751
0.1175
0.1683
0.1726
0.1650
0.1706
0.1769
0.1857

PHI_N =

0 1.0000 0
0.0163 1.0000 1.0000
0.0751 1.0000 1.0000
0.1175 1.0000 1.0000
0.1683 1.0000 1.0000
0.1726 1.0000 1.0000
0.1650 1.0000 1.0000
0.1706 1.0000 1.0000
0.1769 1.0000 1.0000

Theta_N =

0.6138
0.0163
0.0562

Y_k =

0.0163
0.0825
0.1186
0.1446
0.1757
0.1784
0.1737
0.1771
0.1811

sumE2 =

8.3710e-04

J =

4.6505e-05

PHI_N =

0 1.0000 0
0.0163 1.0000 1.0000
0.0751 1.0000 1.0000
0.1175 1.0000 1.0000
0.1683 1.0000 1.0000
0.1726 1.0000 1.0000
0.1650 1.0000 1.0000
0.1706 1.0000 1.0000
0.1769 1.0000 1.0000
0.1857 1.0000 1.0000

Theta_N1 =

0.6125
0.0163
0.0563

G_z =

0.01629 z + 0.05626
-------------------
z - 0.6125

Sample time: 0.5 seconds


Discrete-time transfer function.

G_s =

0.01629 s + 0.1836
------------------
s + 0.9804

Continuous-time transfer function.

nc =

0.0163 0.1836
dc =

1.0000 0.9804

%Sintonizacion PID para el sistema aproximado de segundo orden G_s


%Hallamos el valor de kp
G_s=tf([nc(1,1) nc(1,2)],[dc(1,1) dc(1,2)])
kd=0;
%kp=??
ki=0;
figure(2)
for kp=0:10:100
C_s=tf([kd,kp,ki],[1 0]);
H=1;
%fedback para (G/(1+G*H)
G_s_lc=feedback(C_s*G_s,H);
step(G_s_lc)
hold on
grid
end
hold off

%Valor optimo para kp=30/3=30

%% Hallamos el valor de ki
kp=30;
kd=0;
%ki=??
figure(3)
for ki=0:10:100
C_s=tf([kd,kp,ki],[1 0]);
H=1;
%fedback para (G/(1+G*H)
G_s_lc=feedback(C_s*G_s,H);
step(G_s_lc)
hold on
grid
end
hold off

%%Valor optimo para ki=40/3=13.33

%% Hallamos el valor de kd
kp=30;
%kd=??
ki=13.33;
figure(4)
for kd=0:0.1:1
C_s=tf([kd,kp,ki],[1 0]);
H=1;
%fedback para (G/(1+G*H)
G_s_lc=feedback(C_s*G_s,H);
step(G_s_lc)
hold on
grid
end
hold off
%kd=0 ya que la variacion de este parametro afecta de forma negativa en
la respuesta del sistema
%% FINALMENTE
kp=30;
kd=0;
ki=13.33;
figure(5)
C_s=tf([kd,kp,ki],[1 0]);
H=1;
%fedback para (G/(1+G*H)
G_s_lc=feedback(C_s*G_s,H);
step(G_s_lc)
hold on
grid
hold off

También podría gustarte