Email: [email protected]

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Unexpected phases in fresnel diffraction using fft2

Unexpected phases in fresnel diffraction using fft2

PuTI / 2025-01-14
Unexpected phases in fresnel diffraction using fft2
Matlab News

Hello everyone,

I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.

I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:

A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call

I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:

function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);

k = 2*pi / lambda;

%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);

%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);

%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));

%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);

%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end

The formula this algorithm is based on:

<</matlabcentral/answers/uploaded_files/63558/help.PNG>>

_Image 1: Formula for diffraction_

My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):

<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>

_Image 2: Amplitude and Phase of Aout_

So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:

<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>

_Image 3: Amplitude and Phase of AFt_

It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.

After some try and error I decided to use the same algorithm for a Matrix with an odd size:

>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);

The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.

I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.

My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?

Thank you for your time and attention.

Best regards,

AdrianHello everyone,

I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.

I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:

A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call

I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:

function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);

k = 2*pi / lambda;

%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);

%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);

%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));

%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);

%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end

The formula this algorithm is based on:

<</matlabcentral/answers/uploaded_files/63558/help.PNG>>

_Image 1: Formula for diffraction_

My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):

<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>

_Image 2: Amplitude and Phase of Aout_

So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:

<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>

_Image 3: Amplitude and Phase of AFt_

It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.

After some try and error I decided to use the same algorithm for a Matrix with an odd size:

>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);

The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.

I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.

My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?

Thank you for your time and attention.

Best regards,

Adrian Hello everyone,

I’m relative new to Matlab and encountered trouble trying to realize a Fresnel-diffraction using the Fast-Fourier Algorithm.
Please apologize my somehow lacking English skills. Since it’s not my mother tongue, some of my explanations may sound a little bit weird.

I want to propagate a N x N matrix, whereas N is a power of 2.
The matrix I use as a test case describes a square which is symmetric to the middel of the matrix, I generate the matrix with the following code snippet:

A = zeros(256,256);
A(119:138, 119:138) = 100;
fresnelpropagation(A, 100, 0.682, 0.39, 0.39); %function call

I get a small 20px x 20px square in the middel of a 256 x 256 matrix.
The function I call looks like this:

function Aout=fresnelpropagation2( Ain ,z , lambda, dx , dy )
[nx, ny] = size(Ain);

k = 2*pi / lambda;

%dx and dy in distance z
dx2 = z*lambda/(nx * dx);
dy2 = z*lambda/(ny * dy);

%"coordinates" of matrix Ain
x1 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y1 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X1, Y1] = meshgrid(x1 *dx,y1 *dy);

%Phase of matrix Ain and FFT of Ain
AFtPart = Ain.*exp(1i*k*z + (1i*k/(2*z)).*(X1.^2 + Y1.^2));
AFt = fftshift(fft2(ifftshift(AFtPart)));

%"coordinates" of matrix Aout
x2 = (-nx/2*dx2 + dx2/2 : dx2 : nx/2*dx2 – dx2/2);
y2 = (-ny/2*dy2 + dy2/2 : dy2 : ny/2*dy2 – dy2/2);
[X2, Y2] = meshgrid(x2, y2);

%compare Sf(x,y) in formula
AFoldCore = (1i*k /(2*pi*z)).*exp((1i*k/(2*z)).*(X2.^2 + Y2.^2));
Aout = AFoldCore.*AFt;
end

The formula this algorithm is based on:

<</matlabcentral/answers/uploaded_files/63558/help.PNG>>

_Image 1: Formula for diffraction_

My result for the amplitude of Aout is as expected, the problem lies within the phases, they are not symmetrical (obvious asymmetrical part marked in the picture):

<</matlabcentral/answers/uploaded_files/63559/help2.PNG>>

_Image 2: Amplitude and Phase of Aout_

So I tried to find out where this asymetrical part came into existence. AFoldCore proved to be symmetric, AFtPart appears to be symmetric as well, but the phases of AFt itself are not symmetric:

<</matlabcentral/answers/uploaded_files/63561/help3.PNG>>

_Image 3: Amplitude and Phase of AFt_

It appears as if a Sine with a rather low frequency was mulitplied into the phase. It ´"starts"
in the top left corner and goes down to the bottom right corner.

After some try and error I decided to use the same algorithm for a Matrix with an odd size:

>> A = zeros(257,257);
>> A(119:139, 119:139) = 100;
>> fresnelpropagation(A, 100, 0.682, 0.39, 0.39);

The phase of Aout is symmetric, furthermore the phase of AFt is symmetric as well.
Because I need to use the algorithm a lot of times in my program I intend to work with matrixes,
with a size of N x N, whereas N is a power of 2 for perfomance reasons. Due to that simply "upsacling" to N+1 x N+1 is not a possible solution.

I think I know where the error is to be found: The ifftshift is not able to flip along a Pixel with the coordinates [0,0] if N is even. Due to that somehow the sine enters the phase.

My question is how am I able to surpress this sine in my phase without upscaling my Matrix?
Or is there something wrong with my code?

Thank you for your time and attention.

Best regards,

Adrian fft2, phases error, fft, fresnel diffraction MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Generate ST code from a look-up table with CONSTANT attribute
2025-05-22

Generate ST code from a look-up table with CONSTANT attribute

“no healthy upstream” error when trying to access My Account
2025-05-22

“no healthy upstream” error when trying to access My Account

MATLAB Answers is provisionally back?
2025-05-21

MATLAB Answers is provisionally back?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: [email protected]
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss