A novel technique is presented for developing a near-optimal online real time pulse width modulated specific harmonic elimination (PWM-SHE) switching pattern in which the piecewise linearisation of a fully optimal PWM-SHE switching strategy is applied.