Sampling Rate Optimization and Execution Time Analysis for Two-Degrees-of-Freedom Control Systems

: The current journal paper proposes an end-to-end analysis for the numerical implementation of a two-degrees-of-freedom (2DOF) control structure, starting from the sampling rate selection mechanism via a quasi-optimal manner, along with the estimation of the worst-case execution time (WCET) for the speciﬁed controller. For the sampling rate selection, the classical Shannon–Nyquist sampling theorem is replaced by an optimization problem that encompasses the trade-off between the ﬁdelity of the controllers’ representation, along with the ﬁdelity of the resulting closed-loop systems, and the implementation difﬁculty of the controllers. Additionally, the WCET analysis can be seen as a veriﬁcation step before automatic code generation, a computational model being provided. The proposed computational model encompasses inﬁnite-impulse response (IIR) and ﬁnite-impulse response (FIR) ﬁlter models for the controller implementation, along with additional relevant phenomena being discussed, such as saturation, signal scaling and anti-windup techniques. All proposed results will be illustrated on a DC motor benchmark control problem.


Literature Review
The problem of sampling rate choice to numerically implement a controller designed in the continuous-time domain has significant importance. A sub-optimal value of the sampling period represents a trade-off between the fidelity of the response, given by a shorter sampling rate, and implementability, obtained using a larger sampling rate. The most common manner to choose this sampling period is given by the Shannon sampling theorem [1]. However, this can only be a starting point in a control context, because, in practice, it can lead to unacceptable behavior of the discrete-time controller compared to its continuous-time equivalent, a significant justification being the presence of quantization errors unaccounted for in the signal and system models. In the available literature, the problem of choosing the sampling rate is specifically formulated for the purpose of the particular control system at hand. For example, for a structure with a P-type regulator proposed in [2], the key points used in sampling rate selection are the overshoot and the rise time. For the case of a PID-based control structure, an optimization criterion has been proposed in [3] to find the optimal and/or sub-optimal value of the sampling rate. The problem of sampling rate selection for parameter estimation of an induction machine has been solved via a metaheuristic procedure in [4]. A similar thematic is addressed in [5] in the case of permanent magnet synchronous motors using field programmable gate array devices, while the rapid control prototyping principle is illustrated for discrete-time closedloop control of brushless DC motors in [6,7], respectively. Moreover, an important result regarding the dependence between the stability and the performance of the closed-loop system, and the choice of sampling rate is presented in [8].
After the first step of selecting the sampling period, an analysis regarding the practical implementation of the proposed control structure on a microprocessor-based system should be performed. This analysis needs to encompass several aspects which are not explicitly modeled in the control law, such as the register word lengths of the coefficients which directly influence the number of necessary assembly instructions, and saturation, overflow, underflow verifications on the computed command signals. In the specific context of rapid control prototyping (RCP), one key step before the proper code generation is to certify if its execution abides by the time span given by the sampling period. Moreover, other important verifications for phenomena such as underflow and overflow, or saturation and anti-windup techniques should be also performed before the code-generation step. As such, one important goal consists of approximating the number of software operations necessary to implement the designed control law, mandatory in the context of hard real-time systems. A survey of worst-case execution time computational methods is presented in the seminal paper [9]. A simplified study applied for control system-related interrupt service routines for state-space controller representations is presented in [10]. Another possibility for the computational error analysis is presented in [11].
In the Control Systems domain, the linear control system field plays an important role. Linear controller design techniques are available for both linear plants and nonlinear process models alike. Starting from the classical proportional-integral-derivative (PID) controller [12] towards the domain of robust controller [13][14][15], these techniques can be extended for nonlinear systems via the gain-scheduling method [16] or an additional passivity-based component [17]. Moreover, with great advantage in also coping with disturbance rejection problems, alongside reference tracking specifications are the so-called two-degrees-of-freedom (2DOF) control schemes [13]. In ref. [18], a 2DOF PID controller has been proposed, where the serial compensator is a classical PID controller, while the feedforward compensator is a PD controller, the integral effect being excluded due to the stability requirements. For the case of unstable plants with time delays, a discrete-time 2DOF control scheme has been proposed in [19]. As such, for reference tracking, the serial controller was designed using the H 2 optimal control framework, while the feedforward controller has been tuned by imposing the desired closed-loop transfer function. Additionally, in terms of software toolbox implementations, the robust advanced PID (RaPID) toolbox described in [20] presents a set of possibilities to design a 2DOF PID control structure by minimizing certain error criteria, such as the integral of absolute error or integral of time multiplied by the absolute value of error.

