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

42 ビュー (過去 30 日間)
David Tagawa
David Tagawa 2011 年 10 月 11 日
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 Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by