## 2 Methods
### Instantaneous Correlation Coefficient Method for Detecting R Peaks
#### 2.1.3 R Peak Detection Based on the Instantaneous Correlation Coefficient  
The maximum value of \(R_{x}(n)\) is obtained at the R peak position of \(x(n)\). The detection of the R peak is realised by the detection of \(R_{x}(n)\) peaks. Since the R peak value of the reference heat beat \(h(k)\) established in this paper is positive, if the R peak value of \(x(n)\) is positive, there is a maximum value of \(R_{x}(n)\) at the position of the R peak value of \(x(n)\). On the contrary, if the R peak of \(x(n)\) is negative, there is a minimum value of \(R_{x}(n)\) at the R peak of \(x(n)\). Therefore, R peak detection needs to first determine the direction of the R peak.  
(1) Determining the R Peak Threshold and R Peak Sequence  
Firstly, we calculate the extreme point sequence \(A_{R}(k)\) of \(R_{x}(n)\) (including the maxima and minima) and the corresponding time position sequence \(T_{R}(k)\).  
\[A_{R}(k)=\left\{\begin{array}{ll}R_{x}(n)&\left|R_{x}(n-1)\right|<\left|R_{ x}(n)\right|>\left|R_{x}(n+1)\right|\\ neglect&\hskip 56.905512 pt\mbox{otherwise}\end{array}\right. \tag{3}\]  
\[T_{R}(k)=\left\{\begin{array}{ll}n&\left|R_{x}(n-1)\right|<\left|R_{x}(n) \right|>\left|R_{x}(n+1)\right|\\ neglect&\hskip 56.905512 pt\mbox{otherwise}\end{array}\right. \tag{4}\]  
We calculate the mean and standard deviation of the absolute value of \(A_{R}(k)\). The R peak threshold \(Rh\) is determined by the following formula:  
\[Rh=mean\big{(}\big{|}A_{R}(k)\big{|}\big{)}+stdev\big{(}\big{|}A_{R}(k)\big{|} \big{)} \tag{5}\]  
where \(mean(\cdot)\) represents the mean value function and \(stdev(\cdot)\) represents the standard deviation function.  
The maximum value greater than threshold \(Rh\) in \(A_{R}(k)\) is denoted \(P_{up}(k_{1})\), and the corresponding time position is \(T_{up}(k_{1})\). The minimum value less than \(-Rh\) is denoted \(P_{low}(k_{2})\), and the corresponding time is \(T_{low}(k_{2})\). The respective average values of \(P_{up}\) and \(P_{low}\) are calculated. The larger absolute value of the average value is the R peak sequence, denoted \(R_{peak}(k)\), and the corresponding time sequence is \(T_{peak}(k)\), i.e.,  
\[R_{peak}(k)=\left\{\begin{array}{ll}P_{up}(k_{1})&if\hskip 56.905512 pt \overline{\big{|}P_{up}\big{|}}>\overline{\big{|}P_{low}\big{|}}\\ -P_{low}(k_{2})&if\hskip 56.905512 pt\overline{\big{|}P_{up}\big{|}}< \overline{\big{|}P_{low}\big{|}}\end{array}\right. \tag{6}\]  
\[T_{peak}(k)=\left\{\begin{array}{ll}T_{up}(k_{1})&if\hskip 56.905512 pt \overline{\big{|}P_{up}\big{|}}>\overline{\big{|}P_{low}\big{|}}\\ T_{low}(k_{2})&if\hskip 56.905512 pt\overline{\big{|}P_{up}\big{|}}< \overline{\big{|}P_{low}\big{|}}\end{array}\right.. \tag{7}\]  
(2) Eliminating Wrong R Peaks  
There may be non-R peak data in \(R_{peak}(k)\), which need to be discriminated and eliminated. First, the RR interval \(T_{RR}(k)\) and mean RR interval \(\overline{T_{RR}(k)}\) are calculated for \(R_{peak}(k)\):  
\[T_{RR}(k)=T_{peak}(k+1)-T_{peak}(k) \tag{8}\]  
\[\overline{T_{RR}(k)}=\frac{1}{K-1}\hskip-2.845276 pt\sum_{k=1}^{K-1}T_{peak}(k) \tag{9}\]  
where \(K\) is the cardinality of \(R_{peak}(k)\).  
\(T_{RR}(k)<0.5\overline{T_{RR}}\) indicates that there is a wrong R peak between \(R_{peak}(k)\) and \(R_{peak}(k+1)\) that needs to be removed. When \(T_{RR}(k)=(0.2\sim 0.5)\overline{T_{RR}(k)}\), if \(T_{RR}(k-1)>\overline{T_{RR}(k)}\), \(R_{peak}(k+1)\) is eliminated,and if \(T_{RR}(k-1)+T_{RR}(k)<\overline{T_{RR}(k)}\), \(R_{\text{path}}(k)\) is eliminated. In addition, the smaller absolute value of \(R_{peak}(k)\) and \(R_{peak}(k+1)\) is eliminated.  
After eliminating the wrong R peak, we recalculate \(T_{RR}(k)\) and \(\overline{T_{RR}(k)}\). We repeat the above steps until there is no wrong R peak to be eliminated.