In this paper, a new method for achieving high-quality voltage in multilevel inverters is presented. The method is based on the selective harmonic mitigation pulse width modulation (SHM-PWM) technique applied on a cascaded Hbridge multilevel inverter (CHBMLI), which employs a variable DC-link voltage to reduce the amount of the total harmonic distortion (THD) in the output waveform. The variable DC sources in a CHBMLI can increase the modulation index to an acceptable range in the low output voltage values and also increase the number of harmonics to be eliminated in the SHM technique due to increasing the number of voltage levels. In the proposed method, the optimal switching angles are calculated by the particle swarm optimization (PSO) algorithm and the switching angles are stored in lookup tables (LUTs). Implementing the proposed method allows the CHB inverter to improve the performance in producing a high-quality voltage compared with conventional methods. As an applicable example, a single-phase CHBMLI, fed by two isolated DC sources, is examined in this paper. The analysis presented in this paper shows a significant improvement in the quality of the output voltage, especially for low output voltage conditions. The simulation and experimental results are presented to confirm the proposed approach.