Contributions and Paper Structure
The current journal paper represents an extension of the conference papers [10,21], and proposes a joint analysis on sampling time selection and execution time framing of the microcontroller operations into the previously established optimum for the case of a 2DOF control structure. The main contributions of the paper are: (i) to extend the functionals initially proposed in [21] in order to encompass the fidelity of both controllers from the 2DOF structure and of the resulting closed-loop systems, i.e., ensuring the tracking and servo behavior of the initially designed continuous-time controllers, along with the implementation difficulty of the proposed controllers in terms of quantization and sampling rate span; (ii) to formulate the optimization problem for sampling rate selection of a 2DOF control structure without considering any further normalizations of the final functional's terms and propose a metaheuristic-based solution to find an optimal or quasi-optimal value of the sampling rate which can offer a good trade-off between implementability and fidelity; (iii) to extend the WCET analysis, initially proposed in [10] for the case of state-space regulator implementations, for the case of controllers implemented as infinite-impulse response (IIR) or finite-impulse response (FIR) filters, offering an upper bound estimation of the time span necessary to perform all the operations involved in the numerical implementation of the proposed 2DOF controller; (iv) to offer an exhaustive analysis which can be further performed in an automatic manner and to be integrated in our open-source MATLAB-based CACSD toolbox [22]; (v) to present an end-to-end design procedure for the case of a DC motor control problem, starting from the controller design, followed by choice of the quasi-optimal sampling rate and the worst-case execution time analysis, finalizing with a detailed discussion.
The rest of the paper is organized as follows: Section 2 presents the 2DOF structure which will be studied, along with a mathematical background for the sampling rate choice and worst-case execution time analysis, and a set of theoretical results and optimization problems extended and adapted for the proposed control structure; in Section 3 a case study consisting of an end-to-end design procedure of a 2DOF PID controller is illustrated, while Section 4 deals with a set of conclusions and further research directions.

Notations
We denote by C(z, r) the circle with the center in z ∈ C and radius r > 0. Additionally, P(G) and Z(G) denote the pole and zero sets of an LTI system G, respectively. An arbitrary sampling period will be denoted T s ≡ T > 0 throughout the paper. Continuous-time regulators will be denoted K(s) ≡ K, while their discrete counterparts, as a function of the sampling period will be used as K T (z) ≡ K T . The set of continuous-time systems will be denoted by G, while the set of discrete-time systems will be denoted by G D . The standard growth functions and their notations according to [23]:

Numerical Closed-Loop Control
Modern control systems make use of numerically implemented regulators to coordinate continuous-time processes. The classical configuration of a numerical regulator is presented in Figure 1. It uses sample and hold circuits as interfaces to the continuous-time adjacent components and, as such, it imposes the zero-order hold discretization method for the plant G. As such, define the plant discretization methodology as the mapping with G denoting the continuous-time model set, G D being the discrete-time model set, and with the digital-to-analog converter, i.e., zero-order hold, model: For the purpose of this paper, we consider a two-degrees-of-freedom (2DOF) control structure as in Figure 2, which has an inner controller K in (s) usually designed for disturbance rejection, and a feedforward controller K ff (s) which provides the necessary compensation for the steady-state tracking behavior, along with the process model with disturbance, described by G(s) and G d (s). As K ff does not influence the signal path from the disturbance d(t) to the output y(t), the usual design workflow is to synthesize K in and, then, to fine-tune the transient response from r(t) to y(t) through K ff . Both continuous-time controllers K in (s) and K ff (s) are assumed to have the following linear and time-invariant (LTI) state-space representations: Given that the continuous-time controllers K in (s) and K ff (s) must be numerically implemented on a microcontroller, the problem of selecting an appropriate sampling period T ∈ (0, ∞) becomes a critical step. For a fixed sampling rate T, the discrete-time form of a controller K x (s) can be written as: To compute the transition matrix Φ x and the input matrix Γ x , a wide selection of discretization methods, denoted by D, can be considered, such as zero-order hold, trapezoidal (Tustin), forward or backward Euler, frequency-response regression and so on. Additionally, in most situations, the output matrix remains the same as in the continuoustime representation, but there exist cases when it may be different than its continuoustime counterpart. As such, from a tuple of a continuous-time transfer matrix K x (s) = (A K,x , B K,x , C K,x , D K,x ) ∈ G and a sampling rate T ∈ R + results an equivalent discrete-time Figure 1. Numeric regulator K T (z) with a specified sampling rate T > 0 and its corresponding interface consisting of a sample and hold with the analog-to-digital converter, along with the digitalto-analog converter followed by a sample and hold circuit.

Figure 2.
Two-degrees-of-freedom (2DOF) numerical control structure with components K in (z) and K ff (z), designed for the process models G(s) with disturbance dynamics G d (s).
The open-loop process model has the input-output representation: while the closed-loop system expression becomes: The discrete-time equivalent closed-loop model will be: which represents the starting point for various control design methodologies.

Sampling Rate Optimization
The current subsection presents an extension of the work from the paper [21].

