%Chapt9Fig7a
%Fabry-Perot optical resonator
clear;
clf;
err=0.00001;
c=3e8;						%speed of light in vacuum
nr=3.3;						%effective refractive index in cavity
lambda0=1310e-9;			%center emission wavelength
Lc=300e-6;					%Cavity length
r1=0.4						%Reflectivity of mirror1
r2=0.8						%Reflectivity of mirror2
r=r1*r2;					%Optical loss per photon round-trip

F=pi*r^0.5/(1-r)			%Optical Finesse
Fconst=(2*F/pi)^2;
Imax=1/((1-r)^2);			%Peak intensity inside cavity normalized to I0
f0=c*1e-12/lambda0			%center frequency in THz
deltaf=c*1e-12/(2*Lc*nr)	%THz
deltawavelength=lambda0^2/(2*Lc*nr)  %m;
gamma_opt=deltaf/F
Q=f0/gamma_opt

for i=[1:1:1000]
   
   Frequency(i)=(f0+i*0.001);
   Fwavelength(i)=c/Frequency(i);
   x=sin(pi*Frequency(i)/deltaf);
   x2=x*x;
   Intensity(i)=Imax/(1+(Fconst*(x2)));
   
end
figure(1);
 plot(Frequency,Intensity);
 axis([f0,f0+1,0,4]); 
 hold on;
 xlabel('Frequency, \nu(THz)'),ylabel('Intensity');
 ttl=sprintf('Chapt9Fig6a2, r_1=%4.2f, r_2=%4.2f, n_r=%4.2f, f_0=%7.2e THz, L_c=%7.2e m',r1,r2,nr,f0,Lc)
 title(ttl);

 figure(2);
 plot(Fwavelength*10^-12,Intensity);
xlabel('Wavelength, \lambda (m)'),ylabel('Intensity');
title(ttl);
