## 2 PMSM Drive System  
To control a PMSM using an ML-based observer, the observer need to be trained with data from a running PMSM control process. Training data were obtained from a simulation model instead of from a workbench control process.  
In general, the mathematical model of a PMSM is expressed in the \(d\)-\(q\) synchronous rotating coordinate as follows:  
\[\left\{\begin{array}{l}v_{d}=r_{s}i_{d}+L_{s}\frac{d}{dt}i_{d}-\omega_{e}L_{s }i_{q}\\ v_{q}=r_{s}i_{q}+L_{s}\frac{d}{dt}i_{q}+\omega_{e}L_{s}i_{d}+\omega_{e}\lambda_ {f}\end{array}\right. \tag{1}\]  
Here, \(v_{d}\) and \(v_{q}\) are the \(d\)- and \(q\)-axis voltages, respectively, and \(r_{s}\) is the winding resistance per phase of the stator. For a surface-mounted PMSM, \(L_{s}=L_{d}=L_{q}\), where \(L_{d}\) and \(L_{q}\) are the \(d\)- and \(q\)-axis inductances, respectively; \(i_{d}\) and \(i_{q}\) denote the \(d\)- and \(q\)-axis currents, respectively; the rotational speed of magnet flux is denoted as \(\omega_{e}\); and the permanent magnet flux linkage is denoted as \(\lambda_{f}\).  
Figure 1 indicates that \(i_{d}\) and \(i_{q}\) are obtained from Clarke and Park transformations of the phase currents. These currents are then controlled using proportional-integral (PI) current controls. The behavior is similar to a DC motor when the current \(i_{d}\) is set to zero. In mode 2, the torque produced by the PMSM can be expressed as follows:  
\[T_{e}=\frac{3N_{p}}{4}\lambda_{f}i_{q}\triangleq K_{t}i_{q} \tag{2}\]  
\[K_{t}=\frac{3N_{p}}{4}\lambda_{f} \tag{3}\]  
Here, \(T_{e}\) is the electromagnetic torque, \(K_{t}\) is the torque constant, and \(N_{p}\) is the pole pairs. If \(T_{L}\) is the load torque, \(J\) is the inertia, and \(B\) is the friction constant, then the dynamic equation for the rotor speed (\(\omega_{r}\)) of PMSM would be as follows:  
\[\frac{d\omega_{r}}{dt}=\frac{1}{J}(T_{e}-T_{L}-B\omega_{r}) \tag{4}\]  
If \(\theta\) is the rotor position angle, the \(d\)-\(q\) axes of \(v_{d}\) and \(v_{q}\) can be returned to the \(\alpha\)-\(\beta\) frame by using [PERSON]'s inverse function:  
\[v_{\alpha}=v_{d}\ cos\ \theta-v_{q}\ sin\ \theta \tag{5}\]  
\[v_{\beta}=v_{d}\ sin\ \theta+v_{q}\ cos\ \theta \tag{6}\]The three-phase currents (\(i_{a}\), \(i_{b}\), and \(i_{c}\)) from the PMSM are turned into two-phase \(\alpha\)-\(\beta\) currents using the Clarke transform:  
\[I_{a}=i_{a} \tag{7}\]  
\[I_{\beta}=\frac{1}{\sqrt{3}}i_{a}+\frac{2}{\sqrt{3}}i_{b} \tag{8}\]  
The two-phase \(\alpha\)-\(\beta\) currents are then transformed into currents in the \(d\)-\(q\) axis as \(i_{d}\) and \(i_{q}\) with the Park transform as follows:  
\[i_{d}=I_{\alpha}\ cos\ \theta+I_{\beta}\ sin\ \theta \tag{9}\]  
\[i_{q}=-I_{\alpha}\ sin\ \theta+I_{\beta}\ cos\ \theta \tag{10}\]  
Figure 1 indicates that the FOC process comprises two control loops, typically called the inner loop and the outer loop. The inner loop control is the control of \(i_{d}\) and \(i_{q}\). The outer loop control is the speed control. Both types of control are achieved using PI control strategies. Furthermore, a Simulink-based control simulation with sensors is performed to obtain the desired training data information for \(v_{x}\), \(v_{\beta}\), \(I_{a}\), \(I_{\beta}\), \(sin\ \theta\) and \(cos\ \theta\).