Linear System Sampling Background
The well-known Shannon theorem [1] states that the necessary sampling rate to avoid information loss must be at most twice time smaller than the inverse of the continuous-time signal's maximum frequency component: Moreover, the theoretical upper bound of the frequency range after which aliasing phenomena occur is called Nyquist frequency and is given by: The above-mentioned version of Nyquist-Shannon theorem for signals can be extended to LTI systems by considering that the resulting discrete-time system must maintain all relevant dynamics of the continuous-time system. The dynamics of a system is given by its set of poles, one possible constraint for the sampling rate implying to be at most twice smaller than the inverse of the real part of the minimum value of poles. However, there are cases when the imaginary part of the poles is relevant, or even the values of the transmission zeros, for a good representation of the system's frequency response.
For the remainder of the paper, the sampling rate will be denoted by T s ≡ T. The analytical relationship between the continuous-time s-plane and the discrete-time z-plane is illustrated by the equation: Considering a point s := σ+jω, with σ, ω ∈ R, the resulting corresponding complex number is z = e σT (cos(ωT) + j sin(ωT)). As such, the left half of the complex s-plane can be split into an infinite number of disjoint strips of height 2π T , due to the periodical nature of the sin(·) and cos(·) functions. The resulting primary strip contains points which correspond to ω ∈ [−ω N , ω N ]. The s-plane to z-plane mapping causes the following topologies of the primary strip of the s-plane: • the imaginary axis in is mapped to the unit circle C(0, 1); • the upper and the lower edges are both mapped to the negative axis; • the negative real axis is mapped to the positive axis inside the unit circle; • the interior of the primary strip is mapped in the unit disk.
When sampling an LTI controller, several remarks can be considered then the behavior of the singularities is studied: (i) unstable zeros and poles tend decreasingly to the unit circle's circumference, i.e., |z| 1 and |p| 1 as T 0; for poles, this aspect is relevant when sampling systems, as controllers generally do not employ unstable poles in their structure; (ii) stable zeros and poles tend increasingly to the unit circle's circumference, i.e., |z| 1 and |p| 1 as T 0, requiring additional decimal or binary digits for an accurate representation. (iii) poles and zeros from the imaginary axis in the s-domain are maintained on the unit circle in the z-domain irrespective of the sampling period T > 0. Additionally, integrator and derivative terms do not matter in deciding the practical sampling time. (iv) the quantization error increases as T 0 in the case of stable closed-loop systems.

Remark 1.
The quantization error mentioned in (iv) increases as T 0 as proved in [24], due to the guaranteed steady-state error being proportional to According to the previously mentioned aspects, a sub-optimal value of the sampling rate must ensure a good trade-off between the fidelity of the representation of the continuous-time controllers and their implementability difficulty. As such, we next introduce a set of functionals to quantify these two aspects.

Proposed Functionals
To measure the similarity between a continuous-time LTI system H(s) and a discretetime system H T (z) over the frequency range Ω, the following functional can be defined as where σ(·) is the maximum singular value. Moreover, as mentioned before, the available frequency domain is Ω = (0, ω N ), ω N being the corresponding Nyquist-Shannon frequency to the sampling rate T. Therefore, the similarity functional S H : D → (0, ∞) becomes: However, to compute the similarity integral term S H , a discrete set from the frequency range (0, ω N ) → Ω = {ω = ω 1 < ω 2 < · · · < ω N − ω ε = ω} can be considered, the performance index being approximated as follows: where ω ε > 0 is a predefined threshold used to avoid the prewarping phenomenon which ensues in the magnitude responses when ω → ω N .

Remark 2.
There are several alternatives in defining the similarity between two LTI systems, with particular interest for closed-loop connections, such as the normalized dissimilarity function metric, described in [25], the standard ν-gap metric, with its limitations exposed in [26], or the improved Vinnicombe ν-gap metric [27], described as: with: where for the reference systems G 1 and G 2 , their right normalized coprime factorizations will be considered: G 1 := N 1 M −1 1 and G 2 := N 2 M −1 2 , which in context of the proposed sampling rate optimization problem, the differences should be computed with the subsystems applied in G 1 ≡ K(s) → jω and G 2 ≡ K T (z) → e jωT , respectively.
To define the fixed-point implementability functional I H (T) : D → (0, ∞) which measures the quantization implementation difficulty of the LTI system H T (z), the following expression can be considered: with P and Z denoting the pole and zero sets of H T , respectively, excluding singularities from the set C(0, 1). Alongside the previous implementability functional, an execution time cost functional T H (T) : D → (0, ∞) becomes necessary to limit the decrease of T 0 which would ideally lead the similarity functional costs to zero: A concluding functional with global effect, J stab(H) : D → {0, ∞}, will define the feasibility domain of the optimization problem, because it accepts or rejects a specific sampling period value. It induces an infinitely valued constant when the numeric system H T becomes unstable, and otherwise, defaults to no extra penalization: For the numerical implementation of the stability functional, a sufficiently large value α ∞ can be considered to mark the feasibility subdomain of D where the system H is stable, leading to an approximation of the original performance index:

