%Functia de repartitie a intervalelor dintre erori pentru modelele de canal tip Bernoulli, Gilbert-Elliot si Fritchman
pbr=0.01;%modelul bernoulli
abr=1:2000;
fbr=(1-pbr).^(abr-1);

p=0.187966*10^(-2);%modelul gilbert-elliot
q=0.080617;
pg=0.563331*10^(-3);
pb=0.417201;
zg=q/(p+q);
zb=p/(p+q);
age=1:7000;
pge=zg*pg+zb*pb;
xx=sqrt(((1-p)*(1-pg)+(1-q)*(1-pb))^2-4*(1-p)*(1-q)*(1-pb)*(1-pg)+4*p*q*(1-pb)*(1-pg));
lamb1=((1-p)*(1-pg)+(1-q)*(1-pb)+xx)/2;
lamb2=((1-p)*(1-pg)+(1-q)*(1-pb)-xx)/2;
y1=(q*(1-pg))/(lamb1-(1-q)*(1-pb));
y2=(q*(1-pg))/(lamb2-(1-q)*(1-pb));
w1=(1/pge)*(zg*pg+y1*zb*pb)*((y2-1)/(y2-y1));
w2=1-w1;
fge=w1*lamb1.^(age-1)+w2*lamb2.^(age-1);

p11=0.998511; %modelul fritchman cu trei stari
p31=0.142542;
p13=0.001489;
p32=0.396651;
p23=0.135132;
p22=0.864868;
afr=1:10000;
pfr3=1/(1+p31/p13+p32/p23);
ffr=(p31/p11)*p11.^(afr-1)+(p32/p22)*p22.^(afr-1);

loglog(abr,fbr,age,fge,afr,ffr)
title('Functia de repartitie a intervalelor dintre erori pentru modelele de canal tip Bernoulli, Gilbert-Elliot si Fritchman');
grid
xlabel('gap-ul');
ylabel('F(a)');
text(550,0.000015,'bernoulli');
text(1900,0.000015,'gilbert-elliot');
text(4000,0.0015,'fritchman');
