rafael-fuente / diffractsim

✨🔬 A flexible diffraction simulator for exploring and visualizing physical optics.
https://rafael-fuente.github.io/simulating-diffraction-patterns-with-the-angular-spectrum-method-and-python.html
Other
651 stars 81 forks source link

How should handle the circular convolution and the linear convolution in the angular spectrum method? #12

Closed MiZhou22 closed 2 years ago

MiZhou22 commented 2 years ago

Hi, there. Firstly, thank you for your great job for the fresh men like me! It's really helpful! So here is the thing, I read the angular spectrum method part to implement the wave propagation, and I noticed you just used two fft2s and ifft. So this is a circular convolution, right? I am wondering what should we choose between circular convolution and linear convolution? Thanks in advance!

rafael-fuente commented 2 years ago

Hi nophy, Circular convolutions require periodic functions, so the angular spectrum method is really a linear convolution. In the implementation, it's not computed directly as a linear convolution since we already know analytically the expression for the Transfer function of free space H = exp(1j kz z), and by using it we save the computation of one FFT.

MiZhou22 commented 2 years ago

Thank you for your reply! @rafael-fuente

I think we can achieve linear convolution by padding the wavefield to twice its size and double sampling the transfer function H in the frequency domain. I implemented this in python, and I got some artifacts ring in the edge of the diffraction pattern. I got the idea from this paper: "A Band-Limited Angle Spectral Method for Numerical Simulation of Free-Space Propagation in Near and Far Fields". Am I saying it right?

I'm still a little confused about the implement of the holography. I'm working on computer-generated holography and I've seen some work using ASM to perform the Gerchberg-Saxton algorithm. But I think we should use FFT instead of ASM cause we could use the fourier lens between the cammera and the SLM.

Anyway, I implement the GS algorithm based on ASM with linear convolution, and I found that the result is much worse than the result based on ASM with circular convolution. So I am confused now!!!

My question might be annoying to ansower cause I am new to this field, and I am not a native English speaker. So thank you very much!!!!