The Gerchberg–Saxton (GS) algorithm is an iterative phase retrieval algorithm for retrieving the phase of a complex-valued wavefront from two intensity measurements acquired in two different planes.
The original paper by Gerchberg and Saxton considered image and diffraction pattern of a sample acquired in an electron microscope.
The pseudocode below performs the GS algorithm to obtain a phase distribution for the plane "Source", such that its Fourier transform would have the amplitude distribution of the plane "Target".
The Gerchberg-Saxton algorithm is one of the most prevalent methods used to create computer-generated holograms.
Aside from optimizations, others may start by performing a forward Fourier transform to the source distribution.