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.