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

12 次查看(过去 30 天)
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().

更多回答(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