## 3 Medical Sensor Applications for Closed Spaces
### Arrhythmia Detection Algorithm  
The goal of this study is to take ECG measurements and detect arrhythmias of subjects who are in motion during a rehabilitation session in an enclosed 100 m \(\times\) 100 m space, which represents the dimensions of typical clinics and rehabilitation centers. The sampling period chosen is based on the signal bandwidth of the electrocardiogram (ECG), which, according to the American Heart Association, has harmonics from 0 to 100 Hz. The most relevant information used to monitor arrhythmias, however, is between 0.5 Hz and 50 Hz. The ECG frequency spectrum can be established with the relevant components of the signal (QRS complex and waves P and T) between 0 and 35 Hz. The Nyquist sampling theorem provides a minimum sampling period (\(T_{s}\)) of about 14 ms. However, for practical purposes, it is necessary to use a sampling period of [\(T_{s}\)/8, \(T_{s}\)/4], so we selected a 3 ms interval. Arrhythmia detection algorithms rely mainly on the detection of the ECG QRS complex. Currently, there are various algorithms that detect this complex. For example, there are algorithms based on neural networks [21], amplitude of first and second derivative algorithms [22], genetic algorithms [23], algorithms that use the wavelet [24], hybrid algorithms [25], bank filter algorithms [26], algorithms based on the correlation of the signal with sample beats [27], and heuristic algorithms based mainly on non-linear transforms [28]. Wireless sensor networks employ nodes that possess limited resources. Consequently, the case study analyzed in this work exclusively considers monitoring ECG signals in real-time conditions. Because of this, it was important to select a QRS detection algorithm that has the necessary sensibility and precision, but most efficiently employs limited resources such as energy, memory and the CPU, without using too many resources. Some algorithms that rely on the Wavelet and Hilbert transform perform well, possessing adequate sensibility and precision, but employ a lot of resources [29]. For this reason, we selected the Pan and Tompkins algorithm because it has relatively simple filters, non-linear transformations and decision methods. Importantly, however, the Pan and Tompkins algorithm is sufficiently precise and possesses adequate sensibility values [30]. This algorithm employs a band pass filter that sets a low pass filter (LPF) and a high pass filter (HPF) to reduce noise, which serves to provide interference against signals outside the frequency band in which the QRS operates. To complement this process, the Pan and Tompkins algorithm has a derivative function that emphasizes the slopes of the R wave. Then, a quadratic function is applied to the resulting signal of the derivative function to further enhance the high frequency characteristics of the QRS complex. Finally, the energy estimate is made with a mobile window size of the longer QRS complex. Figure 1 provides a block diagram of the Pan and Tompkins algorithm with the steps involved in analyzing the ECG signal. Figure 2 shows how the Pan and Tompkins algorithm functions. Initially, an ECG wave with noise is presented. Figure 1: Block diagram of the Pan and Tompkins algorithm. The transfer function low-pass filter is:  
\[H(z)=\frac{(1-z^{-6})^{2}}{(1-z^{-1})^{2}} \tag{1}\]  
The output signal of the LPF is shown in Figure 3.  
The transfer function of high pass filter is:  
\[H_{ip}(z)=\frac{P(z)}{X(z)}=z^{-16}-\frac{H_{ip}(z)}{32} \tag{2}\]  
The output signal of the HPF is shown in Figure 4.  
After the signal is filtered, most of its energy is contained in the QRS complex. Then, the derivative function is applied, high frequencies are accentuated and the low frequencies are attenuated. Therefore, the high slopes are highlighted to generally distinguish the QRS complex within the ECG signal. Figure 4: High pass filtered signal. Figure 3: Low pass filtered signal. Figure 2: ECG vector with noise.