Open Access
This article is

- freely available
- re-usable

*Biosensors*
**2016**,
*6*(4),
55;
https://doi.org/10.3390/bios6040055

Article

TERMA Framework for Biomedical Signal Analysis: An Economic-Inspired Approach

^{1}

Department of Obstetrics & Gynecology, University of British Columbia, Vancouver, BC V6Z 2K5, Canada

^{2}

Department of Electrical and Computer Engineering, University of British Columbia, Vancouver, BC V6T 1Z4, Canada

Academic Editor:
Chung-Chiun Liu

Received: 16 August 2016 / Accepted: 25 October 2016 / Published: 2 November 2016

## Abstract

**:**

Biomedical signals contain features that represent physiological events, and each of these events has peaks. The analysis of biomedical signals for monitoring or diagnosing diseases requires the detection of these peaks, making event detection a crucial step in biomedical signal processing. Many researchers have difficulty detecting these peaks to investigate, interpret and analyze their corresponding events. To date, there is no generic framework that captures these events in a robust, efficient and consistent manner. A new method referred to for the first time as two event-related moving averages (“TERMA”) involves event-related moving averages and detects events in biomedical signals. The TERMA framework is flexible and universal and consists of six independent LEGO building bricks to achieve high accuracy detection of biomedical events. Results recommend that the window sizes for the two moving averages (${W}_{1}$ and ${W}_{2}$) have to follow the inequality $(8\times {W}_{1})\ge {W}_{2}\ge (2\times {W}_{1})$. Moreover, TERMA is a simple yet efficient event detector that is suitable for wearable devices, point-of-care devices, fitness trackers and smart watches, compared to more complex machine learning solutions.

Keywords:

trend-following; lagging indicator; crossover; quasi-periodic signals; eventogram transform; mobile health; global health; internet-of-things devices; wearable sensors; point-of-care devices## 1. Introduction and Motivation

Clinicians use biomedical signals, such as electrocardiogram (ECG), photoplethysmogram (PPG), acceleration photoplethysmogram (APG) and heart sound signals, to screen and diagnose various cardiac abnormalities. Collecting these biomedical signals is relatively easy and inexpensive when compared to invasive alternatives [1]. Therefore, the analysis of biomedical signals has been extensively investigated over the past two decades. Many algorithms using a variety of mathematical formulae have been published to analyze biomedical signals; however, there is no generic methodology with a clear framework that can be used to analyze these signals. Such a generic methodology may provide physicians with greater insights about a patient’s health through non-invasive measures.

A generic framework that has been well established in the field of economics to analyze financial data is the use of two moving averages. A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer term trends or cycles. The use of one moving average is a common analysis tool used by traders to identify trend directions.

Two moving averages have been used together to generate crossover signs [2,3]. A crossover occurs when a faster (shorter) moving average crosses a slower (longer) moving average [2,3], and these crossovers are considered as buy and sell indicators. The use of two moving averages succeeds in detecting the critical events in trading. Looking at the NASDAQ composite index for calendar year 2001, if the closing values are filtered, much of the day-to-day market variations can be removed. For example, with the use of two moving averages—the shorter with a four-day window length and the longer with a 32-day window length—the amount of the remaining variations can be controlled. The moving average with the longer window length works as a threshold to the moving average with the shorter window length and, consequently, presents a crossover as an indicator of a critical event, as shown in Figure 1.

It is common practice in biomedical signal analysis to use the moving average as a filter. It is important to note that the moving average step has not been previously used in the decision making. For example, the moving average used in [4,5,6] was only a filtering step, and it was not used for decision making (thresholding) as it is applied in economics. The implementation of the moving average can be highly numerically efficient (simple, fast, and with fewer calculations required). Therefore, the idea of using two moving averages is promising for analyzing biomedical signals.

Analyzing real-time biomedical signals collected by a battery-driven device needs to be fast and feasible in real time, despite the existing limitations in terms of memory and processor capability. The same holds for the ability to analyze large biomedical signals collected over one or more days. The main goal of this study is to produce a methodology that can be used for detecting different types of events in different types of biomedical signals using two event-related moving averages (TERMA). The window sizes of the moving averages depend on prior knowledge of the expected duration of the event to be detected. In this paper, I will demonstrate and discuss how TERMA can be used to detect events in different research areas related to biomedical signals.

## 2. Methods

#### 2.1. Data Used

In this section, four different biomedical signals are used: ECG, PPG, APG, and heart sounds signals. Each biomedical signal has it is own unique set of features and events. A single ECG heartbeat signal consists of P, QRS, and T waves, a single PPG pulse signal consists of a systolic wave, a single APG heartbeat signal consists of a, b, c, d, and e waves, and a single heart beat signal consists of two waves: S1 and S2. The databases used to detect these events are:

