  We present a method for preparing arbitrary pure states of spatial qudits,
namely, D-dimensional (D > 2) quantum systems carrying information in the
transverse momentum and position of single photons. For this purpose, a set of
D slits with complex transmission are displayed on a spatial light modulator
(SLM). In a recent work we have shown a method that requires a single
phase-only SLM to control independently the complex coefficients which define
the quantum state of dimension D. The amplitude information was codified by
introducing phase gratings inside each slit and the phase value of the complex
transmission was added to the phase gratings. After a spatial filtering process
we obtained in the image plane the desired qudit state. Although this method
has proven to be a good alternative to compact the previously reported
architectures, it presents some features that could be improved. In this paper
we present an alternative scheme to codify the required phase values that
minimizes the effects of temporal phase fluctuations associated to the SLM
where the codification is carried on. In this scheme the amplitudes are set by
appropriate phase gratings addressed at the SLM while the relative phases are
obtained by a lateral displacement of these phase gratings. We show that this
method improves the quality of the prepared state and provides very high
fidelities of preparation for any state. An additional advantage of this scheme
is that a complete 2\pi modulation is obtained by shifting the grating by one
period, and hence the encoding is not limited by the phase modulation range
achieved by the SLM. Numerical simulations, that take into account the phase
fluctuations, show high fidelities for thousands of qubit states covering the
whole Bloch sphere surface. Similar analysis are performed for qudits with D =
3 and D = 7.
