%% START
clc;
close all;
clear all;
fp = 0.9;
alpha_f=0.5;
len = 500; % Length of the signal
epochs = 1000; % Number of times signal passes through ADF for weight adaptation
runs = 10;
tempIc=0;
tempIf=0;
tempIst=0;
for run=1:runs
meu_c = 2e-5;% Step size
meu_f = 2e-5;% Step size
meu_st = 1e-2;% Step size
x=[ones(1,round(len/4)) -ones(1,round(len/4)) ones(1,round(len/4)) -ones(1,round(len/4))];
x=awgn(x,10);
%% Defining Unknown System
h = [2 -0.5 -0.1 -0.7 3];
c = [-5:2:5];
n1=length(c);
W_c = randn(1,n1); % Weights
W_f = randn(1,n1); % Weights
W_st = randn(3,n1); % Weights
beeta=1;
b_c=randn(1);
b_f = b_c;
b_st = b_c;
noise_level = sqrt(0.01);
for k=1:epochs
Ic(k)=0;
If(k)=0;
Ist(k)=0;
U = zeros(3,1);
U(2:end)=[-1 -1];
for i1=1:len
U(1:end-1)=U(2:end);
U(end)=x(i1);
for i2=1:n1
ED_cf(:,i2)=exp((-(norm(U-c(i2))^2))/beeta^2);
end
for i2=1:n1
ED_st(:,i2)=exp((-(abs(U-c(i2))))/beeta^2);
end
%% RBF
yc(i1)=sum(diag(W_c*ED_cf'))+b_c;
d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))))+noise_level*randn();
e_c=d(i1)-yc(i1);
Ic(k)=Ic(k)+e_c*e_c'./len; %%% Objective Function
W_c=W_c+meu_c*e_c*ED_cf;
b_c=b_c+meu_c*e_c;
%% Fractional RBF
yf(i1)=sum(diag(W_f*ED_cf'))+b_f;
% d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))))+0.1*randn();
e_f=d(i1)-yf(i1);
If(k)=If(k)+e_f*e_f'./len; %%% Objective Function
W_f=W_f+meu_f*e_f*ED_cf.*((1-alpha_f)+alpha_f*abs(W_f.^fp));
b_f=b_f+meu_f*e_f.*((1-alpha_f)+alpha_f*abs(b_f.^fp));
%% ST-RBF
yst(i1)=sum(diag(W_st*ED_st'))+b_st;
% d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))))+0.1*randn();
e_st=d(i1)-yst(i1);
Ist(k)=Ist(k)+e_st*e_st'./len; %%% Objective Function
W_st=W_st+meu_st*e_st*ED_st;%*G;
b_st=b_st+meu_st*e_st;
% q = alpha_q*q + gamma_q*eq^2;
% if (q>q_max)
% q=q_max;
% end
end
% q_track(k) = q;
end
% time=toc
% tempq_track= tempq_track + q_track;
tempIc=tempIc+Ic;
tempIf=tempIf+If;
tempIst=tempIst+Ist;
end
% q_track = tempq_track./runs;
Ic=tempIc./runs;
If=tempIf./runs;
Ist=tempIst./runs;
save comparison_train.mat
% plot(q_track)
figure
semilogy(Ic,'r')
hold on
semilogy(If,'k')
semilogy(Ist,'b')
figure
len = 200; % Length of the signal
y=0;
Ic=0;
yf=0;
If=0;
d=0;
x=0;
yst=0;
Ist=0;
x=[-1 -1 ones(1,round(len/4)) -ones(1,round(len/4)) ones(1,round(len/4)) -ones(1,round(len/4))];
x=awgn(x,10);
U(2:end)=[-1 -1];
n1=length(c);
Ic=0;
for i1=1:len-1
U(1:end-1)=U(2:end);
U(end)=x(i1);
for i2=1:n1
ED_cf(:,i2)=exp((-(norm(U-c(i2))^2))/beeta^2);
end
for i2=1:n1
ED_st(:,i2)=exp((-(abs(U-c(i2))))/beeta^2);
end
yc(i1)=sum(diag(W_c*ED_cf'))+b_c;
d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))));
e_c=d(i1)-yc(i1);
SE(i1)=e_c*e_c'; %%% Objective Function
Ic(i1)=mean(SE);
yf(i1)=sum(diag(W_f*ED_cf'))+b_f;
% d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))));
e_f=d(i1)-yf(i1);
SEf(i1)=e_f*e_f'; %%% Objective Function
If(i1)=mean(SEf);
yst(i1)=sum(diag(W_st*ED_st'))+b_st;
% d(i1)= h(1)*U(end) +h(2)*U(end-1)+h(3)*U(end-2)+h(4)*(cos(h(5)*U(end)) +exp(-abs(U(end))));
e_st=d(i1)-yst(i1);
SEq(i1)=e_st*e_st'; %%% Objective Function
Ist(i1)=mean(SEq);
end
hold on
semilogy(Ic,'r')
semilogy(If,'k')
semilogy(Ist,'b')
%saveas(gcf,strcat('Iq.png'),'png')
figure
plot(d,'cy')
hold on
plot(y,'r')
plot(yf,'r')
plot(yst,'b')
legend('RBF','FRBF','desired','qRBF')
%saveas(gcf,strcat('RBF.png'),'png')
% save(strcat('MSE','.mat'));
%save(['q_track','.mat'],'q_track');
% save(['y','.mat'],'y'); save(['yf','.mat'],'yf'); save(['d','.mat'],'d'); save(['yq','.mat'],'yq');
% save(['I','.mat'],'I');save(['Iq','.mat'],'Iq');
save comparison_test.mat
graph_channel