- For QRS detection in ECG signals: Eleven ECG databases are used to evaluate the robustness of the TERMA-based QRS detection algorithm. The 11 representative datasets are published on PhysioNet (https://physionet.org/) and represent different subject groups and recording conditions, such as sampling rates (between 128 Hz and 1 kHz) and interferences. Following is a brief description of the 11 datasets: the MIT-BIH Arrhythmia Database with 109,984 beats [7], the QT Database with 111,301 beats [8], the T Wave Alternans Database with 19,003 beats, selected for its wide range of pathological conditions [9], the Intracardiac Atrial Fibrillation Database with 6705 beats [10], the ST Change Database with 76,181 beats featuring stress ECGs [11], the Supraventricular Arrhythmia Database with 184,744 beats [12], the Atrial Fibrillation Termination Database with 7618 beats [13], the Fantasia Database with 278,996 beats from relaxed healthy subjects [14], the Noise Stress Test Database with 26,370 beats recorded under noise conditions typical of clinical environments [15], the St. Petersburg Institute of Cardiological Technics Arrhythmia Database with 175,918 beats [16] and the Normal Sinus Rhythm Database with 183,092 beats [16]. In the Fantasia Database, one record (‘f2y02’) was corrupted and was therefore excluded. Lead I of every record in these datasets was used without any exclusion. The R peaks in all of these publicly-available datasets were annotated. The training set was the MIT-BIH Arrhythmia Database, while the test set consisted of the other 10 databases.
- For systolic wave detection in PPG signals: One annotated Heat-Stress PPG Database [17] consists of 5071 beats of 40 healthy, heat-acclimatized emergency responders (30 males and 10 females). The PPG data were collected at a sampling rate of 367 Hz, and the duration of each recording was 20 s. The data used in the training set were the PPG signals measured at rest, while the data used in the test set were the PPG signals measured after three simulated heat stress exercises.
- For a, b, c, d and e waves detection in APG signals: One annotated Heat-Stress PPG Database [18] consists of 1469 beats of 27 healthy volunteers (males). The PPG data were collected at a sampling rate of 200 Hz, and the duration of each recording was 20 s. The data used in the training set were the APG signals after 1 h of exercise, while the data used in the test set consisted of the APG signals measured at rest and after 2 h of exercise.
- For S1 and S2 detection in heart sounds: One annotated Heart Sounds Database [19] was used that contains the heart sounds of 22 subjects with and without pulmonary artery hypertension (PAH). The heart sounds were recorded using a 3 M Littmann 3200 digital stethoscope over 20 s with sampling frequencies of 4000 Hz. Heart sounds were recorded sequentially at the second left intercostal space and the cardiac apex for 20 s. The data used in the training set were that of 11 subjects with mean pulmonary arterial pressure (PAP) $\ge 25$ mmHg collected from the apex site, while the data used in the test set were that of 11 subjects with mean PAP $<25$ mmHg collected from the apex site, 11 subjects with mean PAP $\ge 25$ mmHg collected from the second left intercostal space (2 L) site and 11 subjects with mean PAP $<25$ mmHg collected from the 2 L site.

#### 2.2. TERMA Framework

In this section, a new, knowledge-based, numerically-efficient and robust method is proposed to detect main events in biomedical signals using the TERMA algorithm. The structure of the TERMA algorithm is shown in Figure 2.

It is clear that prior knowledge of TERMA parameters supports the decision making in both stages, generating blocks of interest and thresholding. The more precise the prior knowledge is, the higher the overall performance and detection accuracy. The pseudocode of the TERMA detector is shown in Figure 3.

#### 2.2.1. Prior Knowledge

TERMA prior knowledge about the duration of the main events of the biomedical signals can assist in feature extraction and, thus, support the decision making of the algorithm. Four parameters are required as prior knowledge: the frequency band (${F}_{1}$–${F}_{2}$), event-related durations ${W}_{1}$ and ${W}_{2}$ and the offset fraction (β). Usually, the TERMA prior knowledge for these parameters is not reported in the literature.

In the literature, this needed prior knowledge (TERMA parameter values) of all biological events has not been reported yet. Therefore, it is recommended to take a subset of the data to determine the duration of the main events via an optimization step. In other words, the output of the optimization step will be used as prior knowledge for the rest of the dataset.

The optimization step has five decision variables: ${F}_{1}$, ${F}_{2}$, ${W}_{1}$, ${W}_{2}$ and β. The improvement in one objective will result in the worsening of at least one other objective, generating Pareto solutions [20]. Any change in these parameters affects the overall performance of the proposed algorithm. The five decision variables are interrelated and cannot be optimized in isolation. Our goal is to find the Pareto optimal point, within all possible Pareto solutions, for this multi-objective problem. An aggregate objective function denoted by J to combine two objective functions into a scalar function is defined as follows:
where J is the overall accuracy, which is defined as the average of sensitivity ($\mathrm{SE}$) and positive predictivity ($+\mathrm{P}$). $\mathrm{SE}$ and $+\mathrm{P}$ are the two objective functions to be maximized jointly. The Pareto frontier is formed with solutions (the values of five decision variables) which optimise them both. Finding the optimal Pareto point goes through a brute-force search over all parameters, which is time consuming, but once achieved, the optimal solution will be used as is for the implementation.

$$\begin{array}{cc}& \underset{{F}_{1},{F}_{2},{W}_{1},{W}_{2},\beta}{\mathrm{max}}\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}J=\frac{1}{2}\{\left[\mathbf{SE}({F}_{1},{F}_{2},{W}_{1},{W}_{2},\beta )\right]+\left[+\mathbf{P}({F}_{1},{F}_{2},{W}_{1},{W}_{2},\beta )\right]\}\hfill \\ \mathrm{subject}\phantom{\rule{4.pt}{0ex}}\mathrm{to}\hfill & \\ & {f}_{1min}\le {F}_{1}\le {{f}_{1}}_{max}\phantom{\rule{4pt}{0ex}},\hfill \\ & {f}_{2min}\le {F}_{2}\le {{f}_{2}}_{max}\phantom{\rule{4pt}{0ex}},\hfill \\ & {w}_{1min}\le {W}_{1}\le {{w}_{1}}_{max}\phantom{\rule{4pt}{0ex}},\hfill \\ & {w}_{2min}\le {W}_{2}\le {{w}_{2}}_{max}\phantom{\rule{4pt}{0ex}},\hfill \\ & {b}_{min}\le \beta \le {b}_{max}\phantom{\rule{4pt}{0ex}},\hfill \end{array}$$

#### 2.2.2. Band-Pass Filter

Morphologies of normal and abnormal events in biosignals differ widely. Biosignals are often corrupted by noise from many sources; therefore, band-pass filtering is an essential first step for nearly all event detection algorithms. The purpose of band-pass filtering is to remove the baseline wander and high frequencies that do not contribute to detecting these events. A band-pass filter is typically used as a bidirectional Butterworth implementation [21]. It offers good transition band characteristics at low coefficient orders, which makes it efficient to implement [21]. All research was carried out using the TERMA method, a third-order Butterworth filter with a passband of ${F}_{1}$–${F}_{2}$ Hz to remove baseline wander and high frequencies [17,19,22,23,24,25], where ${F}_{1}$ is the starting frequency and ${F}_{2}$ is the stopping frequency, as shown in Line 3 in Figure 3.

#### 2.2.3. Enhancing

The signal is squared point by point to enhance large values and boost high-frequency components using the following equation:
as shown in Line 4 in Figure 3.

$$y\left[n\right]={\left(x\left[n\right]\right)}^{2}$$

#### 2.2.4. Generating Blocks of Interest

Blocks of interest are generated using two event-related moving averages. The first moving average ${\mathrm{MA}}_{\mathrm{event}}$ is used to extract a specific event (within a cycle), while the second moving average ${\mathrm{MA}}_{\mathrm{cycle}}$ extracts the cycle (regularly-repeating events). Next, an event-related threshold is applied to the generated blocks to distinguish the blocks that contain the event peaks from the blocks that include noise. The purpose of the event moving average (${\mathrm{MA}}_{\mathrm{event}}$) is to smooth out multiple peaks corresponding to the event length to emphasize and extract the event area:
where ${W}_{1}$ is the approximate duration of a specific event, rounded to the nearest odd integer, and n is the number of data points. The value of ${W}_{1}$ is determined based on the prior knowledge discussed above.

$$\begin{array}{c}\hfill {\mathrm{MA}}_{\mathrm{event}}\left[n\right]=\frac{1}{{W}_{1}}(y[n-({W}_{1}-1)/2]+\cdots \\ \hfill +y\left[n\right]+\cdots +y[n+({W}_{1}-1)/2])\end{array}$$

The purpose of the cycle moving average (${\mathrm{MA}}_{\mathrm{cycle}}$) is similar to that of the ${\mathrm{MA}}_{\mathrm{event}}$, but emphasizes the cycle area that contains the event of interest to be used as a threshold for the first moving average (${\mathrm{MA}}_{\mathrm{event}}$):
where ${W}_{2}$ is the approximate duration of a cycle (or heartbeat), rounded to the nearest odd integer, and n is the number of data points. The value of ${W}_{1}$ is determined based on the prior knowledge discussed above.

$$\begin{array}{c}\hfill {\mathrm{MA}}_{\mathrm{cycle}}\left[n\right]=\frac{1}{{W}_{2}}(y[n-({W}_{2}-1)/2]+\cdots \\ \hfill +y\left[n\right]+\cdots +y[n+({W}_{2}-1)/2])\end{array}$$

The blocks of interest are generated based on the two moving averages discussed. In other words, applying the second moving average ${\mathrm{MA}}_{\mathrm{cycle}}$ as a threshold to the first moving average ${\mathrm{MA}}_{\mathrm{event}}$ produces blocks of interest, as shown in Figure 4. However, the use of ${\mathrm{MA}}_{\mathrm{cycle}}$ without an added offset reduces the detection accuracy because of its sensitivity to a low signal-to-noise ratio (SNR).

Here, the SNR is defined as the ratio of the mean signal of a region of interest to its standard deviation [26], which means if the statistical mean of the signal increases, the SNR increases. This leads to introducing an offset based on the statistical mean of the signal as:
where β is the fraction of the $\overline{z}$ signal that needs to be removed, $\overline{z}$ is the statistical mean of the squared ECG signal z and α is an offset for the threshold ${\mathrm{MA}}_{\mathrm{cycle}}$ signal. Therefore, α refers to the offset, while β refers to the offset fraction.

$$\alpha =\beta \times \overline{z}$$

In short, to increase the accuracy of detecting events in noisy biosignals, the dynamic threshold value ${\mathrm{THR}}_{1}$ is calculated by offsetting the ${\mathrm{MA}}_{\mathrm{cycle}}$ signal with α, as follows:

$${\mathrm{THR}}_{1}={\mathrm{MA}}_{\mathrm{cycle}}\left[n\right]+\alpha $$

