# Investigating Feature Selection and Random Forests for Inter-Patient Heartbeat Classification
## Appendix A Extraction of QRS Temporal Characteristics and Amplitude Differences  
The extraction of features is implemented as follows. The R spike annotations provided with the MIT-BIH Arrhythmia Database are used as a marker to separate and identify the beats. At each beat location, a segment of 640 ms of signal (96 samples) is considered, 373 ms before the annotation (56 samples), and 267 ms (40 samples) after it. The mean of the signal segment is subtracted from each sample in order to remove the baseline. The absolute maximum value of the signal 100 ms before and after the annotation (\(QRSmax\)) is considered as a reference point. Though such value usually correspondsto the database R spike annotation and the peak of the R wave in typical normal heartbeats, this is not always the case because the QRS may have a complex morphology and fall into one of the broad categories of the standard nomenclature where the R wave is not the one with the highest amplitude [39]. Therefore, only if \(QRSmax\) is positive is it immediately marked as the peak of the R wave (\(Repeak\)). Starting from \(QRSmax\), ten fiducial points are identified: the two locations where the signal reaches half the value of \(QRSmax\) (\(QRSmax/2a,b\)), the two locations where the signal reaches a quarter of the value of \(QRSmax\) (\(QRSmax/4a,b\)), the peak value of the R wave (\(Repeak\)), the peak value of the Q wave (\(Qpeak\)), the peak value of the S wave (\(Speak\)), the beginning of the QRS complex (\(QRSstart\)), the end of the QRS complex (\(QRSend\)), and the peak value of the P wave (\(Ppeak\)). Many of the mentioned fiducial points are individuated by looking for the inflection points in the signal and identifying the locations where the signal first derivative changes direction. For this, a two-point numerical differentiation is applied to the signal. The procedure for identifying the fiducial points can be described with the following steps:  
1. Assume that \(Qpeak\), \(Repeak\), \(Speak\), and \(Ppeak\) equal zero and that the corresponding waves are not present. 3. Look backward from \(QRSmax\) and evaluate the signal and its inflection points in this way: 1. Make \(QRSmax/2a\) equal to the first location where the signal goes below half of \(QRSmax\). 2. Make \(QRSmax/4a\) equal to the first location where the signal goes below a quarter of \(QRSmax\). 3. If the first inflection point is negative and \(Repeak\) is not zero, then \(Qpeak\) equals the value at such point. 4. If the first inflection point is positive or zero and \(Repeak\) is not zero, then it is marked as \(QRSstart\), and \(Qpeak\) is considered zero. 5. If the first inflection point is positive and \(Repeak\) is zero, then make \(Repeak\) equal to the value at such point and make \(Speak\) equal to QRS max. 6. If the second inflection point is negative, \(Qpeak\) is zero, and \(QRSmax\) is positive, then make \(Qpeak\) equal to the value at such point. 7. If \(Qpeak\) is not zero and the signal crosses zero, then the first non-negative point is marked as \(QRSstart\). 8. If the second inflection point is positive or zero and \(QRSstart\) has not been found yet, then it is marked as \(QRSstart\). 4. Look forward from \(QRSmax\) and evaluate the signal and its inflection points in this way: 1. Make \(QRSmax/2b\) equal to the first location where the signal goes below half of \(QRSmax\). 2. Make \(QRSmax/4b\) equal to the first location where the signal goes below a quarter of \(QRSmax\). 3. If the first inflection point is negative and \(Repeak\) is not zero, then make \(Speak\) equal to the value at such point. 4. If \(Speak\) is not zero and the signal cross zero, then the first non-negative point is marked as \(QRSend\). 5. If the second inflection point is positive or zero and \(QRSend\) has not been found yet, then it is marked as \(QRSend\). 5. Find the maximum value of the signal in the segment that goes between 233 ms (35 samples) and 67 ms (10 samples) before \(QRSstart\).