# QRS Detection Based on Medical Knowledge and Cascades of Moving Average Filters
## 2 Materials and Methods
### Methods
#### 2.2.2 Derivative Filter Selection  
The next step of the algorithm further enhances the QRS complex with respect to the other waves. The QRS complex features a high derivative which involves an interval of about 100 ms. Thus, a derivative transform enhances the prominent characteristic of the QRS complex. However, the degree of enhancement will depend on how the derivative matches the QRS shape. Hence, a specific derivative transform may better enhance the QRS complex in some ECG recordings than others. For this reason, the authors designed a dictionary of 18 different derivative filters. Each filter results from the subtraction between two MACs, involving about 8-30 ms of the signal each and shifted by 8-30 ms. These  
Figure 3: Impulsive response of MAC(0.02, 0.008)–MAC(0.12, 0.024) at a sampling frequency of 250 Hz. derivative filters will be referred to as dMACs. A few examples of such derivative filters (dMACs) are shown in Figure 4.  
These derivative filters are designed to match the rising or falling fronts of the QRS complex. Thus, the output of these filter is highest when the length of the longest (rising or falling) front of the QRS complex matches the main front of the derivative filter's impulsive response. This characteristic makes these filters inherently specific for the target signal, and less susceptible to noise. Since the QRS complexes do not have a perfectly fixed duration and shape in each ECG recording, different shapes of derivative filters may perform better than others in different recordings. The dMAC that better enhances the QRS complexes of a specific record is automatically chosen for each channel in the initialization phase of the algorithm. This choice is performed by maximization of the signal quality index (SQI) defined as  
\[\text{SQI}=\frac{\text{k}_{\text{s}}+\text{mD}_{\text{s}}}{\text{k}_{n}+\text {mD}_{n}} \tag{1}\]  
The SQI  
Figure 5 shows an example of the derivative filters selected with SQI maximization for different records of the MIT-BIH Arrhythmia database. Each row refers to the first channel of a different record: top row refers to record 100, middle row refers to record 200 and the bottom row refers to record 203. Narrow derivative filters are selected to enhance narrow QRS complexes (top row), while wide derivative filters are selected for records that display wider QRS complexes (middle and bottom row). The 15 s interval where the derivative filter is chosen is, ideally, the beginning of the record. However, it is common to find flatlines or transitory interference at the very beginning of an ECG record. For this reason, the selected 15 s interval is identified in the initialization phase of the algorithm using a signal quality index similar to the previous one that includes an additional artifact-specific term. The index is computed for successive intervals of 15 s using a non-specific raw dMAC. In this process, the algorithm looks for an interval of acceptable ECG quality. The duration of the initialization phase, 15 s, is an arbitrary number. It should be high enough to capture at least five m\({}_{\text{s}}\) windows, but low enough to avoid the computational burden of an unnecessarily long SQI maximization phase. Figure 5: (**a**) Three ECG excerpts from the MIT-BIH database. From top to bottom: record 100, 200, 203. (**b**) Absolute derivative resulting from the application of three distinct dMACs, portrayed in (**c**). The dMAC used for each record is chosen with SQI maximization (Equation (I)). 2.2.3. Decision Logic  
The decision logic of the QRS detection algorithm compares a dynamic threshold T with the absolute value of the derivative signal (the feature signal). Figure 6 shows the result of the processing stages described above for a sample ECG excerpt, from input signal to absolute derivative. When the absolute derivative crosses the detection T, a detection is registered. T is first defined in the initialization phase, and then updated in a bounded fashion depending on its initial value, after each successful QRS detection.