# Real-Time Psychological Stress Detection According to ECG Using Deep Learning
## 2 Materials and Methods
### The Proposed Network  
Most conventional machine learning methods used prior knowledge to manually extract features. Due to the limitations of prior knowledge, conventional feature extraction methods would inevitably ignore some non-linear relationship between ECG and stress. The purpose of this article was to avoid the limitations of prior knowledge by using deep learning technology. With deep learning, we could extract features from the original ECG signal automatically and establish mapping from the original ECG for the psychological pressure to meet the real-time application (using less than 1 min ECG to speculate stress with high accuracy). CNN is one of the most popular neural networks, and it has greatly promoted the development of image processing. Unlike RNN, its features are local connecting and weight sharing, using local connection and weight sharing CNN could automatically extract the structural features of the image in space, which makes it good at recognizing the data's displacement, scaling and rotation [24]. On the other hand, the model's complexity is greatly reduced, so it is easy to optimize compared with a fully connected network. A typical CNN net usually contains a convolution layer, a pooling layer, and a fully connected layer as shown in Figure 9. The convolutional layer performs simplified convolution operations between the input data that is intercepted by the window function and the convolution kernel. Therefore, the convolution layer can extract the features from the input data that relate to the convolution kernel. As different convolution kernels can extract different features, increasing the number of feature kernels within a certain range can increase the computing time. The pooling layer after convolution mainly plays the role of down sampling, which can highlight the effective ingredient of the features and reduce the amount of calculations. Taking into account the CNN's ability at extracting local features, we designed the process to use CNN instead of manually extracting features via conventional methods and also by increasing the number of convolution kernels to increase the number of features. The choice of CNN was based on the fact that it does not require feature engineering. Traditional neural networks assumed that all the data entered before and after are independent. Therefore, it was not possible to take advantage of the progressive relationship within the time series signals, such as language. RNN [25] is one of the most popular networks, as it advances through time by a fixed step size and continuously generates historical status, in the process of advancement, the historical information of the previous moment is also taken as a part of the input, so it can use the back-and-forth connection of time-series signals. It showed excellent performance in the field of natural language processing. LSTM (as shown in Figure 10) is a kind of RNN which uses the forget gate and memory gate to address the disadvantages of short-term memory. Figure 9: The typical convolutional neural network (CNN) with one conv layer which has one channel and three filters, one pooling layer and one fully connected layer. Throughout the entire time series of ECG, the state of the current moment was also affected by the future moment. The characteristics of the next moment could also be used to predict the current moment's status. BiLSTM (shown in Figure 11) is a widely used variant of LSTM [26]. It consists of two LSTM units that can extract the features from both positive and negative sequences separately and then jointly determine the output. There are generally three ways to combine the outputs of two LSTM units, including addition, multiply and series connection (as shown in Figure 12). BiLSTM were used to further extract features from the whole time, considering that ECG belongs to time series signal that is suitable for BiLSTM. The three methods have been tried and the results are given in the result section.