TITLE: How to choose phase to give a desired Fourier transform
QUESTION [6 upvotes]: Cross posted from MSE.
I have a mathematical problem arising from a physics application, which I feel must have been solved before, but I don't know the terminology associated with it.  I am looking for references.  Briefly, the problem is this:

Given an input function $f$ and a desired output function $g$, find a real-valued function $\phi$ such that the modulus of the Fourier transform $\left|\mathcal{F}\left\{fe^{i\phi}\right\}\right|$ is as close as possible to $|g|$ (with respect to some norm--say $L^2$).

(In my particular case, all functions are defined on a compact subset of $\mathbb{R}^2$, in case it matters.)
In practice, the input function $f$ is an electric field, the phase function $\phi$ is provided by a "spatial light modulator", and the magnitude of the Fourier transform gives the output intensity of a light field, which you want to have a specified form. 
I'm interested in both abstract results and algorithmic solutions to this problem.

REPLY [7 votes]: After spending many months working on this problem, I've learned enough that I feel I can give a fairly complete answer now.  First off, this problem has been studied many times in many different fields, and goes by the name "phase retrieval problem".  However, this term actually includes two rather different problems, one being the problem considered in the OP, and another being the problem of finding the phase of a complex function given its magnitude and given that its Fourier transform is positive.  Annoyingly, the literature often does not make a distinction between these two problems, because there's one famous class of algorithms (the GS algorithm and kin, mentioned below) which works for both of them.  However, there are some algorithms that only work for the case considered in the OP.  
The main algorithm used for these problems goes by the name "Gerchberg–Saxton algorithm" or "error reduction algorithm".  There is a ton of literature on this algorithm and its variations, the most famous being "Phase retrieval algorithms: a comparison" by J. R. Fienup.  Also useful is a later retrospective paper by the same author titled "Phase retrieval algorithms: a personal tour", which I found useful.  Important features of these algorithms include: 

They are easy to implement.
They generate a reasonably accurate solution reasonably quickly.
They never (in my experience) generate a very accurate solution. 
As far as I can tell, no one has given a rigorous proof that these algorithms converge.  (There's a straightforward argument that these algorithms can't make a solution worse, but no one seems to be able to show that they necessarily converge.)

As mentioned above, these algorithms work for both types of phase retrieval.  However, the phase retrieval problem of the OP has considerably more structure than the other problem, and consequently there are much better solutions in this case.  Unfortunately, it is the other phase retrieval problem which enjoys the most attention in the literature, primarily on account of its prominence in x-ray diffraction.
The best algorithmic solutions I've been able to find for the problem of the OP come from the "Monge-Ampere equation".  The problem of the OP can be reduced to the Monge-Ampere equation under a stationary phase approximation that works as long as the functions involved do not oscillate too rapidly.  In this case, there are some analytical solutions for 1D problems and for 2 or higher dimensional problems with radial symmetry or which can be separated into a product of 1D problems.  In the general case, this paper details a Monge-Ampere solver algorithm which has by far the best results I've seen. 
Lastly, I think there is quite a bit of theory for uniqueness of solutions for this problem, largely due to M. V. Klibanov.  The Wikipedia page on phase retrieval has lots of references to his work.  Typically solutions are non-unique in some trivial ways (e.g. complex conjugation), and Gerchberg-Saxton type algorithms tend to yield outputs which are patchworks of these different solutions, leading to noisy output.  The Monge-Ampere algorithm largely evades this problem.