# From Modeling to Failure Prognosis of Permanent Magnet Synchronous Machine
## 3 Hidden Markov Model
### The HMM of Our System
If we consider the case of a 1 mm crack in one piece of the magnet, the states of the trellis diagram, other than the initial healthy state, will be 5: the first state refers to 1 mm crack in magnet 1, state 2 refers to the faulty state where the 1 mm crack deepens and becomes a 2 mm crack, state 3 refers to the faulty state where the 2 mm crack deepens and becomes a 3 mm crack, state 4 refers to the faulty state where the 3 mm crack deepens and becomes a 4 mm crack and state 5 refers to the faulty state where the crack becomes a complete fracture. Hence, in our case, we have a multilevel trellis diagram that can be schematically represented as in Figure 20.  
Figure 19: Trellis diagram example. In our case, the considered states are the healthy state and the faulty states with primitive fault. The observations are a continuous signals function of time; the extracted features from those signals (average for torque and vibration signal and spectral amplitude for temperature) will be the input of the model. A global HMM will be built where all the states and observables highlighted in red are grouped in a single model. The observed features {[SO\({}_{\rm H}\)], [SO\({}_{\rm 1-1}\)], [SO\({}_{\rm 2-1}\)], [SO\({}_{\rm 3-1}\)]... } will be linked to the discrete states of HMM (SH\({}_{\rm H}\), SF\({}_{\rm 1-1}\), SF\({}_{\rm 2-1}\), SF\({}_{\rm 3-1}\)... ) where each number designates a pre-settled state. For example, state '0' designates the machine in the healthy case, state '1' designates the machine in the case of turn-to-turn short circuit in slot 1,..., state '37' designates the machine with crack in magnet 1,..., '49' designates the machine with eccentricity fault... In the same context, observation '0' is the range of average vibration detected by the vibration sensor when the machine is healthy, observation '1' is the range of average vibration detected by the vibration sensor when the machine has a turn-to-turn short circuit fault in slot 1,..., observation '53' is the range of average torque detected by the torque sensor when the machine is healthy...  
Figure 20: Multi-level trellis diagram. In other words, the constructed model will encounter the first layers highlighted in red in Figure 19 because these layers represent the system with the small scale faults we are interested in. As we stated previously, the observations of the HMM will come from three observers: torque, vibration and temperature sensors. For each state of the machine there is data coming from the three sensors. However, some states share the same observations. For example, the temperature of the machine remains almost the same in the healthy case, case of eccentricity fault or case of crack in one magnet. Torque in the case of turn-to-turn short circuit remains the same wherever the short circuit is. The same is applied for the case of crack in one magnet or eccentricity fault. Hence, the total number of observations will be 94 encountering 53 vibration ranges, 4 torque ranges and 37 temperature ranges. Accordingly, the size of the transition matrix is \((53\times 53)\), the size of the emission matrix is \((53\times 94)\), and the initial state of the machine is considered to be healthy  
by calculating the likelihood probability. A schematic representation of the combination between the HMM and the Viterbi algorithm, where the states and the observations are shown, is presented in Figure 21.  
For illustration, let's consider a simple example where the sequence of observations is {SOH, SOH, SOF-1} that corresponds to the sequence of states {SH, SH, SFI-1}. Figure 22 shows how this sequence will be decoded through the Viterbi algorithm and the corresponding sequence of states is detected. At the start, the probability that the system is healthy is '0.6', and the probability that the system is faulty is '0.4'. The probability that the system state is SH if the observation is SOH is '0.6', and the probability that the system state is SFI-1 if the observation is SOH is '0'.