

pcr=100;
mcr=10;
icr=40;
rif=1/16;
rdf=1/4;

ni=[0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
ci=[0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
er=[100 100 100 100 100 100 100 100 100 100 100 100 100 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 40 40 40 80 80 80 80 80 100 100 100 100 100 100 40 40 100];

ACR=zeros(1,46);
ACR(1)=icr;

    for i=1:1:45
        if ((ni(i)==0) & (ci(i)==0))
            ACR(i+1)=min(er(i),(ACR(i)+rif*pcr));
        end
        if ((ni(i)==0) & (ci(i)==1))
            ACR(i+1)=min(er(i),(ACR(i)-rdf*ACR(i)));
        end
        if ((ni(i)==1) & (ci(i)==0))
            ACR(i+1)=min(er(i),ACR(i));
        end
        if ((ni(i)==1) & (ci(i)==1))
            ACR(i+1)=min(er(i),(ACR(i)-rdf*ACR(i)));
        end
    end
 
   for i=1:1:46
       if (ACR(i)<mcr)
           ACR(i)=mcr;
       end 
   end
    
    plot(ACR,'b');
    title('ACR traffic smoothing');
    xlabel('time');
    ylabel('cell rate');
    