A method is presented to compute the switching angles for selected harmonic elimination (SHE) in a multilevel inverter using the particle swarm optimisation technique. For a desired fundamental voltage, the switching angles are computed by the developed algorithm while eliminating the lower-order harmonics. Also, the selected higher-order harmonics are eliminated by additional switching to contribute minimum total harmonic distortion (THD) for the output voltage. The switching angles computed for optimum THD at varying modulation index are stored as a look-up table in digital signal processor (DSP) memory for online application, thus reducing the online computational burden of solving the non-linear equations of SHE problem. Direct solution of non-linear transcendental equations of SHE problem can lead to discontinuity at certain modulation indices. Here the switching angles are computed offline considering optimum voltage THD whereas selected harmonics are eliminated at all possible modulation indices including the point of discontinuity. The computed angles are used in an experimental setup to validate the simulated results.