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

12 vues (au cours des 30 derniers jours)
CH
CH le 19 Mai 2021
Commenté : Image Analyst le 19 Mai 2021
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;

Réponse acceptée

Image Analyst
Image Analyst le 19 Mai 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().
  2 commentaires
CH
CH le 19 Mai 2021
It worked, thanks!
Image Analyst
Image Analyst le 19 Mai 2021
So, can you then "Accept this answer"? Thanks in advance.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by