The blocks of interest are then generated by comparing the ${\mathrm{MA}}_{\mathrm{event}}$ signal with ${\mathrm{THR}}_{1}$. If a block is higher than ${\mathrm{THR}}_{1}$, it is classified as a block of interest containing biosignal features (different events) and noise, as shown in Lines 10–16 in Figure 3. By this stage, the blocks of interest are generated and stored in $Blocks\left[n\right]$ as a square pulse (ones and zeros). Therefore, the next step is to reject the blocks that result from noise. The rejection should be related to the anticipated block width.

#### 2.2.5. Thresholding

Here, blocks containing undesired (or out of interest) events and noise are rejected using the new ${\mathrm{THR}}_{2}$ threshold. By applying the ${\mathrm{THR}}_{2}$ threshold, the accepted blocks contain only the required events:

$${\mathrm{THR}}_{2}={W}_{1}$$

As discussed, the threshold ${\mathrm{THR}}_{2}$ equals ${W}_{1}$, which corresponds to the anticipated event width. If the block width equals the window size ${W}_{1}$, then the block contains an event. However, the event duration varies in terms of the durations of the abnormal events within the processed signal. Therefore, the condition is set to capture both normal and abnormal event durations. Therefore, if a block width is greater than or equal to ${W}_{1}$, it is classified as an event. If not, the block is classified as an undesired event or noise.

#### 2.2.6. Detecting Event Peak

The last stage is finding the maximum absolute value within each block or the event peak.

## 3. Results

The event detection algorithm is typically run using two statistical measures: $\mathrm{SE}$ and $+\mathrm{P}$, where $\mathrm{SE}=\mathrm{TP}/(\mathrm{TP}+\mathrm{FN})$ and $+\mathrm{P}=\mathrm{TP}/(\mathrm{TP}+\mathrm{FP})$. Here, TP is the number of true positives (events detected as events), FN is the number of false negatives (events that have not been detected as events) and FP is the number of false positives (non-events detected as events). The SE reports the percentage of true events that were correctly detected by the algorithm. The +P reports the percentage of event detections that were true events.

#### 3.1. Training Results

The training dataset for each detection problem is discussed in the Data Used subsection. A rigorous optimization using a brute-force search over all parameters is conducted as follows.

- For QRS detection in ECG signals: The optimization of the beat detector’s spectral window for lower frequency varied from ${{f}_{1}}_{min}={{f}_{2}}_{min}=1$ Hz to ${{f}_{1}}_{max}=10$ Hz, with the higher frequency up to ${{f}_{2}}_{max}=26$ Hz. All combinations of the frequency band were 1–26 Hz. The window size of the ${W}_{1}$ ranged from ${{w}_{1}}_{min}=55$ ms to ${{w}_{1}}_{max}=111$ ms, whereas the window size of ${W}_{2}$ changed from ${{w}_{2}}_{min}=555$ ms to ${{w}_{2}}_{max}=694$ ms. However, the offset β was tested over the range ${b}_{min}=0\%$ to ${b}_{max}=10\%$.
- For T wave detection in ECG signals: All combinations of the frequency band ranged from ${{f}_{1}}_{min}={{f}_{2}}_{min}=0$ Hz to ${{f}_{1}}_{max}={{f}_{2}}_{max}=10$ Hz. The window size of the ${W}_{1}$ ranged from ${{w}_{1}}_{min}=40$ ms to ${{w}_{1}}_{max}=80$ ms, whereas the window size of ${W}_{2}$ changed from ${{w}_{2}}_{min}=100$ ms to ${{w}_{2}}_{max}=200$ ms. However, the offset β was tested over the range ${b}_{min}=0\%$ to ${b}_{max}=10\%$.
- For systolic wave detection in PPG signals: The lower frequency resulted in a value from ${f}_{1min}=0.5$ Hz to ${{f}_{1}}_{max}=1$ Hz, while the higher frequency resulted in a value from ${f}_{2min}=7$ Hz to ${{f}_{2}}_{max}=15$ Hz. The window size of ${W}_{1}$ varied from ${{w}_{1}}_{min}=54$ ms to ${{w}_{1}}_{max}=111$ ms, whereas the window size of ${W}_{2}$ varied from ${{w}_{2}}_{min}=545$ ms to ${{w}_{2}}_{max}=694$ ms. The offset β was tested over the range ${b}_{min}=0\%$ to ${b}_{max}=10\%$.
- For a and b wave detection in APG signals: The lower frequency resulted in a value from ${f}_{1min}=0.5$ Hz to ${{f}_{1}}_{max}=1$ Hz, while the higher frequency resulted in a value from ${f}_{2min}=7$ Hz to ${{f}_{2}}_{max}=15$ Hz. The window size of ${W}_{1}$ varied from ${{w}_{1}}_{min}=100$ ms to ${{w}_{1}}_{max}=200$ ms, whereas the window size of ${W}_{2}$ varied from ${{w}_{2}}_{min}=1000$ ms to ${{w}_{2}}_{max}=1250$ ms. The offset β was tested over the range ${b}_{min}=0\%$ to ${b}_{max}=10\%$.
- For c, d and e wave detection in APG signals: The lower frequency varied from ${{f}_{1}}_{min}=0.5$ Hz, while the higher frequency varied from ${f}_{2min}=4$ Hz to ${{f}_{2}}_{max}=10$ Hz. The window size of ${W}_{1}$ varied from ${{w}_{1}}_{min}=5$ ms to ${{w}_{1}}_{max}=25$ ms, whereas the window size of ${W}_{2}$ varied from ${{w}_{2}}_{min}=10$ ms to ${{w}_{2}}_{max}=15$ ms, while the range of β varied from ${b}_{min}=0\%$ to ${b}_{max}=10\%$.
- For S1 and S2 detection in heart sounds: The frequency band was optimized over from ${f}_{1min}={{f}_{2}}_{min}=0$ Hz to ${{f}_{1}}_{max}={{f}_{2}}_{max}=2000$ Hz; ${W}_{1}$ varied from ${{w}_{1}}_{min}=20$ ms to ${{w}_{1}}_{max}=200$ ms; ${W}_{2}$ varied from ${{w}_{2}}_{min}=30$ ms to ${{w}_{2}}_{max}=400$ ms; and β varied from ${b}_{min}=0\%$ to ${b}_{max}=10\%$.

The databases used in the optimization process contains abnormal rhythms, different event morphologies, heat stress signals and low SNR signals. Several publications have listed the use of all files in the database, excluding the paced patients, segments and certain beats [27]. However, in the optimization process, all records were used without excluding any segment or beat.

As we have multiple objectives, plotting the Pareto frontier (the objective space of possible Pareto solutions) cannot be achieved. Therefore, all Pareto solutions were sorted in descending order according to the overall accuracy (objective function J) [17,19,22,23,24,25]; and thus, the first combination is considered the optimal Pareto solution.

After applying the multi-objective optimization step, the optimal Pareto solution for QRS detection in ECG signals was ${F}_{1}=8$ Hz, ${F}_{2}=20$ Hz, ${W}_{1}=97$ ms, ${W}_{2}=611$ ms and $\beta =8\%$, while for T wave detection in ECG signals, the optimal solution was ${F}_{1}=0.5$ Hz, ${F}_{2}=10$ Hz, ${W}_{1}=70$ ms, ${W}_{2}=140$ ms and $\beta =0\%$. To detect the systolic waves in PPG signals, the optimal solution was found to be ${F}_{1}=0.5$ Hz, ${F}_{2}=8$ Hz, ${W}_{1}=111$ ms, ${W}_{2}=667$ ms and $\beta =2\%$. Moreover, the optimal solution for detecting a and b waves was ${F}_{1}=0.5$ Hz, ${F}_{2}=15$ Hz, ${W}_{1}=175$ ms, ${W}_{2}=1000$ ms and $\beta =0\%$, while the optimal solution for detecting c, d and e waves was found to be ${F}_{1}=0.5$ Hz, ${F}_{2}=7$ Hz, ${W}_{1}=5$ ms, ${W}_{2}=15$ ms and $\beta =0\%$. For detecting S1 and S2 in heart sounds, the optimal solution was found to be ${F}_{1}=0$ Hz, ${F}_{2}=60$ Hz, ${W}_{1}=130$ ms, ${W}_{2}=270$ ms and $\beta =3\%$.