Optimization Problem
For the two-degrees-of-freedom control structure proposed in Figure 2 the following functionals will be considered to formulate the optimization problem to determine the sampling rate: • two terms S K in (T) and S K ff (T) representing the similarity between the continuoustime and the discrete-time representations of the controllers K in (s) and K ff(s) over the frequency range (0, ω N ); • two terms S H r cl (T) and S H d cl (T) representing the similarity between the continuoustime and the discrete-time representations of the resulting closed-loop systems H r cl (s) and H d cl (s) over the same frequency range; • the quantization implementation difficulty I K in (T) and I K ff (T) of each controller along with the execution time functional T(T); • the stability functional J stab(H r cl ) (T) of the resulting numerical closed-loop system H r cl,T (z). The first set of three terms are used to measure the fidelity between the components of the continuous-time designed system and the resulting components in the discrete-time domain, considering the transient and steady-state performance altering. The next set of three terms manages to encompass the implementation difficulty of the resulting controller, according to the already-mentioned remarks. The last term is nothing but a correction used to define the feasibility subdomain of D. As such, a trade-off between the first two sets of performance indices must be established by taking into account the last feasibility term, resulting a non-convex optimization problem. However, in order to increase the flexibility of this optimization problem, a set of weights c 1−6 can be considered as follows: the weights c 1 , c 2 , c 3 , and c 4 are for the fidelity measurement indices, while weights c 5 , c 6 , and c 7 are for the implementability indices, the final functional J : D → R + being: Moreover, considering the numerical approximations (14) and (20), the following numerically implementable non-convex optimization problem occurs: For an LTI plant model G(s) included in a two-degrees-of-freedom control structure with the continuous-time inner controller K in (s) and with the continuous-time feedforward controller K ff (s) as in Figure 2, define an ordered set of pulsations, preferably in logarithmic scale: Then, the functional J Ω : D → R + : with weighting terms c 1−7 , leads to the following quasi-optimal sampling time optimization problem: Remark 3. The resulting optimization problem (24) is non-convex by nature. As such, the linesearch procedure used to solve this problem must be able to explore the whole feasible domain. One possible solution is a metaheurisitc approach, such as particle swarm optimization (PSO) [28], which will be used for the purpose of this paper.

Worst-Case Execution Time Analysis
The current subsection presents an extension of the work from the paper [10].

