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

12 views (last 30 days)
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;

Accepted Answer

Image Analyst
Image Analyst on 19 May 2021
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().

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!