# QRS Detection Based on Medical Knowledge and Cascades of Moving Average Filters
## 2 Materials and Methods
### Methods  
ECG signal analysis has often been approached with methods and mindsets pertaining to the field of telecommunications--i.e., frequency characterized signals and linear systems. As a consequence, signal analysis experts who approached ECG signal analysis were trained in that area and therefore applied methods and techniques of the frequency domain to the ECG signal.  
It should be noted that the information of physiological and pathophysiological interest in the ECG signal is concentrated in localized and separable events in time. The P wave is associated with atrial depolarization, the QRS complex with ventricular depolarization and the T wave with ventricular repolarization. On the contrary, in the frequency domain, there is significant overlap of this information and it is not separable. For this reason substantial frequency-based ECG signal analysis is unjustified. There are, however, a few instances of specific frequency components in the ECG like powerline disturbance at 50 or 60 Hz and atrial or ventricular fibrillation.  
Therefore, we designed the signal preprocessing and QRS detection by taking into account the time domain properties of the QRS complex with respect to other events. In addition, to achieve a small processing time, we used combinations of moving average cascades (MACs). A MAC is composed by applying two or more unweighted moving averages in series. When two moving averages of the same length are combined in cascade, the resulting system will exhibit a triangular impulsive response. If two moving averages of different length are combined, the resulting impulsive response will take a trapezoidal shape. As the number of moving averages in cascade increases, the shape of the resulting impulsive response will get smoother, wider, and increasingly similar to the Gaussian bell function. This effect is shown in Figure 1. These cascades of moving averages are equivalent to linear FIR filters. However, we remark that they are designed in time, by taking advantage of the knowledge of the pattern of the target ECG event. Moreover, their application does not require any convolution, which is a time-consuming operation.  
We built two types of linear systems by combining MACs. The first linear system consists in the difference of two centered MACs of different length (Section 2.2.1), which was used to enhance events characterized by mono-directional changes whose time duration is comprised between the lengths of the two MACs. The second linear system (Section 2.2.2) consists in the difference of two time-shifted MACs and was designed to enhance eventswhose ascending or descending fronts' duration is greater than the shift of the two MACs. This second system enhances QRS complexes and has a derivative behavior.  
The proposed QRS detection algorithm is articulated in three steps: noise reduction--i.e., non QRS signal changes; enhancing QRS events with a derivative transform; detecting heartbeats. The absolute value of the derivative transform will also be referred to as the feature signal. Figure 2 shows a diagram of the algorithm. This algorithm does not resample the signal. The filters automatically scale at the sampling frequency of the ECG record that is being processed.