Examples of calculating 2D diffraction patterns

Evaluate these FFT helper functions

fft[list_] := Fourier[list, FourierParameters->{1,-1}];

fftshift2D[list_]:= Module[{m,n,temp},
{m,n}=Dimensions[list];
Which[
EvenQ[n],
temp = RotateRight[list,{0,n/2}],
OddQ[n],
temp = RotateRight[list,{0,(n-1)/2}]
];
Which[
EvenQ[m],
temp =RotateRight[temp,{m/2,0}],
OddQ[m],
temp =RotateRight[temp,{(m-1)/2,0}]
];
temp
]

Case 1: Defining the aperture and electric field in Mathematica.

Uniform field through slit

The electric field is one between the slit, and zero everywhere else.

slitWidth = 0.0001;
slitHeight = 0.0005;
range = 20 *slitWidth;
step = range/500;
slitAperture = Table[If[ -slitWidth/2<x< slitWidth/2 &&-slitHeight/2<y< slitHeight/2, 1,0],{y,-range,range,step},{x,-range,range,step}];

Plot the aperture

ArrayPlot[slitAperture, DataRange->{{-range,range},{-range,range}},FrameTicks->{{-range,0,range},{-range,0,range}},FrameLabel->{"y (m)", "x (m)"},PlotRange->All]

Calculate the 2D Fraunhofer diffraction pattern

(*Calculate the intensity distribution for the Fraunhofer diffraction pattern*)
diffPattern = ((Abs[fft[slitAperture]])^2);
(*center the zero frequency components in the middle of the plot*)
diffPattern = fftshift2D[diffPattern];
(*Add a background intensity to simulate room light*)
diffPatternBackground = diffPattern+ 0.0001*Max[diffPattern];
(*Take the logarithm because your eye can see many orders of magnitude*)
logScalePattern = Log[diffPatternBackground];
(*Normalize the log scale intensity data so it runs between 0 and 1*)
min = Min[logScalePattern];
max = Max[logScalePattern];
logScalePatternNormed = (logScalePattern-min)/(max-min);

(*XRange for zp = 1 meter*)
Xrange = ((zp λ )/(4dx))/.{zp->1.0,λ-> 632.8*^-9,dx->step}
(*Plot the log-scale intensity prediction*)
ArrayPlot[logScalePatternNormed, ColorFunction->Function[z,RGBColor[1,1-z,1-z]], DataRange->{{-Xrange,Xrange},{-Xrange,Xrange}},
FrameTicks->{{-0.05,0,0.05},{-0.05,0,.05}},
FrameLabel->{"y (m)", "x (m)"},PlotRange->All]

Case 2: Defining the 2D aperture using an image

When calculating a uniformly illuminated aperture, you can use an image file to define the shape of the aperture.  If you need to draw your own image a program like Microsoft Paint or Paintbrush for Mac.  You are responsible for choosing the conversion between pixels and meters.  Here is an example

Import the data from an image of the aperture

img = Import["http://www.colorado.edu/physics/phys4430/phys4430_fa17/sample_data/CircularArrayAperture.png"]
imgData = ImageData[img]; (*each data point is a triplet of numbers like {Red, Green, Blue}*)
imgRData = imgData[[All,All,1]]; (*Just grab the "Red" data since Red=Green=Blue for black and white images.*)
ArrayPlot[imgRData, ImageSize->Large]

2890 dot per inch (dpi) means into step size per pixel

I happen to know that this image was generated with a pixel size of 2890 pixels per inch.

dotsPerMeter = 2890*1000/25.4; 
metersPerDot = 1/dotsPerMeter

Calculate the intensity distribution (this code is the same as in the example above)

(*Calculate the intensity distribution for the Fraunhofer diffraction pattern*)
diffPattern = ((Abs[fft[imgRData]])^2);
(*center the zero frequency components in the middle of the plot*)
diffPattern = fftshift2D[diffPattern];
(*Add a background intensity to simulate room light*)
diffPatternBackground = diffPattern+ 0.0001*Max[diffPattern];
(*Take the logarithm because your eye can see many orders of magnitude*)
logScalePattern = Log[diffPatternBackground];
(*Normalize the log scale intensity data so it runs between 0 and 1*)
min = Min[logScalePattern];
max = Max[logScalePattern];
logScalePatternNormed = (logScalePattern-min)/(max-min);

(*X range represented by the FFT in the diffraction plane 1 meter from the aperture*)
(*Note that the range is same for X and Y because the number of pixels per meter is the same in x and y (i.e. the pixels are square).*)
Xrange = ((zp λ )/(4dx))/.{zp->1.0,λ-> 632.8*^-9,dx->metersPerDot}


(*Plot the log-scale intensity prediction*)
ArrayPlot[logScalePatternNormed,
ColorFunction->Function[z,RGBColor[1,1-z,1-z]], 
ImageSize->Large,
DataRange->{{-Xrange,Xrange},{-Xrange,Xrange}},
FrameTicks->{{-0.01,0,0.01},{-0.01,0,.01}},
FrameLabel->{"y (m)", "x (m)"},
PlotRange->All]