• No results found

3.3 AID: Lightweight Usage Anomaly Detection

3.3.2 R-Peak Detection

There are plenty of algorithms (e.g Pan-Tompkins [63]), which can reliably detect the R-Peak under various condition, available. These algorithms require either do-main transform or filters, which are very complex operation and won’t fit on a mote.

Consequently, the existing approaches may not be suitable due to the complexity.

Figure 3.5: The notations of the amplitude difference used to explain the R-Peak Detection in AID

In AID, a simple algorithm is adopted to detect the R-Peak (pseudocode of R-Peak detection is shown in Algorithm 1 between Line 9 to Line 23). In order to clearly ex-plain the R-Peak detection algorithm, the following notations are used to represent the amplitude difference between two data samples. For each data sample, the absolute amplitude difference between itself and its next data sample is denoted as D1; the absolute amplitude difference between itself and its previous data sam-ple is denoted as D2; and the absolute amplitude difference between its previous

data sample and its next data sample is denoted as D3. These notations are illus-trated in Figure 3.5. To perform the R-Peak detection, the algorithm also requires a threshold, denoted as TR, which is set by cardiologist during initial deployment (covered in Section 3.3.5). During the R-Peak detection, for each data sample, if D1 and D2 exceed TR, and D3 is smaller than TR, this specific data sample is re-ported as the R-Peak. Otherwise, the R-Peak is not detected and the algorithm will perform R-Peak detection for the next data sample until the R-Peak is detected.

Figure 3.6: An example to explain the R-Peak Detection in AID

To demonstrate how the algorithm work, Figure 3.6 has illustrated an example signal with the horizontal axis is the sample count and the vertical axis is the am-plitude. Each blue point in the figure represents a data sample whose amplitude is labelled next to the point. For this example, it is assumed that the TR is set to 10, and the fourth data sample (sample count 3 as count starts from 0) is the R-Peak. When the algorithm check whether the fourth data sample is the R-Peak, it calculates the D2, which is 17 in this case, and the D1, which is 13 in this case.

Then, the algorithm calculates the D3, which is 4 in this case. As the D1 and D2is greater than TR and the D3 is smaller than TR, the algorithm reports this point as the R-Peak. On the other hand, let’s use the third data sample (sample count 2) to

be the example to demonstrate how the algorithm will behave when a data sample is not Peak. When the algorithm check whether the third data sample is the R-Peak, it calculates the D1, which is 17 in this case. Then, the algorithm calculates the D2, which is 3 in this case. As the D2 is smaller than TR, the algorithm does not report this point as the R-Peak.

By using this approach, the complexity is reduced compared to other existing ap-proaches. However, as such approach is proposed to be used with the signals captured from the ECG-based HC-BSNs, it assumes that the sampling frequency of the signals is relatively low. Specifically for this research, the sampling frequency is assumed to be 360Hz as the evaluation signal database used in this research is sampled at 360Hz. Despite this assumption, the proposed R-Peak detection algorithm may be generalised to other sampling frequencies with some modifica-tions. The main modification is the data samples used to calculate the amplitude differences (D1, D2 and D3). For example, if the sampling frequency is 1024Hz, instead of calculate those amplitude differences between three adjacent data sam-ples (input[Cnti], input[Cnti − 1], input[Cnti − 2] if using the notations in Algo-rithm 1), the algoAlgo-rithm can be modified to calculate those amplitude differences us-ing three data samples which are more separated (e.g input[Cnti], input[Cnti− 5], input[Cnti− 10] if using the notations in Algorithm 1). This modification is based on the fact that with higher sampling frequency, the captured signal will have more data samples than the signal with lower sampling frequency. As the algorithm still calculates the D1, D2 and D3 using three data samples, the complexity in terms of computation will not increase. However, as the algorithm need to buffer more data samples before the R-Peak detection can be performed, it may increase the overhead of RAM consumption. As generalising the proposed R-Peak detection algorithm is outside the scope of this research, how far the data samples should be separated will not be covered in this research.

Referring to the cases that AID concerns about, when the captured signal is nor-mal, it can detect the R-Peak reliably as illustrate in Figure 3.6. When the No Signal anomaly happens, no R-Peak is exist. As a result, it’s expected that the algorithm

doesn’t report any R-Peak being detected. Subsequently, the No Signal anomaly can be declared. When the Inverted Signal anomaly happens, the highest peak become the lowest peak. As our algorithm compares the absolute difference, it will either report the highest peak (correct R-Peak) or lowest peak (inverted R-Peak) as long as they are significant. As a result, the algorithm will work under this situation.

When the Noisy Signal anomaly happens, depending on the strength of the noise, the algorithm behaves differently. If the noise is much weaker than the R-Peak, the peaks caused by the noise won’t affect the detection due to the thresholds, TR. On the other hand, if the noise is similar or stronger than the R-Peak, the peaks caused by the noise may be reported as R-Peak by this algorithm, in which case the algorithm reports fake R-Peak. However, it’s won’t affect the AID as the R-Peak unrecognisable is one of the key feature of Noisy Signal.