#### 3.2. Testing Results

An optimal event detector is obtained from the training phase. We can then test each detector on its testing dataset ‘straight out of the box’ without any tuning. In other words, the algorithm’s parameters (${F}_{1}$, ${F}_{2}$, ${W}_{1}$, ${W}_{2}$ and β) do not need to be trained in a real-world application for every subject. The parameters are optimized on a large training set; thus, the robustness of the algorithm can be examined against different databases with different sampling frequencies, and the biosignals can be collected by different doctors in dissimilar conditions.

The performance of the TERMA-based detection algorithm on the testing datasets can be summarized as follows.

- For QRS detection in ECG signals: Interestingly, the TERMA-based QRS detector obtained an SE of 99.29% and a +P of 98.11% over the first lead of the validation databases (10 databases with a total of 1,179,812 beats). When applied to the well-known MIT-BIH Arrhythmia Database, an SE of 99.78% and a +P of 99.87% were attained [22]. The TERMA-based QRS detector outperformed most of the well-known QRS detector, such as Pan–Tompkins [4] (SE of 90.95% and +P of 99.56%) and Hamilton–Tompkins [28] (SE of 99.69% and +P of 99.77%).
- For T wave detection in ECG signals: Over the MIT-BIH Arrhythmia Database, the TERMA-based T wave detector achieved an SE of 99.86% and a +P of 99.65%, which are promising results for handling the non-stationary effects, low SNR, normal sinus rhythm (NSR), left bundle branch block (LBBB), right bundle branch block (RBBB), premature ventricular contraction (PVC) and premature atrial contraction (PAC) in ECG signals [25]. The TERMA-based T wave detector was not compared to other algorithms as the annotation of T-waves was published in 2015. However, the results are very promising, as the scored accuracy over arrhythmic ECG signals is $>99.6\%$.
- For systolic wave detection in PPG signals: The TERMA-based systolic wave detection algorithm was evaluated using 40 records after three heat stress simulations containing 5071 heartbeats, with an overall SE of 99.89% and +P of 99.84% [17]. The TERMA-based systolic detector slightly outperformed existing algorithms, such as Billauer’s [29] (SE of 99.88% and +P of 98.69%), Li’s [30] (SE of 97.9% and +P of 99.93%) and Zong’s [31] (SE of 99.69% and +P of 99.71%).
- For a and b wave detection in APG signals: The TERMA-based a wave detection algorithm demonstrated an overall SE of 99.78% and a +P of 100% over signals that suffer from: (1) non-stationary effects; (2) irregular heartbeats; and (3) low amplitude waves. In addition, the b detection algorithm (based on the detection of a waves) achieved an overall SE of 99.78% and +P of 99.95% [24]. The TERMA-based a and b waves detector was not compared to other algorithms, as it is a new area of investigation and is considered a pioneering concept in the field of PPG signal analysis. However, the results are very promising as the scored accuracy over heat-stressed PPG signals is >98%.
- For c, d and e wave detection in APG signals: The performance of the TERMA-based c, d and e wave detector was tested on 27 PPG records collected during rest and after 2 h of exercise, resulting in 97.39% SE and 99.82% +P [23]. The TERMA-based c, d and e waves detector was not compared to other algorithms, as it is a new area of investigation, and the work is a pioneering concept in the field of PPG signal analysis. However, the results are very promising, as the scored accuracy over heat-stressed PPG signals is >97%.
- For S1 and S2 detection in heart sounds: The SE and +P of the TERMA-based S1 and S2 detectors were 70% and 68%, respectively, for heart sounds collected from children with PAH [19]. The TERMA-based heart sounds detector outperformed existing algorithms, such as Liang’s [32] (SE of 59% and +P of 42%), Kumar’s [33] (SE of 19% and +P of 12%), Wang’s [34] (SE of 50% and +P of 45%) and Zhong [35] (SE of 43% and +P of 53%).

Given the simplicity and that the memory and CPU power are not a huge concern nowadays, the proposed TERMA-based algorithm presents a clear advantage over the previously-reported algorithms in terms of detection performance over large datasets and different application problems.

## 4. Discussion

Application of the TERMA-based detectors has been demonstrated in the above section. It is now necessary to further elaborate on the implementation of TERMA-based detectors. It is worth noting that TERMA is simple and clearly laid out in comparison to other detectors published in the literature. For example, well-known algorithms demand more implementation steps [27] and resampling of the biosignals before processing; for example, the Pan–Tompkins algorithm [4] requires a resampling step for any ECG signal not sampled at 200 Hz. Its filters are designed for 200 Hz, so performance will be degraded at other sampling frequencies.

Furthermore, TERMA-based detectors are amplitude-independent, while well-known detectors, such as the Pan–Tompkins algorithm, are amplitude-dependent. Moreover, TERMA-based detectors use an efficient dynamic thresholding, while algorithms, such as the Pan–Tompkins algorithm, have a complicated thresholding step to adjust the threshold. The TERMA-based algorithm does not need to change its threshold based on previous segments.

#### 4.1. Frequency Band Choice

In the literature, most of the researchers developed detection algorithms and determined the frequency bands experimentally without justifying their choice. For example, researchers used 5–15 Hz [36], 5–11 Hz [4,5], 4–13.5 Hz [37], 4.1–33.1 Hz [38], 9–30 Hz [39] and 2.2–33.3 Hz [40] as the optimal frequency band to detect QRS complexes in ECG signals. However, the proposed TERMA method extracts the optimal frequency band during the training stage through a rigorous brute force optimization, which is 8–20 Hz in this case, as discussed above.

The choice of frequency band plays a major role in reducing the amount of noise in the processed signals. However, determining a reasonable estimate for the frequency band can be easily carried out on a part of the sample size using the power spectrum of the investigated event [4], which is a relatively easier step compared to determining the window sizes in the TERMA method.

The band-pass filter consists of two filters, the low-pass filter and the high-pass filter. The low-pass filter is used to remove high frequency noise, and the high-pass filter is used to remove low frequency noise. Usually, a Butterworth filter is used due to its simplicity and is characterized by a magnitude response that is maximally flat in the passband and is monotonic overall. MATLAB provides low-pass and high-pass filters with the simple command $butter(m,f{,}^{\prime}lo{w}^{\prime})$ and $butter(m,f{,}^{\prime}hig{h}^{\prime})$, respectively, where m is the filter order and f is the normalized cut-off frequency. The purpose of this step is to retain the characteristics of the main events within the processed signal, remove the undesired noise and make the main events more salient.

#### 4.2. Window Size Choice

After the noise removal achieved in the previous step, the window sizes of TERMA need to be determined. The two window sizes reflect the event duration and the event repetition period (cyclic duration), which is an individual characteristic that depends on the heart rate and abnormalities and, thus, is hard to predict. It is common that researchers determine the window size of a moving average without a proper justification or reasoning; for example, Pan and Tompkins [4] used one moving average to demarcate the QRS complexes in ECG signals with a window size of 150 ms. However, the proposed TERMA method overcomes the unjustified window sizes and offers two event-related window sizes for the two moving averages. Therefore, the TERMA window sizes depend on the expected duration of the investigated event and repetition period of this event. These window sizes can be adjusted via a predefined dataset or can be optimized over a representative sample during the training phase, as discussed above.

In the TERMA method, the use of two moving averages does not always generate blocks of interest. When the two moving averages are able to generate blocks of interest, this is referred to as “coupled” moving averages. To understand and generalize the coupling process between the two moving averages in TERMA, the ${W}_{2}/{W}_{1}$ ratio needs to be examined. The coupling between the window sizes of the moving averages over different biomedical signals is investigated, as shown in Figure 5.

