% part of this code taken from MJ's code SqzLossModel.m
clear all
close all

%% Losses
% c = 299792458;
% h_bar = 1e-34;
% fg = c/532e-9; 
% wg = 2*pi*fg;
% Rr = .9985; %M2 reflectivity for red
% Rg = .98 ; %M1 reflectivity for green
% Tau = 0.279/c; %optical path length/c [s]
% gamma_r = (1-sqrt(Rr))/Tau; %1064 decay rate at M2 ~ Total decay rate
% gamma_g = (1-sqrt(Rg))/Tau; %532 decay rate at M1 ~ Total decay rate
% nl = 11; %nonlinear coupling parameter
% threshold_P = 1e3*(h_bar*wg*(gamma_r^2)*gamma_g)/(2*nl^2);  %threshold power mW

threshold_P = 12; %mW
un_amp = 0.224; %mW unamplified seed power

%%
%read measurement file
mea = load('pumppwr_seed.txt');
mea_pump = mea(:,1).*0.7.*0.53;
mea_seed = mea(:,2)./un_amp;


%%
%Fractional Power to thershold
x = linspace(0,1,5000); 

%Classical parametric gain
nlg = ((1+sqrt(x))./(1-x)).^2; %Chua's thesis eq. 5.17-5.19
nlg_deamp = ((1-sqrt(x))./(1-x)).^2;


%% Plots

figure(5)
semilogy(mea_pump,mea_seed, '*r','LineWidth' ,4) %nlg is max red amp with pump/red trans without pump
hold on
semilogy(x*threshold_P,nlg,'--',...
         x*threshold_P,nlg_deamp,'--','LineWidth' ,2) %nlg is max red amp with pump/red trans without pump
legend({'Measured Aug 22, 2018', 'NLG amplification (threshold power = 12 mW', 'NLG deamplification'},'FontSize',18)     
xlabel('Pump power (mW)','FontSize',30)
ylabel('Classical Parametric Gain','FontSize',30)
xlim([0 12])
grid on
hold off