This paper presents the application of differential evolution algorithm to obtain optimal switching angles for a single-phase seven-level to improve AC voltage quality. The proposed inverter in this article is composed of two H-bridge cells with non-equal DC voltage sources in order to generate multiple voltage levels. Selective harmonic elimination pulse width modulation (SHPWM) strategy is used to improve the AC output voltage waveform generated by the proposed inverter. The differential evolution (DE) optimization algorithm is used to solve non-linear transcendental equations necessary for the (SHPWM). Computational results obtained from computer simulations presented a good agreement with the theoretical predictions. A laboratory prototype based on STM32F407 microcontroller was built in order to validate the simulation results. The experimental results show the effectiveness of the proposed modulation method.