clear all;
close all;
clc;
L=16; 
p=1.2;
mu=0.0035;%LMP
SNR=20;
NR=100;
N=10000; % Number of iterations
input=randn(N,1);
phi = 0.8;
x = filter(1,[1 -phi],input);
lamda=0.5;
mu1=1e-7;%LMMN
mu2=0.04;%SLMMN
alfa=0.6;
pr=0.01;
Sigma2_I=10^4/12;
ro_ZA=5e-5;
ro_ZA2=1e-4;%ZA-LMP
ro_RZA=1e-4;
ro_RZA2=3e-4;%RZA-LMP
RZAeps=20;
RZAeps2=20;
gamaza=ro_ZA/mu2;
gamarza=ro_RZA/(mu2*RZAeps);
NMSD1 = zeros(N,1);
NMSD2 = zeros(N,1);
NMSD3 = zeros(N,1);
NMSD4 = zeros(N,1);
NMSD5 = zeros(N,1);
NMSD6 = zeros(N,1);
NMSD7 = zeros(N,1);

q1 = waitbar(0,'1','Name','Performing Adaptive Filtering:');
for Nr=1:NR
    K=1;
    h = zeros(1,L);
    q = randperm(L);
    h(q(1:K)) = sign(randn(K,1));
    y = filter(h,1,x); % filters data through channel
    h1=h;
    [ noise ] = addnoise( y,SNR,N );
    coe_i=rand(N,1)<pr;
    v=coe_i.*sqrt(Sigma2_I).*randn(N,1);
    d = y + noise+v;
    
    w1=zeros(L,1);
    u1 = zeros(1,L); 
    w2=zeros(L,1);
    u2 = zeros(1,L);
    w3=zeros(L,1);
    u3 = zeros(1,L); 
    w4=zeros(L,1);
    u4 = zeros(1,L);
    w5=zeros(L,1);
    u5 = zeros(1,L);
    w6=zeros(L,1);
    u6 = zeros(1,L);
    w7=zeros(L,1);
    u7 = zeros(1,L);
    
    for i = 1:N
        %%%%%%%%LMMN%%%%%%%%
        u1 = [x(i) u1(1:end-1)];      % Input signal vector 
        e1 = d(i)- u1*w1;
        w1 = w1+mu1*e1*(lamda+((1-lamda)*e1^2))*u1';
        %%%%%%%%SLMMN%%%%%%%%
        u2 = [x(i) u2(1:end-1)];      % Input signal vector 
        e2 = d(i)- u2*w2;
        Sk=1/(1+exp(-alfa*((lamda*e2^2/2)+((1-lamda)*e2^4/4))));
        w2 = w2+mu2*e2*Sk*(1-Sk)*(lamda+((1-lamda)*e2^2))*u2';
        %%%%%%%%LMP%%%%%%%%
        u3 = [x(i) u3(1:end-1)];      % Input signal vector 
        e3 = d(i)- u3*w3;
        w3 = w3 + mu*abs(e3^(p-1))*sign(e3)*u3';
        %%%%%%%%ZA-SLMMN%%%%%%%%
        u4 = [x(i) u4(1:end-1)];      % Input signal vector 
        e4 = d(i)- u4*w4;
        Sk=1/(1+exp(-alfa*((lamda*e4^2/2)+((1-lamda)*e4^4/4)+gamaza*norm(w4,1))));
        w4 = w4+mu2*e4*Sk*(1-Sk)*(lamda+((1-lamda)*e4^2))*u4'-ro_ZA*sign(w4);
        %%%%%%%%ZA-LMP%%%%%%%%
        u5 = [x(i) u5(1:end-1)];      % Input signal vector 
        e5 = d(i)- u5*w5;
        w5 = w5 + mu*abs(e5^(p-1))*sign(e5)*u5'-ro_ZA2*sign(w5);
        %%%%%%%%RZA-SLMMN%%%%%%%%     
        u6 = [x(i) u6(1:end-1)];      % Input signal vector 
        e6 = d(i)- u6*w6;
        Sk=1/(1+exp(-alfa*((lamda*e6^2/2)+((1-lamda)*e6^4/4)+gamarza*sum(log(1+(RZAeps*abs(w6)))))));
        w6 = w6+mu2*e6*Sk*(1-Sk)*(lamda+((1-lamda)*e6^2))*u6'- ro_RZA*sign(w6)./(1+RZAeps*abs(w6));
        %%%%%%%%RZA-LMP%%%%%%%%
        u7 = [x(i) u7(1:end-1)];      % Input signal vector 
        e7 = d(i)- u7*w7;
        w7 = w7 + mu*abs(e7^(p-1))*sign(e7)*u7'-ro_RZA2*sign(w7)./(1+RZAeps2*abs(w7));
        
        
        msd1(i)=20*log10(norm(h1-w1')/norm(h1)); 
        
        msd2(i)=20*log10(norm(h1-w2')/norm(h1)); 
        
        msd3(i)=20*log10(norm(h1-w3')/norm(h1));
        
        msd4(i)=20*log10(norm(h1-w4')/norm(h1)); 
        
        msd5(i)=20*log10(norm(h1-w5')/norm(h1)); 
        
        msd6(i)=20*log10(norm(h1-w6')/norm(h1)); 
        
        msd7(i)=20*log10(norm(h1-w7')/norm(h1)); 
    end
    NMSD1=NMSD1+transpose(msd1);
    NMSD2=NMSD2+transpose(msd2);
    NMSD3=NMSD3+transpose(msd3);
    NMSD4=NMSD4+transpose(msd4);
    NMSD5=NMSD5+transpose(msd5);
    NMSD6=NMSD6+transpose(msd6);
    NMSD7=NMSD7+transpose(msd7);
waitbar(Nr/NR,q1,[num2str(Nr/NR) '%'])
end
close(q1);
    
MSDlmmn=NMSD1/NR;
MSDslmmn=NMSD2/NR;
MSDlmp=NMSD3/NR;
MSDzaslmmn=NMSD4/NR;
MSDzalmp=NMSD5/NR;   
MSDrzaslmmn=NMSD6/NR;
MSDrzalmp=NMSD7/NR;
    
q = 0.99; 
MSD1 = filter((1-q),[1 -q],MSDlmmn);
MSD2 = filter((1-q),[1 -q],MSDslmmn); 
MSD3 = filter((1-q),[1 -q],MSDlmp);
MSD4 = filter((1-q),[1 -q],MSDzaslmmn);
MSD5 = filter((1-q),[1 -q],MSDzalmp);
MSD6 = filter((1-q),[1 -q],MSDrzaslmmn);
MSD7 = filter((1-q),[1 -q],MSDrzalmp);

C={'b','r','m','k','g','c'};
figure(1)
linewidth = 1.15;
fontsize = 10;
t=1:length(MSD1);
plot(t,MSD1,'Color',C{4},'LineWidth',linewidth);
hold on
plot(t,MSD3,'--','Color',C{1},'LineWidth',linewidth);
plot(t,MSD2,'Color',C{1},'LineWidth',linewidth);
plot(t,MSD5,'--','Color',C{2},'LineWidth',linewidth);
plot(t,MSD4,'Color',C{2},'LineWidth',linewidth);
plot(t,MSD7,'--','Color',C{3},'LineWidth',linewidth);
plot(t,MSD6,'Color',C{3},'LineWidth',linewidth);
legend('LMMN','LMP','SLMMN','ZA-LMP','ZA-SLMMN','RZA-LMP','RZA-SLMMN','Location','best');
set(gca,'FontSize',fontsize);
xlabel('Number of Iterations','fontsize',fontsize);
ylabel('NMSD (dB)','fontsize',fontsize);


