% Program to plot the absorption response and phase shift of a bound electron as a function of Gamma, the 
% damping-term parameter

clear; close all

prompt = 'Lower limit of range of photon energy in units of E_B? [0.2]'; 
Emin = input(prompt); 
if isempty(Emin) 
    Emin = 0.2; 
end 
prompt = 'Upper limit of range of photon energy in units of E_B? [2]'; 
Emax = input(prompt); 
if isempty(Emax) 
    Emax = 2; 
end 
prompt = 'Lower limit of range of Gamma in units of E_B? [0.05]'; 
Gmin = input(prompt); 
if isempty(Gmin) 
    Gmin = 0.05; 
end 
prompt = 'Upper limit of range of Gamma in units of E_B? [0.35]'; 
Gmax = input(prompt); 
if isempty(Gmax) 
    Gmax = 0.35; 
end 

set(0,'defaultfigurecolor',[1 1 1]); % Graph background white instead of default grey
figure('ToolBar','none');
vid = VideoWriter('dampedOscillatorGraph.mp4','MPEG-4');
vid.Quality = 100;
vid.FrameRate = 30;
open(vid); 

for gamma = Gmin:0.00125:Gmax
    newplot
    hold off
    omega = Emin:0.0001:Emax;
    omega0 = 1;
    amp = ((omega0^2 - omega.^2).^2 + (gamma*omega).^2).^(-1);
    delta = atan2(gamma*omega,(omega0^2 - omega.^2));
    yyaxis left
    plot(omega,amp,'b','LineWidth', 2.0)
    set(gca,'YTickLabel',[]);
    set(gca,'YTick',[])
    ax = gca;
    ax.YAxis(1).Color = 'k';
    ylabel('Amplitude [arb. units]','color','b');
    ylim([0,1.1*max(amp)])

    hold on
    yyaxis right
    plot(omega,delta,'r','LineWidth', 2.0)
    ax = gca;
    ax.YAxis(2).Color = 'k';
    ax.YLabel(1).Color = 'r';
    ylabel('Phase [radians]','color','r');
    set(gca,'ytick',[0:pi/2:pi]) % where to set the tick marks
    set(gca,'yticklabels',{'0','\pi/2','\pi'}) % give them user-defined labels
    ylim([0,3.3])

    set(gca,'fontsize',18);
    set(gca,'TickLength',[0.02, 1]);
    set(gca,'linewidth',2);
    xlabel('h\nu/E_B');

    str1 = 'h\Gamma/E_B = ';
    str2 = num2str(gamma,'% 4.3f');
    strTot = [str1,str2];
    hText = text(0.7*Emax, 2, strTot, 'FontSize',18);

    frame = getframe(gcf);
    writeVideo(vid,frame);
    hold off
end
close(vid)