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

조회 수: 42 (최근 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