Você está na página 1de 4

INSTITUTO FEDERAL CATARINENSE - CÂMPUS LUZERNA

MATÉRIA: INTRODUÇÃO A IDENTIFICAÇÃO DE SISTEMAS

APLICAÇÃO DO MÉTODO DO MÍNIMOS QUADRADOS RECURSIVO

● Planta

CÓDIGO

%Mínimos Quadrados recursivo


clear all
close all
nit=500;
for i = 1:nit
if rand > 0.5
u(i)=1;
ruido(i) = u(i)*0.03;
else
u(i) = -1;
ruido(i) = u(i)*0.03;
end

%Segundo caso
% u(i)=1;

%Terceiro caso
% if(i>150)
% u(i)=-1;
% else
% u(i)=1;
% end
y(i) = 0;
end

ga=7;%Número de coeficiente [a1 a2 a3 b0 b1 b2 b3]


da=fix(ga/2);
nb=ga-da;
% Y(Z) b0.Z^3 + b1.Z^2 + b2.Z + b3
% --- = ----------------------------- ->y(t)= - a1*y(t-1) - a2*y(t-2)- a3*y(t-3) + b0*u(t) +
b1*u(t-1) + b2*u(t-2) + b3*u(t-3);
% U(Z) a0.Z^3 + a1.Z^2 + a2.Z + a3
a1 = -1.095;
a2 = 0.6491;
a3 = -0.5531;
b0 = 0;
b1 = -0.5184;
b2 = -0.2062;
b3 = 1.426;

p = 100*eye(ga,ga); % Inicialização de P e TETA


for i=1:ga
Teta(i,1) = 0;
erro(i)=0;
end
c=ga;
for i = 1:c

for j = 1:ga
if(i<nb)
a(i,j) = Teta(j,1);
end
if(i==nb)
c=nb;
end
if(i<=nb && c==nb)
b(i,j) = Teta(j,1);
end
end
end
%%
c=ga;
ii=0;
for t= ga:nit

y(t)= - a1*y(t-1) - a2*y(t-2)- a3*y(t-3) + b0*u(t) + b1*u(t-1) + b2*u(t-2) +


b3*u(t-3)+ruido(t); %Amostragem do sistema
%escrever qual é a função de transferência

phi = [-y(t-1); -y(t-2);-y(t-3); u(t);u(t-1); u(t-2); u(t-3)];


erro(t)=y(t)-Teta'*phi;
k = p*phi/(1+phi'*p*phi);
Teta = Teta+k*erro(t);
p = p- p*phi*phi'*p/(1+phi'*p*phi);
%p = p- k*phi'*p;

for i= 1:c
if(i<nb)
a(i,t) = Teta(i);
end
if(i==nb)
c=nb;
ii=i;
end
if(i<=nb && c==nb)
b(i,t) = Teta(ii+i-1);
end
end

end
%
t = 1:nit;
subplot(241),plot(t,a(1,t)),title('a1'),xlabel('amostragem');
grid
subplot(242),plot(t,a(2,t)),title('a2'),xlabel('amostragem');
grid
subplot(243),plot(t,a(3,t)),title('a3'),xlabel('amostragem');
grid
subplot(245),plot(t,b(1,t)),title('b0'),xlabel('amostragem');
grid
subplot(246),plot(t,b(2,t)),title('b1'),xlabel('amostragem');
grid
subplot(247),plot(t,b(3,t)),title('b2'),xlabel('amostragem');
grid
subplot(248),plot(t,b(4,t)),title('b3'),xlabel('amostragem');
grid

figure
plot(y)
hold;
plot(u)
grid;

Você também pode gostar