To assess the coupling between window sizes, the performance of the created TERMA detectors based on the generated blocks of interest is explored. The performance of TERMA detectors in terms of overall accuracy in detecting a particular event is split into two categories: coupling and non-coupling. The coupling category is when the two moving averages were able to generate blocks of interest and achieved an accuracy >50%, while the non-coupling category is when the two moving averages were unable to generate blocks of interest and achieved an accuracy that is not-a-number ($\mathrm{NaN}$).

Figure 5 demonstrates the effectiveness of the coupling process. For QRS detection in ECG signals, the most dominant ratio that is able to generate blocks of interest is ${W}_{2}/{W}_{1}=6$, as shown in Figure 5A. If there is a rough idea about the expected event duration of the QRS complex, the value of ${W}_{1}$ can be set to be equal to the expected QRS duration and setting the value of ${W}_{2}$ at six-times that of ${W}_{1}$. However, if the value of ${W}_{2}$ is set to be 10-times that of ${W}_{1}$, there will be no coupling, as shown in Figure 5B, and TERMA fails to detect any event. Interestingly, the same ratio (${W}_{2}/{W}_{1}=6$) is the optimal ratio for detecting the systolic and a waves in APG signals, as shown in Figure 5C,E, but TERMA did not fail over the investigated ratios during the training phase, as shown in Figure 5D,F. In the case of detecting $c,d,$ and e waves, the optimal coupling ratio is (${W}_{2}/{W}_{1}=3$), as shown in Figure 5G, while the most non-coupling ratio is (${W}_{2}/{W}_{1}=2$), as shown Figure 5H. To detect the heart sounds, the optimal coupling ratio is (${W}_{2}/{W}_{1}=2$), as shown Figure 5I, while the non-coupling ratio is (${W}_{2}/{W}_{1}=1.5$), as shown Figure 5J. These results show that the optimal coupling for TERMA can be achieved using the following inequality:
where the lower bound is $(2\times {W}_{1})$ and the higher bound is $(8\times {W}_{1})$.

$$(8\times {W}_{1})\ge {W}_{2}\ge (2\times {W}_{1})$$

As can be seen in Figure 5, if the ${W}_{2}$ is not well defined with respect to ${W}_{1}$, the detector fails to detect any events. The TERMA testing results, discussed above, are promising for handling the non-stationary effects, low SNR, left bundle branch block, right bundle branch block, premature ventricular contraction, premature atrial and fast heart rate over different biomedical signals. As it is a new concept, there is a need to publish the current results and let the scientific community evaluate its performance on their studies with different types of noise and abnormalities.

#### 4.3. Offset β Choice

The offsetting step has been used in the literature as the last stage for most of the event detection algorithms [41,42,43,44,45,46,47]. The performance of the offsetting approach will be affected by low SNR signals [4,48]. Usually, the offset is a fixed value and is experimentally defined [4,41,49,50]. The offsets of these algorithms have been selected based on estimations, which in turn had an impact on the algorithms’ performance. Because the offsetting approach is simple (just an IF-THEN-ELSE statement), researchers used it as a computationally-efficient approach to improve accuracy [4,41,49,50]. The use of a fixed offset to detect a particular event is efficient for stationary biomedical signals with normal beat morphology. Due to severe baseline drifting and the movement of patients, the waveforms of the collected biomedical signal may vary drastically from one heartbeat to the next. Therefore, the probability of missing events is high.

In this work, the offsetting idea is adopted, but implemented differently. The TERMA-based detector uses a signal-dependent offset and not a fixed threshold that is optimized during the training phase. With signal-dependent offsetting (as a percentage of the signal amplitude), the probability of missing events, such as QRS complexes, decreases. It is worth mentioning that in the proposed TERMA method, the offset is applied to the moving average signal and not the original signal, as is usually applied in the literature. The main purpose of the offset in the TERMA method is to reduce the number of generated blocks after applying the two moving averages.

The TERMA offset will slightly shift the output of the second moving average up with the longer window size when applied as a threshold to the first moving average with the smaller window size. The use of a fixed offset to detect particular events, such as QRS complexes, is simple and efficient for stationary ECG signals with normal beat morphology. Due to severe baseline drifting and the movement of patients, an ECG signal waveform may vary drastically from one heartbeat to the next. Therefore, the probability of missing QRS complex is high. With signal-dependent offsetting (as a percentage of the signal amplitude), the probability of missing events, such as QRS complexes, decreases.

To assess the impact of the offset on the coupling process, the performance of TERMA detectors is assessed in terms of overall accuracy (>50% and $=\mathrm{NaN}$). Interestingly, the offsetting does not affect the coupling process, as shown Figure 6A,C,E. In other words, the change in β does not affect the generation of blocks of interest, but rather improves the overall detection accuracy, especially when the processed signal is relatively noisy. Moreover, the offsetting step in the case of detecting systolic and a waves did not cause even one non-coupling case, as shown in Figure 6B,D. In the case of detecting heart sounds, the β values had slightly influenced the generation of blocks of interest, as shown in Figure 6G,H.

#### 4.4. Battery-Driven Devices

Simplicity is particularly effective when it comes to mobile and battery-driven device computation. Simple analysis methods that achieve high event detection accuracy require less storage and power and are more suitable for battery-driven devices [22,27,51]. It is important to mention that simplicity cannot be achieved unless reliability is also achieved. Simplicity goes hand-in-hand with reliability and must be established in conjunction with simplicity [51].

A simple, yet efficient, event detector is needed to provide a more accurate analysis for wearable devices, point-of-care devices, fitness trackers and smart watches, especially when performance is compared to more complex machine learning solutions [52,53]. Event detection algorithms have been published in the literature [22,27] and compared based on numerical efficiency. It was concluded that the better the numerical efficiency, the faster the algorithm, and vice versa. In other words, the faster the algorithm, the more suitable it is for battery-driven devices.

In the conclusion of [27], the researchers recommended implementing moving averages for batter-driven devices, as they are highly numerically efficient. The implementation of one moving average to detect for simplicity has been discussed in [54,55]. However, the thresholding phase of these one moving average algorithms was complicated and increased the computational complexity [27]. On the other hand the TERMA detector was more efficient and faster than the one moving average algorithms [22].

It is intuitive to think that the use of one moving average is better than using two moving averages, especially for implementation on batter-driven devices. The problem with this approach is the decision making steps required to detect the event. For example, the one moving average-based algorithm utilizes a fixed window size that is determined empirically, and thresholds depend on the accuracy of the heart rate determined in the previous segment [4,22]. However, the TERMA detector does not need to work with a fixed window size; in fact, TERMA processes the whole recording at once. Moreover, TERMA does not need to check the past segments or the previous detection rate [22]. TERMA is advantageous because it uses the second moving average as a threshold to the first moving average, without the need for any complicated thresholding. Therefore, TERMA is promising for a battery-driven device compared to other algorithms.

#### 4.5. Optimization Step

Note, the optimization step is time consuming and is not computationally efficient. Perhaps, the calculations of the optimization step can take a place with the use of high-performance computers. However, the implementation of the optimization step is essential and needs to be carried only one time to find the optimal Pareto solution. Once the optimal solution is determined, the TERMA algorithm sets the optimal value as the fixed value for each parameter, and this can be implemented on battery-driven devices with low computation power. Notably, machine learning algorithms usually require high computation for both the optimization step and the algorithm implementation step on battery-driven devices, which can pose a challenge.

The TERMA prior knowledge step is important to practically understand the expected characteristics of the events and noise within the signal. During the optimization, the relationship between the processed signal, added noise, existing events and TERMA parameters is considered. In the test phase, the optimal combination of parameters obtained from the optimization step will be used without any further adjustments. It is important to include a wide variety of waveform and noise to obtain the optimal combination that suits most cases.

