%Functia de repartitie a intervalelor dintre erori pentru modelele de canal tip tandem Bernoulli,tandem Gilbert-Elliot si tandem Bernoulli- Gilbert
pbr=0.01;%modelul tandem bernoulli
abr=1:800;
ptbr=2*pbr*(1-pbr);
ftbr=(1-ptbr).^(abr-1);

p1=0.240053*10^(-2);%modelul tandem gilbert-elliot
q1=0.100485;
p2=0.278662*10^(-2);
q2=0.119516;
pg1=0.220591*10^(-3);
pg2=0.563331*10^(-3);
pb1=0.419360;
pb2=0.417201;
h=(p1+q1)*(p2+q2);
z1=q1*q2/h;
z2=q1*p2/h;
z3=p1*q2/h;
z4=p1*p2/h;
age=1:2500;
P1=pg1+pg2-2*pg1*pg2;
P2=pg1+pb2-2*pg1*pb2;
P3=pb1+pg2-2*pb1*pg2;
P4=pb1+pb2-2*pb1*pb2;
pge1=(q1*pg1+p1*pb1)/(p1+q1);
pge2=(q2*pg2+p2*pb2)/(p2+q2);
ptge=(1-pge1)*pge2+(1-pge2)*pge1;
ftge=0.257113*0.994734.^(age-1)+0.322457*0.511988.^(age-1)+(0.403164*10^(-3))*0.405356.^(age-1)+0.420034*0.521180.^(age-1);

P=0.00278662; %modelul tandem bernoulli-gilbert
Q=0.119516;
Pg1=0.0105521;
Pb1=0.418857;
Zg=Q/P+Q;
Zb=P/P+Q;
ptbg=1.98;
atbg=1:1100;
xx=sqrt(((1-P)*(1-Pg1)+(1-Q)*(1-Pb1))^2-4*(1-P)*(1-Q)*(1-Pb1)*(1-Pg1)+4*P*Q*(1-Pb1)*(1-Pg1));
lamb1=((1-P)*(1-Pg1)+(1-Q)*(1-Pb1)+xx)/2;
lamb2=((1-P)*(1-Pg1)+(1-Q)*(1-Pb1)-xx)/2;
y1=(Q*(1-Pg1))/(lamb1-(1-Q)*(1-Pb1));
y2=(Q*(1-Pg1))/(lamb2-(1-Q)*(1-Pb1));
w1=(1/ptbg)*(Zg*Pg1+y1*Zb*Pb1)*((y2-1)/(y2-y1));
w2=1-w1;
ftbg=w1*lamb1.^(atbg-1)+w2*lamb2.^(atbg-1);

loglog(abr,ftbr,age,ftge,atbg,ftbg)
title('Functia de repartitie a intervalelor dintre erori pentru modelele de canal tip tandem Bernoulli,tandem Gilbert-Elliot si tandem Bernoulli- Gilbert');
grid
xlabel('gap-ul');
ylabel('F(a)');
text(400,0.000015,'TBR');
text(2000,0.000015,'TGE');
text(450,0.0015,'TBG');
