clear
y(1)=0;y(2)=0;f(1)=-3;f(2)=-3;alpha=.5;u(1)=0;b=rand;
Wei=rand(1,10);Sigma=rand(3,10);Med=rand(3,10);z=rand(1,10);
for k=2:500
u(k)=sin(2*pi*k/200);
x=[u(k) y(k) y(k-1)];
  for i=1:3
    for l=1:10
Wei(l)=Wei(l)-alpha*(f(k)-y(k))/b*z(l);
Sigma(i,l)=Sigma(i,l)-alpha*(f(k)-y(k))/b*(Wei(l)-f(k))*z(l)*(x(i)-Med(i,l))^2/Sigma(i,l)^3;
Med(i,l)=Med(i,l)-alpha*(f(k)-y(k))/b*(Wei(l)-f(k))*z(l)*(x(i)-Med(i,l))/Sigma(i,l)^2;
    end
  end
        for l=1:10
z1=exp(-((u(k)-Med(1,l))/Sigma(1,l))^2);
z2=exp(-((y(k-1)-Med(2,l))/Sigma(2,l))^2);
z3=exp(-((y(k)-Med(3,l))/Sigma(3,l))^2);
z(l)=z1*z2*z3;
        end
b=sum(z);
a=Wei*z';
N=a/b;
f(k+1)=.3*y(k)+.6*y(k-1)+N;
g(k)=0.6*sin(pi*u(k))+0.3*sin(3*pi*u(k))+0.1*sin(5*pi*u(k));
y(k+1)=.3*y(k)+.6*y(k-1)+g(k);
end
plot(1:501,y,1:501,f,'--')
axis([0 500 -5 5])
xlabel('Iterations','Fontsize',12)
set(gca,'Fontsize',12)
legend('plant','identifier')
title('Learning phase','Fontsize',12)
% testing the identifier, no identifier parameters' update
y(1)=0;y(2)=0;f(1)=0;f(2)=0;alpha=.5;u(1)=0;
for k=2:500
   u(k)=sin(2*pi*k/200);
           for l=1:10
z1=exp(-((u(k)-Med(1,l))/Sigma(1,l))^2);
z2=exp(-((y(k-1)-Med(2,l))/Sigma(2,l))^2);
z3=exp(-((y(k)-Med(3,l))/Sigma(3,l))^2);
z(l)=z1*z2*z3;
        end
b=sum(z);
a=Wei*z';
N=a/b;
f(k+1)=.3*y(k)+.6*y(k-1)+N;
g(k)=0.6*sin(pi*u(k))+0.3*sin(3*pi*u(k))+0.1*sin(5*pi*u(k));
y(k+1)=.3*y(k)+.6*y(k-1)+g(k);
end
figure
plot(1:501,y,1:501,f,'--')
axis([0 500 -5 5])
xlabel('Iteration','Fontsize',12)
set(gca,'Fontsize',12)
legend('plant','identifier')
title('Testing phase','Fontsize',12)