#### 4.6. Significance of TERMA

We saw how TERMA-based detectors succeeded in detecting events, such as QRS, T, systolic, a, b, c, d, e, S1 and S2 in different biomedical signals. These biomedical signals were collected using different biosensors with different sampling frequencies in noisy environments. The databases used in the evaluation of TERMA contain signals suffering from: (1) non-stationary effects; (2) low SNR; (3) PACs; (4) PVCs; (5) LBBBs; (6) RBBBs; (7) PAH; (8) heat stress. Based on a review of the current literature, TERMA is the only framework that can be applied to different applications with great success.

The TERMA framework is not only reliable, but also numerically efficient and intuitive. It is easy to track the detection rate and improve accuracy by adjusting five variables. As discussed above the window sizes (${W}_{1}$ and ${W}_{2}$) play a major role in detecting main events in biomedical signals. In other words, setting the values of ${W}_{1}$ and ${W}_{2}$ will enable fast analysis of the process. Adjusting the windows sizes provides detailed information of the dominant events in terms of morphology and duration.

Results from this paper lend more insight into implementing the block of interest generation step, by defining the relative values between ${W}_{1}$ and ${W}_{2}$ to be $[(8\times {W}_{1})\ge {W}_{2}\ge (2\times {W}_{1})]$. These boundaries can be referred to as the “TERMA rate”; it is defining the limits of the lower boundary and higher boundary of successful coupling between two moving averages ($[(8\times {W}_{1})\ge {W}_{2}\ge (2\times {W}_{1})]$). This is similar to finding the boundaries for signal sampling (Nyquist rate [${f}_{s}$ > 2${f}_{max}$]). To clarify the analogy, if we sample a signal at, or above, the Nyquist rate, we can reconstruct the signal. Similarly with the TERMA rate, if the second window size is larger than double the first window size and less than the octuple of the first window size, we can generate blocks of interest and detect main events. Moreover, the TERMA rate can be used to improve the recently-published visualization tool that depends on two moving averages in generating blocks of interest, which is called the eventogram [53].

TERMA framework significance comes from its generic nature for the detection of patterns in any quasi-periodic signal. TERMA framework consists of six independent steps, which can be viewed as LEGO building bricks, and each one of these steps can be modified independently based on the detection problem. Note, the term “LEGO building bricks” is used instead of “LEGO building blocks” because the word “blocks” was used for generating blocks of interest, and it may confuse the reader if “blocks” were used for two different concepts. Thus, TERMA is flexible, universal and can be applied to any periodic or quasi-periodic signals for achieving high accuracy in detecting dominant events within the processed signal. In other words, TERMA is a generic framework that enables researchers to change the filter type, filter order and moving average type based on their application.

Exploring these findings across different types of periodic and quasi-periodic signals that have similar morphologies and characteristics, as in the discussed biomedical signals in this paper, such as the climatic time series [56] (looks like noisy ECG signals), the plant electrical signal [57] (looks like PPG signals), the optical signal [58] (looks like PPG signals), the geophysical signal [59] (looks like the NASDAQ Stock Market signal), the astrophysical signal [60] (looks like noisy ECG signals), the geophysics signal [61] (looks like a noisy heart sounds) and the acoustic and vibration signal [62] (looks like noisy heart sounds), will improve the generalization across the entire signal analysis discipline.

## 5. Conclusions

Event detection in biomedical signals is an important step before analyzing the corresponding waveform in more detail. A new economics-inspired approach for detecting events in biomedical signals is presented. The new algorithm is referred to as TERMA, and its functionality depends mainly on two moving averages similar to those used in economics to examine gross domestic product, employment or other macroeconomic time series. The existence of prior knowledge about the examined waveforms within the biomedical signals will facilitate the adjustment of the window sizes of the two moving averages. Applying the optimization step provides the optimal values of the TERMA, which is recommended for higher detection accuracy. Once the optimal values of TERMA are determined, there is no further tuning needed. Consequently, the validation of the same detector using another dataset without any later parameter tuning can help to obtain more reliable performance results. The performance of the TERMA-based detector is promising. It has been tested on different databases that contain unusual noise and different waveform morphologies. In the literature, it is common to find several algorithms to detect a particular event in a particular biomedical signal. The power of the TERMA-based detector is that it is a generic framework that can be applied to detect different types of events in different biomedical and quasi-periodic signals.

## Acknowledgments

Mohamed Elgendi is grateful for the support from Mining for Miracles, BC Children’s Hospital Foundation and Women’s Health Research Centre of British Columbia, Vancouver, British Columbia, Canada.

## Conflicts of Interest

The author declares no conflict of interest.

## References

