Optimized generation of spatial qudits by using a pure phase spatial light modulator