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

12 ビュー (過去 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 Center および File ExchangeRead, 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