- Dilaveris, P.E.; Gialafos, E.J.; Sideris, S.K.; Theopistou, A.M.; Andrikopoulos, G.K.; Kyriakidis, M.; Gialafos, J.E.; Toutouzas, P.K. Simple electrocardiographic markers for the prediction of paroxysmal idiopathic atrial fibrillation. Am. Heart J.
**1998**, 135, 733–738. [Google Scholar] [CrossRef] - Lukac, L.P.; Brorsen, B.W.; Irwin, S.H. A test of futures market disequilibrium using twelve different technical trading systems. Appl. Econ.
**1988**, 20, 623–639. [Google Scholar] [CrossRef] - Gençay, R.; Selçuk, F.; Whitcher, B.J. An Introduction to Wavelets and Other Filtering Methods in Finance and Economics; Academic Press: San Diego, CA, USA, 2001. [Google Scholar]
- Pan, J.; Tompkins, W. A real-time QRS detection algorithm. IEEE Trans. Biomed. Eng.
**1985**, 32, 230–236. [Google Scholar] [CrossRef] [PubMed] - Chen, H.; Chen, S. A moving average based filtering system with its application to real-time QRS detection. In Proceedings of the IEEE Computers in Cardiology, Thessaloniki, Greece, 21–24 September 2003; pp. 585–588.
- Chen, S.W.; Chen, H.C.; Chan, H.L. A real-time QRS detection method based on moving-averaging incorporating with wavelet denoising. Comput. Methods Progr. Biomed.
**2006**, 82, 187–195. [Google Scholar] [CrossRef] [PubMed] - Moody, G.B.; Mark, R.G. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng. Med. Biol. Mag.
**2001**, 20, 45–50. [Google Scholar] [CrossRef] [PubMed] - Laguna, P.; Mark, R.; Goldberg, A.; Moody, G. A database for evaluation of algorithms for measurement of QT and other waveform intervals in the ECG. In Proceedings of the IEEE Computers in Cardiology 1997, Lund, Sweden, 7–10 September 1997; pp. 673–676.
- Moody, G.B. The Physionet/Computers in Cardiology challenge 2008: T-wave alternans. In Proceedings of the IEEE Computers in Cardiology, Bologna, Italy, 14–17 September 2008; pp. 505–508.
- Goldberger, A.L.; Amaral, L.A.N.; Glass, L.; Hausdorff, J.M.; Ivanov, P.C.; Mark, R.G.; Mietus, J.E.; Moody, G.B.; Peng, C.K.; Stanley, H.E. PhysioBank, PhysioToolkit, and PhysioNet: Components of a New Research Resource for Complex Physiologic Signals. Circulation
**2000**, 101, e215–e220. [Google Scholar] [CrossRef] [PubMed] - Albrecht, P. S-T Segment Characterization for Long-Term Automated ECG Analysis. Master’s Thesis, MIT Department of Electrical Engineering and Computer Science, Boston, MA, USA, 1983. [Google Scholar]
- Greenwald, S. Improved Detection and Classification of Arrhythmias in Noise-Corrupted Electrocardiograms Using Contextual Information. Ph.D. Thesis, Harvard-MIT Division of Health Sciences and Technology, Boston, MA, USA, 1990. [Google Scholar]
- Moody, G. Spontaneous termination of atrial fibrillation: A challenge from Physionet and Computers in Cardiology 2004. In Proceedings of the IEEE Computers in Cardiology, Chicago, IL, USA, 19–22 September 2004; pp. 101–104.
- Iyengar, N.; Peng, C.K.; Morin, R.; Goldberger, A.L.; Lipsitz, L.A. Age-related alterations in the fractal scaling of cardiac interbeat interval dynamics. Am. J. Physiol. Regulat. Integr. Comp. Physiol.
**1996**, 271, R1078–R1084. [Google Scholar] - Moody, G.B.; Muldrow, W.; Mark, R. A noise stress test for arrhythmia detectors. In Proceedings of the IEEE Computers in Cardiology, Salt Lake City, UT, USA, 18–21 September 1984; pp. 381–384.
- Braunwald, E.; Zipes, D.; Libby, P.; Bonow, R. Braunwald’s Heart Disease: A Textbook of Cardiovascular Medicine, 7th ed.; Saunders: Philadelphia, PA, USA, 2004. [Google Scholar]
- Elgendi, M.; Norton, I.; Brearley, M.; Abbott, D.; Schuurmans, D. Systolic Peak Detection in Acceleration Photoplethysmograms Measured from Emergency Responders in Tropical Conditions. PLoS ONE
**2013**, 8, e76585. [Google Scholar] [CrossRef] [PubMed][Green Version] - Matsuyama, A. ECG and APG Signal Analysis during Exercise in a Hot Environment. Ph.D. Thesis, Charles Darwin University, Darwin, Australia, 2009. [Google Scholar]
- Elgendi, M.; Kumar, S.; Guo, L.; Rutledge, J.; Coe, J.Y.; Zemp, R.; Schuurmans, D.; Adatia, I. Detection of Heart Sounds in Children with and without Pulmonary Arterial Hypertension–Daubechies Wavelets Approach. PLoS ONE
**2015**, 10, e0143146. [Google Scholar] [CrossRef] [PubMed] - Mattson, C.A.; Mullur, A.A.; Messac, A. Smart Pareto filter: Obtaining a minimal representation of multi-objective design space. Eng. Opt.
**2004**, 36, 721–740. [Google Scholar] [CrossRef] - Oppenheim, A.; Shafer, R. Discrete-Time Signal Processing; Prentice Hall: Upper Saddle River, NJ, USA, 1989. [Google Scholar]
- Elgendi, M. Fast QRS Detection with an Optimized Knowledge-Based Method: Evaluation on 11 Standard ECG Databases. PLoS ONE
**2013**, 8, e73557. [Google Scholar] [CrossRef] [PubMed] - Elgendi, M. Detection of c, d, and e waves in the acceleration photoplethysmogram. Comput. Methods Programs Biomed.
**2014**, 117, 125–136. [Google Scholar] [CrossRef] [PubMed] - Elgendi, M.; Norton, I.; Brearley, M.; Abbott, D.; Schuurmans, D. Detection of a and b waves in the acceleration photoplethysmogram. Biomed. Eng. Online
**2014**, 13, 139. [Google Scholar] [CrossRef] [PubMed] - Elgendi, M.; Eskofier, B.; Abbott, D. Fast T Wave Detection Calibrated by Clinical Knowledge with Annotation of P and T Waves. Sensors
**2015**, 15, 17693–17714. [Google Scholar] [PubMed] - Firbank, M.; Coulthard, A.; Harrison, R.; Williams, E. A comparison of two methods for measuring the signal to noise ratio on MR images. Phys. Med. Biol.
**1999**, 44, 261–264. [Google Scholar] [CrossRef] - Elgendi, M.; Eskofier, B.; Dokos, S.; Abbott, D. Revisiting QRS Detection Methodologies for Portable, Wearable, Battery-Operated, and Wireless ECG Systems. PLoS ONE
**2014**, 9, e84018. [Google Scholar] [CrossRef] [PubMed][Green Version] - Hamilton, P.S.; Tompkins, W.J. Adaptive matched filtering for QRS detection. In Proceedings of the IEEE Annual International Conference Engineering in Medicine and Biology Society, New Orleans, LA, USA, 4–7 November 1988; Volume 1, pp. 14–18.
- Billauer, E. Peakdet: Peak Detection Using MATLAB. Available online: http://billauer.co.il/peakdet.html (accessed on 28 October 2012).
- Li, B.N.; Dong, M.C.; Vai, M.I. On an automatic delineator for arterial blood pressure waveforms. Biomed. Signal Process. Control
**2010**, 5, 76–81. [Google Scholar] [CrossRef] - Zong, W.; Heldt, T.; Moody, G.B.; Mark, R.G. An open-source algorithm to detect onset of arterial blood pressure pulses. In Proceedings of the IEEE Computers in Cardiology, Thessaloniki, Greece, 21–24 September 2003; pp. 259–262.
- Liang, H.; Lukkarinen, S.; Hartimo, I. Heart sound segmentation algorithm based on heart sound envelogram. In Proceedings of the IEEE Computers in Cardiology, Lund, Sweden, 7–10 September 1997; pp. 105–108.
- Kumar, D.; Carvalho, P.; Antunes, M.; Henriques, J.; Eugenio, L.; Schmidt, R.; Habetha, J. Detection of S1 and S2 heart sounds by high frequency signatures. In Proceedings of the 28th Annual International Conference of the IEEE Engineering in Medicine and Biology Society, New York, NY, USA, 31 August–3 September 2006; pp. 1410–1416.
- Wang, X.; Li, Y.; Sun, C.; Liu, C. Detection of the first and second heart sound using heart sound energy. In Proceedings of the 2009 2nd International Conference on Biomedical Engineering and Informatics, Tianjin, China, 17–19 October 2009; pp. 1–4.
- Zhong, J.; Scalzo, F. Automatic heart sound signal analysis with reused multi-scale wavelet transform. Int. J. Eng. Sci.
**2013**, 2, 50–57. [Google Scholar] - Thakor, N.V.; Webster, J.G.; Tompkins, W.J. Optimal QRS detector. Med. Biol. Eng.
**1983**, 21, 343–350. [Google Scholar] [CrossRef] - Li, C.; Zheng, C.; Tai, C. Detection of ECG characteristic points using wavelet transforms. IEEE Trans. Biomed. Eng.
**1995**, 42, 21–28. [Google Scholar] [PubMed] - Sahambi, J.S.; Tandon, S.; Bhatt, R.K.P. Using wavelet transforms for ECG characterization. An on-line digital signal processing system. IEEE Eng. Med. Biol. Mag.
**1997**, 16, 77–83. [Google Scholar] [CrossRef] [PubMed] - Moraes, J.C.T.B.; Freitas, M.M.; Vilani, F.N.; Costa, E.V. A QRS complex detection algorithm using electrocardiogram leads. In Proceedings of the IEEE Computers in Cardiology, Memphis, USA, 22–25 September 2002; pp. 205–208.
- Mahmoodabadi, S.Z.; Ahmadian, A.; Abolhasani, M.D. ECG feature extraction using Daubechies wavelets. In Proceedings of the Fifth IASTED International Conference, Benindorm, Spain, 7–9 September 2005; pp. 343–348.
- Holsinger, W.; Kempner, K.; Miller, M. QRS preprocessor based on digital differentiation. IEEE Trans. Biomed. Eng.
**1971**, 18, 212–217. [Google Scholar] [CrossRef] - Okada, M. A Digital Filter for the QRS Complex Detection. IEEE Trans. Biomed. Eng.
**1979**, 26, 700–703. [Google Scholar] [CrossRef] [PubMed] - Morizet-Mahoudeaux, P.; Moreau, C.; Moreau, D.; Quarante, J.J. Simple microprocessor-based system for on-line e.c.g. arrhythmia analysis. Med. Biol. Eng. Comput.
**1981**, 19, 497–500. [Google Scholar] [CrossRef] [PubMed] - Benitez, D.S.; Gaydecki, P.A.; Zaidi, A.; Fitzpatrick, A.P. A new QRS detection algorithm based on the Hilbert transform. In Proceedings of the IEEE Computers in Cardiology, Cambridge, MA, USA, 24–27 September 2000; pp. 379–382.
- Arzeno, N.; Poon, C.; Deng, Z. Quantitative Analysis of QRS Detection Algorithms Based on the First Derivative of the ECG. In Proceedings of the 28th Annual International Conference of the IEEE Engineering in Medicine and Biology Society, New York, NY, USA, 31 August–3 September 2006; pp. 1788–1791.
- Zhang, F.; Lian, Y. Electrocardiogram QRS Detection Using Multiscale Filtering Based on Mathematical Morphology. In Proceedings of the 29th Annual International Conference of the IEEE Engineering in Medicine and Biology Society, Lyon, France, 22–26 August 2007; pp. 3196–3199.
- Arzeno, N.; Deng, Z.; Poon, C. Analysis of First-Derivative Based QRS Detection Algorithms. IEEE Trans. Biomed. Eng.
**2008**, 55, 478–484. [Google Scholar] [CrossRef] [PubMed] - Friesen, G.; Jannett, T.; Jadallah, M.; Yates, S.; Quint, S.; Nagle, H. A comparison of the noise sensitivity of nine QRS detection algorithms. IEEE Trans. Biomed. Eng.
**1990**, 37, 85–98. [Google Scholar] [CrossRef] [PubMed] - Englese, W.A.H.; Zeelenberg, C. A single scan algorithm for QRS detection and feature extraction. In Proceedings of the IEEE Computers in Cardiology, Geneva, Switzerland, 26–28 September 1979; pp. 37–42.
- Fraden, J.; Neuman, M. QRS wave detection. Med. Biol. Eng. Comput.
**1980**, 18, 125–132. [Google Scholar] [CrossRef] [PubMed] - Elgendi, M.; Howard, N.; Lovell, N.; Cichocki, A.; Brearley, M.; Abbott, D.; Adatia, I. A Six-Step Framework on Biomedical Signal Analysis for Tackling Noncommunicable Diseases: Current and Future Perspectives. JMIR Biomed. Eng.
**2016**, 1, e1. [Google Scholar] - Elgendi, M. Optimal Signal Quality Index for Photoplethysmogram Signals. Bioengineering
**2016**, 3, 21. [Google Scholar] [CrossRef] - Elgendi, M. Eventogram: A Visual Representation of Main Events in Biomedical Signals. Bioengineering
**2016**, 3, 22. [Google Scholar] [CrossRef] - Christov, I.I. Real time electrocardiogram QRS detection using combined adaptive threshold. Biomed. Eng. Online
**2004**, 3, 28. [Google Scholar] [CrossRef] [PubMed][Green Version] - Chiarugi, F.; Sakkalis, V.; Emmanouilidou, D.; Krontiris, T.; Varanini, M.; Tollis, I. Adaptive threshold QRS detector with best channel selection based on a noise rating system. In Proceedings of the IEEE Computers in Cardiology, Durham, NC, USA, 30 September–3 October 2007; pp. 157–160.
- Mann, M.E.; Lees, J.M. Robust estimation of background noise and signal detection in climatic time series. Clim. Chang.
**1996**, 33, 409–445. [Google Scholar] [CrossRef] - Chatterjee, S.K.; Das, S.; Maharatna, K.; Masi, E.; Santopolo, L.; Mancuso, S.; Vitaletti, A. Exploring strategies for classification of external stimuli using statistical features of the plant electrical response. J. R. Soc. Interface
**2015**, 12. [Google Scholar] [CrossRef] [PubMed] - Koos, C.; Vorreau, P.; Vallaitis, T.; Dumon, P.; Bogaerts, W.; Baets, R.; Esembeson, B.; Biaggio, I.; Michinobu, T.; Diederich, F.; et al. All-optical high-speed signal processing with silicon–organic hybrid slot waveguides. Nat. Photon.
**2009**, 3, 216–219. [Google Scholar] [CrossRef] - Furuya, M.; Hamano, Y.; Naito, I. Quasi-periodic wind signal as a possible excitation of Chandler wobble. J. Geophys. Res. Solid Earth
**1996**, 101, 25537–25546. [Google Scholar] [CrossRef] - Stella, L.; Vietri, M. Lense-Thirring Precession and Quasi-periodic Oscillations in Low-Mass X-ray Binaries. Astrophys. J. Lett.
**1998**, 492, L59. [Google Scholar] [CrossRef] - Jerolmack, D.J.; Paola, C. Shredding of environmental signals by sediment transport. Geophys. Res. Lett.
**2010**, 37. [Google Scholar] [CrossRef] - Tandon, N.; Choudhury, A. A review of vibration and acoustic measurement methods for the detection of defects in rolling element bearings. Tribol. Int.
**1999**, 32, 469–480. [Google Scholar] [CrossRef]

