# Adaptive Estimation Algorithm for Photoplethysmographic Heart Rate Based on Finite State Machine
## 2 Algorithm
### Spectral Tracking  
#### 2.3.1 FSM  
Since the denoising ability of RLS and EWT is limited to remove MA in all cases, the FSM is combined with adaptive spectral peak tracking based on the denoising effect. A new FSM framework is constructed by referring to the FSM proposed in the literature [11].  
In this framework, three main states are included, which are a stable state, a transitional state, and an unstable state. The conditions for transitions among states include the CF and the distance dist between the highest peak position of the current window and the heart  
Figure 6: Spectrum comparison before and after EWT. (**a**) Spectrogram before EWT; (**b**) spectrogram of the ewt1 component after EWT; (**c**) spectrogram of the ewt2 component after EWT; and (**d**) spectrogram of the ewt3 component after EWT.  
rate position of the previous window. CF is defined as the ratio of the peak amplitude to the root mean square of the whole signal:  
\[CF(i)=\frac{x_{peak}(i)}{x_{rms}(i)} \tag{11}\]  
In most cases, the highest peak of the spectrogram tends to correspond to the true heart rate. So, the CF of the highest peak in the spectrogram of each window is chosen to be calculated. If the CF of the dominant frequency is larger, it can be considered to be less affected by the MA. While analyzing multiple sample signals from different subjects, we investigated the variation of CF values under different conditions. The results showed that when the main peak was more pronounced, its corresponding CF value was usually greater than 3, and most values were between 3 and 4. Based on this observation, we chose 3.5 as the CF threshold \(\mathrm{TH_{CF}}\). In addition to the CF threshold, the distance factor also needs to be considered. Since the main peak may not represent the true peak and may be caused by motion artifacts, further constraints are needed. Considering that there is a 6-s overlap among neighboring windows and that the heart rate does not fluctuate drastically over a short period of time, we set the distance threshold \(\mathrm{TH_{dist}}\) at 5. According to Equation (12), a distance of 5 points corresponds to a heart rate variation of approximately 9.15 bpm:  
\[\Delta BPM=\frac{F_{S}}{N_{FFT}}\times 60\times\Delta dist \tag{12}\]  
where \(\mathrm{N_{FFT}}\) denotes the number of points of the Fourier transform, which is set to 4096, \(F_{S}\) is the sampling frequency, and \(\Delta dist\) is the distance between the spectral peaks.  
The state transition rules of the FSM are shown in Figure 7. If \(\mathrm{CF(i)}>\mathrm{TH_{CF}}\), the CF condition is satisfied. If \(\mathrm{dist}<\mathrm{TH_{dist}}\), the dist condition is satisfied. When the previous state is a stable state, then judge whether CF and dist of the current window satisfy the condition. If both are satisfied, then the stable state is maintained. If CF satisfies but dist does not, then it will be a transitional state. If CF is not satisfied, then it will be an unstable state. When the previous state is a transitional state, if both CF and dist are satisfied, then it is a stable state. If CF is satisfied but dist is not satisfied, then it remains a transition state. If CF is not satisfied, then it is an unstable state. When the previous state is unstable, the estimated heart rate in this state is not reliable; at this time, only the CF needs to be judged. If CF satisfies the condition, then it is a transition state; otherwise, the unstable state should be kept.  
Figure 7: Block diagram of FSM state transition. (The “!” in the figure indicates that the condition is not satisfied).