How do I create a diffraction pattern from a circular aperture in matlab?

41 views (last 30 days)
Hi all,
I am wondering how to make a diffraction pattern from a circular aperture in matlab. I am relatively new at using matlab so any help would be much appreciated.
Here is my code so far:
%--------------------------------------------------------------------
we=500; %1/e**2 radius in microns
x=-1000:1:1000; %in microns
y=-1000:1:1000;
G=zeros(length(x),length(y));
for i=1:length(x)
for j=1:length(y)
G(i,j)=exp(-(x(i)^2+y(j)^2)/(we^2/2)); %2-D Gaussian
end
end
[x2 y2] = meshgrid(-1000:1:1000);
C = sqrt((x2).^2+(y2).^2)<20; %Circular aperture
cap = G*C; %Creating Diffraction Pattern
figure; imagesc(cap);
cap_ft = fft2(cap);
cap_ft = fftshift(cap_ft,2);
cap_ftlog = log10(1+abs(cap_ft));
cap_ftlog = ifftshift(cap_ftlog);
cap_ftlog = ifftshift(cap_ftlog,2); %Dont know why this works but it does after some trial and error
figure; imagesc(x,y,cap_ftlog);
%-------------------------------------------------------------------------------------------------
After failing to create a diffraction pattern by doing G*C and taking the Fourier transform, I'm left with two questions:
Is my code essentially correct but with bugs? Or is there a better way to create the pattern?

Accepted Answer

Image Analyst
Image Analyst on 11 Oct 2011
You have a Gaussian, but you aren't cropping it properly by doing G*C. It should be G .* C. Also, the diffraction pattern of a circular aperture is a sombrero function. But you don't have that. You have a Gaussian multiplied by a circ function so your result should be a sombrero function convolved with a Gaussian (since the FT of a Gaussian is another Gaussian), which is basically a blurry sombrero function. Actually since your image is square it will also be convolved with a 2D sinc function. This will give a pretty messy sombrero function, which is what you'll see when you make the correction I gave you. I hope that's what you're expecting.
  2 Comments
David Tagawa
David Tagawa on 11 Oct 2011
Thanks, yes I should have included that simple operator. It is indeed a little messy. I tried convolving first to multiply in the frequency domain but it gave me the diffraction pattern I would see with a rectangular aperture. Anyways, much appreciated.
Image Analyst
Image Analyst on 12 Oct 2011
I'm not sure what you're talking about. You get a circularly symmetric pattern just like you're supposed to. In fact since your image size is larger than your Gaussian and aperture, the artifacts due to the rectangular window is less than the circular pattern from your aperture and Gaussian. This is why your pattern is largely circularly symmetric - a Sombrero function like it should be. What do you mean you see a rectangular aperture diffraction pattern, which would be a 2D sinc function? As far as I can see your problem is solved. What do you mean "anyways..." - don't you consider it to be solved too? You sound like you don't.

Sign in to comment.

More Answers (1)

Iain Robinson
Iain Robinson on 11 Oct 2011
What does G represent in your code?
  1 Comment
David Tagawa
David Tagawa on 11 Oct 2011
It represents the 2-D Gaussian beam source, seen in the code above,
G=zeros(length(x),length(y));
for i=1:length(x)
for j=1:length(y)
G(i,j)=exp(-(x(i)^2+y(j)^2)/(we^2/2)); %2-D Gaussian
end
end

Sign in to comment.

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!