Abstract. We address the Selective Harmonic Modulation (SHM) problem in power electronic engineering, consisting in designing a multilevel staircase control signal with some prescribed frequencies to improve the performances of a converter. In this work, SHM is addressed through an optimal control methodology based on duality, in which the admissible controls are piece-wise constant functions, taking values only in a given finite set. To fulfill this constraint, the cornerstone of our approach is the introduction of a special penalization in the cost functional, in the form of a piece-wise affine approximation of a parabola. In this manner, we build optimal multilevel controls having the desired staircase structure.