%	Se vor introduce parametrii:

% delta,	n1,	d=2a(in microni),	lambda (in micrometri),	vg (in Km/s),	alfas,	alfaj,
% cojon,	coin,	cofin,	G,		K,		eta. 
% T -latimea impulsului (in nanosecunde), po (puterea injectata in fibra, in decibeli)
% ao (atenuarea sistemului optic), alfafibra (atenuarea fibrei)
delta=0.003;
n1=1.46;
d=9;
lambda=1.3;	%valoarea in microni
vg=200000;
alfas=0.25;
coin=0;
cofin=10;
G=50;
K=0.09;
eta=0.67;
T=1000;		%in nanosecunde
po=3;
ao=5;
alfafibra=0.32;


%	Se definesc constantele: 

c=3*10^8; 					% viteza luminii in vid
h=6.625*10^(-34);		% constanta lui Plank
e=1.6*10^(-19);			% sarcina electronului

% Se definesc vectorii:

Popt=ones(1,1);
nivel=ones(1,1);
Ne=ones(1,1);
M=ones(1,1);
sigma=ones(1,1);
par=ones(1,1);
sigmai=ones(1,1);

%	Se calculeaza:

a=d/2;						% raza miezului
alfasnp=alfas/4.34;		% alfas in neperi
omega=(c/lambda)*10.^6;	% frecventa optica in Hz 
pas=(cofin-coin)/10;		% pasul de calcul
pdioda=po-ao;				% nivelul de putere pe dioda

AN=n1*sqrt(2*delta);		% apertura numerica
V=(pi*d*AN)/lambda;		% frecventa normalizata
Wo=(0.5*2*a)*(0.65+1.619*(V.^(-1.5))+2.879*(V.^(-6)));	% marimea spotului in microni
S=(3*delta*(a.^2))/((Wo.^2)*(V.^2));		%coeficientul de retrofifuzie pentru fibra monomod
R=0.5*S*alfasnp*vg*(T/2)*10^(-9);					% notatie

for k=1:2
	nivel(k)=pdioda+10*log10(R)-2*alfafibra*pas*(k-1);			% nivelul de putere retrodifuzata
	Popt(k)=0.001*10.^(nivel(k)/10);						% nivel(k)reprezinta nivelul puterii retrodifuzate
	Ne(k)=(Popt(k)*eta*T*(10.^(-9)))/(h*omega); 	% numarul de electroni primari in pasul k	
	F=K*G+(1-(1/G))*(1-K);										% factorul de zgomot in exces	
	M(k)=(Ne(k)*e*G)/(T*10.^(-9))*10^9							% Curentul mediu in nanoamperi
	sigma(k)=((sqrt(Ne(k)*F))*G*e)/(T*10.^(-9));			% abaterea standard a curentului
	par(k)=(sqrt(Ne(k)*F))/(F-1);				
	sigmai(k)=(sigma(k)*e/T)*10^9;
   
   x=1:500;
   
	P=ones(1,length(x));   
   
   
   
      
ui=1+(x-M(k))./(par(k).*sigmai(k));
wi=(1./(sqrt(2*pi).*sigmai(k).*ui.^1.5)).*exp(-1.*(x-M(k)).^2 ./(2*sigmai(k)^2 .*ui));

      plot(x,wi)
      grid
      xlabel('Curentul in nanoamperi')
      ylabel('Densitatea de probabilitate')
    
end         