clc
clear all
close all
%Define input arguments:

% Uin(complex double): initial field distribution: NxN (N= 2^p)
N = 1024;

% DeltaZeta (double): distance between pixels in Uin in meters
DeltaZeta = 5e-6;

% dx (double): propagation distance in meters
d1 = 0.1;

% wavelength (double): in meters
wavelength = 500e-9;

%output arguments:
x = -(N-1)/2:(N-1)/2; % -1023/2 to 1023/2
x = x*DeltaZeta;
y = x;
[X,Y] = meshgrid(x,y);

%RECTANGULAR aperture
a = 10e-4; 
Z1 = ones(N,N).*(abs(X)<a/2); %ones() create array of all ones
Z2 = ones(N,N).*(abs(Y)<a/2);
Zr = Z1.*Z2; % rect()
figure(1)
imagesc(X,Y,Zr); %shows aperture
xlabel('x [m]')
ylabel('y [m]')

%Diffraction Profile using FieldPropagation2021
[Ur1,x1,y1] = FieldPropagation2023(Zr,DeltaZeta,d1,wavelength);

%Normalized
Ur1n = (abs(Ur1)/max(max(abs(Ur1)))).^2;

%figure
figure(2)
imagesc(x1,y1,Ur1n);
axis on
xlabel('x [µm]')
ylabel('y [µm]')
