## 3 Modelling and Optimization
### Current Tracking  
The nine (highlighted) valid switching states of the HMLI defined in Table 1 are used for tracking load current. For grid-tied HMLI with inductive (_R-L_) loads, the analytical expression can be written as in (6):  
\[V_{\text{inv}}-R_{g}I_{g}-L_{g}\frac{dI_{g}}{dt}-V_{g}=0 \tag{6}\]  
where \(V_{\text{inv}}\) is output voltage, \(R_{g}\) is grid filter resistance, and \(L_{g}\) is filter inductance. To predict the current for the next sampling instant, Equation (6) needs to be converted into discrete time. The variation of \(I_{g}\) at two sampling instances, \(k\) and \(k+1\), are alienated by a sampling time of \(T_{S}\). This can be expressed in (7) as follows:  
\[\frac{dI_{g}}{dt}=\frac{I_{g,k+1}-I_{g,k}}{T_{S}} \tag{7}\]  
To derive an expression for current prediction, the relation between \(V_{inv}\) and the grid current \(I_{g}\) needs to be expressed in discrete time. The future value of the current can be predicted by using a first-order Taylor series [24]. Considering \(h\) as the prediction horizon, the grid current can be written as in (8):  
\[I_{g}(k+h)=\left(1-\frac{R_{g}\times T_{s}}{L_{g}}\right)\times I_{g}(k+h-1)+ \frac{T_{s}}{L_{g}}\big{(}V_{\text{inv}}(k+h-1)-V_{g}(k+h-1)\big{)} \tag{8}\]  
As there is more than one term each for different purposes, weighting components will be assigned with each term. However, for the \(V_{\text{inv,min}}\) calculation, only the term that regulates current is considered. The cost function (CF) is an essential factor in MPC. Here CF is defined as \(G_{1}\), \(G_{2}\), and so on for different parameters. \(G_{1}\) is taken as a CF for current tracking and grid synchronisation as given in Equation (9). Weighting factors (\(W_{1}\), \(W_{2}\), etc.) are assigned to each term of CF, which regulates the robustness of the control parameter. The CF (\(G_{1}\)) for current tracking can be expressed as:  
\[G_{1}=W_{1}\Big{(}I_{g}^{*}-I_{g,k+1}\Big{)}^{2} \tag{9}\]  
where \(I_{g}^{*}\) is the reference amplitude of the grid current. Substituting Equation (8) in (9),  
\[G_{1}=(I_{g}^{*}(k+1)-\left(1-\frac{R_{g}\times T_{s}}{L_{g}}\right)\times I_{ g}(k)-\frac{T_{s}}{L_{g}}\big{[}V_{\text{inv}}(k)-V_{g}(k)\big{]})^{2} \tag{10}\]  
The conventional MPC iterates over all of the voltage vectors. However, in this work, the voltage vectors are reduced to nine for each voltage level. The voltage vectors are further reduced to three by implementing the optimization discussed below. The optimum voltage can be obtained by differentiating \(G_{1}\) by \(V_{\text{inv}}\) to zero, given in (11) as follows:  
\[\frac{dG_{1}}{dV_{\text{inv}}}=0 \tag{11}\]  
The derivative of \(G_{1}\) w.r.t \(V_{\text{inv}}\) can be written as in (12):  
\[\frac{dG_{1}}{dV_{\text{inv}}}=\frac{-2T_{s}}{L_{g}}[I_{g}^{*}(k+1)-\left(1- \frac{R_{g}\times T_{s}}{L_{g}}\right)\times I_{g}(k)-\frac{T_{s}}{L_{g}} \big{[}V_{\text{inv}}(k)-V_{g}(k)\big{]}) \tag{12}\]  
By solving Equation (12),  
\[V_{\text{inv, min}}=\frac{-L_{g}}{T_{s}}A \tag{13}\]where \(A=\bigg{(}1-\dfrac{R_{g}\times T_{s}}{L_{g}}\bigg{)}\times I_{g}(k)+\dfrac{T_{s}}{L_{ g}}\Big{(}V_{g}(k)-I_{g}^{*}(k+1)\Big{)}\) (14)  
The minimum voltage can be written in (15) as follows:  
\[V_{\text{inv,min}}=-\dfrac{L}{T_{S}}\bigg{(}\bigg{(}1-\dfrac{R\cdot T_{S}}{L} \bigg{)}\cdot I_{g,k}-I_{ref}\bigg{)}+V_{g} \tag{15}\]  
As the slope of Equation (15) is negative, it ascertains that minimum voltage is generated. \(V_{\text{inv}}\) is bound to \(V_{\text{(p-p)}}\). It needs to be cut to allow the choice of the correct voltage vectors. Out of the chosen voltage vectors, a maximum of three are hard-coded. When \(V_{\text{min}}\) is within the constrained voltage range, the modified MCP loop iterates through only three vectors to predict the vector that will provide the minimum-cost value. A detailed explanation is shown in Figure 3. The program iterates follow CF minimisation. These modifications lessen the running time per multiple iteration.