How do I create a diffraction pattern from a circular aperture in matlab?
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 11 Okt. 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 Kommentare
Image Analyst
am 12 Okt. 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.
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!