# Dynamic Segmentation for Physical Activity Recognition Using a Single Wearable Sensor
## 4 Proposed Method
### Determining Segment Boundaries  
In dynamic activity segmentation, it was necessary to determine the segment time boundaries to obtain a successful partition among different activities [27]. In the proposed algorithm, there were two types of boundaries for the activities based on the number of peaks in each activity. The first type was the peak boundaries, which was used when a single activity contained two peaks (as in the case of IR and extension). In this type, as the name suggests, these peaks were regarded as the boundaries of the segment. The second type was the valley boundaries, which was applied when an activity consisted of only one peak. In this type, the two valleys that directly preceded and followed each peak were identified to represent the start- and endpoints of the segment, respectively. Therefore, the length of a segment changed dynamically according to the duration of the corresponding activity. To determine the suitable type of boundaries for the segmentation, the algorithm checked the signal characteristics of each identified peak, as illustrated in Figure 5.  
Peak boundaries were chosen if the value of Y-axis was smaller than the value of \(Z\)-axis at peak\({}_{i}\) and peak\({}_{i+1}\), as shown in Figure 6a. Moreover, the algorithm checked the signal's characteristics between every two consecutive peaks. If there was no intersection between Y-axis and X-axis along these peaks, as illustrated in Figure 6b, peak boundaries were also applied. Otherwise, if an intersection existed at any point between the peak and the valley that directly follows the peak, as shown in Figure 6c-g, valley boundaries were used. The pseudocode that describes how to segment the acceleration signal of physical activities adaptively is shown in Algorithm 1. The input values to Dynamic Segmentation are represented in line 2, and the output value is represented in line 5. The input of the  
Figure 5: Determining boundary type based on signal characteristics (P: Peak; V: Valley). algorithm is a set of tri-axial accelerometer data S, which is divided into multiple segments. The \"for\" loop in lines 9-28 represents the process of determining the type of boundaries in all peaks except the last one. The \"if\" and \"else if\" statements in lines 10-14 and 15-23, respectively, examine the signal's characteristics in each peak and divide the signal using peak or valley boundaries. Lines 28-36 repeat the process for the last peak using only valley boundaries. ```
1:Input:
2: S: a set of tri-axial accelerometer data
3:Output:
4: A set of segments: Seg = [seg1, seg2,..., segn]
5: peaks = indices of all peaks in Y-axis using Threshold1 and Distance
6: valleys = indices of all valleys in Y-axis using Threshold2
7: p = total number of peaks
8: v = total number of valleys
9:for i = 0 to p-2 do
10:if Y-axis value is smaller than Z-axis value at peak(i) and peak(i+1)
11: OR no intersection between X-axis and Y-axis from peak(i) to peak(i+1) then
12:for h = peaks (i) to peaks (i+1) do
13: Add S(h) to Segi
14:endfor
15:else if intersection exists between X-axis and Y-axis at any point from peak(i) to next valley then
16:for k = 1 to v-1 do
17:if valleys (k) is the valley that directly follows peaks (i)
18: AND valleys (k-1) is the valley that directly precedes peaks (i) then
19:For h = valleys (k-1) to valleys (k) do
20: Add S(h) to Segi
21:endfor
22:endif
23:endfor
24:else
25: i = i+1
26:endif
27:endfor
28:for k = 1 to v-1 do
29:if valleys (k) is the valley that directly follows peaks (p-1)
30: AND valleys (k-1) is the valley that directly precedes peaks (p-1)
31:AND intersection exists between X-axis and Y-axis from peaks(p-1) to valleys (k) then
32:for h = valleys (k-1) to valleys (k) do
33: Add S(h) to Segi
34:endfor

## 5 Experimental Setup

An experiment was performed to evaluate and compare the results of the proposed method. This section describes the overall process and experimental details. ### Data Acquisition

This section describes the demographics of the participants.