%Matlab source code

 

%% Script to generate graphs of cost vs shift/aperture.  f_onelayer is % essentially Peter's script

%For varying aperture

% Define parameters
minAp = 0.5;
maxAp = 2*2.46;
increment = 0.1;

% Run a loop with different offsets
m3Ap_loop = minAp:increment:maxAp;
for ii = 1:length(m3Ap_loop)
    cost(ii) = f_onelayer(m3Ap_loop(ii));
end
figure(2);
plot(m3Ap_loop,cost); grid

%For varying shifts

% Define parameters
t =cputime;
maxShift = 2;
increment = 0.1;

% Run a loop with different offsets
m3Shift_loop = -(maxShift):increment:maxShift;
for ii = 1:length(m3Shift_loop)
    cost2(ii) = f_onelayer(m3Shift_loop(ii));
end
figure(3);
plot(m3Shift_loop,cost2); grid
e = cputime-t

%%Addition to Peter's script made by Tali and Camille:

Power4(kk) = sum(T_wo(find(abs(x-mlShift_(kk))<abs(photodiodeWidth/2)))) ./ sum(T_wo(find(abs(x-apertureShift)<abs(apertureWidth/2))))    

%% Optimizations done with fminsearch at the terminal eg:

xmin = fminsearch(@(x) f_onelayer(x),1);

% to find optimal shift for one metal layer, starting by looking around 1 % um.  f_onelayer is essentially Peter's code.