A method for operating an electrical converter , the method comprising: determining an optimized pulse pattern (22, v ( t )) from a fundamental voltage reference v ̅ ctr 1 t for the electrical converter , wherein the optimized pulse pattern (22, v̅ ( t )) is determined from a first lookup table and comprises discrete voltage amplitude values changing at predefined switching instants ; characterised in that the method further comprising: determining a harmonic content reference ( ψ ( t )) from the fundamental voltage reference v ̅ ctr 1 t based on a second lookup table , wherein the harmonic content reference is a filtered voltage reference ( ψ ( t )) determined by applying a first order frequency filter to a voltage, which voltage is generated, when the optimized pulse pattern is applied to the electrical converter wherein the harmonic content reference ( ψ ( t )) in the second lookup table has been calculated offline from the corresponding optimized pulse patterns applied to a model of the electrical converter ; determining a harmonic content error (ψ̃( t )) from the harmonic content reference ( ψ ( t )) by subtracting an estimated output voltage ( ψ ( t )) of the electrical converter from the harmonic content reference ( ψ ( t )); modifying the optimized pulse pattern (22, v ( t ) by timeshifting switching instants such that the fundamental voltage reference v ̅ ctr 1 t is tracked and the harmonic content error ( ψ̃ ( t )) is corrected by the timeshifted switching instants , wherein the harmonic content error (ψ̃( t )) is corrected by minimizing a cost function, which comprises a term quadratic in the harmonic content error and/or a term quadratic in timeshifts of the switching instants; applying the modified optimized pulse pattern ( v ( t )) to semiconductor switches of the electrical converter . determining a harmonic content reference ( ψ ( t )) from the fundamental voltage reference v ̅ ctr 1 t based on a second lookup table , wherein the harmonic content reference is a filtered voltage reference ( ψ ( t )) determined by applying a first order frequency filter to a voltage, which voltage is generated, when the optimized pulse pattern is applied to the electrical converter wherein the harmonic content reference ( ψ ( t )) in the second lookup table has been calculated offline from the corresponding optimized pulse patterns applied to a model of the electrical converter ; determining a harmonic content error (ψ̃( t )) from the harmonic content reference ( ψ ( t )) by subtracting an estimated output voltage ( ψ ( t )) of the electrical converter from the harmonic content reference ( ψ ( t )); modifying the optimized pulse pattern (22, v ( t ) by timeshifting switching instants such that the fundamental voltage reference v ̅ ctr 1 t is tracked and the harmonic content error ( ψ̃ ( t )) is corrected by the timeshifted switching instants , wherein the harmonic content error (ψ̃( t )) is corrected by minimizing a cost function, which comprises a term quadratic in the harmonic content error and/or a term quadratic in timeshifts of the switching instants; applying the modified optimized pulse pattern ( v ( t )) to semiconductor switches of the electrical converter . <EOS>