Upload files to "/"
This commit is contained in:
@@ -0,0 +1,568 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% ZScan_beam_simulation
|
||||
%
|
||||
% Version: 1.3.4
|
||||
% Date: 06/23/19
|
||||
%
|
||||
% Calculates Open and Closed aperture z-scan curves based on
|
||||
% instantaneous (chi-3) NLR and 2PA. Takes slices in
|
||||
% radius and time, and uses analytic solutions to SVEA dI/dz and dphi/dz
|
||||
% in the thin sample approximation (constant beam size across sample).
|
||||
% Integrates irradiance at end of sample for Open Aperture (OA).
|
||||
% Propogates electric field (square root of irradiance with accumulated
|
||||
% phase) to closed aperture and integrates for Closed Aperture. Done
|
||||
% entirely in matrix form, requiring no for-loops.
|
||||
%
|
||||
% The algorithm is based on the following papers:
|
||||
%
|
||||
% 1: Reichert, M., et al. (2014). "Temporal, spectral, and polarization
|
||||
% dependence of the nonlinear optical response of carbon disulfide
|
||||
% Optica 1(6): 436.
|
||||
%
|
||||
% Copyright (C) 2017 Manuel Ferdinandus
|
||||
%
|
||||
% This program is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% This program is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
tic
|
||||
clc
|
||||
clear all
|
||||
format long
|
||||
close all
|
||||
|
||||
%% FILE PARAMETERS
|
||||
|
||||
% Set write = 1 to get output.
|
||||
write = 0;
|
||||
|
||||
import_filepath = ...
|
||||
'C:\Users\Public\Documents\Research\Data\2019\20191022 - ZS CSP 2.0 um V pol\20191022 - ZS CSP 46C3_1 OA_CA run 5.txt';
|
||||
|
||||
% extra label to append to output files
|
||||
extra_label = '';
|
||||
|
||||
% columns in data file
|
||||
z_col = 1;
|
||||
CA_col = 2;
|
||||
OA_col = 5;
|
||||
REF_col = 8;
|
||||
FREQ_col = 4;
|
||||
|
||||
% processing parameters
|
||||
use_ref = 1; % use reference channel
|
||||
flip_z = 1; % flip z-axis
|
||||
do_norm_OA = 1; % normalized OA channel
|
||||
do_norm_CA = 1; % normalized CA channel
|
||||
|
||||
% flip signals
|
||||
flip_OA = 0;
|
||||
flip_CA = 0;
|
||||
flip_REF = 0;
|
||||
|
||||
% flip display for fitting
|
||||
flip_OA_disp = 0;
|
||||
flip_CA_disp = 0;
|
||||
|
||||
show_CA = 1; % show CA or OA/CA
|
||||
|
||||
%% INPUT PARAMETERS
|
||||
|
||||
% Nonlinear parameters
|
||||
n_2 = -5e-19; % third order nonlinear refractive index [m^2/W]
|
||||
n_3 = 0e-33; % fifth order nonlinear refractive index [m/W]
|
||||
n_4 = 0e-48; % seventh order nonlinear refractive index [m/W^2]
|
||||
|
||||
alpha_2 = -5e-13; % two photon absorption coefficient [m/W]
|
||||
alpha_3 = 0e-28; % three photon absorption coefficient [m/W^2]
|
||||
alpha_4 = 1e-43; % four photon absorption coefficient [m/W^3]
|
||||
|
||||
% Offset the OA and CA lines if required
|
||||
Delta_z_OA = +0.05; % OA z-position offset [mm]
|
||||
Delta_z_CA = +0.23; % CA z-position offset [mm]
|
||||
Delta_z_OACA = +0.0; % OACA z-position offset [mm]
|
||||
|
||||
% Sample parameters
|
||||
n = 3.0337; % Linear refractive index (used to calculate Fresnel Reflections)
|
||||
L = 0.188e-3; % Sample thickness [m]
|
||||
T_lin = 1.0; % Linear transmittance [1]
|
||||
|
||||
% Laser parameters
|
||||
E = 180e-9; % Pulse energy [J]
|
||||
lambda = 2000e-9; % Wavelength [m]
|
||||
w_0 = 19e-6; % Beam waist HW1/e^2M of I [m]
|
||||
tau_FWHM = 50e-15; % Pulse duration FWHM of I [s]
|
||||
M2 = 1.0; % Beam quality parameter
|
||||
|
||||
% Measurement parameters
|
||||
S = 0.33; % Linear transmission of aperture
|
||||
d = 1.0; % Distance from focus to aperture [m]
|
||||
|
||||
% Error parameters
|
||||
E_err = 10/100; % Energy error [%]
|
||||
w_err = 10/100; % Beam waist error [%]
|
||||
tau_err = 10/100; % Pulse duration error [%]
|
||||
|
||||
%% INPUT DATA AND PROCESS REFERENCE TO CLEAN UP DATA
|
||||
|
||||
% Read the data from the files
|
||||
V_DATA = dlmread(import_filepath,'',1,0);
|
||||
|
||||
% Extract relevant data from voltage data.
|
||||
Z_DATA = (-1)^flip_z * V_DATA(:,z_col);
|
||||
FREQ_DATA = V_DATA(:,FREQ_col);% / median(V_DATA(:,FREQ_col));
|
||||
OA_DATA = 2*median(V_DATA(:,OA_col))*flip_OA + (-1)^flip_OA*V_DATA(:,OA_col);
|
||||
CA_DATA = 2*median(V_DATA(:,CA_col))*flip_CA + (-1)^flip_CA*V_DATA(:,CA_col);
|
||||
|
||||
% Calculate the scaling factors and scale the reference data if required
|
||||
if use_ref
|
||||
|
||||
% use the reference channel to chlean up the data
|
||||
REF_DATA = 2*median(V_DATA(:,REF_col))*flip_REF + (-1)^flip_REF*V_DATA(:,REF_col);
|
||||
|
||||
rat = (OA_DATA / median(OA_DATA) - 1) ./ (REF_DATA / median(REF_DATA) - 1);
|
||||
m_rat = median(rat);
|
||||
REF_SCALED = (REF_DATA - median(REF_DATA)) * m_rat + median(REF_DATA);
|
||||
REF_SCALED = REF_SCALED / median(REF_SCALED);
|
||||
OA_DATA_CORR = OA_DATA ./ REF_SCALED;
|
||||
|
||||
rat = (CA_DATA / median(CA_DATA) - 1) ./ (REF_DATA / median(REF_DATA) - 1);
|
||||
m_rat = median(rat);
|
||||
REF_SCALED = (REF_DATA - median(REF_DATA)) * m_rat + median(REF_DATA);
|
||||
REF_SCALED = REF_SCALED / median(REF_SCALED);
|
||||
CA_DATA_CORR = CA_DATA ./ REF_SCALED;
|
||||
|
||||
else
|
||||
|
||||
% do not use the reference channel
|
||||
OA_DATA_CORR = OA_DATA;
|
||||
CA_DATA_CORR = CA_DATA;
|
||||
|
||||
end
|
||||
|
||||
CAOA_DATA = CA_DATA ./ (OA_DATA / median(OA_DATA));
|
||||
|
||||
%% NORMALIZE THE DATA AND AJUST FOR SLOPE
|
||||
|
||||
DATA(:,1) = Z_DATA - median(Z_DATA);
|
||||
DATA(:,2) = OA_DATA /median(OA_DATA);
|
||||
DATA(:,3) = OA_DATA_CORR / median(OA_DATA_CORR);
|
||||
DATA(:,4) = CA_DATA / median(CA_DATA);
|
||||
DATA(:,5) = CA_DATA_CORR / median(CA_DATA_CORR);
|
||||
|
||||
endpts = floor(0.1*size(DATA(:,1)));
|
||||
|
||||
% calculate OA normalization line
|
||||
if do_norm_OA
|
||||
|
||||
OA_wings = [DATA(1:endpts,1:3);DATA(end - endpts:end,1:3)]; % Get data on wings
|
||||
OA_coeff = polyfit(OA_wings(:,1),OA_wings(:,3),1); % Calculate coefficients
|
||||
norm_OA = polyval(OA_coeff,DATA(:,1)); % Calculate fit line
|
||||
|
||||
else
|
||||
|
||||
norm_OA = DATA(:,1)*0 + 1; % flat fit line
|
||||
|
||||
end
|
||||
|
||||
% show the original data and fit line
|
||||
scrsz = get(groot,'ScreenSize');
|
||||
norm_plot = figure('Name','Referenced and normalized data','OuterPosition',...
|
||||
[1 1 round(scrsz(3)/1.5) round(scrsz(4)/1.5)]);
|
||||
line_width = 1.25;
|
||||
|
||||
% show OA data and normalization line
|
||||
subplot(1,2,1)
|
||||
plot(DATA(:,1),DATA(:,2),'r-');
|
||||
axis tight
|
||||
hold on
|
||||
plot(DATA(:,1),DATA(:,3),'r-','Linewidth',line_width);
|
||||
plot(DATA(:,1),norm_OA,'k-','Linewidth',line_width);
|
||||
|
||||
pbaspect([1.25 1 1])
|
||||
title('Open aperture (raw / referenced)')
|
||||
xlabel('z (mm)');
|
||||
ylabel('Transmission (normalized)');
|
||||
hold off;
|
||||
|
||||
% calculate CA normalization line
|
||||
if do_norm_CA
|
||||
|
||||
CA_wings = [DATA(1:endpts,1:5);DATA(end - endpts:end,1:5)]; % Get data on wings
|
||||
CA_coeff = polyfit(CA_wings(:,1),CA_wings(:,5),1); % Calculate coefficients
|
||||
norm_CA = polyval(CA_coeff,DATA(:,1)); % Calculate fit line
|
||||
|
||||
else
|
||||
|
||||
norm_CA = DATA(:,1)*0 + 1; % flat fit line
|
||||
|
||||
end
|
||||
|
||||
% show the CA data and normalization line
|
||||
subplot(1,2,2)
|
||||
|
||||
plot(DATA(:,1),DATA(:,4),'b-');
|
||||
axis tight
|
||||
hold on;
|
||||
plot(DATA(:,1),DATA(:,5),'b-','Linewidth',line_width);
|
||||
plot(DATA(:,1),norm_CA,'k-','Linewidth',line_width);
|
||||
|
||||
ax = gca;
|
||||
ax.YAxisLocation = 'right';
|
||||
pbaspect([1.25 1 1])
|
||||
title('Closed aperture (raw / referenced)')
|
||||
xlabel('z (mm)');
|
||||
ylabel('Transmission (normalized)');
|
||||
hold off;
|
||||
|
||||
% put the plots next to each other
|
||||
ha = get(gcf,'children');
|
||||
set(ha(1),'position',[.5 .1 .4 .9])
|
||||
set(ha(2),'position',[.1 .1 .4 .9])
|
||||
|
||||
% append normalized data to array
|
||||
DATA(:,6) = DATA(:,1) - Delta_z_OA; % OA z-axis
|
||||
DATA(:,7) = DATA(:,3) ./ norm_OA; % Normalized OA
|
||||
DATA(:,8) = DATA(:,1) - Delta_z_CA; % CA z-axis % z-axis
|
||||
DATA(:,9) = DATA(:,5) ./ norm_CA; % Normalized CA
|
||||
DATA(:,10) = DATA(:,1) - Delta_z_OACA; % OACA z-axis
|
||||
DATA(:,11) = DATA(:,9) ./ DATA(:,7); % Normalized OACA
|
||||
|
||||
% flip arrays if required
|
||||
DATA(:,7) = 2*flip_OA_disp + (-1)^flip_OA_disp*DATA(:,7);
|
||||
DATA(:,9) = 2*flip_CA_disp + (-1)^flip_CA_disp*DATA(:,9);
|
||||
DATA(:,11) = 2*flip_CA_disp + (-1)^flip_CA_disp*DATA(:,11);
|
||||
|
||||
%% SIMULATION PARAMETERS
|
||||
|
||||
% Determines the quality of fit, larger the better, but will take longer to
|
||||
% calculate! Also, you must be careful becuase it is very easy to make the
|
||||
% simulation space large enough to run out of RAM. The most important
|
||||
% parameter here is r_points, which should never be set less than 200, and
|
||||
% should be more if you have the RAM! This samples with electric field
|
||||
% distribution after the sample for propagation for the aperture. If
|
||||
% undersampled will result in numerical errors, typically a bowing up in
|
||||
% the middle
|
||||
% (see H:\Home\NLO\shared2\Matt\Programs\Z-Scan\References\Beam_propagation.pptx)
|
||||
|
||||
z_points = 75; % Number of z-scan points (must be even)
|
||||
r_points = 500; % Number of points in radial domain on sample
|
||||
r_max = 3; % Size of radial integration [w]
|
||||
t_points = 50; % Number of points in temporal domain
|
||||
t_max = 3; % Size temporal integration [tau]
|
||||
ra_points = 50; % Number of points in radial domain at close aperture
|
||||
|
||||
%% CALCULATED PARAMETERS
|
||||
|
||||
% physical constants
|
||||
c = 299792458; % Speed of light [m/s]
|
||||
epsilon_0 = 8.854187817620e-12; % Permittivity of free space [F/m]
|
||||
h = 6.62606957e-34; % Plank's constant [J s]
|
||||
|
||||
% calculated parameters
|
||||
tau = tau_FWHM/(2*sqrt(log(2))); % Pulse duration HW1/eM of I [s]
|
||||
k_0 = 2*pi/lambda; % Wavenumber [m^-1]
|
||||
|
||||
alpha = -log(T_lin)/L; % Linear absorption coefficient [m^-1]
|
||||
kappa = alpha*lambda / (4*pi); % Extinction coefficient [1]
|
||||
Io = 2*E./(pi^(3/2)*w_0^2*tau); % Peak Irradiance [W/m^2]
|
||||
|
||||
z_0 = pi*w_0^2/lambda; % Rayleigh range [m]
|
||||
w_a = w_0*(1 + M2*(d/z_0)^2)^(1/2); % Beam radius at aperture [m]
|
||||
r_a = w_a*sqrt(-1/2*log(1-S)); % Aperture radius [m]
|
||||
z_range = (max(abs(DATA(:,1))) + abs(max([Delta_z_OA, Delta_z_CA, Delta_z_OACA]))) /(z_0*1e3); % Full z-scan range [z_0];
|
||||
|
||||
Tot_err = sqrt(E_err^2 + w_err^2 + tau_err^2); % Total error [1]
|
||||
|
||||
%% INITIALIZATION
|
||||
|
||||
if alpha_2 + alpha_3 + alpha_4 == 0 % Prevent division by zero
|
||||
alpha_2 = 1e-20; % This is in here because these
|
||||
end % constants occur in the denominator
|
||||
if n_2 + n_3 + n_4 == 0 % in certain locations in the
|
||||
n_2 = 1e-50; % calculation, and thus must not
|
||||
end % be zero or and error would occur
|
||||
|
||||
z = -1 : 2/z_points : 1; % adjust the space of z_scan position, make it densier near focus.
|
||||
z = sign(z).*(z.^2);
|
||||
z = z*z_range*z_0; % Z-scan range [m]
|
||||
|
||||
w = w_0*(1+(z./z_0).^2).^(1/2); % Beam radius [m]
|
||||
w = w_0*(1 + M2*(z./z_0).^2).^(1/2);
|
||||
R = z + z_0^2./z; % Radius of curvature [m]
|
||||
zeta = atan(z/z_0); % Gouy shift [rad]
|
||||
|
||||
r = w' * (0 : r_max/r_points : r_max); % Radial vector [m]
|
||||
dr = r(:,2);
|
||||
|
||||
t = 0 : t_max*tau/t_points : t_max * tau; % Temporal vector [s]
|
||||
dt = t(2);
|
||||
|
||||
ra = 0 : r_a/ra_points : r_a; % Aperture radial vector [m]
|
||||
dra = ra(2);
|
||||
|
||||
da = d - z; % Distance from sample to aperture [m]
|
||||
|
||||
%% CALCULATE IRRADIANCE THROUGH SAMPLE
|
||||
|
||||
w = repmat(permute(w, [2 1]), [1, length(r(1,:))]); % Make waist vector a 2D matrix for multiplication
|
||||
I_r = Io * (w_0./w).^2 .* exp(-2*(r./w).^2); % Radial irradiance distribution as a fuction of z-position
|
||||
|
||||
Delta_n = n_2 * I_r; % Index change vs. radius and z-position
|
||||
Ref = ((n+Delta_n-1).^2 + kappa^2)./((n+Delta_n+1).^2 + kappa^2); % Reflectivity vs. radius and z-position
|
||||
|
||||
I_r1 = I_r .* (1 - Ref); % Irradiance that makes it through front surface
|
||||
I_t = exp(-(t./tau).^2); % Temporal irradiance distribution
|
||||
I = reshape(I_r1(:)*I_t, [length(z) length(r(1,:)) length(t)]); % 3D irradiance matrix (z,r,t) at sample input
|
||||
|
||||
if alpha == 0
|
||||
I_exit = I ./ ( 1 + (alpha_2 + alpha_3*I + alpha_4*I.^2)*L.*I ); % 3D irradiance matrix (z,r,t) at sample output
|
||||
nl_phi = k_0*(n_2 + n_3*I + n_4*I.^2) ./ (alpha_2 + alpha_3*I + alpha_4*I.^2) .* log(1 + (alpha_2 + alpha_3*I + alpha_4*I.^2)*L.*I); % 3D nonlinear phase matrix (z,r,t) accumulated at sample output
|
||||
else
|
||||
I_exit = alpha*I ./ ((alpha + (alpha_2 + alpha_3*I + alpha_4*I.^2).*I).*exp(alpha.*L) - (alpha_2 + alpha_3*I + alpha_4*I.^2).*I); % 3D irradiance matrix (z,r,t) at sample output
|
||||
nl_phi = k_0*(n_2 + n_3*I + n_4*I.^2) ./ (alpha_2 + alpha_3*I + alpha_4*I.^2) .* (log((alpha + (alpha_2 + alpha_3*I + alpha_4*I.^2).*I).*exp(alpha.*L)... % 3D nonlinear phase matrix (z,r,t) accumulated at sample output
|
||||
- (alpha_2 + alpha_3*I + alpha_4*I.^2).*I) - alpha*L - log(alpha));
|
||||
end
|
||||
I = I_exit;
|
||||
|
||||
R = repmat(R', [1 length(r(1,:))]);
|
||||
zeta = repmat(zeta',[1 length(r(1,:))]);
|
||||
G_phase = repmat((1i*k_0*r.^2./(2*R) + 1i*zeta),... % Gaussian phase from radius of curvature and Gouy shift
|
||||
[1 1 length(I(1,1,:))]);
|
||||
|
||||
E_exit = (2/(c*epsilon_0) * I).^(1/2)... % Complex electric field matrix (z,r,t) at sample output
|
||||
.* exp(1i*nl_phi) .* exp(G_phase);
|
||||
|
||||
%% PROPOGATE TO CLOSED APERTURE
|
||||
|
||||
ra = permute(ra,[1,3,4,2]); % Matrix manipulations to get multiplications to work out
|
||||
E_EXIT = repmat(E_exit,[1 1 1 length(ra)]);
|
||||
R_THING_b = repmat(r,[1 1 1 length(ra)]);
|
||||
DR = repmat(dr, [1 1 length(t) length(ra)]);
|
||||
RA = repmat(ra, [size(E_EXIT(:,1,:,1)) 1]);
|
||||
RA_b = repmat(ra, [size(E_EXIT(:,:,1,1)) 1 1]);
|
||||
DA = repmat(da',[1, 1,...
|
||||
length(E_EXIT(1,1,:,1)), length(ra)]);
|
||||
DA_b = repmat(da',[1, length(E_EXIT(1,:,1,1)),1, length(ra)]);
|
||||
|
||||
A = k_0 ./(1i*DA) .* exp(1i*pi/(lambda*DA).*RA.^2); % Fresnel propogation integral to closed aperture
|
||||
B = R_THING_b.*exp(1i*pi/(lambda*DA_b).*R_THING_b.^2)...
|
||||
.*besselj(0,k_0*R_THING_b.*RA_b./(DA_b));
|
||||
B = repmat(B, [1 1 length(t) 1]);
|
||||
E_ap = A(:,1,:,:) .* trapz(E_EXIT.*B,2).*DR; % Complex electric field at closed aperture
|
||||
|
||||
%% CALCULATE OA AND CA SIGNALS
|
||||
|
||||
OA = trapz(trapz(I,3)*(2*dt).*r,2).*(2*pi*dr);
|
||||
OA = OA/OA(1); % Normalized Open Aperture
|
||||
ra1 = repmat(ra, [length(z) 1 1 1]);
|
||||
CA = c*epsilon_0/2 * trapz(trapz(abs(E_ap).^2,3)...
|
||||
.*(2*dt).*ra1,4).*(2*pi*dra);
|
||||
CA = CA / ((CA(1) + CA(end))/2); % Normalized Closed Aperture
|
||||
CAOA = CA ./ OA;
|
||||
|
||||
%% CALCULATE GOODNESS OF FIT METRICS
|
||||
|
||||
OA_interp = interp1(z*1e3,OA,DATA(:,6),'spline');
|
||||
OA_chi_square_arr = rmmissing(((OA_interp - DATA(:,2)).^2) ./ OA_interp);
|
||||
OA_chi_square = sum(OA_chi_square_arr);
|
||||
|
||||
CA_interp = interp1(z*1e3,CA,DATA(:,8));
|
||||
CA_chi_square_arr = rmmissing(((CA_interp - DATA(:,3)).^2) ./ CA_interp);
|
||||
CA_chi_square = sum(CA_chi_square_arr);
|
||||
|
||||
CAOA_interp = interp1(z*1e3,CAOA,DATA(:,10));
|
||||
CAOA_chi_square_arr = rmmissing(((CAOA_interp - DATA(:,4)).^2) ./ CAOA_interp);
|
||||
CAOA_chi_square = sum(CAOA_chi_square_arr);
|
||||
|
||||
%% PLOT
|
||||
|
||||
fit_plot = figure('Name','Normalized and fit data','OuterPosition',...
|
||||
[scrsz(3)/3 1 scrsz(3)/1.5 scrsz(4)/1.5]); % open a new plot windwow
|
||||
|
||||
% OA plot
|
||||
subplot(1,2,1)
|
||||
plot(DATA(:,6),OA_interp,'-r','Linewidth',line_width);
|
||||
hold on;
|
||||
plot(DATA(:,6),DATA(:,7),'r.')
|
||||
axis tight;
|
||||
pbaspect([1.25 1 1])
|
||||
title('Open aperture (data / fit)')
|
||||
xlabel('z (mm)');
|
||||
ylabel('T (normalized)');
|
||||
box on;
|
||||
hold off;
|
||||
|
||||
if show_CA
|
||||
|
||||
% CA plot
|
||||
subplot(1,2,2)
|
||||
plot(DATA(:,8),CA_interp,'-b','LineWidth',line_width);
|
||||
hold on;
|
||||
plot(DATA(:,8),DATA(:,9),'b.')
|
||||
ax = gca;
|
||||
ax.YAxisLocation = 'right';
|
||||
axis tight;
|
||||
pbaspect([1.25 1 1])
|
||||
title('Closed aperture (data / fit)')
|
||||
xlabel('z (mm)');
|
||||
ylabel('T (normalized)');
|
||||
box on;
|
||||
hold off;
|
||||
|
||||
else
|
||||
|
||||
% OACA plot
|
||||
subplot(1,2,2)
|
||||
plot(DATA(:,10),CAOA_interp,'-b','LineWidth',line_width);
|
||||
hold on;
|
||||
plot(DATA(:,10),DATA(:,11),'b.')
|
||||
ax = gca;
|
||||
ax.YAxisLocation = 'right';
|
||||
axis tight;
|
||||
pbaspect([1.25 1 1])
|
||||
title('Closed over open aperture (data / fit)')
|
||||
xlabel('z (mm)');
|
||||
ylabel('T (normalized)');
|
||||
box on;
|
||||
hold off;
|
||||
|
||||
end
|
||||
|
||||
% put the plots next to each other
|
||||
ha=get(gcf,'children');
|
||||
set(ha(1),'position',[.5 .1 .4 .9])
|
||||
set(ha(2),'position',[.1 .1 .4 .9])
|
||||
|
||||
% delta PV comparison
|
||||
deltaOAdata = 1 - min(DATA(:,7));
|
||||
deltaOAfit = 1 - min(OA_interp);
|
||||
deltaOAcomp = [deltaOAdata, deltaOAfit]
|
||||
|
||||
deltaCAdata = max(DATA(:,9)) - min(DATA(:,9));
|
||||
deltaCAfit = max(CA_interp) - min(CA_interp);
|
||||
deltaCAcomp = [deltaCAdata, deltaCAfit]
|
||||
|
||||
deltaCAOAdata = max(DATA(:,11)) - min(DATA(:,11));
|
||||
deltaCAOAfit = max(CAOA_interp) - min(CAOA_interp);
|
||||
deltaCAOAcomp = [deltaCAOAdata, deltaCAOAfit]
|
||||
|
||||
%% OUTPUT
|
||||
|
||||
% Set write = 1 at the top, and define output as desired save file.
|
||||
% Saves both fit and shifted and normalized input data in one file
|
||||
if write == 1
|
||||
|
||||
export_filepath = strrep(import_filepath,'.txt',[extra_label,'_fit.txt']);
|
||||
|
||||
export_data = cat(2, DATA(:,6), DATA(:,7), OA_interp, DATA(:,8), DATA(:,9), CA_interp, DATA(:,10), DATA(:,11), CAOA_interp);
|
||||
export_fid = fopen(export_filepath,'w+');
|
||||
fprintf(export_fid, 'Position (mm),OA (Data),OA (Fit),Position (mm),CA (Data),CA (Fit),Position (mm),OACA (Data),OACA (Fit)');
|
||||
dlmwrite(export_filepath,export_data,'newline','pc','delimiter',',','precision',8,'-append','roffset',1);
|
||||
|
||||
% Write Log
|
||||
logfile_exportpath = strrep(export_filepath,'.txt','_log.txt');
|
||||
logfile_fid = fopen(logfile_exportpath,'w+');
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[datestr(now),': Begin Z-scan program: ',mfilename('fullpath'),'.']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',['Import data file ',import_filepath,'.']);
|
||||
|
||||
% Write Data Offsets to Log
|
||||
fprintf(logfile_fid,'%s\r\n','Data Offsets:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' Delta_z_OA: ',num2str(Delta_z_OA),' mm']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' Delta_z_CA: ',num2str(Delta_z_CA),' mm']);
|
||||
|
||||
% Write Simulation Parameters to Log
|
||||
fprintf(logfile_fid,'%s\r\n','Simulation Parameters:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' z_points: ',num2str(z_points),]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' z_range: ',num2str(2*z_range,'%6.3f'),' z_0']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' r_points: ',num2str(r_points)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' r_max: ',num2str(r_max),' w']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' t_points: ',num2str(t_points)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' t_max: ',num2str(r_max),' tau']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' ra_points: ',num2str(ra_points)]);
|
||||
|
||||
fprintf(logfile_fid,'%s\r\n','Processing Parameters:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' use_ref: ',num2str(use_ref)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' flip_z: ',num2str(flip_z)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' do_norm_OA: ',num2str(do_norm_OA)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' do_norm_CA: ',num2str(do_norm_CA)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' flip_OA: ',num2str(flip_OA)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' flip_CA: ',num2str(flip_CA)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' flip_REF: ',num2str(flip_REF)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' flip_OA_disp: ',num2str(flip_OA_disp)]);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' flip_CA_disp: ',num2str(flip_CA_disp)]);
|
||||
|
||||
% Write Fit Parameters to Log
|
||||
fprintf(logfile_fid,'%s\r\n','Fit Parameters:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' n_2: ',num2str(n_2*1e13),' cm^2/GW']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' n_3: ',num2str(n_3*1e26),' cm^4/GW^2']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' n_4: ',num2str(n_4*1e39),' cm^6/GW^3']);
|
||||
|
||||
fprintf(logfile_fid,'%s\r\n',[' alpha_2: ',num2str(alpha_2*1e11),' cm/GW']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' alpha_3: ',num2str(alpha_3*1e24),' cm^3/GW^2']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' alpha_4: ',num2str(alpha_4*1e37),' cm^5/GW^3']);
|
||||
|
||||
fprintf(logfile_fid,'%s\r\n',[' E: ',num2str(E*1e9),' nJ']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' I_0: ',num2str(Io*1e-13,'%6.3f'),' GW/cm^2']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' lambda: ',num2str(lambda*1e9),' nm']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' w_0 (HW1/e^2M): ',num2str(w_0*1e6),' um']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' z_0: ',num2str(z_0*1e3,'%6.3f'),' mm']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' tau (FWHM): ',num2str(tau_FWHM*1e15),' fs']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' tau (HW1/eM): ',num2str(tau*1e15,'%6.3f'),' fs']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' M^2: ',num2str(M2)]);
|
||||
|
||||
fprintf(logfile_fid,'%s\r\n',[' n: ',num2str(n)]);
|
||||
fprintf(logfile_fid,'%s\r\n',[' L: ',num2str(L*1e3),' mm']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' T_lin: ',num2str(T_lin)]);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' kappa: ',num2str(kappa,'%6.3f')]);
|
||||
|
||||
fprintf(logfile_fid,'%s\r\n',[' S: ',num2str(S)]);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' d: ',num2str(d*1e3),' mm']);
|
||||
|
||||
% deltaPV comparisons
|
||||
fprintf(logfile_fid,'%s\r\n','DeltaT_PV comparison:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' Delta_OA_comp: ',num2str(deltaOAcomp,'%6.3f'),' (data / fit)']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' Delta_CA_comp: ',num2str(deltaCAcomp,'%6.3f'),' (data / fit)']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' Delta_CAOA_comp: ',num2str(deltaCAOAcomp,'%6.3f'),' (data / fit)']);
|
||||
|
||||
% write fit quality parameters to log
|
||||
fprintf(logfile_fid,'%s\r\n','Fit Quality:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' OA_chi^2: ',num2str(OA_chi_square,'%6.3f'),'']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' CA_chi_2: ',num2str(CA_chi_square,'%6.3f'),'']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' CAOA_chi_2: ',num2str(CAOA_chi_square,'%6.3f'),'']);
|
||||
|
||||
% write error estimates to log
|
||||
fprintf(logfile_fid,'%s\r\n','Error estimates:');
|
||||
fprintf(logfile_fid,'%s\r\n',[' E_err: ',num2str(E_err*100),' %']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' w_err: ',num2str(w_err*100),' %']);
|
||||
fprintf(logfile_fid,'%s\r\n',[' tau_err: ',num2str(tau_err*100),' %']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',[' Tot_err: ',num2str(Tot_err*100,'%6.2f'),' %']);
|
||||
|
||||
% save a picture of the plot
|
||||
splitInd = regexp(export_filepath,'.txt');
|
||||
pictureFileName = strcat(export_filepath(1:splitInd - 1),'.jpg');
|
||||
saveas(fit_plot,pictureFileName,'jpg')
|
||||
|
||||
% save an emf to make nice plots for presentations
|
||||
pictureFileName = strcat(export_filepath(1:splitInd - 1),'.emf');
|
||||
saveas(fit_plot,pictureFileName,'emf')
|
||||
|
||||
% write elapsed time to log
|
||||
el_time = toc;
|
||||
fprintf(logfile_fid,'%s\r\n',['Export results to ',export_filepath,'.']);
|
||||
fprintf(logfile_fid,'%s\r\n\r\n',['Elapsed time is ',num2str(el_time,'%6.2f'),' seconds.']);
|
||||
fclose(logfile_fid); % Close log file.
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user