# Real Driving Cycle-Based State of Charge Prediction for EV Batteries Using Deep Learning Methods
## 4 Methodology  
### Dynamic Time Warping (DTW) for Similarity of Real Driving Cycles  
First proposed by [31] in the speech recognition field, the DTW is an algorithm that measures similarity between time series, which may vary in length. The technique performs non-linear warpings so that the time series are stretched or shrinked in order to find the optimal alignment between them. It has a wide range of applications, such as data mining, gesture recognition, robotics, speech-processing, manufacturing and medicine [32]. We propose a method to find similar driving routes based on the DTW algorithm, using the acceleration of the vehicle as input. The reason why acceleration is used is that the SOC is closely related to power consumption, which, in turn, is closely related to the acceleration of the vehicle. There were more than 30 driving-cycle-related data collected  
Figure 2: Real Driving Cycle with Google MAP. and, due to the large noise and uncertainty existent in the dataset, only similar segments were used for the prediction. Therefore, the goal of the algorithm is to find the most similar acceleration time series segments to use them as input to the ML models. The algorithm that was used can be described in the following manner:  
* First of all, the _base_ time series which we want to use to find other similar time series must be defined. For this present work, we defined the route shown in the map of the Figure 2, represented by the time series in the Figure 3, as the base route to which the remaining 30 time series will be compared. * Secondly, the base time series may further be split into an arbitrarily number of base segments. Considering the Figures 2 and 3, the markers from A to F and the dotted black vertical lines represent situations in which the velocity of the car reached zero or, in other words, the start and the end points of each of the four segments (A to C, C to D, D to E, E to F). Note that the point B was not taken into account, because we regarded it as noise due to its proximity to point A, and that the each of the base segments are shown in greater detail in the subfigures of Figure 4.
* Thirdly, for each of the four _base_ segments, we set the lower bound and the upper bound times for the similar patter- finder algorithm by subtracting and adding an \(\epsilon\) arbitrary small amount of time. For example, the second _base_ segment was extracted from second 69 to 135 of the _base_ time series. If \(\epsilon=50\), then the lower-bound and upper-bound times for a similar pattern-finder algorithm will be, respectively, 19 s and 185 s, as shown in Table 1.
* With the lower and upper bounds of the algorithm defined, we split the period between the lower and upper bounds into smaller search periods, spaced by an arbitrary time interval. Intuitively, the lower the interval is, the higher the accuracy of the algorithm. These smaller search periods are shown in Table 1 for an interval of five seconds between each period. * Next, we looped through the search periods. * Inside the search-periods-loop, we loop through the remaining 30 time series, which will be compared to the _base_ time series. * Next, we extract the corresponding search period of the time series to be used in the comparison. * Next, we obtain the distance between the extracted time series and the _base_ segment by DTW. * Finally, after the two loops are finished, we rank the all the extracted time series according to their cost, computed by DTW, and obtain the 10 periods that have the lowest cost, which will form the training and test datasets for the machine learning models. Figure 3: Speed and acceleration over time of the base time series. (**a**) Speed \(\times\) time of the base time series. (**b**) Acceleration \(\times\) time of the base time series. Figure 4: Speed and acceleration over time of the four base segments.