Estimating Phosphorus and COD Concentrations Using a Hybrid Soft Sensor: A Case Study in a Norwegian Municipal Wastewater Treatment Plant

: Online monitoring of wastewater quality parameters is vital for an efﬁcient and stable operation of wastewater treatment plants (WWTP). Several WWTPs rely on daily/weekly analysis of water samples rather than online automated wet-analyzers due to their high capital and maintenance costs. Soft-sensors are emerging as a viable alternative for real-time monitoring of parameters that either lack a reliable measuring principle or are measured using expensive online sensors. This paper presents the development, implementation, and validation of a hybrid soft sensor used to estimate Total Phosphorus (TP) and Chemical Oxygen Demand (COD) in the inﬂuent and efﬂuent streams of a full-scale WWTP. A systematic method for cleaning and processing sensor data, identifying statistically signiﬁcant correlations, and developing a mathematical model, is discussed. A nonintrusive Industrial Internet of Things (IIoT) infrastructure for soft-sensor deployment and a web-based GUI for data visualization are also presented in this work. The values of TP and COD estimated by the soft sensor are validated by comparing the estimated values to the daily average of their corresponding lab measurements. The data validation results demonstrate the potential of soft sensors in providing real-time values of essential wastewater quality parameters with an acceptable degree of accuracy.


Introduction
The chemical wastewater treatment process, which includes coagulation and flocculation followed by sedimentation, is one of the most commonly used wastewater treatment processes in Norway [1]. The operational efficiency of Wastewater Treatment Plants (WWTPs) based on chemical treatment is maintained by ensuring an optimal dosage of coagulants and flocculants. Several control strategies varying from simple flow proportional to sophisticated multi-parameter-based dosing control strategies [2] can be found in the literature. The growing number of users of the multi-parameter-based dosing control strategies provide impetus to monitor additional wastewater quality parameters in WWTPs.
WWTPs use several methods to monitor essential wastewater quality parameters. These methods vary from the offline analysis of water samples using standardized lab tests [3] to online sensors that can relay real-time data to the Supervisory Control And Data Acquisition (SCADA) system of the treatment plant. Standardized lab measurements provide information on the overall efficiencies of the treatment plant. However, the delay in obtaining the measurement results and the relatively large timescale (once every day or 2 days) associated with sample collection limits their utility in automation and process control algorithms or decision support systems. Adoption of new technologies such as ballasted flocculation and separation [4] or the potential use of nano-material [5] has further encouraged the use of automation, process control, and advanced monitoring in WWTPs. A rapid growth in sensor technology in the past decade has resulted in several new online measuring techniques and a significant drop in the prices of online sensors. The current market provides sensors to monitor several parameters in wastewater that are otherwise measured offline using standardized lab tests. However, the high installation costs of these online sensors and the regular maintenance costs associated with the replacement of calibration solutions and reagents, cleaning of source lamps/lenses often make it economically infeasible, especially for small to medium-sized WWTPs [6]. A comprehensive review of online monitoring systems used in the coagulation/flocculation process presented in [7] shows that most wastewater quality parameters such as Total Phosphates (TP), Chemical Oxygen Demand (COD), and Total Nitrogen (TN) are measured offline using standardized lab analysis. However, parameters such as pH, Dissolved Oxygen (DO), conductivity, Oxidation-Reduction Potential (ORP), water level, and flowrate, that can be measured using reliable, inexpensive, and low maintenance sensors are often measured online in most treatment facilities including small to medium WWTPs [8].
Software sensors, also known as soft sensors or virtual software sensors are viable alternatives that are being actively explored [9]. Soft sensors are mathematical models implemented in software that can use real-time data from easy to measure physical sensors to estimate essential wastewater quality parameters that are either difficult to measure or are measured offline using lab analysis. A detailed review of different soft sensor algorithms used in WWTPs is presented in [10]. Several case studies presenting both simulator-based evaluations [11] and pilot-scale implementations [12] of soft sensors can be found in the literature. However, we found hardly any full-scale implementations of soft sensors especially in wastewater treatment processes using coagulation/flocculation and sedimentation.
The primary aim of this work is to design, test, and validate a hybrid soft sensor to estimate influent and effluent concentrations of TP and COD in a full-scale municipal wastewater treatment facility located in Norway. The real-time data from easy to measure online sensors installed in a full-scale WWTP are correlated to the data obtained from periodic lab-analysis of raw and treated water samples. A concise data-analysis tool for cleaning and transforming online data, comparison between various soft sensor models, state-of-the-art algorithm deployment strategy, and practical issues encountered during soft sensor deployment are investigated.