Execution Time Model
This subsection proposes the study of the implementation details for the case of linear control structures, where controllers will be modeled as infinite-impulse response (IIR) and finite-impulse response (FIR) filters. Starting from [10], a set of implementation aspects which are treated for state-space realizations will be considered in a unified manner for the case of transfer matrices in this paper. Additionally, this section also analyzes the 2DOF extension. The duration for each operation involved in the control structure can significantly impact the regulator implementability.
The necessary mathematical operations to fully implement an LTI-based control law must be formally defined. Besides the LTI-control law, the classical saturation and antiwindup nonlinearities will be considered, which are usually related to said LTI laws. The unary and binary mathematical operators defined in Table 1 and gathered in the operations alphabet O := {n, a, m, s, w, l}, are considered with real operands and must be accounted for into a microprocessor-based environment.  [12,29,30] for integrators As such, the process of computing a command signal y[k] as in Figure 1 implies a finite and formal computational finite sequence Sc ∈ O N , where all terms are mathematical operations as in Table 1 where N depends on the structure of the controller K(z). Moreover, in order to additionally specify a set of practical hardware specifications and constraints H and to uniformly describe the problem, the finite sequence can be now extended to a full sequence Sc K,H ∈ O ∞ : Starting from an array Sc K,H of operations as (25), we follow with a general-purpose instruction set model. Assume a Random-Access Machine (RAM) computational model as in [23], with deterministic operations. RAM machines have practical counterparts, materialized through RISC machines. Reconfigurable RISC machines specialized on certain problems have been proposed in [31]. Additionally, there is the approach of multiply and accumulate (MAC) instructions supported in digital signal processors (DSP) [32]. Depending on the supported computer architectures of the RCP framework, relevant are also Single Instruction stream/Multiple instruction Pipelining (SIMP) [33] constructions with respect to single-processor architectures, or Single Instruction/Multiple Data (SIMD) features, which allow the practical parallelization of addition and multiplication operations for several sets of operands. Definition 1. The hardware constraints and specification set H encompasses metadata which imply extra operations or different approaches to the standard operations performed on the controller signals and implementation-specific information, with various outcomes on the total execution time, frequently found in practice being: • availability of Direct Memory Access (DMA) modules, MAC instructions, circular buffers in opposition to linear buffering, or output bypassing, which has the advantage of discarding p i ∈ {l} operations.
Such specifications will be quantified by scaling factors γ j to the base duration of the RISC machine model operations. Depending on the significance of the alternative instruction, γ j could be less than, equal to, or greater than one, respectively.
Therefore, a set of instructions Sc K,H can be manually designed or automatically deduced. For manual modeling, the control engineer needs to find this set for each control law, while for automatic mode, an RCP tool can already deduce this set. Such an RCP tool generally deals with the code generation for different environments. Now, the sequence of operations generator procedures can be seen as a functional: To implement the mathematical operations p i ∈ O from Table 1, the atomic assembly instructions a i ∈ A = {NOP, MF, MS, ADD, MUL, SH, JMP, CMP} from Table 2 will represent the starting point. It covers the basic arithmetical operations required in linear systems, with the additivity and homogeneity properties, conditional jumps for saturations and the antiwindup of integrator terms, forced and imposed delays through data acquisition hardware and access to memory devices. Each arbitrary atomic assembly operation will be denoted by a, as part of the formal set A all the equivalent assembly instructions supported by H for the implementation of Sc, with the RISC machine assumption that each instruction takes a fixed clock tick value T clk > 0. The number of ways in obtaining the resulting assembly instructions is not unique and it further depends on the structure of H. A straightforward example to illustrate this phenomenon is when the regulator coefficients are stored contiguously in the memory in comparison to arbitrary and uncorrelated memory registers. The execution time implications are obtained through different pointer operations. To conclude, a new mathematical operator analogous to (26), tasked with the generation of a computer-equivalent set of instructions given by the functional Sp ∈ A ∞ is: which results in an infinite sequence of atomic software instructions, but with a finite number of them being different to NOP, located at the start of the sequence, which implement the linear controller formula: Sp K,H := (a 1 , . . . , a M , NOP, NOP, . . . ), a i ∈ A.
The difference between the sets Sc and Sp is that Sc contains abstract mathematical operations p i ∈ O, and each such operation p i will be practically implemented using equivalent a i,j ∈ A steps, j = 1, N i , as in the mapping: the number of atomic operations different from NOP being M = N 1 + N 2 + · · · + N N . The importance of the previously defined sequences and functionals, i.e., Sc K,H , Ψ, Sp K,H and Ξ, respectively, and the implications of estimating the number of assembly operations in a tight manner was insisted upon in the base paper [10]. Figure 3 gathers them and illustrates their connections in an RCP context. The mapping from (K, H) to the set Sc K,H is usually performed for Model-in-the-Loop (MiL) simulations through an application Ψ, while the mapping (K, H) → Sp K,H is made through Software-in-the-Loop (SiL) testing using an application Ξ. The master RCP program, with access to both Sc K,H and Sp K,H , can subsequently perform a worst-case execution time analysis on the implementation of the digital regulator K(z) in the production hardware context H. Compare CMP s, w, l SIMP Figure 3. Rapid control prototyping relationship between the formal sets and functionals necessary to perform a worst-case execution time analysis for a regulator K(z) ∈ G D in the production context H. Figure 4 presents the sequence diagram with the timing constraints of the discretetime controller K with respect to other software threads from the microcontroller, with an illustration of the WCET of the controller interrupt service routine (ISR) thread. The main result of the section is gathered in the following theorem. Theorem 1. Given a numerical control law given by K ∈ G D , along with a microcontroller specification set Hand a code-generation procedure given by a pair of MiL and SiL (Ψ, Ξ), the worstcase execution time estimation can be computed by the following formula: where Sp K,H represents the number of atomic assembly operations a i ∈ A as in (28)  Proof. According to the schematic representation from Figure 3, starting from the control law K ∈ G D and the specification set H, the set Sc K,H can be obtained via the MiL operator Ψ, resulting in p 1 , p 2 , . . . , p N ∈ O. However, in order to measure each p i , the set of atomic operations must be attached via the SiL operator Ξ: p i → a i,1 , a i,2 , · · · , a i,N i , each such atomic operation requiring exactly T clk , leading to: where t(·) is the time necessary to execute an operation or a set of operations.
Additionally, a second term T 2 = ∑ ISR λ accumulates ISR switching and stackhandling operations handled by the scheduler, bounded by a processor-dependent constant λ > 0, which can be modeled as O(1) × T clk . As such, the worst-case execution time can now be written as: which concludes the proof. Two additional performance qualifiers can be employed to globally assess the controller ISR implementation impact on the scheduling algorithm of the processor. Definition 2. The processor usage level qualifier relative to a fixed sampling period T > 0 of a discrete-time regulator K(z) ∈ G D , described in a relative manner, is defined by: Definition 3. The processor idle time qualifier with respect to a fixed sampling period T > 0 of a discrete-time regulator K(z) ∈ G D , described in absolute units, is defined by:

Modeling Duration of Finite and Infinite-Impulse Response Topologies
Denote by H ∈ G p×m D a MIMO regulator with m inputs and p outputs, thus fully described by the expressions of m × p transfer functions H ij ∈ G D : Each element of the transfer matrix H, i.e., H ij , can be modeled as an infinite-impulse response (IIR) filter or as a finite-impulse response (FIR) filter. The case where H is modeled as a state-space representation is treated in the base conference paper [10], namely in Algorithm 1 and Table I, Using this notation, the transfer function H(z) can be written using a series of secondorder sections and an additional first-order component, if necessary, as: with the terms from each triplet (b i,2 , b i,1 , b i,0 ) not all null, H 1 known as a first-order section, and each H 2,i , with i = 1, n 2 being denoted in the literature as a second-order section (SOS).

