# Fault-Tolerant Model Predictive Control Applied to a Sewer Network
## 3 Proposed Method for Fault Detection, Diagnosis and Reconfiguration  
When we try to apply directly the PCA-based fault detection and diagnosis techniques, as explained in the previous section, these techniques do not work due to the high variability of the data taken from the system affected by disturbances and due to the method used to calculate the tank outlet flow setpoints, as these setpoints are continuously changing depending on the wastewater stored in the tanks at any given time. Therefore, these conditions mean that the thresholds calculated offline in normal operating situations are not useful for online fault detection and diagnosis. To try to solve this problem, it will be necessary to have normal operating data generated online to calculate the threshold corresponding to a certain range of values, considering the effect of disturbances and changes in output flow references. These data will be generated by a feedforward neural network trained with normal operating data and will form a moving data window at each time that allows us to calculate an adaptive threshold for the whole simulation data set [20; 38; 39]. Once trained, the network will be able to generate normal operating data based on the disturbances.  
The procedure to apply will be the following:  
1. Initialization: A matrix \(\mathbf{X}_{p}\in\Re^{nxm}\) formed by \(n\) data of \(m\) process variables is filled up with operating data obtained by simulation. This matrix is normalized and is going to be considered a sliding window of process data, with length \(n\).
2. Obtaining the \(Q\) statistic: a data vector \(x\in\Re^{mx1}\) with the measurements of the system variables is formed. The \(x\) data are normalized and the PCA method is applied to this new data, and the \(Q\) statistic is calculated as indicated in Equation (6). This value is stored and updated every time a new sample is acquired, up to a maximum of \(n\) values, because each time a new sample is taken, the oldest one is discarded.
3. \(Q_{\alpha}\) (\(Q\) threshold) calculation: to obtain the threshold of the \(Q\) statistic adaptively in the sliding window, the value of the actual disturbances taken from the plant and the value of the rest of the process variables under normal operating conditions are required. These variables are calculated with a neural network. This network has as inputs the disturbances, and the past value of the process variables. The output of the network is the prediction of the process variables at the next time instant. Thus, for the online procedure, a matrix \(\mathbf{X}\in\Re^{nxm}\) is now constructed with the current disturbances and the network outputs, in the sliding window, to calculate the threshold of \(Q\) according to Equation (7). Since each time a new sample is taken, the oldest one is discarded, the calculated threshold is adapted to new disturbances.
4. Fault detection: the number of times that the \(Q\) statistic exceeds the calculated threshold (number of alarms) is calculated, and if this number reaches \(M\) consecutive values, it is considered that a fault has occurred. Then, go to STEP 5; otherwise, go to STEP 2.
5. Fault diagnosis: the fault instant is determined, and to calculate the contribution of each variable to the fault, the residue of the first \(H\) samples of \(M\) values that were used to detect the fault is evaluated by Equation (6). The variable whose mean of the residue is higher than those calculated for the \(H\) samples considered is determined and the failing device is identified.  
* Reconfiguration of the MPC: mainly, sensor and actuator faults are considered. Thus, if a sensor fails, its real value can be estimated using other measurements of the process, taking advantage of redundancy. On the other hand, if an actuator fails, MPC can be recalculated by adding new constraints about this device.  
Section 4.3 will specify the details necessary for the application of this methodology to the system under consideration.