Computer ‐ Aided Nonlinear Frequency Response Method for Investigating the Dynamics of Chemical Engineering Systems

: The Nonlinear Frequency Response (NFR) method is a useful Process Systems Engineering tool for developing experimental techniques and periodic processes that exploit the system nonlinearity. The basic and most time ‐ consuming step of the NFR method is the derivation of frequency response functions (FRFs). The computer ‐ aided Nonlinear Frequency Response (cNFR) method, presented in this work, uses a software application for automatic derivation of the FRFs, thus making the NFR analysis much simpler, even for systems with complex dynamics. The cNFR application uses an Excel user ‐ friendly interface for defining the model equations and variables, and MATLAB code which performs analytical derivations. As a result, the cNFR application generates MATLAB files containing the derived FRFs in a symbolic and algebraic vector form. In this paper, the software is explained in detail and illustrated through: (1) analysis of periodic operation of an isothermal continuous stirred ‐ tank reactor with a simple reaction mechanism, and (2) experimental identification of electrochemical oxygen reduction reaction.


Introduction
Knowledge about process dynamics is crucial in chemical engineering, as well as in other engineering fields. One of the particularly useful tools for investigating process dynamics is frequency response (FR) [1][2][3][4][5][6][7]. FR is a response of the investigated system to sinusoidal input modulation and it enables defining a convenient model form in the frequency domain, usually called frequency transfer function or frequency response function [8]. As a rule, the frequency transfer function is a linear model and can be used only for linear systems. On the other hand, the great majority of real systems are nonlinear, so nonlinear tools are necessary for their analysis. One such tool is the nonlinear frequency response method, which is used in this paper.
In our research, we use the term nonlinear frequency response (NFR) for a quasi-steady-state (often called periodic steady-state) response of a stable, weakly nonlinear system to a sinusoidal input change with a relatively high amplitude [9]. The quasi-steady-state response is obtained when the transient response of the system vanishes and it can be described as a sum of the first (basic) and, theoretically, an infinite number of higher harmonics, a nonperiodic (i.e., constant-in-time) term (DC component) and the steady-state operation value ( Figure 1). For linear systems, or when the forcing amplitude is sufficiently small, both the DC component and all higher harmonics become zero.
In our investigations, we are using the NFR method based on the concept of higher-order frequency response functions (FRFs) [9]. This approach is mathematically based on the Volterra series [10] and multidimensional Fourier transform [11]. Thus, it can be applied only on systems that can be represented with convergent Volterra series [12]. Another limitation is that the analyzed systems must be stable with no multiple steady states [13], and weakly nonlinear [9], for which all nonlinear terms can be expressed as Taylor series expansions. In other words, all terms in the model equations must be continuous and differentiable functions [9].
The NFR method replaces the nonlinear dynamic model of a weakly nonlinear system with a set of FRFs of the first, second, and higher orders [9,14]. For an exact representation of the nonlinear model, an infinite sequence of FRFs would be needed, but approximations using only the first and second, or eventually third-order FRFs have shown very good results [15][16][17][18][19][20][21][22][23][24][25][26][27][28][29]. The NFR method has been proven to be an excellent analytical process systems engineering (PSE) tool for analyzing nonlinear dynamic systems in the field of chemical engineering. Our research using the NFR analysis was developed in three main directions: 1. Developing experimental techniques for investigating process equilibrium and kinetics and estimating the related parameters.
2. Developing a computational method for direct prediction of the periodic steady-state of cyclic processes.
This approach was used for predicting the complete temporal profiles of the process variables in the periodic steady-state, for inherent periodic processes which can be operated only in the periodic mode (usually called cyclic processes), such as adsorption cycles [18]. The process variables are computed using the previously derived theoretical FRFs and all computations are performed in the frequency domain, using only simple algebra. In this way, numerical solutions of the nonlinear model equations, which can be long and tedious, especially for slow systems with long transient times, are avoided. The method is analytical and essentially approximate, as only a finite number of FRFs of the analyzed system are used. Nevertheless, it was shown that even predictions based only on the first three FRFs showed reasonably good agreement with numerical simulations [18].
3. Developing a method for fast and easy evaluation of possible enhancement of process performances through forced periodic modulations of the system inputs.
This method uses the NFR analysis for predicting the time-average values of the process outputs of interest in the periodic steady-state, which are directly related to the DC component shown in Figure 1. This method is also analytical and essentially approximate, but it was shown that very good predictions of the time-average behavior in the periodic steady-state can be obtained by using only the asymmetrical second-order FRFs [20,[25][26][27][44][45][46][47][48][49][50][51]. Up to now, the applications were limited to the analysis of periodically operated chemical reactors. The method was successfully applied to isothermal [20,25,50] and nonisothermal [26,27,[45][46][47][48] reactors, with one [20,26,27,50] or two [25,[45][46][47][48] modulated inputs, for sinusoidal [20,25,26,45,46,48,50,51] or any other shapes [47,52] of the modulated inputs. In addition to the answer whether the periodic operation can be superior to the corresponding steady-state operation, the NFR analysis enables finding the best set of input forcing parameters (frequency, amplitudes, and phase difference in the case of two inputs) for the chosen performance criteria, e.g., conversion, yield, selectivity, etc. [44].
All these applications are based on theoretical FRFs which need to be derived from a relevant nonlinear dynamic model. The procedure for derivation of the theoretical FRFs is clear, well established, and documented in a number of our previous publications [18,[20][21][22]53]. It is schematically shown in Figure 2. Most of the steps shown in Figure 2 are self-explanatory. In Step 5, harmonic probing is performed by collecting all terms of the same frequency and power of the input amplitude and equating them to zero. This is a crucial step in which the analysis is transferred from time-to frequency domain and the set of nonlinear ODEs is replaced by a larger set of linear algebraic equations.
The following notation for the FRFs is used in Figure 2 and throughout this paper: , the first-order FRF relating output and input , , , the second-order FRFs relating output and input and , , the cross second-order FRF relating output to inputs and .
In most cases, it is convenient to define the inputs and outputs in a dimensionless form, as relative deviations from their steady-state values: As a consequence, the derived FRFs are also dimensionless, as well as the input amplitudes which are always in the range between 0 and 1.
In Figure 2 the procedure is shown in detail for the derivation of the FRFs up to the second order. Nevertheless, it can easily be extended to the derivation of higher-order FRFs. The derivation procedure is recursive (the first-order FRFs are derived first, then the second-order FRFs, etc.) [14,20].
Although this procedure does not use any sophisticated mathematical tools, the derivation of the analytical expressions of the FRFs requires time, diligence, and specific mathematical skills from the user, especially for complex systems defined with large sets of differential equations and with several input/output combinations that need to be considered.
This work presents an advancement of the NFR method, the so-called computer-aided Nonlinear Frequency Response (cNFR), which uses a user-friendly software application for automatic derivation of the needed FRFs. The application will be explained in detail and its use illustrated in two examples.

Software Application for Computer-Aided Nonlinear Frequency Response Method
The structure of software application for the computer-aided Nonlinear Frequency Response (cNFR) method for automatic derivation of the needed FRFs, which upgraded our previously developed Nonlinear Frequency Response (NFR) method, is shown in Figure 3. The application consists of two linked segments: an Excel template which serves as a user interface and a MATLAB 2019b (MathWorks, Natick, MA, USA) program that performs the symbolic mathematical computations executing the derivation procedure shown in Figure 2 (Section 1). The cNFR Excel interface consists of two different windows. The cNFR Main Window (shown in Figure 4) is used for defining the model equations, the modulated inputs, the outputs of interest, as well as all system variables and model parameters. In the current version, the model equations need to be defined as a set of ODEs and algebraic equations. In the case of distributed parameter systems (described by sets of PDEs), the model PDEs need to be discretized before using the cNFR application.
The following general form of the model equations was chosen ( Figure 4): where is the total number of equations (same as the total number of all possible outputs ), is the maximal number of exponential terms, while , , , , , and are, in principle, rational functions of time, input, and output variables, defined for each equation . All this information is supplied by the user on the left-hand side of the cNFR interface Main Window, shown in Figure 4. The parameter is inserted as one function-term, while parameters , , , , and , are inserted as vectors of function-terms. In a system with model equations, all differential terms of equation must be separated by commas or spaces and defined in each , field as a vector. If there are no differential terms in the balance equation, the user can just insert one zero. Analogously, if different exponential terms are present in the balance equation , then all of these terms have to be defined in the same fashion as the differential terms, separated by commas or spaces, in the corresponding , and , vector fields. How the parameters , , , , and , are defined in practice will be demonstrated in two examples in Section 3. Additionally, the user can choose to perform analysis with a dimensionless time, by setting a parameter which defines the relation between dimensional ( ) and dimensionless time ( ) as: If 1, the dimensional time is assumed. It should be noted that the choice of the parameter reflects on the dimensions of the frequency which is the independent variable for the derived FRFs. For dimensional time ( 1), the corresponding frequency is dimensional, (e.g., rad/s or rad/min). On the other hand, if nondimensional time is used, the corresponding frequency will also be nondimensional, . On the right-hand side of the cNFR Main Window (Figure 4), the user defines the input variables, , and the output variables, . The order ( ) of defining output variables must match the order of elements in vector , , and vice versa. The inputs and outputs are inserted in their original, dimensional form. The cNFR application automatically transforms them into dimensionless form (as relative deviations from their steady-state values, according to Equation (1)). It is not necessary to declare explicitly other variables, constants, and parameters in the Main Window, as the cNFR application will define all used symbols automatically in the complex domain. However, if the parameters are declared, they are treated as real values, which can be useful and potentially shorten the computing time for the automatic procedure of FRF derivation.
The cNFR interface also allows the user to define some additional settings, including specifications of the information to be generated by the cNFR application. In the Navigation Window, which is part of Main Window (Figure 4), the user can click on the following seven navigation buttons: (1) Order of Derivation, (2) Project Name, (3) Balance Equations (4) Inputs, (5) Outputs, (6) General Settings, and (7) Optional Settings. Clicking on these buttons will quickly navigate the user to the corresponding fields to be filled.
By clicking on "General and Optional Settings", or "Order of Derivation" button, the user is transferred to the Settings Window, shown in Figure 5. In the Settings Window, the user can choose to derive the DC components and the optimal amplitudes and phase angle for the chosen output of interest. Also, the user can select whether the cNRF application will automatically generate files for matrices, FRFs, and the characteristic equation. The only mandatory field in the Settings Window is the "Maximal Order of FRF" which defines the order up to which the cNFR application will derive the FRFs. At the bottom of the Settings Window the user can see the Legend Window ( Figure 6) that explains the names of the matrix and FRF files automatically generated by the cNFR application, along with some examples. The file generated for matrices contains FRFs of all outputs defined ( Figure 4) and -th input. E.g., matrix file name G1_xi would contain the matrix with the first-order FRFs of all outputs for modulation of the -th input variable. On the other hand, FRF file names contain only one FRF for a -th output and -th input. In systems with a very large number of output variables, it is convenient and faster to create only files for matrices instead of • number of files for FRFs, as all necessary FRFs can be easily withdrawn from the matrices. After filling the necessary fields, the user can start the derivation by running the MATLAB code (step two shown in Figure 3). The code reads the user-supplied data and performs the automatic derivation of the FRFs and further computations which give insight into the system dynamics.
MATLAB Symbolic Math Toolbox is used for variable creation, the transformation of the variables into dimensionless form, Taylor series expansion, creation of the Volterra series of all outputs, symbolic substitutions, harmonic probing, solving the systems of equations, deriving the FRFs, and generating the characteristic equation (essentially for all derivation steps defined in Figure  2, Section 1). All derived functions are recorded in symbolic form, as well as in an optimized vector form through automatically generated MATLAB function files. These function files can be used for fast simulations and rapid rigorous optimizations. By simplifying the procedure shown in Figure 2 (Section 1) through automation, further computations, and simulation-ready file creation, the NFR method becomes user-friendly and easy-to-apply in a fast manner, even for complex systems.
The use of the cNFR application, its verification, and functionality will be demonstrated in two cases: (1) isothermal continuous stirred-tank reactor (CSTR) with simple reaction mechanism; and (2) electrochemical reaction (ECR) process.

Problem Formulation
One of the simplest cases to which the standard Nonlinear Frequency Response (NFR) method (Section 1) was applied was an isothermal CSTR with constant volume and simple irreversible -th order reaction [20,25]: following a simple reaction rate law: • The mathematical model of this reactor is defined by the material balances for the reactant and product , which are described with the following ordinary differential equations: where is time, is the volumetric flow rate (the inlet and outlet flow rates are equal owing to the assumption of a constant volume of the reaction mixture), is the reactant inlet concentration, and and are the outlet concentrations of reactant and product, respectively. is the volume of the reaction mixture, is the reaction order, and is the reaction rate constant. It has to be noted that, in cases when the volumetric flow rate is modulated, for proper evaluation of the periodic operation it is necessary to consider the time-average values of the molar flow rates of the reactant and product, and [25,49], so the equations in which they are defined need to be added, as well:

Filling in the cNFR Interface and Generating Results
To apply the cNFR method, the user needs to perform Steps 1, 2, and 3, shown in Figure 3 (Section 2). The total number of equations is four ( 4), with no exponential terms ( 0). Two possible modulated inputs are considered: inlet reactant concentration, (input 1) and volumetric flow rate, (input 2), which can be modulated separately or simultaneously (Figure 7). Like in the work by Nikolic Paunic and Petkovska [25], nondimensional time is used, defined as a ratio of the dimensional time and the reactor residence time. Accordingly, the parameter Equation (3) (Section 2) is defined as a reciprocal value of the steady-state residence time ( Figure 8): As a result of Equation (10), the frequency of input change, , will also be nondimensional. Considering the order of the declared output variables: , , , , the parameters corresponding to the differential terms in the first equation Equation (6) In Equation (6), there are no exponential terms, so the parameters and are zero: The remaining terms in Equation (6) represent the parameter : Analogously, the parameters corresponding to Equation (7) are defined in the following way: Equations (8) and (9) have no differential or exponential terms so their parameters are defined as: , … 0, 0, 0, 0 The Main Window in which the parameters defined in Equations (10)- (22) have been inserted is shown in Figure 8.
The FRFs are derived up to the second order (Figure 9), and the files that are automatically generated by the cNFR application are: (1) all FRFs (for theoretical verification of the cNFR method), (2) characteristic equation (for stability analysis), (3) the DC components of the molar flow rates, and (4) the optimal phase angle maximizing the fourth output variable, , i.e., the molar flow rate of the product, (for analyzing the forced periodic operation). After filling the Project Name field in the cNFR Main Window (Figure 8), the user starts the second stage of the cNFR routine ( Figure 3) by running the MATLAB code and inserting the name of the project Excel worksheet. When the program has finished running, the user obtains a folder created by the cNFR application. The folder bears the name of the project specified by the user in the Main Window ( Figure 8). For Example 1, a folder named "CSTR" is created, which contains the function files for the first and second-order FRFs and the DC components for the outlet molar flow rates for three different scenarios: (1) single-input modulation of the reactant concentration; (2) single-input modulation of the volumetric flow rate, and (3) simultaneous modulation of the reactant concentration and volumetric flow rate. The names of the FRF files are generated using the principle shown in the Legend Window in Figure 6 (e.g., G1_x1_y4 is the first-order FRF for the product outlet molar flow rate when reactant inlet concentration is modulated). The DC component files will start with letters 'DC' (e.g., DC_x1x2_y4 is the DC component for the product outlet molar flow rate when both reactant inlet concentration and volumetric flow rate are modulated), while the optimal phase angle file will be present in the folder under the name 'OPT_FI'. The cNFR application also leaves a ".mat" file that contains all derived analytical formulas in its symbolic form and informs the user about the time needed for the computation to be completed. For Example 1, the computation time was only 51.3 s.

Simulating the FRFs Derived Using cNFR and its Verification
The FRFs derived using the cNFR application are theoretical analytical functions. However, they are not obtained in their most concise or elegant form and can seem quite cumbersome at first sight. That is the reason why they are not presented here. Nevertheless, by setting the values of the model parameters and the frequency range, they can be used for simulation of the FRFs and DC components of interest.
The software application for the cNFR method was first verified by comparing the automatically derived FRFs with the same functions derived using the classical approach [49]. The asymmetrical second-order FRFs corresponding to the outlet molar flow-rates of the product were chosen for comparison. Their analytical expressions from the literature [49] are:


For modulation of the inlet reaction concentration, (input ): For modulation of the volumetric flow rate, (input ): The cross-function: In Equations (23)- (25), two auxiliary dimensionless parameters, and , have been introduced [49]: All three asymmetrical second-order FRFs corresponding to the outlet molar flow rate of the product were simulated using Equations (23)- (27) and the automatically derived functions using the cNFR application, with parameter and constant values given in Table 1 [49]. As shown in Figure 10  From the simulated FRFs, the user can analyze the dynamics of the system in the desired frequency range, for any set of operational parameters. However, the NFR method is applicable only if the system is stable. Therefore, the cNFR application also generates an algebraic and vector form of the system characteristic equation. The system will be stable only if the roots of the characteristic equation are negative or have negative real parts (if they are complex numbers). This is especially important while estimating system parameters or optimizing operational values, as the roots of the characteristic equation can be used as algebraic constraints. In Example 1, the cNFR generated characteristic equation is: Therefore, the roots of the characteristic equation must satisfy the following condition: i.e., which is identical to the stability condition for this example reported previously by Nikolic Paunic [49].

Analyzing System Forced Periodic Operation
As explained shortly in Section 1 and extensively documented in our previous publications [44,49], the NFR analysis offers an easy way to evaluate the potential of intensification of an operation which is classically performed in a steady state by forced periodic modulation of one or more inputs around their steady-state values. If we refer to Figure 1 (Section 1), the intensification is directly related to the DC component of the output of interest, which can be approximately evaluated using only the asymmetrical second-order FRFs and the input parameters.
For a simultaneous co-sinusoidal modulation of the feed concentration and flow rate , around their steady-state values , and , with amplitudes and , frequency , and phase shift , defined as: the DC component can be approximately obtained as [25,49]: The optimal phase difference between the modulated inputs, maximizing the cross effect and, accordingly the DC component, is evaluated from the cross asymmetrical second-order FRF [25,49]: Figure 11b shows the DC component corresponding to the outlet molar flow rate of the product in a wide frequency range, calculated using the parameters given in Table 1 and the optimal phase difference, shown in Figure 11a. As shown in Figure 11b, the highest values of , , i.e., an increase of , is predicted in the high-frequency range where the corresponding optimal phase angle will be 0 rad (both inputs are modulated in-phase).
This analysis can be further extended to investigating the product yield corresponding to the periodic operation, which can be easily evaluated from the DC component of the outlet molar flow rate [48,49]: The product yield simulation results are shown in Figure 11c and they show that the highest product yield is also achieved in the high-frequency range.

Problem Formulation
The cNFR application will also be illustrated in the case of electrochemical oxygen reduction reaction (ORR) on a rotating disc electrode, for which the NFR method was applied experimentally [39]. The FRFs derived using the cNFR method will be compared to the ones estimated from the experimental measurements.
The ORR single-step mechanism can be written as [39]: In this study, we use the mathematical model for the single-step ORR mechanism from Kandaswamy et al. [39]. All model equations are written in the standard form defined by Equation (2) (Section 2).
The electrical charge balance can be written as: where is the double-layer capacitance, the electrode overpotential, the Faraday's constant, the ORR reaction rate expression, and the current density, which is the main output of interest.
The potential balance is: where is the electrode potential, which is a possible modulated input, while is the standard electrode potential, and ohmic resistance. The kinetics of the ORR is described by the following reaction rate expression: where is the apparent rate constant of the ORR, which is a function of overpotential and temperature, defined by the equation: is the ORR kinetic constant, the transfer coefficient, the universal gas constant, and the reaction temperature, which is assumed to be constant in our current analysis.
In Equation (39) is the intermediary oxygen concentration derived from the discretized mass balance equation [39]: where is the electrode boundary layer thickness and depends on the electrode rotation rate and some physical parameters (the oxygen diffusivity in the boundary layer, , and the kinematic viscosity of the NaOH solution in which the reaction takes place, ) according to the equation:

Filling in the cNFR Interface and Generating Results
In the current study, only one input is considered -the electrode potential E, which was used as the modulated input in the experimental study by Kandaswamy et al. [39]. In principle, other inputs could also be used, e.g., the electrode rotation rate or the bulk concentration.
The input, and well as its steady-state symbol ( ) are declared in the Main Window of the cNFR application, as shown in Figure 12.
In the cNFR Settings Window (Figure 14), it was chosen that files are generated for the FRFs up to the second order.
For Example 2, the cNFR method computational time was 64 s.

Comparison with Experimental FRFs and Model Identification
The experimental FRFs can be directly estimated from the harmonics and the DC component of the measured output, obtained in the experimental frequency response measurements, as shown in Figure 1 (Section 1). In our previous study [39] the harmonics of the NFR were measured using a Solartron Energy Lab XM potentiostat made by Ametek. From the measurements, the first-order and the symmetrical second-order FRFs were estimated.
The files generated using the cNFR application contain the analytical expressions of the theoretical first and second-order FRFs corresponding to the model defined in Section 3.2.1. Due to their rather cumbersome form, the analytical expressions of the derived theoretical FRFs are not given here but can be found in the Supplementary Material of Kandaswamy et al. [39].
The generated function files allow fast and easy simulation of the FRFs for any set of parameter values. They were simulated for the experimental conditions used in the experimental investigation [39], for two different cases with vastly different electrolyte concentration in the electrochemical reaction (0.1 M and 11 M NaOH solution). The values of the constants and parameters used for simulation are given in Table 2.
The comparison of the experimental and theoretical FRFs derived using the cNFR application, relating the current density as the output of interest and the potential, is shown in Figure 15. For easier comparison with the experimentally estimated functions, the FRFs are given in their dimensional form. The derived first-order FRF results can be seen in Figure 15a (amplitude) and 15b (phase), and the symmetrical second-order FRF in Figure 15c (amplitude) and 15d (phase).
The results, shown in Figure 15a,b, correspond to the admittance of the Electrochemical Impedance Spectroscopy (EIS). For both cases (0.1 and 11 M NaOH solution) excellent agreement between the experimental and simulated amplitudes and phases for the first-order FRFs (admittance) is obtained. Therefore, EIS, which focuses on the linear part of the response, would suggest that the mathematical model given in Section 3.2.1 successfully describes the ORR reaction, both for low and high concentrations of NaOH.
On the other hand, by comparing the experimental and theoretical symmetrical second-order FRFs, it is obvious that good agreement is obtained only for the case of diluted solution (0.1 M NaOH) for low and moderate frequencies, while the agreement for the case of concentrated solution (11 M NaOH) is poor. The discrepancies between the experimental and theoretical symmetrical secondorder FRFs (corresponding to the nonlinear part of the response), which are distinctive for the 11 M solution, could be a result of some phenomena that were not mathematically described by the single-step mechanism (Equations (37)-(42), Section 3.2.1) used for deriving the theoretical FRFs. This result is a strong indication that a more complex several-step mechanism of the ORR system should be considered and used for deriving the theoretical FRFs. By using the cNFR application, this should be a rather simple and easy task.

Conclusions
The computer-aided Nonlinear Frequency Response (cNFR) method, presented in this paper, is an important upgrade of the Nonlinear Frequency Response method developed and used in our research group over the last two decades. It uses an original software application for automatic derivation of theoretical frequency response functions (FRFs) that are a very convenient and useful way of mathematically representing the dynamics of nonlinear systems. The automation of the derivation process facilitates the use of the NFR method substantially and will, hopefully, encourage other researchers and engineers to use it more extensively.
The cNFR application uses an Excel-based interface for defining the model equations, inputs, and outputs of the investigated system and a MATLAB code that performs the symbolic mathematical derivations. As a result, the cNFR application generates MATLAB function files containing the derived FRFs in a symbolic form, which can be used for simulation, analysis, experimental identification, and process optimization. Although the derivation procedure underlying this application is rather complex, the application itself is user-friendly and requires only the basic knowledge of Excel and MATLAB.
The automatic derivation of the FRFs is just the first step in the process of full automation of the NFR method. One direction of this automation, related to developing of new experimental techniques and sophisticated software instruments, would assume integration of the current cNFR application with an automated system for running the frequency response measurements, collecting and analyzing data, estimation of the experimental FRFs, mechanism discrimination, and model identification based on comparison of the experimental and theoretical FRFs and parameter estimation. Another direction, related to the development and optimization of periodic processes, would assume integration of the cNFR application with multi-objective optimization tools.
The presented cNFR application is a prerequisite for any further advancements in both directions.