Remark 4.
Second-order sections are usually described with an additional gain term multiplied separately to the output of the transfer function as: To not further complicate the notations, we will not explicitly write this gain term for every second-order section, but it will be implicitly considered in the implementation and execution time analysis.
There are multiple approaches of implementing digital biquadratic filters, a good example being the description from the monograph [34]. Table 3 exposes the four usual topologies, which principally implement the same input-output transfer function, but with important differences regarding numerical stability when selecting fixed-point or floatingpoint implementations. These configurations are referred to as the canonical forms: Direct Form I, Direct Form II, Transposed Form I, Transposed Form II, which differ in the numerical properties of their implementations and in the number of necessary delay elements. As observed in the third column of the table, all biquad topologies are based on four additions, five multiplications, and a different number of load/store operations, depending on the definition of the internal state variables. Such implementation details are relevant when studying particularized structures, such as in the situations treated in [35,36]. Table 3. Digital biquadratic topology implementations; all difference equations implement the same input-output second-order transfer function, but differ through the configurations of the state signals.

IIR SOS Topology Difference Equation min Sc K,H
Direct Form I (DFI)

4a, 6m, 14l
Transposed Direct Form I (TDFI) 4a, 6m, 14l Transposed Direct Form II (TDFII) 4a, 6m, 16l The ISR model for IIR controller structures is based on the pseudocode exposed in Algorithm 1. hlBased on the specifications for H, each line of the pseudocode will have a set of mandatory mathematical operations, along with optional operations, which will be accounted for in the execution time analysis model through different constant weights.

Algorithm 1 Infinite-impulse response (IIR) filter interrupt service routine (ISR)
Input: H ij (z) as in (35), topology as in Table 3 Output: Execution time profiler for routine iirFiltIsr 1: Construct software structures H 1 , H 2,1 -H 2,n 2 according to (37) and Table 3 2: Initialize delays involved in second-order sections to zero 3 Scale by second-order section gain g 19: return y[k] 20: end function In ref. [10], an analysis has been performed on the simplified case of a nth order IIR SISO transfer function in a series connection, described as: −1 z m−1 + · · · + b 0 z n + a n−1 z n−1 + a n−2 z n−2 + · · · + a 0 , which, by design, it can implicitly include a delay z −n d by forcing the first n d coefficients b i to zero. Such a transfer function has its corresponding difference equation as: A further particularization on the structure of H ij (z) is to consider the expression of a FIR filter topology, which, by design, discards the previous output delays. The present command signal y[k] will, as such, depend only on an array of delays, i.e., delay tap of inputs u[k − i], modeled as: Four typical canonical forms are distinguished for FIR-type filters, namely the Direct Form (DF), Direct Form Transposed (DFT), Symmetric and Antisymmetric [34], respectively, with their definitions exposed in Table 4. The main difference between DF and DFT is that for the former, the delay word lengths are that of the input signals u[k−i], while for the latter, the delays have the word length of the accumulator variable. The Symmetric and Antisymmetric cases make use of the linear phase of the filter through the regularity of the first N 2 coefficients as the symmetrical or antisymmetrical equivalents of the latter half of the coefficients. As mentioned in the third column of the table, this has a significant impact on the necessary multiplications and load operations involved in the implementation of y[k], k ≥ 0. Algorithm 2 emphasizes the corresponding SISO FIR filter ISR routine starting from the mathematical basis of Equation (41) and information from Table 4. Table 4. Digital FIR filter topology implementations; all difference equations implement the same input-output Nth order transfer function, but vary through the configuration of the accumulator. (35), where each component H ij (z), i ∈ 1, p, j ∈ 1, m can be described as an IIR filter of form (37), with second-order sections as in Table 3 or a FIR filter of form (41), with difference equations as in Table 4, the WCET can be computed as:

Direct Form
with coefficients γ ij > 0 accounting for the hardware specifications set H from Definition 1, each assembly operation set Sp H ij ,H determined individually by the RCP application, given the microprocessor tick T clk > 0, and O(1) depends only on the other higher-priority software threads.

Algorithm 2 Finite-impulse response (FIR) filter interrupt service routine (ISR)
Input: H ij (z) as in (41), topology as in Table 4 Output: Execution time profiler for routine firFiltIsr Shift input delay tap 7: y ← H.call( u) According to column 2 of Table 4 8: Scale y[k] and write to output device 10: end procedure The proof immediately follows based on Theorem 1 by replacing the general-purpose sequence Sp K,H with its corresponding sum of subsystems H ij from the full MIMO regulator K ≡ H and their definitions.

Case Study
The Case Study section concerns with illustrating the proposed extensions on a motor servo control example, and will encompass the following key points: process description, control performance specifications, continuous-time controller design, regulator discretization methods, sampling time optimization, selection of different controller implementation topologies along with the worst-case execution time analysis and a detailed discussion of the obtained results. The reason for selecting this example is that the proposed theory can be illustrated in the same manner for a simple process model and a modest microcontroller device setup, compared to a more complex process and an adequate microcontroller setup, leading to similar processor workloads.

