# Elderly Fall Detection in Complex Environment Based on Improved YOLOv5s and LSTM
## 4 Fall Detection with WiFi Signal Based on LSTM Model
### Fall Detection
#### 4.5.2 Improved LSTM Model  
1. LSTM model  
LSTM is a special recurrent neural network (RNN) that is proposed to solve the problems of gradient disappearance and gradient explosion when a traditional RNN processes long sequence data [33]. The inspiration comes from the human memory mechanism, in which the human brain processes information to decide whether to retain or forget according to the information's importance, enabling the human brain to deal with complex long-term dependencies. LSTM introduces a \"gate\" structure and a \"cell state\". Gate structures can control the inflow and outflow of information, and cell states can store states for a long time. This allows LSTM to better capture dependencies in long sequences. The overall processing flow of LSTM is shown in Figure 8.  
Input layer: Consistent with RNN, the input sequence needs to be converted into numerical form. Hidden layer: In the hidden LSTM layer, each time step receives an input and the cell state of the previous time step. Then, the cell state and hidden state of the current time step are calculated through a series of gating mechanisms (including forget gate, input gate, and output gate) and cell state updates and finally output. These gating mechanisms control the flow of information, deciding what information to forget, what new information to add, and what information to output. Figure 7: Filtered CSI signals with wavelet transform filter. There are two lines at each LSTM time point \(T_{n}\): \(C_{t}\) and the output of \(T_{n-1}\). The forget gate determines how much of the previous cell state information to forget, calculated from the current input and the hidden state of the previous time step. The two pass through a fully connected layer and the Sigmoid function is applied to give the forgotten gate value. This value ranges from 0 to 1, where 0 means completely forgotten and 1 means completely retained. It is assumed that \(K_{f},K_{i},K_{c},K_{o}\) are the weighted matrices; \(b_{f},b_{i},b_{c},b_{o}\) are bias terms, and \(\sigma\) is the Sigmoid function. For the cell state of previous time step \(C_{t-1}\), the model takes the output \(h_{t-1}\) of the last stage and the input \(x_{t}\) of the current stage into the Sigmoid function to determine how much \(C_{t-1}\) can forget, as shown in the following formula:  
\[f_{t}=\sigma\Big{(}K_{f}\cdot[h_{t-1},x_{t}]+b_{f}\Big{)} \tag{12}\]  
The input gate compares the previous generation's output with the current generation's input, and then selects how much to add to the current main input \(C_{t}\). This consists of two parts: one is the input gate, which determines which parts of the memory cell will be updated; the other part is a Tanh layer, which creates a new candidate value vector to add to the memory cell--both the input gate value and the candidate value are calculated from the current input and the hidden state of the previous time step. The candidate value is computed as follows:  
\[i_{t}=\sigma(K_{i}\cdot[h_{t-1},x_{t}]+b_{i}) \tag{13}\]  
The input value is as follows:  
\[\widetilde{C}_{t}=\tanh(K_{c}\cdot[h_{t-1},x_{t}]+b_{c}) \tag{14}\]  
Then, the new information that needs to be updated is generated according to the decisions of the forget gate and the input gate. The cell state is multiplied by the forgetting gate value, indicating the forgotten part of the state information. The input gate value is then multiplied and added to the candidate value, indicating that new state information has been added. The formula of the updated cell state is as follows:  
\[C_{t}=f_{t}*C_{t-1}+i_{t}*\widetilde{C}_{t} \tag{15}\]  
Finally, \(C_{t}\) is put into the Tanh function in the output gate and multiplied by \(Z_{t}\), giving the final output \(h_{t}\). \[h_{t}=Z_{t}*\tanh(C_{t}) \tag{16}\]  
where  
\[Z_{t}=\sigma(K_{o}\cdot[h_{t-1},x_{t}]+b_{o}) \tag{17}\]  
Figure 8: Processing flow of LSTM.