Søndre Follo Wastewater Treatment Plant (SFR)
SFR is a municipal wastewater treatment facility located in Vestby municipality, Norway. The treatment plant has a treatment capacity of 29,000 p.e and uses a conventional coagulation/flocculation process to remove colloids, particles, and soluble ortho-phosphates from municipal wastewater. The wastewater initially passes through a grit removal unit, removing larger particles, and enters a fat and sand removal unit. The coagulant is dosed at the entry point of the sand removal unit due to the high mixing rates achieved in this process. Flocculants are dosed to the wastewater at the entry point of the flocculation units, equipped with paddle mixers for slow mixing to ensure the formation of flocs. Wastewater with sufficiently developed flocs is distributed to six rectangular sedimentation tanks that provide adequate residence time for the flocs (sludge) to settle down in the bottom. The treated wastewater passes over weirs to the effluent channel. Sludge, which is removed from the bottom of the sedimentation unit is sent to anaerobic digestion after dewatering, thickening, and sludge stabilization.
The treatment plant is equipped with online pH, TSS, conductivity, ORP, level, and flow sensors that relay real-time information to a SCADA system provided by GUARD Automation (https://guard.no/) assessed on 15 December 2021. A multi-parameter-based dosing control system [13], provided by DOSCON, ensures an optimal dosing of coagulant and polymer in the treatment plant. The layout of the treatment process, the location of Water 2022, 14, 332 3 of 16 online sensors, dosing points for coagulants and flocculants, and the flow distribution of wastewater along the WWTP are presented in Figure 1.
Water 2022, 14, x FOR PEER REVIEW 3 of 17 dosing control system [13], provided by DOSCON, ensures an optimal dosing of coagulant and polymer in the treatment plant. The layout of the treatment process, the location of online sensors, dosing points for coagulants and flocculants, and the flow distribution of wastewater along the WWTP are presented in Figure 1. In addition to the online sensors located in several sections of the WWTP, auto-samplers are installed at raw and treated wastewater sampling points to collect composite samples. The auto-samplers are programmed to collect 50 mL samples when the cumulative wastewater flow reaches 200 m 3 . The composite samples are then analyzed for TP and COD using standardized methods as described in [3]. TP is analyzed as a daily average (from 8:00 a.m. of every working day to 7:00 a.m. of the next working day) and COD is analyzed once every week as weekly averages (on Fridays). The mean and standard deviation of the influent and effluent TPI and COD along with the removal rates are presented in Table 1. The distribution of data obtained from online sensors (pH, TSS, Flowrate, conductivity, ORP, PAX and Polymer dose flow-meters) and the values measured using standardized lab measurements (TP and COD) for the year 2020-2021 are presented in Figure 2a,b. The x-axis shows the range of the data used to calibrate the soft-sensor, and the y-axis shows the percentage of data corresponding to the value presented in the x-axis. In addition to the online sensors located in several sections of the WWTP, autosamplers are installed at raw and treated wastewater sampling points to collect composite samples. The auto-samplers are programmed to collect 50 mL samples when the cumulative wastewater flow reaches 200 m 3 . The composite samples are then analyzed for TP and COD using standardized methods as described in [3]. TP is analyzed as a daily average (from 8:00 a.m. of every working day to 7:00 a.m. of the next working day) and COD is analyzed once every week as weekly averages (on Fridays). The mean and standard deviation of the influent and effluent TPI and COD along with the removal rates are presented in Table 1. The distribution of data obtained from online sensors (pH, TSS, Flowrate, conductivity, ORP, PAX and Polymer dose flow-meters) and the values measured using standardized lab measurements (TP and COD) for the year 2020-2021 are presented in Figure 2a,b. The x-axis shows the range of the data used to calibrate the soft-sensor, and the y-axis shows the percentage of data corresponding to the value presented in the x-axis.

Mathematical Modelling
Mathematical models based on a mechanistic understanding of the coagulation-flocculation process can be found in the literature [14]. The increase in data availability caused by the recent adoption of online monitoring in most WWTP resulted in the increased use of data-driven models to describe the coagulation-flocculation process. The basic structure of these models varies from easily interpretable statistical models such as PCA/PCR to complex models such as Artificial Neural Network (ANN), Support Vector Machines (SVM) or Ensemble Tree (ET). Multiple Linear Regression (MLR) is a commonly used data-driven modelling technique used to predict output variables using multiple independent predictors. Instances of MLR implementation to predict effluent wastewater quality are found in the literature [15]. The mathematical representation of the MLR model is presented in Equations (1)-(3). Ŷ = ( 1 , 2 , . . ) = 0 + 1 1 + 2 2 + ⋯ + + (1)

Mathematical Modelling
Mathematical models based on a mechanistic understanding of the coagulationflocculation process can be found in the literature [14]. The increase in data availability caused by the recent adoption of online monitoring in most WWTP resulted in the increased use of data-driven models to describe the coagulation-flocculation process. The basic structure of these models varies from easily interpretable statistical models such as PCA/PCR to complex models such as Artificial Neural Network (ANN), Support Vector Machines (SVM) or Ensemble Tree (ET). Multiple Linear Regression (MLR) is a commonly used data-driven modelling technique used to predict output variables using multiple independent predictors. Instances of MLR implementation to predict effluent wastewater quality are found in the literature [15]. The mathematical representation of the MLR model is presented in Equations (1)- (3). whereŶ is the predicted responses corresponding to the measured values Y, x i are the predictors, β are the model coefficients, and is model error. Non-linear dependencies between the response and the predictors are introduced in the model by including the square and interaction terms of x i as described in Equation (2). Several algorithms ranging from simple ordinary least square algorithm presented in Equation (3) to more complex stochastic algorithms [16] can be used to minimize the error between Y andŶ and obtain the optimal set of the regression coefficients (β).

Workflow of Soft Sensor Development
The steps involved in the processing of online sensor data and development of mathematical models for estimating TP and COD in the influent and effluent are presented in Figure 3. where Ŷ is the predicted responses corresponding to the measured values Y, are the predictors, are the model coefficients, and is model error. Non-linear dependencies between the response and the predictors are introduced in the model by including the square and interaction terms of as described in Equation (2). Several algorithms ranging from simple ordinary least square algorithm presented in Equation (3) to more complex stochastic algorithms [16] can be used to minimize the error between Y and Ŷ and obtain the optimal set of the regression coefficients ( ).

Workflow of Soft Sensor Development
The steps involved in the processing of online sensor data and development of mathematical models for estimating TP and COD in the influent and effluent are presented in Figure 3.

Step 1-Data Cleaning and Transformation
Data rich does not imply information rich [17]. In this context using noisy data ridden with outliers would result in inaccurate mathematical models, incapable of generating meaningful predictions. Therefore, data cleaning and outlier removal is the first and foremost stage before using online sensor data for model generation. Several outlier detection methods tailored to detect outliers in wastewater treatment processes can be found in the literature [18,19]. The moving window approach described in [19] was used to clean the data before using it for model calibration.

Step 2-Generate Influent TP and COD Model
The sensor layout of WWTP ( Figure 1) shows that the flowrate ( Q ), level in the influent channel ( LVL ), suspended solids ( SSI ), conductivity ( CNI ), ORP ( ORP ), and pH ( PHI ) of the raw wastewater are monitored online. From a mechanistic point of view, the particulate fraction of TP and COD varies proportionally to the TSS in the wastewater. Inverse dependencies between flowrate/level and TP/COD can be observed by comparing the average raw wastewater flowrate with the lab-measured values of TP and COD. The

Step 1-Data Cleaning and Transformation
Data rich does not imply information rich [17]. In this context using noisy data ridden with outliers would result in inaccurate mathematical models, incapable of generating meaningful predictions. Therefore, data cleaning and outlier removal is the first and foremost stage before using online sensor data for model generation. Several outlier detection methods tailored to detect outliers in wastewater treatment processes can be found in the literature [18,19]. The moving window approach described in [19] was used to clean the data before using it for model calibration.

Step 2-Generate Influent TP and COD Model
The sensor layout of WWTP ( Figure 1) shows that the flowrate (x Q ), level in the influent channel (x LVL ), suspended solids (x SSI ), conductivity (x CNI ), ORP (x ORP ), and pH (x PHI ) of the raw wastewater are monitored online. From a mechanistic point of view, the particulate fraction of TP and COD varies proportionally to the TSS in the wastewater. Inverse dependencies between flowrate/level and TP/COD can be observed by comparing the average raw wastewater flowrate with the lab-measured values of TP and COD. The inverse correlation can be explained by the fact that a sudden increase in raw wastewater flowrate is often caused by rainfall or snowmelt events that can dilute wastewater and reduce TP/COD concentrations. Several prior works found in the literature indicate a correlation between variations in conductivity [20], pH, ORP [21], and the soluble fractions of TP/COD. A linear combination of predictors influencing the soluble and particulate components of TP and COD would be an ideal choice of predictors for the model. Therefore, the influent raw wastewater quality parameters would be the best choice of independent predictors that can be used to correlate influent TP and COD values. An MLR model was developed for prediction COD and TP. The MLR model coefficients were generated using several model calibration algorithms as mentioned in [16]. The algorithm that showed the best fit between the lab-measured data was selected, and the functions were saved to be used in the next steps.

Step 3-Build Mass Balance Equations for TP and COD
A dynamic model was developed by conducting a material balance of TP and COD in the coagulation/sedimentation process. A generic form of the material balance equation used in modelling the effluent parameters is presented in Equation (4).
In Equation (4),ŷ OUT is the effluent COD/TP values andŷ IN is the influent TP/COD values. An n th order kinetics is used to model the TP/COD removal rates in the process. The rate constant r and the reaction order n can be determined by fitting the effluent wastewater quality data to the dynamic model. The holdup volume V for WWTP is calculated by conducting tracer tests and at different flowrates.

Step 4-Generate TP and COD Removal Models
Dosage of coagulant (x PAX ) and dosage of polymer (x POL ) are important control variables, used to adjust the removal efficiencies of solids and phosphates in WWTPs [13]. A positive correlation between the dosage of coagulant/flocculant and the removal percentages, substantiated with systematically designed jar tests, can be found in the literature [22]. The results of these jar tests are often used as a basis to determine the optimal dosage of coagulants and polymer. Most industrial coagulants have an optimal pH range beyond which a substantial reduction in removal percentages can be observed. Treatment plant operators also tune dosing control algorithms to ensure that the operating pH range is not crossed. Therefore, x clean, REM = x PAX x POL x PHO is chosen as predictor for the mathematical functions defining the removal rates r. The batch model calibration approach, involving minimization of a quadratic error function between estimated and lab-measured value, is a commonly used technique for estimating parameters of dynamic models built using mass balance and reaction kinetics [23,24]. The parameter estimation method explained in [15] was used as a basis to construct the dynamic optimization problem.

Step 5-Save MLR Models/Coefficients
The coefficients of the MLR model developed for both the influent and for removal rates are saved in a structured form which can be later used for real time deployment.

Software Packages
The open-source programming language Python (www.python.org) accessed on 18 December 2021 was used to process the raw sensor data, generate mathematical models, and deploy algorithms for real-time estimation. The open-source BSD-licensed library, pandas, version 1.3 (https://pandas.pydata.org/) accessed on 18 December 2021, was used to clean and condition raw data and generate concurrent datasets of the same timestamp. Scikit-learn, a free Python library (https://scikit-learn.org/) accessed on 18 December 2021 provides several algorithms to train MLR models and obtain the regression coefficients β described in Equation (1). The dynamic optimization problem (mentioned in step 4) was implemented in Python and solved using the optimization algorithms provided as a part of Python's open-source SciPy library (https://scipy.org/) accessed on 18 December 2021. The 'scipy.optimize' package provides a multitude of algorithms that can be used for solving unconstrained optimization problems. In this work, four different optimization solving algorithms, a. Nelder-Mead (NM) [25], b. Trust-region Newton conjugate gradient (TR) [26], c. Sequential Least Squares Quadratic Programming (SLSQP) [27], and d. Broyden-Fletcher-Goldfarb-Shanno (BFGS) [28] were used separately, and the results were assessed based on the regression fit and the time required by the optimization solver to converge to an optimal solution. A generic version of the script that can be used to calibrate the model can be downloaded from the github repository (https://github.com/abhilash2134/MLR-Model.git) accessed on 21 January 2022.

Soft Sensor Deployment
A multitude of options for the deployment of soft sensor scripts and control algorithms are available in the market today. The deployment methods vary from direct implementation of scripts in a PLC/microcontroller/PC (edge computing) [29], or remote nonintrusive implementation presented in [30] using either cloud services or own infrastructure. In this paper, a more secure and robust version of the non-intrusive soft sensor deployment strategy discussed in [30] was used as a basis to build the IIoT infrastructure of DOSMON. An overview of the IIoT architecture of DOSMON used to acquire telemetry data from field devices and deploy the soft sensor algorithms in real-time is presented in Figure 4. to clean and condition raw data and generate concurrent datasets of the same timestamp. Scikit-learn, a free Python library (https://scikit-learn.org/) accessed on 18 December 2021 provides several algorithms to train MLR models and obtain the regression coefficients described in Equation (1). The dynamic optimization problem (mentioned in step 4) was implemented in Python and solved using the optimization algorithms provided as a part of Python's open-source SciPy library (https://scipy.org/) accessed on 18 December 2021. The 'scipy.optimize' package provides a multitude of algorithms that can be used for solving unconstrained optimization problems. In this work, four different optimization solving algorithms, a. Nelder-Mead (NM) [25], b. Trust-region Newton conjugate gradient (TR) [26], c. Sequential Least Squares Quadratic Programming (SLSQP) [27], and d. Broyden-Fletcher-Goldfarb-Shanno (BFGS) [28] were used separately, and the results were assessed based on the regression fit and the time required by the optimization solver to converge to an optimal solution. A generic version of the script that can be used to calibrate the model can be downloaded from the github repository (https://github.com/abhi-lash2134/MLR-Model.git) accessed on 21 January 2022.

Soft Sensor Deployment
A multitude of options for the deployment of soft sensor scripts and control algorithms are available in the market today. The deployment methods vary from direct implementation of scripts in a PLC/microcontroller/PC (edge computing) [29], or remote nonintrusive implementation presented in [30] using either cloud services or own infrastructure. In this paper, a more secure and robust version of the non-intrusive soft sensor deployment strategy discussed in [30] was used as a basis to build the IIoT infrastructure of DOSMON. An overview of the IIoT architecture of DOSMON used to acquire telemetry data from field devices and deploy the soft sensor algorithms in real-time is presented in Figure 4. The backend of DOSMON core mainly consists of two servers. The primary server is used for the acquisition and storage of data from the IoT devices and Lab Information Management System (LIMS) software (database server), while the secondary server is used for running the soft sensor algorithms (algorithm server). The communication and data exchange between algorithm and data server is established using DOSMON's REST API. The algorithm server pulls the raw sensor telemetry from the data server and pushes The backend of DOSMON core mainly consists of two servers. The primary server is used for the acquisition and storage of data from the IoT devices and Lab Information Management System (LIMS) software (database server), while the secondary server is used for running the soft sensor algorithms (algorithm server). The communication and data exchange between algorithm and data server is established using DOSMON's REST API. The algorithm server pulls the raw sensor telemetry from the data server and pushes algorithm results back to the data server. The software architecture presented in Figure 4 allows us to have reliable and robust IoT communication and dedicated computing power for executing soft sensor algorithms. The IIoT architecture also allows us to manage changes in the algorithms and tune model parameters a minimal downtime at the plan.
The MLR models developed using the methods described in Section 2.3 are stored using the 'pickle' functionality of Python. The pickled models simplify the model parameter storage as we do not have to create our own data storage formats. These models can be created in any Python environment, both offline and online, and can be loaded in the deployment stage.

Model Calibration Results
Real-time data from the online sensors were obtained from the treatment plant's SCADA system and lab-measured values of TP and COD were obtained from LIMS software. Online and lab-measured data for a period of 12 months (from 10 April 2020 to 10 April 2021) are used to calibrate the model and obtain the MLR model coefficients. The results of model calibration showing a comparison between the model predicted and labmeasured values are presented in Figure 5. The plots also show the mean-square error (MSE) and the Pearson correlation coefficient (R 2 ) for the models calibrated using the four different calibration algorithms mentioned in Section 2.4. The slope and intercept of the regression line are also presented in the Figure 2 plots. The scatter plot of a perfect prediction model would be a 45-degree line with a slope = 1 and intercept = 0 and an R 2 value of 1. A quantitative assessment of different prediction models is conducted by comparing the values of R 2 and regression line equations. algorithm results back to the data server. The software architecture presented in Figure 4 allows us to have reliable and robust IoT communication and dedicated computing power for executing soft sensor algorithms. The IIoT architecture also allows us to manage changes in the algorithms and tune model parameters a minimal downtime at the plan. The MLR models developed using the methods described in Section 2.3 are stored using the 'pickle' functionality of Python. The pickled models simplify the model parameter storage as we do not have to create our own data storage formats. These models can be created in any Python environment, both offline and online, and can be loaded in the deployment stage.

Model Calibration Results
Real-time data from the online sensors were obtained from the treatment plant's SCADA system and lab-measured values of TP and COD were obtained from LIMS software. Online and lab-measured data for a period of 12 months (from 10 April 2020 to 10 April 2021) are used to calibrate the model and obtain the MLR model coefficients. The results of model calibration showing a comparison between the model predicted and labmeasured values are presented in Figure 5. The plots also show the mean-square error (MSE) and the Pearson correlation coefficient ( 2 ) for the models calibrated using the four different calibration algorithms mentioned in Section 2.  The plots presented in Figure 5a as well as a comparison between correlation coefficients ( 2 and MSE) show minimal difference between the results obtained with all four algorithms. However, the model coefficient obtained by the Ridge algorithm shows relatively better results with ( 2 = 0.86 and MSE = 0.81) as compared to an 2 = 0.82 for OLS algorithm, 2 = 0.83 for LAR, and 2 = 0.84 for BR algorithm. Similar results are observed in Figure 5b which shows a comparison between predicted and lab measured values of different algorithms used to obtain MLR model coefficients for influent COD. The Ridge algorithm showed an 2 of 0.72 compared to a value of 0.70 for LAR, 0.52 for BR, and 0.71 for OLS. The regression line for the Ridge algorithm (for influent TP) showed a slope of 0.97 and an intercept of 0.08 which ensures a random distribution of error along the ideal prediction line. The slope and intercept value close to the ideal prediction line of y = x also shows that MLR model coefficients obtained using Ridge algorithm has a comparatively better model fit. Therefore, the model coefficients obtained by the Ridge algorithm is deployed in DOSMON's algorithm server for real-time estimation of influent TP and COD.
The plots presented in 5b as well as the metrics presented in Table 2 show that model calibration using SLSPQ and NM algorithms provides better results compared to BFGS and TR algorithms. A faster convergence to an optimal solution is observed in the NM algorithm compared to the other three algorithms. However, the minima obtained by the SLSPQ algorithm shows a better fit ( 2 = 0.76) compared to the other three algorithms, with 2 values of 0.35 for TR, 0.71 for NM, and 0.63 for BFGS algorithm. Along with an 2 value close to 1, the model obtained from the SLSPQ algorithm also presents a slope and intercept value of 0.79 and 0.01, respectively, which is closer to the ideal prediction line (with a slope = 1 and intercept = 0) compared to the NM, TR and BFGS algorithms. Slower convergence of the minimization algorithm implies a higher computational requirement to solve the optimization problem. The solver time presented in Table 2 also shows a significant increase in solver time of 18.4 h for the SLSPQ algorithm compared to The plots presented in Figure 5a as well as a comparison between correlation coefficients (R 2 and MSE) show minimal difference between the results obtained with all four algorithms. However, the model coefficient obtained by the Ridge algorithm shows relatively better results with (R 2 =0.86 and MSE = 0.81) as compared to an R 2 =0.82 for OLS algorithm, R 2 =0.83 for LAR, and R 2 =0.84 for BR algorithm. Similar results are observed in Figure 5b which shows a comparison between predicted and lab measured values of different algorithms used to obtain MLR model coefficients for influent COD. The Ridge algorithm showed an R 2 of 0.72 compared to a value of 0.70 for LAR, 0.52 for BR, and 0.71 for OLS. The regression line for the Ridge algorithm (for influent TP) showed a slope of 0.97 and an intercept of 0.08 which ensures a random distribution of error along the ideal prediction line. The slope and intercept value close to the ideal prediction line of y = x also shows that MLR model coefficients obtained using Ridge algorithm has a comparatively better model fit. Therefore, the model coefficients obtained by the Ridge algorithm is deployed in DOSMON's algorithm server for real-time estimation of influent TP and COD.
The plots presented in 5b as well as the metrics presented in Table 2 show that model calibration using SLSPQ and NM algorithms provides better results compared to BFGS and TR algorithms. A faster convergence to an optimal solution is observed in the NM algorithm compared to the other three algorithms. However, the minima obtained by the SLSPQ algorithm shows a better fit (R 2 = 0.76) compared to the other three algorithms, with R 2 values of 0.35 for TR, 0.71 for NM, and 0.63 for BFGS algorithm. Along with an R 2 value close to 1, the model obtained from the SLSPQ algorithm also presents a slope and intercept value of 0.79 and 0.01, respectively, which is closer to the ideal prediction line (with a slope = 1 and intercept = 0) compared to the NM, TR and BFGS algorithms. Slower convergence of the minimization algorithm implies a higher computational requirement to solve the optimization problem. The solver time presented in Table 2 also shows a significant increase in solver time of 18.4 h for the SLSPQ algorithm compared to 9.1 h for the NM algorithm. Therefore, the use of the NM algorithm is preferred in situations with limits in computational resources or circumstances where frequent recursive calibration of MLR models is required [20]. As computation power and recalibration of the MLR models were not an issue in this study, the results which provided the lowest values of MSE were deployed in real-time for estimating effluent TP and COD values.

GUI for Visualizing Soft Sensor Data in DOSMON
The 'Dashboard Designer' provided as a part of the DOSMON core (shown in Figure 4) can be used to build dashboards for visualizing data on dial-gauge widgets, trend curves, or layout maps. A user-friendly dashboard was created to visualize the values estimated by the soft sensor deployed in the algorithm server. DOSMON also provides the possibility of downloading the raw data from the web interface that can be used for further data analysis and validations. The interactive interface allows the selection of a desired timescale to visualize both real-time and historical data. A snapshot of the dashboard's front-end page showing both the estimated and the lab-measured data is presented in Figure 6.
Water 2022, 14, x FOR PEER REVIEW 10 of 17 9.1 h for the NM algorithm. Therefore, the use of the NM algorithm is preferred in situations with limits in computational resources or circumstances where frequent recursive calibration of MLR models is required [20]. As computation power and recalibration of the MLR models were not an issue in this study, the results which provided the lowest values of MSE were deployed in real-time for estimating effluent TP and COD values.

GUI for Visualizing Soft Sensor Data in DOSMON
The 'Dashboard Designer' provided as a part of the DOSMON core (shown in Figure  4) can be used to build dashboards for visualizing data on dial-gauge widgets, trend curves, or layout maps. A user-friendly dashboard was created to visualize the values estimated by the soft sensor deployed in the algorithm server. DOSMON also provides the possibility of downloading the raw data from the web interface that can be used for further data analysis and validations. The interactive interface allows the selection of a desired timescale to visualize both real-time and historical data. A snapshot of the dashboard's front-end page showing both the estimated and the lab-measured data is presented in Figure 6. The dashboard designed for visualizing soft sensor data shows real-time estimated values of TP and COD, and NH (currently in the development stage and is not validated) as dial-gauge widgets in the bottom right corner. The dashboard also displays three timeseries plots showing the mean real-time estimate (of TP influent, TP effluent and TP removal percentage) as discrete red circles along with the upper and lower limits of prediction error as continuous blue lines. The default timescale of the dashboard is three days, which can be changed manually by the end-user. The lab-measured value of TP influent and TP effluent obtained daily from the treatment plants LIMS software is also provided as discrete purple points in the time-series plots. A guest user account, to access and visualize the live dashboard shown in Figure 6, can be provided on request.

Soft Sensor Validation Results
The soft sensor estimations of the influent and effluent TP/COD were monitored for four months (from 15 April 2021 to 18 August 2021). A comparison between the values estimated by the soft sensor along with the prediction error (calculated according to the method described in [31]) and the lab-measured values are presented in Figure 7. The dashboard designed for visualizing soft sensor data shows real-time est values of TP and COD, and NH (currently in the development stage and is not vali as dial-gauge widgets in the bottom right corner. The dashboard also displays thre series plots showing the mean real-time estimate (of TP influent, TP effluent and moval percentage) as discrete red circles along with the upper and lower limits of p tion error as continuous blue lines. The default timescale of the dashboard is three which can be changed manually by the end-user. The lab-measured value of TP in and TP effluent obtained daily from the treatment plants LIMS software is also pro as discrete purple points in the time-series plots. A guest user account, to access a ualize the live dashboard shown in Figure 6, can be provided on request.

Soft Sensor Validation Results
The soft sensor estimations of the influent and effluent TP/COD were monito four months (from 15 April 2021 to 18 August 2021). A comparison between the estimated by the soft sensor along with the prediction error (calculated according method described in [31]) and the lab-measured values are presented in Figure 7.  The discrete red points in Figure 7 represent values measured using standardized lab tests, and the continuous blue lines show daily averages of the values estimated by the soft sensor. The discrete blue points show the mean estimated values, and the error bar shows the prediction error of the soft sensor. The plots in Figure 7 show that the soft sensor estimates follow similar trends compared to the lab-measured values. It can be observed that about 90% of the actual lab measured values lie within the prediction limits of the soft sensor estimates. A few distinct inaccuracies in estimation values are observed in the influent TP estimation when the lab-measured values are above 12 mg/L. A possible reason for the reduction in prediction accuracy could be the insufficiency of data points in the range TP > 12 mg/L used to calibrate the influent MLR model. The discrete red points in Figure 7 represent values measured using standardized lab tests, and the continuous blue lines show daily averages of the values estimated by the soft sensor. The discrete blue points show the mean estimated values, and the error bar shows the prediction error of the soft sensor. The plots in Figure 7 show that the soft sensor estimates follow similar trends compared to the lab-measured values. It can be observed that about 90% of the actual lab-measured values lie within the prediction limits of the soft sensor estimates. A few distinct inaccuracies in estimation values are observed in the influent TP estimation when the lab-measured values are above 12 mg/L. A possible reason for the reduction in prediction accuracy could be the insufficiency of data points in the range TP > 12 mg/L used to calibrate the influent MLR model.
The accuracy of the soft sensor estimations can be further substantiated with the plots presented in Figure 8, where a comparison between estimated and lab-measured values along with the perfect prediction line and R 2 values are presented. An R 2 value of 0.81 for TP inlet, 0.73 for TP effluent, 0.76 for COD inlet, and 0.69 for COD effluent shows that a reasonable estimation of wastewater quality parameters in both influent and effluent streams can be achieved using the hybrid soft sensor. It can be observed that TP estimations have a lower prediction error and a better correlation coefficient (R 2 = 0.81) compared to COD (R 2 = 0.72). This is most likely due to the difference in the number of data points used in calibrating the MLR models for TP and COD. The daily measurements of TP provided a higher number of data points (283 data points) as compared to the weekly average values (51 data points) available for calibrating the MLR model for COD.
Evaluating a soft-sensor algorithm in a full-scale WWTP is especially challenging compared to simulator-based evaluation or pilot-scale testing. Full-scale treatment facilities are subjected to a wide range of unpredicted diurnal and season fluctuations. A better control (or even prior knowledge) of influent disturbances is available while evaluating soft sensor algorithms in a simulator or a pilot-scale unit. The uncertainties in influent disturbances, inherent to a full-scale treatment plant, provide an excellent platform to assess the robustness of the soft sensor algorithm. A comparison between the lab-measured and estimated values presented in Figures 6-8   Evaluating a soft-sensor algorithm in a full-scale WWTP is especially challenging compared to simulator-based evaluation or pilot-scale testing. Full-scale treatment facilities are subjected to a wide range of unpredicted diurnal and season fluctuations. A better control (or even prior knowledge) of influent disturbances is available while evaluating soft sensor algorithms in a simulator or a pilot-scale unit. The uncertainties in influent disturbances, inherent to a full-scale treatment plant, provide an excellent platform to assess the robustness of the soft sensor algorithm. A comparison between the lab-measured and estimated values presented in Figures 6-8 shows the ability of the soft sensor to consistently deliver reliable estimates of both influent and effluent TP/COD values even in the presence of the disturbances of a full-scale treatment facility.

Benefits of Using a Dynamic Model for Estimating Effluent Wastewater Quality Parameters
The soft sensor development workflow, presented in Section 2.3, shows a difference between the approaches used to develop influent and effluent estimation models. While a conventional MLR model correlating the TP/COD values to their corresponding online sensor data was used for influent wastewater quality parameters, a dynamic model was used for the effluent wastewater quality parameters. A few case studies presenting the estimation of effluent wastewater quality parameters using data-driven soft sensors are found in the literature [32][33][34]. These case studies show that it is possible to develop a statistically significant correlation between effluent TP/COD and their corresponding online sensor data. Correlation coefficients of 2 = 0.72 and MSE = 0.013 for effluent TP and 2 = 0.62 and MSE = 15.5 for effluent COD were obtained when the daily/weekly averaged values of flowrate, effluent suspended solids effluent, PAX/Polymer dosage, and pH (after dosing) were correlated to the lab-measured effluent TP and COD values. However, several issues were encountered while deploying the effluent MLR models in

Benefits of Using a Dynamic Model for Estimating Effluent Wastewater Quality Parameters
The soft sensor development workflow, presented in Section 2.3, shows a difference between the approaches used to develop influent and effluent estimation models. While a conventional MLR model correlating the TP/COD values to their corresponding online sensor data was used for influent wastewater quality parameters, a dynamic model was used for the effluent wastewater quality parameters. A few case studies presenting the estimation of effluent wastewater quality parameters using data-driven soft sensors are found in the literature [32][33][34]. These case studies show that it is possible to develop a statistically significant correlation between effluent TP/COD and their corresponding online sensor data. Correlation coefficients of R 2 = 0.72 and MSE = 0.013 for effluent TP and R 2 = 0.62 and MSE = 15.5 for effluent COD were obtained when the daily/weekly averaged values of flowrate, effluent suspended solids effluent, PAX/Polymer dosage, and pH (after dosing) were correlated to the lab-measured effluent TP and COD values. However, several issues were encountered while deploying the effluent MLR models in the algorithm servers for real-time estimations. The estimation error was particularly visible for effluent TP, where the soft sensors estimated values that were mechanistically impossible to attain. The estimated values frequently showed as negative effluent TP values or effluent TP being higher than influent TP. The frequent extremities of the estimated TP and COD values can be dealt with by implementing an averaging filter, by imposing min-max limits, or by integrating conditional loops limiting the TPO to always be below TPI estimates. However, these constraints failed to achieve a general smoothness in the TP and COD estimations in the effluent. A comparison between the effluent TP estimated by the conventional MLR model versus the dynamic model is presented in Figure 9.
possible to attain. The estimated values frequently showed as negative effluent TP values or effluent TP being higher than influent TP. The frequent extremities of the estimated TP and COD values can be dealt with by implementing an averaging filter, by imposing minmax limits, or by integrating conditional loops limiting the TPO to always be below TPI estimates. However, these constraints failed to achieve a general smoothness in the TP and COD estimations in the effluent. A comparison between the effluent TP estimated by the conventional MLR model versus the dynamic model is presented in Figure 9. The dynamic model used to estimate the effluent wastewater quality parameters are based on the mass balance of TP/COD in the coagulation-flocculation process. An n-order kinetics is assigned to the removal term to ensure that the TP/COD removal decreases significantly when the estimated values reach a value close to 0. This mathematical constraint prevents the estimated values of effluent TP and COD from dropping to negative values. It should also be noted that the estimated values of influent TP and COD are included in the dynamic model, which ensures that the effluent TP and COD values are lower than their influent values. The concept of integrating mechanistic and data-driven techniques in the soft sensor algorithm has resulted in a significant improvement in the estimated effluent values. The improvement in effluent TP estimation can be observed in the plots presented in Figure 9, where during the first 15 days (15 April 2021-5 May 2021), the soft sensor used the MLR model to estimate TP values, after which (from 5 May 2021 onwards) the estimator algorithm switched to the dynamic model. The rapid variations in the estimated TP values (sudden jumps between the upper limits of 1.6 mg/L and the lower limit of 0.1 mg/L) frequently occurring in the first 15 days are non-existent after the soft-sensor algorithm switches to the dynamic model.

Limitations of Hybrid Estimator and Possible Improvements
The hybrid soft sensor developed in this work uses the daily average value of TP and weekly averages of COD to calibrate the regression models. Although the soft-sensor algorithm has demonstrated a reasonably accurate estimation of the average TP and COD values during the validation stage, the estimation accuracies of their diurnal variations were not validated. The variations observed in estimated TP and COD values are due to the diurnal variations in the predictors (flowrate, suspended solids, conductivity, and pH) included in the estimation model. However, the possibility of a mismatch between the actual TP/COD values and values estimated by the soft sensor cannot be completely ruled out. The dynamic model used to estimate the effluent wastewater quality parameters are based on the mass balance of TP/COD in the coagulation-flocculation process. An n-order kinetics is assigned to the removal term to ensure that the TP/COD removal decreases significantly when the estimated values reach a value close to 0. This mathematical constraint prevents the estimated values of effluent TP and COD from dropping to negative values. It should also be noted that the estimated values of influent TP and COD are included in the dynamic model, which ensures that the effluent TP and COD values are lower than their influent values. The concept of integrating mechanistic and data-driven techniques in the soft sensor algorithm has resulted in a significant improvement in the estimated effluent values. The improvement in effluent TP estimation can be observed in the plots presented in Figure 9, where during the first 15 days (15 April 2021-5 May 2021), the soft sensor used the MLR model to estimate TP values, after which (from 5 May 2021 onwards) the estimator algorithm switched to the dynamic model. The rapid variations in the estimated TP values (sudden jumps between the upper limits of 1.6 mg/L and the lower limit of 0.1 mg/L) frequently occurring in the first 15 days are non-existent after the soft-sensor algorithm switches to the dynamic model.

Limitations of Hybrid Estimator and Possible Improvements
The hybrid soft sensor developed in this work uses the daily average value of TP and weekly averages of COD to calibrate the regression models. Although the soft-sensor algorithm has demonstrated a reasonably accurate estimation of the average TP and COD values during the validation stage, the estimation accuracies of their diurnal variations were not validated. The variations observed in estimated TP and COD values are due to the diurnal variations in the predictors (flowrate, suspended solids, conductivity, and pH) included in the estimation model. However, the possibility of a mismatch between the actual TP/COD values and values estimated by the soft sensor cannot be completely ruled out.
A possible solution to improve the soft sensor is to increase the time-resolution of the lab-measured data used in calibrating the MLR models. A rigorous sampling campaign should be conducted where composite samples are collected once or twice every hour to measure TP and COD concentrations. This hourly (or half-hourly) data can provide a better insight into the diurnal variations in wastewater quality parameters at the influent and the effluent. The MLR models calibrated using these high time-resolution lab measured data can better capture diurnal variations and subsequently improve the estimation results.

Conclusions
An alternative cost-effective method for monitoring essential wastewater quality parameters such as TP and COD in a full-scale wastewater treatment plant was tested and validated in this work. The secure, non-intrusive, cost-effective system enables the codes written in scientific programming languages such as Python to be deployed for real-time estimation. The results presented in this work demonstrates that MLR models can be used to develop statistically significant correlations between online sensor data and wastewater quality parameters such as TP and COD. Among various different algorithms used to calibrate the MLR models, the Ridge algorithm showed the best model fit for the influent TP/COD, while the SLSQP algorithm provided the best fit for the removal model used to estimate effluent TP/COD values. Hybrid models combining mechanistic elements with data-driven techniques have shown better prediction accuracy compared to purely blackbox models. The systematic approach presented in the work can be further expanded to estimate additional wastewater quality parameters (nitrogen, VFA, etc.) provided adequate lab-measured values are available. The IIoT architecture described in this work presents a seamless infrastructure to deploy, modify, and tune soft sensors in a full-scale treatment plant without causing any operational downtime.