Process Model and Controller Synthesis
To illustrate the proposed theoretical techniques, we consider a numerical case study based on a brushed direct-current (DC) motor position control system. Figure 5 shows the closed-loop structure, emphasizing both the process model and the 2DOF regulator structure. The motor process has a control input represented by the source voltage V a [V], along with the disturbance load torque T d [Nm], and the output is considered to be the angular position θ [rad]. As noticeable from the transfer function blocks, the DC motor model has order three, and the nominal component values are listed in Table 5.  The process model from its two inputs to the angular position output is described by: with the armature transfer function H a , along with the load component H L and the reverse loop term H r which denotes the back-electromotive voltage constant K b : The 2DOF controller components have the proportional-integral-derivative plus filter (PIDF) structure for K in , while the integral term is canceled for the feedforward controller K ff . This structure allows straightforward implementation in many industrial contexts as such PIDF regulators can be directly acquired and there are multiple validated approaches in the literature for their parameter tuning [18,20]. As such, their mathematical expressions become: with the feedforward parameters usually specified as b and c, with b = −1 + b and c = −1 + c. The command signal applicable to the motor input is comprised of two components derived from the 2DOF regulator as: The closed-loop control specifications were selected as follows: a reference tracking settling time of t s ≤ 1.5 [s] with an overshoot M p ≤ 0.05 ≡ 5[%], with the rise time as short as possible. Additionally, regarding the disturbance rejection specifications, a load torque of 1 [Nm] must be rejected in less than t d s ≤ 1[s], i.e., its effect on the output measurement should become less than 0.1 [rad] in the specified t d s , with a maximum allowed disturbance of y d max = 0.65 [rad]. The recommended approach in such designs [12] is to tune the inner PIDF controller K in to account for the disturbance rejection coefficients, as K f f does not influence that control loop, as written in the discrete-time counterpart expressions (54). The PIDF parameter tuning has been done using global optimization methods by encompassing the desired specifications. The first iteration which covered all disturbance rejection performances was accepted and halted the optimization procedure. Additionally, a further optimization as been performed on the 2DOF parameters b and c of (46) with, again, halting the procedure after the reference tracking requirements have been fulfilled. The outcomes of the regulator tuning are illustrated in Table 6, where, alongside the PIDF and additional PD synthesis, a separate 1DOF PIDF regulator has been also added, to account for only the tracking response. The closed-loop step responses for the reference tracking and disturbance rejection problems are portrayed in Figure 6, showing the effects of the three controller examples from Table 6, case in which the 2DOF structure is validated, as the obtained performance metrics are t s ≈ 1.5[s], M p ≈ 0[%], rise time t r ≈ 0.75 [s] and steady-state error ε ss = 0. As illustrated in the figure, the 2DOF structure manages to ensure both the transient response performances and the disturbance rejection behavior, being the only regulator from the proposed triplet to cover both areas.

Sampling Rate Selection
For the discretization of the PID regulators, the forward Euler method has been considered for the integrator term, with the approximation: while the derivative term is discretized using the backward Euler method as: leading to the expression of K in : with an expression of K ff also as: which will be further used in the proceeding illustration of the sampling time analysis. Starting from the continuous-time open-loop model from (43), the discrete-time equivalent using the zero-order hold method becomes: with the auxiliary notations: The closed-loop system's expression thus becomes: By imposing the functionals S Ω K in , S Ω K ff , , T, and J α ∞ stab(H 0 ) from Equation (23), two weighting sets c 1 -c 7 were considered as in Table 7, corresponding to two distinct experiments, the first numerical column designating emphasis on the difficulty of implementation functionals, while the second numerical column coefficients focus mainly on open-loop and closed-loop fidelity. With said coefficients, using a generalpurpose PSO implementation as specified in Remark 3, [28], the optimal implementability sampling period becomes T   There are multiple approaches for implementing the two PID regulators. Both K in (z) and K ff (z) can be fully encompassed into a biquadratic filter topology and, furthermore, a first-order structure for K ff . The two main ones, given the simplicity of their structure, would be to implement it in parallel versus in series. For the inner regulator, the parallel topology, denoted with the superscript p can be split into three subsystems: while the series topology, denoted with the superscript s, is: where the equivalent normalized coefficients are obtained: In the same manner, the parallel form of the feedforward regulator is adapted as: with a first-order series form of: and equivalent normalized coefficients:

