## Materials and Methods
### Signal Preprocessing
To eliminate this linear trend in SPW, the least squares method is used to find the straight line (see Figure 8a) of this trend. Then, each PPG signal value is decreased  
Figure 4: PPG with signal preprocessing window (SPW), blood pressure estimation window (BPEW) and peak detection window (PDW). (4) _Pulse wave peak point detection_ is performed using the adaptive peak detection window (PDW) method [44], which starts by setting PDW as the minimum heart contraction period. Then, PDW is divided into three parts, and according to the proposed algorithm, the heart rate is calculated. PDW is increased, divided into three parts and the heart rate is calculated again. This process is repeated until the PDW width reaches its maximum possible period. The histogram is constructed from the obtained heart rates, and the period corresponding to the most commonly found heart rate is used as optimal PDW. Such an algorithm sometimes gives incorrect results when more than two pulse waves fall into PDW; for example, if a heart rate is 200 bpm and PDW width reaches 1.5 s (40 bpm), then 5 pulse waves will fall into the PDW. Besides, if the heart rate is low, this algorithm is not efficient in terms of calculation time. We modified this method by changing the PDW definition rules. These rules are applied for each SPW separately, as defined in Algorithm 1. ```
1 procedurepdw(p1,p2)VA: Input Signal \(\
abla\)mHR: min Heart Rate
2\(T_{min}=(1/m\text{HR})^{\text{t}}1/2\); \(L=round(T_{min}/F_{s})\);
3\(i=1\); \(N=length(A)/L\);
4 while(i+1)\({}^{\text{t}}\)L \(<=N\)do
5[\(k1\), \(c\)] = linaprox(A(\(i^{\text{t}}\)L-\(k1\): \(i^{\text{t}}\)L))
6[\(k2\), \(c\)] = linaprox(A(\(i^{\text{t}}\)L-\(i\)+\(1\))\({}^{\text{t}}\)L))
7 if\(\text{k1}>0\)and\(\text{k2}<0\)then\(p1=i^{\text{t}}\)L-\(L\)+1; \(p2=(i+1)^{\text{t}}\)L;
9 goto16 line
10 end if
11 if(\(k1<0\)and\(k2<0\))or(\(k1<0\)and\(k2>0\))
12 then\(i=i+1\); goto15 line
13 if(\(k1>0\)and\(k2>0\))
14 then\(L=L+0.1^{\text{t}}\)L;
15 end/*While*/
16 end if
```  
**Algorithm 1** PDW size calculation  
The first part of PDW can contain a pulse wave falling edge (or part of it), while the rising edge of the wave appears at the end of PDW. In such a case, the pulse wave peak will not fall into PDW. To detect the beginning of PDW (\(p_{1}\)) and its end (\(p_{2}\)), PDW = 2L signal values are taken from SPW, where L is number of values fitting in half of the minimum period \(T_{min}\). The least squares method is used to derive straight lines through A(p1:L) and A(L:p2). If the slopes of these lines are negative (\(k_{1}<0\), \(k_{2}<0\)), then the values belong to the falling edge of the pulse wave (see Figure 9a), and PDW is shifted to the right by the L values. If the slope coefficients are positive (\(k_{1}>0\), \(k_{2}>0\)), then the values belong mostly to the rising edge, but they do not contain peak values (see Figure 9c). In this case, L is increased by 1/10 and new slope coefficients are found. When \(k_{1}<0\) and \(k_{2}>0\) values belong to the rising and falling edges of the pulse wave, but do not contain a peak (see Figure 9b), the PDW is shifted to the right by the L values. Only when \(k_{1}>0\) and \(k_{2}\)\(<0\) does the PDW contain a peak value (see Figure 9d). (5) _Pulse wave valley point detection_ is performed using the algorithm proposed in Reference [45]. (6) _Base line correction_: This step is performed when the starting points of pulse waves in BPEW are found. When a PPG signal is filtered, the unwanted harmonics are eliminated, while base line corrections give a signal whose values vary about a constant value. However, the line connecting the starting points of each pulse waveform a piecewise linear curve. This means that the amplitude values of the pulse wave's starting and ending points are different. For this reason, incorrect start points, peak points, and rising edge slopes of the pulse wave can be found; thus, base line correction is implemented as explained in Reference [46] (see Figure 10a).