%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% .m script of web demo "Insert title here" 
% Written for GNU Octave
% INSTITUTE OF TELECOMMUNICATIONS  
% University of Stuttgart 
% www.inue-uni-stuttgart.de 
% author: Mahmudul Hasan   
% date: 29.02.2016  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This example script just prints the values of the given parameters.
% Make sure that the function prototype matches the prototype defined
% in the XML config file. (Parameter names are arbitrary but should be the same
% for better readability)
%%demo_2_fun(code1,code2,code3,ch1,ch2,filename)
function demo_2_main( code1,code2,code3,ch1,ch2,filename)

% define formats
landscape = "-S930,350";
portrait  = "-S640,480";

% select format
output_format = portrait;

% Create an invisible figure.
fh = figure(1);
set(fh, "visible", "off");

% define style
set(0, "defaultlinelinewidth", 2);
set(0, "defaultaxesfontsize", 8);
set(0, "defaultaxesfontname", "Helvetica");
set(0, "defaulttextfontsize", 8);
set(0, "defaulttextfontname", "Helvetica");

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if code1~=0 && code2~=0 && code3~=0

if code1==1;
    load('results_16080153.mat')
    t3=['n=16200']
    name1=['Docsis 3.1 long code ',t3]
    b=['  Capacity for code Rate R= .889'];
    color=['red']
    es_n0_db = demo_xxx (sigma,R,ch2,ch1)
    semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
    xlim([x_lower  4])
    ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'color',color);

end
if code1==2;
   
    load('results_7678470.mat')
    t3=['n=5940']
    name1=['Docsis 3.1 medium code ',t3];
    color=['red']
    b=['  Capacity for code Rate R= .8485'];
    es_n0_db=demo_xxx (sigma,R,ch2,ch1);
    semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    %semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
    xlim([x_lower  4])
    ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'color',color);