Execution Time Analysis
After the discretization procedure as specified by (48) and (49), using the right-hand side notation for the coefficients in (56) and (60), the numerical values of the coefficients become as in Table 8, using the for deduced sampling rates from Section 3.2, T opt s,1 , T opt s,2 , T s,3 , T s,4 . As observed, the gain coefficient g ≡ b 2 for K in and g ≡ b 1 for K ff , respectively, remains invariant in this set of experiments, while the remaining non-unitary coefficients vary with respect to T s > 0 and necessitate increasingly more decimals as the sampling rate tends to zero. To account for the necessary word length analysis, two frequently used configurations have been considered: the first case is to store the operands, i.e., coefficients and inputs, states, outputs into 16-bit registers, considered the standard length for the RISC machine hosting the 2DOF controller, followed by a set of 32-bit length registers, which will increase the working precision, but with added execution time overhead, as modeled in continuation. Given the dynamic range of the final filter gains g, this final multiplication will be considered separately. Thus, the set H for this case study will encompass the properties: • it has a clock tick period of T clk =  The mathematical operations p i ∈ O, along with their assembly instruction correspondents as in (29) are detailed in Table 9, with an emphasis on each type of operation based on its physical significance, as written in the last column. The hyperparameters γ i in the case of standard 16-bit word lengths have been considered with the value 1, denoting that each base arithmetical operations costs only T clk , while the values are scaled upwards for the case when the operands exceed the word length to 32 bits. The impulse counter assembly operation cost for Θ[k] has been computed as 80,000 ×0.1 × 15 × T. Additionally, Table 10 totalizes the number of assembly operations based on the previous table's description, along with computing the worst-case execution times for the three stable sampling rate values: T opt s,1 -T s,3 . As seen from the table, the optimal sampling rate solution featuring implementability emphasis T opt s,1 occupies the microprocessor for less than 25[%] of its capability in either 16 or 32-bit quantizations alike, with the Shannon theorem approach T s,3 following with sufficient headroom in the scheduler algorithm, while the fidelity-based approach in this case occupies the scheduler with small margins in the case of 16-bit quantizations, and exceeds the allowed time frame in the case of the 32-bit configuration. Table 9. Encountered operations in the implementation of the 2DOF structure for the DC motor case study in the hypothesis of a base word length of L = 16 bits and two considered quantization levels for the controller coefficients: 16-bit and 32-bit lengths, respectively.  Based exclusively on the previous WCET analysis, there are several feasible solutions. In order to decide between the three sampling rate and quantization pair configurations, further analysis is performed on the frequency response of the K in and K ff controllers, along with the closed-loop responses using said controllers. As such, Figures 8 and 9, respectively, gather the previously said behaviors. In addition to the three sampling rates, for completeness, the fourth, unstable sampling rate T s,4 is shared, along with the ideal continuous-time equivalent controllers in the frequency-response plot. In both figures, columns one and two expose the 32-bit and 16-bit quantization configurations, respectively, while the lines distinguish between the K in , K ff controllers in the frequency-response figure and reference step response compared to the step disturbance responses in the time-domain simulation, respectively. The main conclusion drawn from this final pair of Figures is that the considered 2DOF control scheme is sensitive to the coefficient quantization levels, such that for T s,2 and T s,3 , the only acceptable solution would be to use the precise 32-bit configuration, with the exception of the implementability solution which manages to follow the imposed closed-loop transient response specifications with a reasonable degradation of the performances. The 16-bit quantization frequency responses for K in (z) drastically alter the integrator effect, which, in effect, disturbs the ability of the closed-loop motor system to track reference signals and to reject step-like load torque disturbances.
To conclude the case study, the acceptable solutions are to consider the implementabilitybased sampling rate optimum T opt s,1 , with practically ideal behavior if a 32-bit word length setup is acceptable, and with a small performance degradation if only the 16-bit standard word length is supported, depending also on other execution threads running in the microprocessor, not covered in this experiment.
Further extensions, as in using more complex controllers for both the tracking regulator and the feedforward component, considering cases such as fractional-order controllers or 2DOF robust control synthesis results can be treated in an analogous manner by splitting such control laws into their component second-order sections and applying the theory from Tables 3 and 4, along with Algorithms 1 and 2, respectively. Figure 8. DC motor example regulator frequency magnitude responses; the first line gathers the inner regulator K in (z) with 32-bit and 16-bit quantized regulator coefficients, respectively, while the second line gathers the feedforward controller K ff (z) in the same 32-bit and 16-bit configurations. For completeness, the continuous-time ideal regulators K in (s) and K ff (s) were also added alongside their discrete-time counterparts.

Conclusions
This paper gathered a set of analysis and design tools to determine the sampling rate of one and 2DOF control structures using an optimization-based approach, along with an approach of deducing a WCET for linear and time-invariant-based regulators through a formal language model which can be implemented in an RCP software tool. The execution time model is based on a deterministic, RISC architecture, where each operation is quantified with the same base clock tick duration. The end-to-end DC motor case study emphasizes the design of the controllers for the widely used benchmark system, by also focusing on the proposed framework.
Future work will concern on an online sampling rate optimization, as it is necessary in linear-parameter varying and linear-time variant models, along with the study and analysis of the continuity property of the regulator coefficient quantization effects as a function of the sampling rate. The problem of process controllability loss is also known in the literature and will be investigated for variable sampling rates in subsequent research. The mathematical framework proposed and extended in this paper will be included in the software toolbox initially proposed by the authors in [22], with the great advantage of obtaining an end-to-end solution for RCP, starting from the continuous-time controller design up to the optimal numerical implementation of said controller on a microprocessorbased system with a given set of specifications. A separate theoretical direction would be to investigate the link between sampling rate T > 0 and quantization step Q > 0 to guarantee that the minimum imposed performances are also fulfilled in the discrete domain.

Conflicts of Interest:
The authors declare no conflict of interest.

Abbreviations
The following abbreviations are used in this manuscript: