## 4 Discussion  
We propose a new method of detecting R peaks from acquired long-term ECG data for use in HRV analysis. The proposed method combines a syntactical with a statistical approach to address the problem of signal recognition. The use of a preprocessing step reduces the complexity of the syntactical recognition step, thereby making this inherently fast process even faster, and resulting in an overall process that is very fast and computationally efficient. The performance of the method was verified using the MIT-BIH NSR and Fantasia databases. The results from the MIT-BIH NSR database showed that it had a sensitivity, positive predictivity rate, detection error rate, and accuracy of 99.998, 99.999, 0.003, and 99.996%, respectively. Meanwhile, the Fantasia database showed that it had a sensitivity, positive predictivity rate, detection error rate, and accuracy of 99.957, 99.991, 0.053, and 99.947%, respectively. The Fantasia database showed poorer results than the MIT-BIH NSR database because the proposed method failed to recognize the typical waveform that sometimes occurred in the database annotated as beats (Figure 7). Figure 8 demonstrates a real example of the effect of R peak misdetection from the proposed method compared to the actual R peaks during HRV analysis. The misdetection occurred once in MIT-BIH NSR database record #19830 from 2670 s to 2700 s. We used a windows length of 30 s to show the difference of the HRV analysis with a single misdetection compared to that with no misdetection in the HRV frequency domain analysis. The misdetection greatly changed the frequency component compared to the actual NN interval without misdetection. Hence, the misdetection of the R peaks must be minimized in the HRV analysis. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Method** & **Se (\%)** & **PPR (\%)** & **DER (\%)** & **Ac (\%)** \\ \hline Proposed & 99.957 & 99.991 & 0.053 & 99.947 \\ [PERSON] et al. [16] & 99.90 & 99.91 & 0.19 & 99.81 \\ [PERSON] et al. [17] & 99.98 & 99.87 & - & - \\ Pan and Tompkins [18] & 89.16 & 99.89 & - & - \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Performance comparison with the Fantasia database. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Method** & **Se (\%)** & **PPR (\%)** & **DER (\%)** & **Ac (\%)** \\ \hline Proposed & 99.993 & 99.999 & 0.007 & 99.993 \\ [PERSON] et al. [16] & 99.361 & 99.426 & 1.212 & 98.808 \\ [PERSON] et al. [17] & 99.99 & 99.96 & - & - \\ Pan and Tompkins [18] & 96.91 & 99.97 & - & - \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Performance comparison with the MIT-BIH NSR database. The method needed 33.6 and 38.5 ns processing time per sample when tested with the MIT-BIH NSR and Fantasia databases, respectively. The records needed different processing times, but were evaluated with the same duration. Although the computation time needed in the preprocessing stage was proportional to the number \(n\) of data points, it had variations related to noise. In fact, a change in the signal slope can lead to a different branch in the preprocessing algorithm, which has a slightly different processing time compared to other branches. The preprocessing stage resulted in \(m\) data points for the next stage, where \(m\) was lower than \(n\). The computation time needed by the automata in the recognition stage was proportional to \(m\). When evaluated with the MIT-BIH NSR and Fantasia databases, the average time needed for the preprocessing stage was approximately 86% of the total processing time, whereas the average of recognition stage needed approximately 14% of the total processing time. This observation confirmed that the preprocessing method reduced the time needed for the recognition of the R peaks. As a comparison, other methods use cascading FIR filters, each with a computation time of (\(m\times n\)), where \(m\) is the kernel size and \(n\) is the data size. Such filters result in \(n\) data points for the next stage, followed by a relatively complex algorithm for R peak detection.