  We propose a protocol for measurement of the phonon number distribution of a
harmonic oscillator based on selective mapping to a discrete spin-1/2 degree of
freedom. We consider a system of a harmonically trapped ion, where a transition
between two long lived states can be driven with resolved motional sidebands.
The required unitary transforms are generated by amplitude-modulated
polychromatic radiation fields, where the time-domain ramps are obtained from
numerical optimization by application of the Chopped RAndom Basis (CRAB)
algorithm. We provide a detailed analysis of the scaling behavior of the
attainable fidelities and required times for the mapping transform with respect
to the size of the Hilbert space. As one application we show how the mapping
can be employed as a building block for experiments which require measurement
of the work distribution of a quantum process.
