A method for controlling an electrical converter system, the method comprising: determining a reference output ω m * and an estimated output ( ω m) of the electrical converter system based on measurements in the electrical converter system; determining an optimized pulse pattern ( u i,n) by selecting from a table of precalculated optimized pulse patterns, which is chosen based on the reference output ω m * and the estimated output ( ω m), a pulse pattern comprising a sequence of switching instants ( t *) applied to the electrical converter system; determining a resonant oscillation ( ψ s,h) in the electrical converter system, whereby the resonant oscillation ( ψ s,h) is composed of an electrical machine of the electrical converter system and a LC filter of the electrical converter system; characterized in the following steps: determining a sequence of future states of the electrical converter system by solving a mathematical model of the electrical converter system subject to optimizing a cost function and subject to a constraint that a modified pulse pattern ( u i) is applied to the electrical converter system, which modified pulse pattern ( u i) comprises time shifted switching instants with respect to the optimized pulse pattern ( u i,n), wherein the cost function comprises a term compensating the resonant oscillation ( ψ s,h) with a pulse response oscillation caused by the time shifted switching instants of the modified pulse pattern ( u i) and wherein the mathematical model is constrained such that the switching instants of the modified pulse pattern (ui) have the same order as the switching instants of the optimized pulse pattern (ui,n); applying the modified pulse pattern ( u i) to the electrical converter system. determining a reference output ω m * and an estimated output ( ω m) of the electrical converter system based on measurements in the electrical converter system; determining an optimized pulse pattern ( u i,n) by selecting from a table of precalculated optimized pulse patterns, which is chosen based on the reference output ω m * and the estimated output ( ω m), a pulse pattern comprising a sequence of switching instants ( t *) applied to the electrical converter system; determining a resonant oscillation ( ψ s,h) in the electrical converter system, whereby the resonant oscillation ( ψ s,h) is composed of an electrical machine of the electrical converter system and a LC filter of the electrical converter system; characterized in the following steps: determining a sequence of future states of the electrical converter system by solving a mathematical model of the electrical converter system subject to optimizing a cost function and subject to a constraint that a modified pulse pattern ( u i) is applied to the electrical converter system, which modified pulse pattern ( u i) comprises time shifted switching instants with respect to the optimized pulse pattern ( u i,n), wherein the cost function comprises a term compensating the resonant oscillation ( ψ s,h) with a pulse response oscillation caused by the time shifted switching instants of the modified pulse pattern ( u i) and wherein the mathematical model is constrained such that the switching instants of the modified pulse pattern (ui) have the same order as the switching instants of the optimized pulse pattern (ui,n); applying the modified pulse pattern ( u i) to the electrical converter system. determining a sequence of future states of the electrical converter system by solving a mathematical model of the electrical converter system subject to optimizing a cost function and subject to a constraint that a modified pulse pattern ( u i) is applied to the electrical converter system, which modified pulse pattern ( u i) comprises time shifted switching instants with respect to the optimized pulse pattern ( u i,n), wherein the cost function comprises a term compensating the resonant oscillation ( ψ s,h) with a pulse response oscillation caused by the time shifted switching instants of the modified pulse pattern ( u i) and wherein the mathematical model is constrained such that the switching instants of the modified pulse pattern (ui) have the same order as the switching instants of the optimized pulse pattern (ui,n); applying the modified pulse pattern ( u i) to the electrical converter system.