end
 if code1==3;
    load('results_7676313.mat')
    t3=['n=1080']
    name1=['Docsis 3.1 short code ',t3]
    color=['red']
    b=['  Capacity for code Rate R= .75'];
    es_n0_db=demo_xxx (sigma,R,ch2,ch1);
    semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
    xlim([x_lower  4])
    ylim([1e-5 1e0])
    hold on;
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'color',color);
end
if code1==4;
   
   load('results_96909235.mat')
   name1=['wifi code R=.5, N=648'];
   color=['red']
   b=['  Capacity for code Rate R= .50'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
   semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
   x_lower=min(min(es_n0_db));
   x_upper=max(max(es_n0_db));
   xlim([x_lower  4])
   ylim([1e-5 1e0])
   hold on
   xlim([-4 4])
   [A,B]=Capacity(3,ch1,ch2,R);
   plot(A,B,'color',color);

end
if code1==5;
   
     load('results_25397363.mat')
   name1=['wifi code R=.67, N=648'];
   color=['red']
   b=['  Capacity for code Rate R= .67'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'DisplayName','LineWidth',3','color',color);

end
if code1==6;
   
    load('results_25403605.mat')
   name1=['wifi code R=.75, N=648'];
   color=['red']
   b=['  Capacity for code Rate R= .75'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
    xlim([x_lower  4])
    ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'color',color);

end
if code1==7;
   
   load('results_25410650.mat')
   name1=['wifi code R=.83, N=648'];
   color=['red']
   b=['  Capacity for code Rate R= .83'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
   semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==8;
   
    load('results_5406090.mat')
   name1=['wifi code R=.5, N=1296'];
   color=['red']
   b=['  Capacity for code Rate R= .50'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
    plot(A,B,'DisplayName','LineWidth',3','color',color);

end

if code1==9;
   
    load('results_25421061.mat')
   name1=['wifi code R=.67, N=1296'];
   color=['red']
   b=['Capacity for code Rate R=.67'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==10;
   
     load('results_25422565.mat')
   name1=['wifi code R=.75, N=1296'];
   color=['red']
   b=['Capacity for code Rate R= .75'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==11;
   
     load('results_25424440.mat')
   name1=['wifi code R=.83, N=1296'];
   color=['red']
   b=('  Capacity for code Rate=')
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==12;
        load('results_5428279.mat')
   name1=['wifi code R=.5, N=1296'];
   color=['red']
   b=['  Capacity for code Rate R=.83'];
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

if code1==13;
   
     load('results_25430934.mat')
   name1=['wifi code R=.67, N=1296'];
   color=['red']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==14;
   
   load('results_25432693.mat')
   name1=['wifi code R=.75, N=1296'];
   color=['red']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==15;
   
     load('results_25435121.mat')
   name1=['wifi code R=.83, N=1944'];
   color=['red']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==16;
    load('results_63878886.mat')
%     load('results_16080153.mat')
   name1=['WiMax code R=.5 ,N=2304']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==17;
    load('results_63887961.mat')
%     load('results_16080153.mat')
   name1=['WiMax IEEE 802.16 with Rate = 0.67A and block size 96']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==18;
    load('results_63895029.mat')
%     load('results_16080153.mat')
   name1=['WiMax code R=.67B ,N=2304']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
 if code1==19;
     load('results_63898362.mat')
   name1=['WiMax IEEE 802.16 with Rate = 0.75A and block size 96']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==20;
     load('results_63900792.mat')
   name1=['WiMax code R=.75B ,N=2304']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code1==21;
     load('results_63903128.mat')
   name1=['WiMax code R=.83 ,N=2304']
   color=['red']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
 if code2==1;
    load('results_16080153.mat')
   name2=[' Docsis 3.1 long code ']
   b=['  Capacity']
   color=['blue']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
   x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on

    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end


if code2==2;
   
    load('results_7678470.mat')
   name2=['Docsis 3.1 medium code '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
 if code2==3;
   load('results_7676313.mat')
   name2=['Docsis 3.1 short code ']
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
   semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
   x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on;
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

 end
if code2==4;
   load('results_96909235.mat')
%     load('results_7678470.mat')
   name2=['Wifi code R=.50, N=648'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==5;
   load('results_25397363.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.67 ,N=648'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  x_upper+3])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==6;
   
    load('results_25403605.mat')
   name2=[' wifi code R=.75 ,N=648 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==7;
   
   load('results_25410650.mat')
   name2=[' wifi code R=.83 ,,N=648 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==8;
   
    load('results_5406090.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.5 ,N=1296'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

if code2==9;
   
    load('results_25421061.mat')
   name2=[' wifi code R=.67 ,N=1296'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==10;
   load('results_25422565.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.75 ,N=1296 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==11;
    load('results_25424440.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.83 ,N=1296 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==12;
    load('results_5428279.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.5 ,N=1944'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

if code2==13;
   
load('results_25430934.mat')
   name2=[' wifi code R=.67 ,N=1944'];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==14;
   
   load('results_25432693.mat')
   name2=[' wifi code R=.75 ,N=1944 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==15;
  
   
     load('results_25435121.mat')
%     load('results_7678470.mat')
   name2=[' wifi code R=.83 ,N=1944 '];
   color=['blue']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==16;
    load('results_63878886.mat')
%     load('results_16080153.mat')
   name2=['WiMax code R=.5 ,N=2304']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==17;
    load('results_63887961.mat')
%     load('results_16080153.mat')
   name2=['WiMax IEEE 802.16 with Rate = 0.67A and block size 96']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==18;
    load('results_63895029.mat')
%     load('results_16080153.mat')
   name2=['WiMax code R=.67B ,N=2304']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
  if code2==19;
load('results_63898362.mat')
   name2=['WiMax IEEE 802.16 with Rate = 0.75A and block size 96']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==20;
load('results_63900792.mat')
   name2=['WiMax code R=.75B ,N=2304']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code2==21;
load('results_63903128.mat')
name2=['WiMax code R=.83 ,N=2304']
   color=['blue']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
 

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
if code3==1;
    load('results_16080153.mat')
   name3=[' Docsis 3.1 long code ']
   b=['  Capacity']
   color=['green']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on

    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end


if code3==2;
   
     load('results_7678470.mat')
   name3=['Docsis 3.1 medium code '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
 if code3==3;
    load('results_7676313.mat')
   name3=[' Docsis 3.1 short code']
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
   semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
   x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on;
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

 end
if code3==4;
   load('results_96909235.mat')
%     load('results_7678470.mat')
   name3=[' wifi code R=.5 ,N=648'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==5;
   load('results_25397363.mat')
%     load('results_7678470.mat')
   name3=[' wifi code R=.67 ,N=648'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==6;
   
    load('results_25403605.mat')
   name3=[' wifi code R=.75 ,N=648 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==7;
   
   load('results_25410650.mat')
   name3=[' wifi code R=.83 ,,N=648 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==8;
   
    load('results_5406090.mat')
   name3=[' wifi code R=.5 ,N=1296'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

if code3==9;
   
     
    load('results_25421061.mat')
   name3=[' wifi code R=.67 ,N=1296'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==10;
   
    load('results_25422565.mat')
   name3=[' wifi code R=.75 ,N=1296 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==11;
   
     load('results_25424440.mat')
   name3=[' wifi code R=.83 ,N=1296 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==12;
   
    load('results_5428279.mat')
   name3=[' wifi code R=.5 ,N=1944'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end

if code3==13;
   
    load('results_25430934.mat')
   name3=[' wifi code R=.67 ,N=1944'];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==14;
   load('results_25432693.mat')
   name3=[' wifi code R=.75 ,N=1944 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==15;
   
   load('results_25435121.mat')
   name3=[' wifi code R=.83 ,N=1944 '];
   color=['green']
   b=['  Capacity']
   es_n0_db=demo_xxx (sigma,R,ch2,ch1);
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color);
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==16;
    load('results_63878886.mat')
   name3=['WiMax code R=.5 ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==17;
    load('results_63887961.mat')
   name3=['WiMax code R=.67A ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
if code3==18;
    load('results_63895029.mat')
   name3=['WiMax code R=.67B ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);

end
 if code3==19;
    load('results_63898362.mat')
   name3=['WiMax code R=.75A ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);
end
if code3==20;
    load('results_63900792.mat')
   name3=['WiMax code R=.75B ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);
end
if code3==21;
    load('results_63903128.mat')
   name3=['WiMax code R=.83 ,N=2304']
   color=['green']
   b=['  Capacity']
  es_n0_db = demo_xxx (sigma,R,ch2,ch1)
semilogy(es_n0_db,(BER_sim),'LineWidth',3,'color',color); 
    x_lower=min(min(es_n0_db));
    x_upper=max(max(es_n0_db));
     xlim([x_lower  4])
     ylim([1e-5 1e0])
    hold on
    [A,B]=Capacity(3,ch1,ch2,R);
     plot(A,B,'color',color);
end

es_n0_db = demo_xxx (sigma,R,ch2,ch1)	%in order to trigger x/y labeling again

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 if code1>0 && code2==0 && code3==0
 %title(strcat('GPU Decoder Results for  ' , name1));
 legend('off');
 legend(name1,'location','NorthEast');
 legend('show');
 elseif code1==0 && code2>0 && code3==0
 %title(strcat('GPU Decoder Results for  ' , name2));
 legend('off');
 legend(name2,'location','NorthEast');
 legend('show');
 elseif code1==0 && code2==0 && code3>0
     %title(strcat('GPU Decoder Results for  ' , name3));
     legend('off');
  legend(name3,'location','NorthEast');
  legend('show');
  elseif code1>0 && code2>0 && code3==0
   %title(strcat('GPU Decoder Results compare'));
   legend('off');
  legend(name1, name2,'location','NorthEast');
  legend('show');
  elseif code1>0 && code2==0 && code3>0
   %title(strcat('GPU Decoder Results compare'));
   legend('off');
  legend(name1,name3,'location','NorthEast');
  legend('show');
  elseif code1==0 && code2>0 && code3>0
   %title(strcat('GPU Decoder Results compare'));
   legend('off');
  legend(name2,name3,'location','NorthEast');
  legend('show');
 elseif code1>0 && code2>0 && code3>0
   %title(strcat('GPU Decoder Results compare'));
   legend('off');
  legend(name1,name2,name3,'location','NorthEast');
  legend('show');
 else
   %title(strcat('GPU Decoder Results compare'));
%   
%  
 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
%legend(strcat('BER (Job=', job_id,')'));
 grid on;
 hold on;

% toggle legend(to trigger update)


% Create an image file. This png image is displayed on the webpage. Its size 
% must be 930x350.
print(filename, "-dpng", output_format);

end
function [es_n0_db]=demo_xxx (sigma,R,ch2,ch1)
if(ch2==0 && ch1==0) 
   
    es_n0_db=10*log10(1./(2*sigma.^2));
    xlabel('SNR (E_S/N_0) in[dB]');
    ylabel('BER')   

else    
    es_n0_db=10*log10(1./(2*sigma.^2))-10*log10(R);
    xlabel('SNR (E_b/N_0) in [dB]');
    ylabel('BER')
    
end
end
function[A,B]=Capacity(channel,ch1,ch2, R)  
if channel==3 && ch1==1 % BIAWGN soft-dec
    
    N_it=13;    %bisection iterations
    N_mc=3e6; %monte carlo trials for expectation value
% leg='BIAWGN (soft-) Capacity';    
    s_t=0.5;        %use s_t for biscetion (between 0 and 1) and calc. sigma according to s_max and s_min
    s_max=4;
    s_min=0.3;
    s=(s_max-s_min)*s_t+s_min;  %sigma
    for i=1:N_it
        y=s*randn(1,N_mc)+2*randi(2,1,N_mc)-3;
        p_y_pos=1./(sqrt(2*pi)*s).*exp(-(y-1).^2./(2*s.^2));
        p_y_neg=1./(sqrt(2*pi)*s).*exp(-(y+1).^2./(2*s.^2));
        p_y=0.5*(p_y_pos+p_y_neg);
        t=-1/N_mc*sum(log2(p_y));
        C=t-0.5*log2(2*pi*exp(1)*s^2);
        if C<R
            s_t=s_t-1/2^(i+1);
        else
            s_t=s_t+1/2^(i+1);
        end
        s=(s_max-s_min)*s_t+s_min;
        
        C=10*log10(1/(2*R*s^2));
        
    end
    
    C=10*log10(1/(2*R*s^2)); 
    
A=[C C];
B=[1e-2 1e-8];
elseif channel==3 && ch1==1&& ch2==1
     N_it=15;    %bisection iterations
    N_mc=1e7; %monte carlo trials for expectation value
% leg='BIAWGN (soft-) Capacity';    
    s_t=0.5;        %use s_t for biscetion (between 0 and 1) and calc. sigma according to s_max and s_min
    s_max=4;
    s_min=0.3;
    s=(s_max-s_min)*s_t+s_min;  %sigma
    for i=1:N_it
        y=s*randn(1,N_mc)+2*randi(2,1,N_mc)-3;
        p_y_pos=1./(sqrt(2*pi)*s).*exp(-(y-1).^2./(2*s.^2));
        p_y_neg=1./(sqrt(2*pi)*s).*exp(-(y+1).^2./(2*s.^2));
        p_y=0.5*(p_y_pos+p_y_neg);
        t=-1/N_mc*sum(log2(p_y));
        C=t-0.5*log2(2*pi*exp(1)*s^2);
        if C<R
            s_t=s_t-1/2^(i+1);
        else
            s_t=s_t+1/2^(i+1);
        end
        s=(s_max-s_min)*s_t+s_min;
        
        C=10*log10(1/(2*R*s^2));
        
    end
    
    C=10*log10(1/(2*R*s^2))
A=[C C];
B=[1e-2 1e-8];
 
end
end