# Real-time Neural Networks Implementation Proposal for Microcontrollers
## 2 System Description
### Associated Variables  
The implementation is composed of four main variables that are passed by reference between the modules. These variables are the input signals matrix, \(\mathbf{Y}^{k=0}\left(n\right)\) defined as  
\[\mathbf{Y}^{0}\left(n\right)=\left[\mathbf{y}_{1}^{0}\left(n\right),\ldots, \mathbf{y}_{s}^{0}\left(n\right),\ldots,\mathbf{y}_{\mathbb{N}}^{0}\left(n \right)\right], \tag{1}\]  
where \(k=0\) means that this matrix is dealing with the input layer of the MLP, \(n\) represents the iteration number of the training algorithm. \(\mathbb{N}\) is defined as the number of samples of a training set and \(\mathbf{y}_{s}\) the \(s\)-th sample defined as  
\[\mathbf{y}_{s}^{0}\left(n\right)=\left[y_{s1}^{0}\left(n\right),\ldots,y_{s}^{ 0}\left(n\right),\ldots,y_{p}^{0}\left(n\right)\right]^{T}, \tag{2}\]  
Figure 1: Block diagram detailing the modules of the matrix implementation for a Multilayer Perceptron (MLP) trained with a backpropagation (BP) algorithm proposed in [25].  
where \(P\) is the number of available inputs of the MLP. The synaptic weights matrix from the \(k\)-th layer, \(\mathbf{W}^{k}\left(n\right)\), is defined as  
\[\mathbf{W}^{k}\left(n\right)=\left[\begin{array}{ccccc}w_{10}^{k}\left(n \right)&\ldots&w_{1h}^{k}\left(n\right)&\ldots&w_{1H^{k-1}}^{k}\left(n\right) \\ \vdots&\ddots&\vdots&\ddots&\vdots\\ w_{j0}^{k}\left(n\right)&\ldots&w_{jh}^{k}\left(n\right)&\ldots&w_{jH^{k-1}}^{k }\left(n\right)\\ \vdots&\ddots&\vdots&\ddots&\vdots\\ w_{H^{k}0}^{k}\left(n\right)&\ldots&w_{H^{k}h}^{\left(y\right)}&\ldots&w_{H^{k }H^{k-1}}^{k}\left(n\right)\\ \end{array}\right], \tag{3}\]  
where \(H^{k}\) is the number of neurons from the \(k\)-th layer and \(w_{ij}^{k}\left(n\right)\) represents the synaptic weight associated with the \(i\)-th artificial neuron, from the \(j\)-th input signal of the \(k\)-th layer at the \(n\)-th iteration. The output signals matrix, \(\mathbf{Y}^{L}\left(n\right)\), is defined as  
\[\mathbf{Y}^{L}\left(n\right)=\left[\mathbf{y}_{1}^{L}\left(n\right),\ldots, \mathbf{y}_{s}^{L}\left(n\right),\ldots,\mathbf{y}_{\mathbb{N}}^{L}\left(n \right)\right], \tag{4}\]  
where \(L\) is the number of layers of the MLP and also defines which layer is last, and \(y_{s}^{L}\left(n\right)\) represents the output signal associated with the \(s\)-th sample input \(y_{s}^{0}\) that is defined as  
\[\mathbf{y}_{s}^{L}\left(n\right)=\left[y_{1}^{L}\left(n\right),\ldots,y_{s}^{ L}\left(n\right),\ldots,y_{M}^{L}\left(n\right)\right]^{T}, \tag{5}\]  
where \(M\) is the number of output neurons.  
The \(\mathbf{D}\left(n\right)\) variable represents the desired values or labels of the training set composed of the \(\mathbf{D}\left(n\right)\) and the \(\mathbf{Y}^{0}\left(n\right)\), which is defined as  
\[\mathbf{D}\left(n\right)=\left[\mathbf{d}_{1}\left(n\right),\mathbf{d}_{2} \left(n\right),\ldots,\mathbf{d}_{s}\left(n\right),\ldots,\mathbf{d}_{\mathbb{ N}}\left(n\right)\right], \tag{6}\]  
where \(\mathbf{d}_{s}\left(n\right)\) is the vector of desired values referring to the \(s\)-th sample associated with the \(y_{s}^{0}\left(n\right)\) input signal, which is defined as  
\[\mathbf{d}_{s}\left(n\right)=\left[d_{1}\left(n\right),\ldots,d_{s}\left(n \right),\ldots,d_{M}\left(n\right)\right]^{T}. \tag{7}\]  
For an MLP with two layers, \(\mathbf{W}^{1}\left(n\right)\) represents the synaptic weights matrix from the hidden layer (\(H^{0}=P\)), and \(\mathbf{W}^{2}\left(n\right)\) is the weights matrix from the output layer (\(H^{2}=M\)) at the \(n\)-th iteration. In addition to these two matrices, a few others are created to accommodate intermediary results from feedforward and backward propagation operations of the MLP.