**Figure 1.**Filtered and unfiltered closing values of the NASDAQ composite index for calendar year 2001. The dashed black line is the first moving average with a four-day window length, and the dotted red line is the second moving average with a 32-day window length.

**Figure 2.**Flowchart of the two event-related moving averages (TERMA) algorithm for detecting the main event in a quasi-periodic signal. The algorithm consists of six LEGO building bricks: signal, filtering, enhancing, generating blocks of interest, thresholding and prior knowledge.

**Figure 3.**Pseudocode for the TERMA-based detector function. The function has six inputs: biomedical signal (Sig), ${F}_{1}$, ${F}_{2}$, ${W}_{1}$, ${W}_{2}$ and β. The band-pass filter will be determined by the frequency band ${F}_{1}$–${F}_{2}$ Hz, while ${W}_{1}$ and ${W}_{2}$ are the window sizes of the two moving averages ${\mathrm{MA}}_{\mathrm{event}}$ and ${\mathrm{MA}}_{\mathrm{cycle}}$, respectively. However, β is used to calculate the statistical threshold α.

**Figure 4.**Demonstrating the effectiveness of TERMA in detecting events in biomedical signals. (

**A**) QRS detection; (

**B**) T wave detection; (

**C**) systolic wave detection; (

**D**) a wave detection; (

**E**) $c,d,$ and e wave detection; and (

**F**) first and second heart sounds detection. The dashed black line is the ${\mathrm{MA}}_{\mathrm{event}}$ with ${W}_{1}$, and the dotted red line is the ${\mathrm{MA}}_{\mathrm{cycle}}$ with ${W}_{2}$. The peak of the investigated event is detected using TERMA (represented by a black plus sign) within the blocks of interest (represented by a green square pulse).

**Figure 5.**Influence of window sizes on the generation of blocks of interest based on overall accuracy. (

**A**,

**B**) QRS detection; (

**C**,

**D**) systolic waves detection; (

**E**,

**F**) a waves detection; (

**G**,

**H**) $c,d,$ and e wave detection; (

**I**,

**J**) heart sound detection. The left column represents the coupling between the two moving averages by scoring >50% accuracy, while the right column represents non-coupling. The coupling is referred to as accuracy >50%, while non-coupling is referred to as not-a-number (NaN). The green bar represents the most dominant ${W}_{2}/{W}_{1}$ ratio in coupling, while the red bar represents the most dominant ${W}_{2}/{W}_{1}$ in non-coupling.

**Figure 6.**Influence of the offset (β) on the generation of blocks of interest on overall accuracy. (

**A**,

**B**) QRS detection; (

**C**,

**D**) systolic wave detection; (

**E**,

**F**) a wave detection; and (

**G**,

**H**) heart sound detection. The impact of the β value on the coupling by scoring >50% accuracy is represented in the left column, while the non-coupling is represented in the right column. The coupling is referred to with accuracy >50%, while non-coupling is referred to with not-a-number (NaN).

© 2016 by the author; licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC-BY) license (http://creativecommons.org/licenses/by/4.0/).