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

% This function creats animationNumberOfPictures frames and prints the values
% of the parameters that have been passed as well as an increasing frame number.
% 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) 

function [] = rate_loss( d_v, d_c, L_max, W, 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", 15);
set(0, "defaulttextfontname", "Helvetica");


%Definitions
%d_v=3;
%d_c=6;
L_limit=10000;
%W=3;

%check values for plausibility
if(L_max>L_limit)
    L_max=L_limit;
end
%positiv code rate
if(d_v>d_c)
    d_v=d_c;
end

L=W-1:L_max;
rate_term=1-(L+W-1)./(L)*d_v/d_c;
rate_tail=1-(L)./(L)*d_v/d_c;

hold;
plot(L,rate_term,'color','blue');
plot(L,rate_tail,'color','red');
legend('design rate R_{D,term} of terminated SC-LDPC code','design rate R_{D,tail} of tail-biting SC-LDPC code','Location','SouthEast');
xlim([W-1,L_max]);
ylim([0, (1-d_v/d_c)*1.1]);
xlabel('L');
ylabel('R_D');

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

end
