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

44 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2011-10-11
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 个评论
David Tagawa
David Tagawa 2011-10-11
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 2011-10-12
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.

请先登录,再进行评论。

更多回答(1 个)

Iain Robinson
Iain Robinson 2011-10-11
What does G represent in your code?
  1 个评论
David Tagawa
David Tagawa 2011-10-11
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by