How to create a diffraction pattern for a double square aperture?

조회 수: 14 (최근 30일)
CH
CH 2021년 5월 19일
댓글: Image Analyst 2021년 5월 19일
I have a code that creates a circular aperture from one circle but I want to change it to produce two squares that are 30 units apart.
How to I write the code for a double square aperture?
This is the code I found for a circle:
n=2^10;
M=zeros(n);
I=1:n;
x=I-n/2;
y=n/2-I;
[X,Y]=meshgrid(x,y);
R=10;
A=(X.^2+Y.^2<=R^2);
M(A)=1;
figure(1); imagesc(M);
axis image; colorbar;
I want to then plot it's 2D fourier transform
DP=fftshift(fft(M));
figure(2); imagesc(abs(DP));
axis image; colorbar;
This is how I changed the code to make it for a square but it didn't work
n=2^10;
M=zeros(n);
I=1:n;
x=I-n/2;
y=n/2-I;
[X,Y]=meshgrid(x,y);
X=40;
Y=40;
A=X*Y;
M(A)=1;
figure(1); imagesc(M);
axis image; colorbar;

채택된 답변

Image Analyst
Image Analyst 2021년 5월 19일
No, not even close, not to mention you're creating a 20 billion row by 20 billion column matrix. Make it easy. Just create an image of all zeros of like 1024 by 1024,
M = zeros(1024);
Then set some places to 1, like
M( 200:300, 200:300) = 1; % One square
M( 600:700, 600:700) = 1; % Other square
Now use fft2().
  댓글 수: 2
CH
CH 2021년 5월 19일
It worked, thanks!
Image Analyst
Image Analyst 2021년 5월 19일
So, can you then "Accept this answer"? Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by