1 Introduction

Experimental testing plays an important role in the development, calibration, and validation of mathematical models of physical systems. Systematic testing is of particular importance for nonlinear systems, where the presence of bifurcations can result in a significantly different response for a small parameter change. A range of bifurcations can be seen in nonlinear systems. These can pose challenges to simple parameter-sweep tests, with issues including a system going unstable, or jumping to different response regimes to those of interest, and not returning due to hysteresis. Furthermore, with open-loop testing, bifurcation structures and system dynamics can only be inferred from stable responses. Unstable responses contain much information for parameter fitting [36, 37, 78], model identification, and inferring separatrices; however, they are not normally observable.

Control-based continuation (CBC) is able to systematically reveal both stable and unstable dynamics within an experiment, through a combination of feedback control and path-following methods [75]. It is a model-free experimental method, so that the resulting bifurcation analysis does not depend on modelling assumptions or fitted parameters. CBC uses feedback control to isolate the dynamics of interest, and to stabilise unstable responses. A selection of advanced controller strategies have been investigated for CBC, including adaptive and model-predictive control [10, 39,40,41]. Appropriate control targets are solved for iteratively, using standard numerical methods and, when necessary, Fourier–Galerkin discretisation.

CBC has seen significant success on mechanical systems, with examples including resonance curves of a harmonically forced nonlinear oscillator [3], mapping out fold bifurcations in two parameters [68], and finding solution branches of self-excited oscillations [36]. It has been applied to systems exhibiting complex dynamics, such as high levels of friction [29], isolated vibration modes [30], and the collective dynamics of pedestrian flows [57, 58]. Solution sets such as equilibria, bifurcations, and periodic orbits can be traced out across a parameter range, uncovering the bifurcation structure of a system, even when faced with noise [10, 70]. As well as tracing out response curves, features such as backbone curves [69] and dynamical stability [3, 5, 67] can be inferred. The collected data can be used for advanced system identification and parameter estimation [4, 10, 76].

Phase-locked loop (PLL) controllers provide an alternative to CBC when the response curves of interest can be parameterised in terms of shifts between forcing and response phase [54, 62]. PLL methods have found great success in experimentally computing the backbone curves and nonlinear frequency response functions of mechanical systems [11, 53, 63]. CBC and PLL methods both provide consistent, agreeing results [1, 55], and can be coupled together in cases where PLLs fail [2]. Nevertheless, CBC is more general than PLL testing, and able to compute a wider range of features, as it does not require a phase-parameterisation of the response curve.

Fig. 1
figure 1

Block diagram for control-based continuation experiments. A controllable black-box system of interest is combined with a feedback controller, which provides a stabilising input to the system. The CBC algorithm is used to iteratively update the control target \(x^*\), and the system parameter \(\lambda \)

Slow-fast dynamics appear regularly throughout the physical sciences, whereby state variables evolve at disparate rates. In engineering, large control gains can cause timescale separations in controlled systems, causing slow-fast responses [31]. In physics, the behaviours of a laser under optical feedback can show mixed-mode oscillations—an example of multiple-timescale dynamics [46]. Biochemical systems such as gene networks often show a range of expression rates, which produce dynamics over well-separated timescales [6]. Similarly, chemical reactions can produce relaxation oscillations, as a result of their slow-fast dynamics; the Oregonator [19] is a classical model of a chemical reaction undergoing relaxation oscillations. Further examples of systems demonstrating slow-fast dynamics and relaxation oscillations include Josephson junctions in electronics [82]; predator–prey systems [43]; and models of societal growth [52]. See [32] for additional examples, as well as a detailed coverage of slow-fast dynamical systems.

In principle, CBC is directly applicable to relaxation oscillations, and multiple-timescale systems more generally. Nevertheless, the tools are limited in practice. Numerical differentiation is required within the correction step of the continuation. Due to the model-free nature of CBC, this must be performed using finite differences. Continuation of periodic responses requires discretisation, with each additional discretisation coefficient imposing an additional system evaluation during finite differencing. Numerical solutions therefore become impractically slow, when using the large discretisation sizes necessary for relaxation oscillations. The extra computations also introduce more opportunities for error from noise and system drift [70]. Consequently, parsimonious discretisation methods are required to successfully apply CBC to slow-fast systems.

A further issue is that multiple-timescale systems are often autonomous, with no explicit time-dependency. Oscillatory solutions of autonomous systems comprise of a family of phase-shifted trajectories, making it an underdetermined problem to solve for a single oscillatory response. Some form of phase condition is needed to extract a unique solution. Options include the integral phase-condition, used as standard in numerical continuation [34] and demonstrated numerically with CBC [75], or phase-plane CBC [36], which is ideally suited for mechanical systems. However, both methods have limitations—the integral phase condition can lead to poor numerical stability with CBC, and phase-plane CBC can result in larger discretisation sizes than necessary when applied to relaxation oscillations.

To overcome these problems, we develop an alternative discretisation method and phase constraint for CBC. B-splines are used in place of the Fourier basis, so that the discretising basis functions can be tailored to the signals of interest. Optimisation-based techniques are introduced for producing an adaptive discretisation. The combination of basis functions and adaptation methods allows for an accurate discretisation, with lower dimensionality than Fourier methods.

In addition, we propose an angle-based parameterisation of the discretised control target. This acts similarly to the recently developed phase-plane CBC [36] to provide a phase constraint for CBC; however, our method can lead to lower discretisation sizes on slow-fast signals. Our angle-based phase constraint does not require knowledge of oscillation frequencies, improving both the speed and accuracy of numerical solutions when compared to the integral phase constraint. Together, these methods open up possibilities for faster, more accurate CBC experiments on relaxation oscillations.

This work is structured as follows. Section 2 introduces the workings of CBC, and the limitations of standard discretisation methods. Section 2.1 discusses how to construct periodic B-spline models, and Sect.  2.2 explains how these may be used as an alternative to the Fourier basis for Galerkin-discretisation. Section 2.3 considers the selection of an optimal B-spline basis for the problem of interest, and how to adapt the discretisation to new data. Next, Sect. 2.4 introduces the method of angle-encoded control targets as a phase constraint for autonomous systems. Our techniques are demonstrated through simulations on a model of a synthetic gene oscillator and chemical reaction network in Sect. 3. Section 4 discusses some pertinent aspects of our methods, and Sect. 5 concludes the work.

2 Control-based continuation of relaxation oscillations

Pseudo-arclength continuation systematically computes the solution manifolds of an underdetermined system [49, 72]. With CBC, response families of an experimental system are defined through a specific type of control target, referred to as a noninvasive target, and traced out using pseudo-arclength continuation. Figure 1 depicts a block-diagram of a typical CBC experiment. It consists of three parts: a controllable system, a stabilising feedback controller operating in real-time, and a suite of numerical methods, operating without time constraints to detect and trace dynamics of interest [3, 75]. The controller is used to probe and manipulate the dynamics of the system. If properly designed, it stabilises any unstable responses, and steers the system towards the dynamics of interest. A controlled system maps a control target \(x^*(t)\) to an observed output \(x(t)\), referred to as the input–output, or IO-mapping. Continuation equations are defined on the IO-map. Parameters and control targets are chosen using a numerical solver within a pseudo-arclength continuation, to locate responses that are intrinsic to the uncontrolled system.

CBC seeks noninvasive control [75]. A controller is noninvasive if it stabilises a limit cycle or equilibrium that exists within the uncontrolled system, without changing its position in parameter space. Hence, for control target \(x^*(t)\) and measured system response \(x(t)\), a sufficient condition for an applied control action \(u(x^*, x, t)\) to be noninvasive is if \(x^*\) is stabilised, and \(u\equiv 0\) for all time. Characteristics such as the geometry, oscillatory period, and location of steady-state system responses remain unchanged in the presence of noninvasive control. However, unstable features are stabilised, and become directly observable.

Fixed points of the IO-map are any control targets that are exactly tracked by the system output, and therefore satisfy \(x^* = x\). For a proportional or proportional-plus-derivative controller, the total control action \(\Vert u(x^*, x, t)\Vert \) is zero if and only if \(x^*(t) = x(t)\), so that noninvasive control is given by fixed points of the IO-map. Hence, noninvasive control targets are found by using a nonlinear solver to solve for \(x(t) - x^*(t) = 0\), guaranteeing zero control input and natural system dynamics.

Fig. 2
figure 2

An illustrative cubic spline model, constructed from five basis functions, each with equispaced knots. Each cubic B-spline is constructed from five consecutive knots. The range of these five knots gives the domain of that B-spline function. Within this domain, the spline is referred to as being active. The domain of the cubic spline curve itself, shown here in dotted grey, is the region within which exactly four B-spline functions are active. As a result, knots must be placed on or outside the domain of the spline model, to provide the appropriate number of B-splines within the domain. These are referred to as exterior knots

Solving for fixed-points is performed using standard numerical methods, such as Newton or quasi-Newton iterations [75]. These cannot be applied directly when \(x^*\) is oscillatory; instead, the zero-problem must be discretised. All current CBC implementations use a Fourier discretisation, in which control targets and system responses are represented by truncated Fourier series, and equality is sought between Fourier coefficients [75]. Assume the control target and measured system output are well-approximated by their first \(n\) Fourier modes. Expanding both functions in the Fourier basis gives

$$\begin{aligned} x^*(t)&= a_0^* + \sum _{k=1}^n a_k^*\cos (k\omega t) + b_k^*\sin (k\omega t)~, \end{aligned}$$
(1)
$$\begin{aligned} x(t)&= a_0 + \sum _{k=1}^n a_k\cos (k\omega t) + b_k\sin (k\omega t)~, \end{aligned}$$
(2)

where \(\omega \) is the oscillatory frequency. Then, \(x^*-x=0\) is satisfied when \(a_0^* - a_0 = 0\), \(a_k^* - a_k = 0\) and \(b_k^* - b_k=0\), for \(k\in \{1, \dots , n\}\). Unlike the original problem, the discretised problem can be solved using standard numerical methods. Furthermore, the projection onto basis functions provides a degree of noise-averaging, improving robustness with noise-corrupted measurements.

Fourier discretisation has been used successfully in existing CBC experiments, where signals are well-approximated by few Fourier harmonics. Nevertheless, it presents challenges for systems which undergo rapid changes, such as relaxation oscillations or impacting and friction dynamics. Such systems produce highly changeable signals, and many Fourier modes are needed for producing an accurate discretisation. This results in a high-dimensional continuation problem, which in turn slows down experiments and introduces more opportunities for error. Here, we develop a B-spline discretisation scheme to overcome this issue.

2.1 Periodic B-splines

A spline is a maximally smooth, piecewise-polynomial curve. Splines are defined by choosing a set of knot points and connecting them together with sections of polynomial. Polynomial coefficients are determined partially by ensuring that each polynomial starts and ends at its boundary knots, and meets its neighbouring polynomials smoothly. In addition, a pair of boundary conditions are required. In this work, we assume periodic boundary conditions.

Spline curves are often expressed as a weighted sum of basis functions, to simplify computations. B-splines are a family of minimal-support basis functions for spline curves [9]. The B-spline basis is constructed from a set of scalar-valued knots, defining the \(x\) positions at which each section of polynomial meets. The \(y\) positions are determined by the basis function coefficients.

The B-spline basis can be obtained through the following recurrence relation (see [9] for a detailed discussion and proof). Let \(\Xi = \{\xi _0 \le \dots \le \xi _n\}\) be an ordered set of knots. Given \(\Xi \), the first-order B-splines, consisting of piecewise-constant terms, are defined as

$$\begin{aligned}B_{i,1}(t) = {\left\{ \begin{array}{ll} 1, &{}\quad \text {if } \xi _i \le t \le \xi _{i+1} \\ 0, &{}\quad \text {otherwise.} \end{array}\right. }\end{aligned}$$

Higher-order spline functions are constructed recursively; let

$$\begin{aligned} \omega _{i,k}(t) = {\left\{ \begin{array}{ll} \frac{t - \xi _i}{\xi _{i+k-1} - \xi _i}, &{}\quad t_{i+k-1} \ne t_i \\ 0, &{}\quad \text {otherwise.} \end{array}\right. }\end{aligned}$$

Then, the \(i\)th B-spline of order \(k\), defined on knots \(\Xi \), is given as

$$\begin{aligned} B_{i,k}(t) = \omega _{i,k}(t)B_{i,k-1}(t) + \big [1-\omega _{i+1,k}(t)\big ]B_{i+1,k-1}(t)~. \end{aligned}$$

B-spline functions are generally evaluated using the Cox–de Boor algorithm [8]. Implementations are provided as standard in many scientific computing packages.

Figure 2 depicts a cubic B-spline model with equidistant knots. By definition, each B-spline function has minimal support across a domain determined by its knots. Within the domain, the spline is referred to as being active. It is observed that exactly four B-splines are active at any point within the domain of the spline curve for which the B-splines form a basis. A consequence of this is that knots are also required outside of the spline domain, to ensure the correct number of active B-splines within the domain. We refer to the knots outside of the domain as exterior knots, and knots within the domain as interior knots. Exterior knots dictate the boundary conditions of the spline model. Here we recall how exterior knots can be chosen to give periodic boundary conditions, using the method of periodic extension [9]. Section 2.3 then considers how to select optimal interior knots.

Fig. 3
figure 3

Knot positions (dots) and basis functions (green, red curves) of a B-spline model with periodic boundary conditions (orange curve). The last three interior knots of the spline model (blue dots) are shifted back by one period to get the left exterior knots (green dots), and first three interior knots are shifted forward by one period to get the right exterior knots. Boundary knots (black dots) mark the points at which the resulting periodic boundary conditions are applied. Note that if an identical spline model were to be created one period in the past or future, the interior knots of the adjacent periods (red dots) would overlap exactly with the interior knots of this period; pairs of boundary knots would overlap exactly. As a result, the basis functions of the adjacent periods (red curves) would exactly overlap those of this period (green curves), providing the equalities necessary for periodic boundary conditions. (Color figure online)

As depicted in Fig. 3, periodic boundary conditions require the exterior knots and B-spline functions from one period to overlap with those of adjacent periods. This is achieved simply by shifting appropriate sets of interior knots by one period [9]. Given a knot on the lower and upper domain boundary, and three or more interior knots, periodic exterior knots for a cubic set are found by

  • shifting the last three interior knots (blue dots in Fig. 3) backwards by one period, to produce the first three exterior knots (green dots);

  • shifting the first three interior knots (blue dots) forward by one period, to produce the last three exterior knots (green dots);

  • enforcing equality between respective pairs of coefficients for the first and last three B-splines.

This ensures equality between the B-spline functions at the start and end of the period and produces periodic boundary conditions.

More rigorously, consider a cubic spline curve

$$\begin{aligned} b(t) = \sum _{i=-3}^n \beta _i B_i(t), \end{aligned}$$
(3)

defined on the domain \(t\in [0,T]\), with periodic boundary conditions. The boundary conditions require \(b(0) = b(T)\), and likewise for all available derivatives. Exactly four basis functions are active at the start of the domain, and equivalently at the end. Considering only these active basis functions, it is seen that periodic boundary conditions require

$$\begin{aligned} \sum _{i=-3}^{0}\beta _iB_i(t) = \sum _{i=n-3}^n \beta _iB_i(t+T)~, \end{aligned}$$
(4)

implying

$$\begin{aligned} \sum _{i=-3}^{0}\beta _iB_i(t) = \sum _{i=n- 3}^n \beta _iB_i(t+T)~, \end{aligned}$$
(5)

and

$$\begin{aligned} B_{-3}(t) = B_{n-3}(t+T), \quad \dots , \quad B_0(t) = B_n(t+T). \nonumber \\ \end{aligned}$$
(6)

Each cubic B-spline is defined over a set of five knots; let B-spline \(B_i(t)\) be constructed from knots \(\Xi ^i = \{\xi ^i_1 \le \xi ^i_2 \le \xi ^i_3 \le \xi ^i_4 \le \xi ^i_5\}\). Shifting a set of B-spline knots by some amount \(T\) produces an equivalent shift in the resulting B-spline function. That is, given \(\Xi _T^i = \{\xi ^i_1 + T\le \xi ^i_2 + T \le \xi ^i_3 +T \le \xi ^i_4 +T \le \xi ^i_5 + T\}\), the corresponding B-spline function \(B_i^T(t)\) satisfies \(B_i^T(t+T) = B_i(t)\). Hence, for (\(B_{-3}(t+T) =B_{n-3}(t)\)) to be satisfied, we must have [\(\Xi ^{n-3} = \Xi ^{-3} + T\),    \(\Xi ^{n-2} =\Xi ^{-2} + T\), etc.]

2.2 B-spline discretisation for CBC

B-spline discretisation for CBC proceeds in much the same way as Fourier discretisation. Noninvasiveness is sought by solving for equality between the control target and system output, when proportional or proportional-plus-derivative control are used. This is achieved by projecting a system response onto a B-spline basis, and seeking equality between the target and response coefficients. Control targets are represented as a sum of basis functions \(B_i\) weighted by coefficients \(\beta _i^*\), as given by

$$\begin{aligned} x^*(t) = \sum _{i=1}^n \beta _i^* B_i(t)~. \end{aligned}$$
(7)

Periodicity of the control target is guaranteed by selecting basis functions \(B_i\) for periodic boundary conditions, as discussed in Sect. 2.1. Target \(x^*(t)\) is used to control the system of interest, using a proportional or proportional-plus-derivative strategy. Recorded samples \((t_j, x_j)\) from the system output \(x(t)\) are projected back onto the basis functions \(B_i\) using least-squares. Given samples \((t_j, x_j)\) for \(j\in \{1,\dots , N\}\), let

$$\begin{aligned}{}[{\mathcal {B}}]_{u,v}&= B_v(t_u) ~, \end{aligned}$$
(8)
$$\begin{aligned} \beta&= [\beta _1, ~ \beta _2, ~ \dots , ~ \beta _n]^T ~, \end{aligned}$$
(9)
$$\begin{aligned} X&= [x_1, x_2, \dots , x_N]^T ~. \end{aligned}$$
(10)

Equation (7) suggests \(X = {\mathcal {B}}\beta \); however, given sufficient data, this is overdetermined, with a least-squares error \(e\) of

$$\begin{aligned} e = \Vert X - {\mathcal {B}}\beta \Vert ^2~. \end{aligned}$$
(11)

Coefficients \(\beta _\textrm{lsq}\) that minimise this error are given by the least-squares Eq.

$$\begin{aligned} \beta _\textrm{lsq} = \left( {\mathcal {B}}^T {\mathcal {B}}\right) ^{-1} {\mathcal {B}}^T X~. \end{aligned}$$
(12)

Hence, the B-spline representation \(x(t)\) of samples \((t_j, x_j)\) is given by

$$\begin{aligned} x(t) \approx \sum _{i=1}^n \beta _i B_i(t)~, \end{aligned}$$
(13)

for \(\beta _\textrm{lsq} = [\beta _1,~ \dots ,~ \beta _n]\). Noninvasiveness is met when \(\beta _i^* - \beta _i =0\) for all \(i\in \{1,\dots ,n\}\).

Here, we exclusively consider cubic spline models. Nevertheless, the methods presented in this work can be implemented using splines of any order.

2.3 Selecting and adapting interior knots

figure a

B-spline knots act analogously to a mesh in finite element methods. While uniformly spaced knots could be used, it is typically beneficial to tailor the knots to the problem of interest. Smaller discretisation sizes are almost always achieved when knot positions are selected specifically for the system of interest. Here, we discuss a method to select an optimal set of spline knots and to adaptively update them throughout a continuation.

Many methods have been proposed for selecting spline knots. Free-knot methods choose knots either through one of many optimisation-based techniques [25, 26, 71, 81], using various heuristics [38, 51], or by creating probabilistic distributions over knot sets [14, 42, 45]. For CBC, the experimenter should be free to determine their desired discretisation size. As such, optimisation-based knot placement strategies are appealing, whereby the experimenter chooses the number of knots, and the experimental results inform where they are best placed. We use numerical optimisation to automatically place a predetermined number of knots, in order to minimise the least-squares error between a set of reference data, and the best-fit spline model of those data.

The optimisation procedure is summarised in algorithm 1, and knot selection proceeds as follows. For each iteration of a local optimiser, a set of interior knots are produced. From these, exterior and boundary knots are added, and used to construct a set of basis functions. A least-squares fit to a reference signal is produced using these basis functions, and the local-optimiser algorithm performs further iterations to find the interior knots that minimise this fitting error. We choose a bounded limited-memory BFGS (L-BFGS-B) local optimiser, implemented in SciPy [83]. To avoid local minima, the optimisation is repeated several times from random initial conditions, and the best result is selected as the final knot set. The reference signal can be measurements from an uncontrolled system evaluation when initialising knots, or the last accepted continuation solution when following the knot adaptation procedure discussed next. As observed in Fig. 3, optimal knots tend to be placed around turning-points within a signal.

To ensure the optimiser proposes valid knots, constraints are applied to the problem, to restrict proposed knots to within the model domain. Samples are projected onto a single period. We choose, without loss of generality, to rescale that period onto the unit interval. Each B-spline knot \(\xi \) can then be constrained to \(\xi \in [0,1]\), providing bounds on the search space.

The objective function requires no additional evaluations of the controlled or uncontrolled system. Optimisation can be performed entirely offline in a matter of seconds. Globally optimal knots are typically found. An alternative to random restarts is a global optimiser such as simulated annealing. In our tested cases, this is found to generally produce the same knots as random restarts, however random restarts produced satisfactory results more rapidly for larger discretisation sizes.

Continuation solutions will change during an experiment, as parameters are varied. It is preferable to adapt the discretisation basis throughout the continuation. We achieve this by running an optimisation step on the current knots every time a new solution has been accepted. We choose either a sequential least-squares quadratic programming (SLSQP), or constrained trust-region optimisation method for this, both implemented in SciPy [83]. A new, different set of globally optimal knots may emerge during an experiment. The experimenter may therefore choose to perform a full multi-restart knot optimisation when the discretisation error increases beyond a predetermined threshold. When using adaptive discretisation, care must be taken to ensure that the same basis functions are used to discretise all solutions within a given prediction–correction step; pairs of previous results cannot be used for secant prediction if their discretised solutions are obtained from different basis functions. Consistency in secant predictions is obtained by rediscretising previous solution data, and projecting all samples onto the newly updated basis functions. Hence, an accepted solution is used as a reference signal for selecting knots, then the same set of basis functions are used throughout all calculations in the next prediction–correction step.

2.4 Angle-encoding phase constraint

Fig. 4
figure 4

Schematic diagram of the angle-encoded control strategy. Measurements \(x(t)\) from the controlled system are embedded in a planar limit cycle. The angle of the current embedded state is used to find the instantaneous control target. The control target is sent to a feedback controller, compared to measurements, and fed back into the system as a control action

A phase constraint is required to produce a unique solution for the continuation of oscillations in an autonomous system. Here, we obtain a unique solution by indexing control targets in terms of an angle-based independent variable, instead of time. As CBC solutions now lack any time-dependency, phase shifts cease to be meaningful, and oscillatory solutions become (locally) unique. We refer to our method as angle-encoding, since control targets are solved for in the angle-domain. Noninvasiveness is achieved when equality is reached between the angle-encoded system response and control target.

Angle-encoding proceeds by taking time-dependent samples \((t_i, x_i)\), and converting them to time-independent samples \((\phi _i, x_i)\). This is performed by replacing the time index variable \(t\) with an angle-based independent variable \(\phi \). Control targets are then constructed to give the desired system output at some state-angle \(\phi \).

Fig. 5
figure 5

Examples of an angle-encoded control target and system response, before and after a correction step. Noninvasive control is achieved when equality is found between the angle-encoded discretisations of the control target and system response

The full angle-encoding procedure is as follows. Some system response \(x(t)\) is measured. A second variable \(z(t)\) is also required, referred to as the embedding variable. The embedding variable is used to reconstruct a planar limit cycle from the observed data; it can come from an explicitly measured state variable in an experiment, or from a proxy for the state, such as delay or derivative coordinates. Embedding variable \(z(t)\) is used in conjunction with state variable \(x\) to calculate an instantaneous state angle \(\phi \). The chosen embedding must produce a unique mapping from angles to control targets.

For some embedding variable \(z(x,y)\), the angle of an embedded state \((x(t), z(t))\) is given by

$$\begin{aligned} \phi (x, z) = \textrm{atan2}\left( \sigma \left( z - \mu _z\right) , x - \mu _x\right) . \end{aligned}$$
(14)

Parameters \(\mu _x\) and \(\mu _z\) shift the embedded limit cycle to encircle the origin, and \(\sigma \) scales it. Origin choice \((\mu _x, \mu _z)\) is found to affect the performance of the controller, as discussed further in Sect. 4. Scale-factor \(\sigma \) is beneficial in the cases where \(x\) and \(z\) have significantly different amplitudes. Such cases often arise with slow-fast systems, when using derivative coordinates as an embedding scheme. The scale factor ensures angles are well-distributed across the interval \([0, 2\pi )\), so that the angle-encoded control target can be represented in an effective manner. A good choice for \(\sigma \) is anything that brings \(x(t)\) and \(\sigma z(x, y)\) into comparable amplitudes. Principal component analysis may be used in place of scale factor \(\sigma \), to transform embedded states when \(x\) and \(z\) are highly correlated, for example, in delay embeddings.

Angle-encoded signals are time-independent, so phase-shifts are no longer meaningful. Solution phases are instead determined by the combination of system dynamics and angle definition. As such, angle-encoding ensures that solving for an oscillatory response is a well-posed problem, with a unique solution. Furthermore, no knowledge of oscillatory period is required. This simplifies the continuation equations, by avoiding the need to calculate the response frequency of the system.

2.5 Angle-based control

Control proceeds as sketched in Fig. 4. At any given instant, the system is observed. Observed measurements \(x(t)\) are combined with some embedding variable \(z\) and transformed, to reconstruct a planar limit cycle. The angle of the current state on this limit cycle is calculated with Eq. (14), and a proportional control law of form

$$\begin{aligned} u(x, z) = k_p\left( x^*(\phi ) - x(\phi )\right) \end{aligned}$$
(15)

is chosen. Control force \(u\) is then fed back into the system, to stabilise target \(x^*\).

The continuation zero problem is replaced by its angle-encoded counterpart, as

$$\begin{aligned} x(\phi ) = x^*(\phi )~. \end{aligned}$$
(16)

This requires the measured system output to be translated into an angle-encoded output, in the same way as is performed by the controller. Equation (16) is discretised and solved identically to its time-dependent counterpart.

Angle-encoded noninvasiveness behaves exactly the same as temporal noninvasiveness, by guaranteeing zero control action. An example is plotted in Fig. 5, showing angle-encoded targets and responses. These are taken from the first prediction–correction step of the gene oscillator CBC simulation discussed in Sect.  3.2, except with a larger stepsize of 0.75. Angle-encoded control targets and system responses are shown, both for an uncorrected prediction, and for the same solution after Newton-correction. It is seen that equality has been found between the angle-encoded control target and system response, giving a noninvasive solution.

3 Case studies

Our methods are demonstrated through simulations of two slow-fast models—a gene oscillator, and an oscillating chemical reaction. Notes on possible experimental implementations are provided, the CBC method is discussed, and simulated results are presented for each system.

The first test-system is taken from synthetic biology. Mathematical modelling and systems identification are powerful tools within systems and synthetic biology [12, 47, 48]. Recent developments in the field have produced a range of novel methods for the automatic feedback control of gene expression and signalling pathways in live cells [27, 44, 50, 59, 60, 65, 66, 73]. Accordingly, methods are being actively developed to exploit these control methods, for applying CBC to synthetic gene networks [10], which could be of great benefit when it is difficult to derive or calibrate models for the biological system of interest. Here we show numerical results of a CBC experiment, to track oscillations in a modelled slow-fast gene regulatory network. Results are obtained from a nondimensional model taken from [23]. For proteins X and Y, with respective (nondimensionalised) concentrations \(x\) and \(y\), the network dynamics is given by

$$\begin{aligned} \frac{\textrm{d} x}{\textrm{d} t}&= \frac{1 + x^2 + \alpha \sigma x^4}{(1 + x^2 + \sigma x^4)(1 + y^4)} - \gamma _x x ~ , \end{aligned}$$
(17)
$$\begin{aligned} \tau _y \frac{\textrm{d} y}{\textrm{d} t}&= \frac{1 + x^2 + \alpha \sigma x^4}{(1 + x^2 + \sigma x^4)(1 + y^4)} - \gamma _y y ~, \end{aligned}$$
(18)

with \(\tau _y=10\), \(\alpha =11\), \(\gamma _x=0.105\), \(\sigma =2\); we consider continuation parameter \(\gamma _y \in [0.01, 0.05]\). All parameter values are as given in [23], except for design parameter \(\tau _y\). This quantifies the system timescale separation in the system, which we increase to 10 to further widen the timescale separation. Bifurcation parameter \(\gamma _y\) quantifies the degradation rate of protein Y, which can be modified by varying the concentration of isopropyl-\(\beta \)-D-thiogalactopyranoside (IPTG) [23]. Recent methods have been developed to modify IPTG concentrations online for cell cultures in microfluidic chambers. In these cases, IPTG is used as a control input to cells [27, 73]; the same method can be used to change IPTG concentrations for modifying bifurcation parameter \(\gamma _y\). Existing genomic control experiments use bang-bang control strategies [35]; it remains to be seen whether these methods have the necessary fidelity to stabilise unstable oscillations. Optogenetic methods provide an alternative approach for implementing control strategies, by using various wavelengths of light to control gene expression [7, 56, 77].

Our second test system is the reduced Oregonator model, describing the dynamics of the oscillating, autocatalytic Belousov–Zhabotinsky reaction. Forcing and feedback control have been used for a variety of experiments on the dynamics of Belousov–Zhabotinsky reactions. A wide range of feedback controllers have been proposed [17], with common experimental strategies include combining video measurements and optical feedback [20,21,22, 28, 79], and by modifying reactant inflow rates [18, 64]. Other experiments use electrical stimulation to provide perturbations into the experiment [33, 61, 74]. We consider feedback control of an ODE model, representing a well-stirred Belousov–Zhabotinsky reaction which could be controlled through modification of reactant inflow rates. Dynamics is governed by a two-variable nondimensionalised Oregonator, obtained through a quasi steady-state approximation of the full system [80]. The model is given by

$$\begin{aligned} \varepsilon \frac{\textrm{d} x }{\textrm{d} t}&= x(1-x) - f\frac{y(x-q)}{x+q} ~, \end{aligned}$$
(19)
$$\begin{aligned} \frac{\textrm{d} y }{\textrm{d} t}&= x - y~. \end{aligned}$$
(20)

We take \(\varepsilon =0.1\), \(q=0.025\), and \(f\) is to be varied, as the continuation parameter.

3.1 CBC parameters

Simulations are produced using custom code in Python 3. For both systems, a proportional feedback law is chosen. A gain \(K_p=0.1\) is chosen for the gene oscillator, and gain \(K_p=4\) for the Oregonator. Gains are chosen through trial and error, by seeking the smallest gain that stabilises the unstable branch of orbits. Small gains are preferred for experimental applications, to avoid amplifying measurement noise. Control is applied additively in both cases, to the state variable \(x\) of Eqs. (17) and (19). For both systems, the second state variable \(y\) is used as an angle-encoding embedding variable. Errors are calculated between an angle-encoded target \(x^*(\phi )\) and the state variable \(x\) at angle \(\phi (x,y)\).

Cubic B-splines are used for the discretisation basis functions. A discretisation with ten coefficients is used for the gene network, and seven coefficients for the Oregonator. Discretisation size is found by seeking the fewest coefficients necessary to capture open-loop, initialising data with satisfactory accuracy. B-spline knots are adapted after each successful prediction–correction step. Pseudo-arclength continuation is chosen, with a secant prediction scheme. Corrections are made by a Newton-solver, with forward finite-differences for Jacobian estimation, and a finite-differences stepsize of \(5\times 10^{-3}\) for the gene oscillator, and \(1\times 10^{-2}\) for the chemical oscillator. Randomness in experiments limits the accuracy of a numerical solution. It can be beneficial to cap the number of solver iterations to avoid excessive experimental effort in noisy regions. To recreate experimentally relevant conditions, we take a maximum of three Newton iterations per correction step. Convergence is declared when either the normed Newton-step-size or solution residual falls below \(5\times 10^{-3}\), or three iterations have been reached. Continuation is terminated when a solution amplitude falls below 0.05.

Fig. 6
figure 6

Simulated CBC results for an oscillating synthetic gene network [23]. CBC results are shown on a in black, and are overlaid on a bifurcation diagram generated in XPPAUTO (version 8.0), showing stable (pink) and unstable (grey-dotted) equilibria, and stable (green) and unstable (purple dotted) limit cycles. The dynamics of the oscillator are shown in b, c, as a time-series plot of the \(x\) variable (panel b), and a phase-plane diagram illustrating the nullclines (blue, orange lines), limit cycle (black line), equilibrium (open circle), and flow-field (black arrows), (c). Time series and phase plane plots are produced at \(\gamma _y = 0.03\), indicated by the vertical blue line in the bifurcation diagram. Stable and unstable branches of periodic orbits are marked as such; CBC stabilises the unstable branches, to render them observable. In the open-loop system, branches of periodics emerge at the marked Hopf bifurcations; branch stability switches at the saddle-node of periodic orbits bifurcation (SNP), and on the canard explosion. CBC results are seen to match the XPPAUTO results almost perfectly, with the exception of the canard explosion which CBC cannot follow. (Color figure online)

Fig. 7
figure 7

a Bifurcation diagram of an autocatalytic chemical reaction model, described by a planar Oregonator. The dynamics of the oscillator are shown in b, c, as a time-series plot of the \(x\) variable (b), and a phase-plane diagram illustrating the nullclines (blue, orange lines), limit cycle (black line), equilibrium (open circle), and flow-field (black arrows), panel (c). Time series and phase plane plots are produced at \(f = 1.0\), indicated by the vertical blue line in the bifurcation diagram. CBC results are shown (black lines) in the top panel, on top of a bifurcation diagram for the same system generated by XPPAUTO (version 8.0) with the same colour scheme as Fig. 6. CBC continuation is terminated when the solution amplitude falls below 0.05; results are seen to match those produced by XPPAUTO. (Color figure online)

Continuation is initialised from two open-loop oscillations. These are observed at parameters \(\gamma _y=0.03\) and \(\gamma _y=0.0301\) for the gene oscillator, and \(f=0.75\) and \(f=0.755\) for the chemical oscillator. Two separate experiments are run, one continuing forward, then one backward. A fixed prediction stepsize is used for the chemical oscillator, of \(0.1\) for the forward run, and \(0.05\) for the backward run.

A simple stepsize-adaption routine is chosen for the gene oscillator, to assist with continuation around the sharp fold of periodics. Note that this method is not necessarily the best choice for CBC experiments, as it can be computationally inefficient. Other stepsize adaptation methods for CBC are considered in [70]. Stepsize adaptation proceeds as follows. ‘Current stepsize’ is defined as the distance between the current corrected solution guess, and the most recently accepted solution. The ratio between prediction stepsize and current stepsize is calculated from the solver solution at each step. If they are within a scale-factor of 1.2, the solution is accepted, and the stepsize is increased. Stepsize is capped at a maximum of 0.2 for the forward-run, and 0.1 for the backward run. If the solution distance is not within a scale-factor of 1.2, the stepsize is reduced, and a new prediction–correction step is taken. Stepsize is capped at a minimum of \(1\times 10^{-3}\). If the stepsize is decreased below this, a convergence failure is declared, and the continuation terminates.

A polar origin must be chosen for angle-encoding, as described in Sect. 2.4. Careful choice of polar origin is important for successful control; Sect. 4.2 discusses origin placement, and defines and motivates the placement options used here. The gene oscillator uses a max–min placement for the polar origin of the forward-continuation; a min–max origin for the backward-continuation. The chemical oscillator uses a middle-origin for the forward continuation, and a max–max origin for the backward run. The polar origin is updated alongside the discretisation, after each new solution has been accepted.

Fig. 8
figure 8

Comparison of Fourier and B-spline discretisation for noise-corrupted observations of the chemical oscillator studied in Sect. 3.2, at parameter \(f=1\). A control target is generated from a deterministic, open-loop oscillation. Synthetic noisy data are generated by controlling the system using a proportional controller and the deterministically obtained control target, with controller measurements corrupted by i.i.d. Gaussian white noise of variance \(\sigma ^2=0.1\), to simulate noise-corrupted observations. Spline discretisation is seen capture the true, noise-free data more accurately than Fourier

3.2 Results

Gene network results are shown in Fig. 6. To validate the results, a bifurcation diagram is also generated directly from Eqs. (17), (18), using pseudo-arclength continuation and orthogonal collocation, with XPPAUTO version 8.0. [16] It is seen that CBC traces out most of the bifurcation diagram with an exact agreement to XPPAUTO. However, unlike XPPAUTO, the CBC procedure only requires measurements of a controlled system. This allows the system dynamics to be studied directly in an experiment, instead of through mathematical models. CBC is unable to trace out the canard explosion at approximately \(\gamma _y = 0.01575\). Nevertheless, canard orbits are structurally unstable and very short-lived in planar systems [13], so would be very difficult to observe in an experiment. We therefore do not consider this a shortcoming of our methods, but rather an inherent challenge of studying physical slow-fast systems. Note that some methods exist for controlling canard cycles [15, 24].

Figure 7 shows the results of CBC on an Oregonator model. CBC solutions are again overlaid on a bifurcation diagram generated with XPPAUTO. Our methods are shown to trace out both stable and unstable periodic responses, with comparable accuracy to XPPAUTO.

4 Discussion

4.1 Robustness to observation noise

Spline models are appealing for CBC: piecewise-polynomials offer the broad descriptive capabilities of polynomial fitting, without suffering from Runge’s phenomenon. In addition, the combination of model smoothness and low-degree polynomials provide compelling noise-filtering capabilities, as shown in Fig. 8. Plotted are synthetic data, from a slow-fast system controlled with a proportional controller. Data are generated from the Oregonator model described in Sect. 3. To recreate a realistic experiment, controller observations are subject to measurement noise, producing a stochastic system with a noisy response. B-spline discretisation outperforms Fourier discretisation of the noisy data. With low discretisation sizes, Fourier discretisation struggles to match the slow-changing section of the signal; with larger discretisation sizes, it becomes susceptible to noise corruption. B-splines provide a more accurate description of the underlying deterministic process, and are robust against observation noise.

4.2 Angle-encoding origin choices

Fig. 9
figure 9

Phase planes demonstrating mechanism of stalling for angle-encoded control, showing flow-field (arrows), \(x\) and \(y\) nullclines (blue, orange lines, respectively), stable and unstable equilibria (filled, open circles), angle-encoding origin (black cross), and limit cycle trajectory where appropriate (black closed curve). a Phase-plane of an uncontrolled Oregonator at parameter \(f=0.65\). b A noninvasive control target for parameter \(f=0.67\) is found from a discretisation of open-loop oscillations. This is then used as an angle-encoded control target at parameter \(f=0.65\), using a min–max origin. The controller is seen to put a stable equilibrium into the system, so that oscillations disappear. c The same control target is now used with a max–min origin. Moving the polar origin has changed the nullclines, such that the previous stable equilibrium has destabilised, and the desired oscillations return

Angle-encoding requires a polar origin \((\mu _x, \mu _z)\), from which state angles are computed. Easily computed choices for \(\mu _x\) and \(\mu _z\) are the mean over one period of the signals \(x(t)\) and \(z(t)\), respectively. Nevertheless, these values do not work in all cases. With some systems, the controller can settle to a spurious equilibrium—an invasive equilibrium, near an equilibrium of the uncontrolled system. Spurious equilibria are not representative of the true, uncontrolled equilibrium at that parameter value.

Figure 9 shows a set of phase plane diagrams that elucidate this stalling mechanism. Controllers modify the dynamics of a system; as angle-encoding is a time-independent control strategy, the modified dynamics can be shown on phase portrait diagrams. The controller changes the nullcline of the controlled variable, which can introduce additional equilibria into the system, or cause changes in the position of existing equilibria. Although noninvasive control is generally successful with angle-encoded control targets, the controlled dynamics are not always robust. A small change in control target shape or system parameters can be enough to push one of these unstable equilibria onto the stable nullcline branch. Such changes are to be expected within the prediction and correction steps of a continuation experiment. Figure 9 highlights this—a noninvasive control target is found for the Oregonator, at parameter \(f=0.67\). Periodic orbits are controlled successfully with this target, however when the same target is used at a parameter of \(f=0.65\), oscillatory dynamics are seen to have disappeared, the equilibrium has stabilised, and the system has settled to an invasive equilibrium (Fig. 9b).

In such cases, the oscillatory response can often be restarted by changing \(\mu _x\) and \(\mu _z\) to move the polar origin towards the spurious equilibrium. Changing the polar origin also changes the nullclines of the controlled system. This can push the invasive equilibrium back onto the unstable nullcline branch, so that oscillatory dynamics reappear (Fig. 9c). To this end, we define a selection of choices of polar origin which, while heuristic, are found to often move the nullclines in an appropriate manner as to destabilise the invasive equilibria.

Two heuristics are sketched in Fig. 10. The first heuristic—the min–max origin—can fix spurious equilibria that would otherwise appear in the top-left of the reconstructed cycle, by moving the polar origin up and left slightly. It is defined by taking \(\mu _x\) as the \(x\) coordinate of the state with minimal \(z\) value, and \(\mu _z\) as the \(z\) coordinate of the state with maximal \(x\) value. The second heuristic—the max–min origin—moves the polar origin slightly down and right, and prevents spurious equilibria from appearing in the bottom-right of the reconstructed cycle. It is defined as the \(x\) value at the state with maximal \(z\) value, and the \(z\) value of the state with minimal \(x\) value. Additionally, a max–max and min–min origin can be defined, following the same pattern. More alternatives are a middle-origin, where the polar origin placed in the centre of a minimal bounding box for the limit cycle; to use the results of an equilibrium CBC to inform origin placement; or to manually select the polar origin and keep it fixed throughout a continuation. These heuristics succeed in our tested cases, however it must be noted that they are merely heuristics, and may not succeed in every case, or with every embedding strategy. Future work should investigate robust and automated polar origin placement.

Fig. 10
figure 10

Sketch of the min–max and max–min polar origin choices for determining a state angle from an embedded limit cycle

5 Conclusion

CBC is a model-free method for performing a bifurcation analysis of black-box and physical systems. To promote faster, more accurate CBC experiments for relaxation oscillations, we considered methods for adaptive discretisation using a B-spline basis. Spline models are able to capture changeable system responses more succinctly than the standard truncated Fourier series method. Furthermore, we proposed the angle-encoding phase constraint, which complements phase-plane CBC [36] and produces lower-dimensional discretisations on relaxation oscillations. Angle-encoding parameterises control targets by an angle rather than time. It acts as a phase constraint, and removes the need to compute response frequencies.

Our angle-encoding and B-spline-discretisation methods were demonstrated on simulations of a synthetic gene oscillator [23] and autocatalytic chemical oscillator [80]. CBC produced accurate results, which visually matched those obtained using XPPAUTO. B-splines were found to be an efficient discretiser for CBC of slow-fast systems. Angle-encoding offers a compelling choice of phase-constraint for autonomous systems, and both simplifies numerical computations by avoiding computation of response period, and gives robustness against drifts in response frequency.

Our methods are immediately beneficial for any system whose responses contain many Fourier harmonics. While relaxation oscillations form the motivation of this work, we anticipate our methods will prove beneficial to a wide range of systems. B-splines are able to succinctly capture rapidly changing responses, such as those arising in impacting and stick–slip oscillators, and indeed any system for which Fourier discretisation is not desirable. In addition, the phase constraint and discretisation methods are distinct. B-spline discretisation can be used without angle-encoding on nonautonomous systems, and angle-encoding can be used with Fourier discretisation when the Fourier–Galerkin method is appropriate. Together, these two methods open up the possibility of applying control-based continuation to a much wider range of systems—those exhibiting autonomous responses, and those with significant amounts of higher-order harmonics.

Angle-encoding is sometimes found to cause issues within the controller. State angles can cease to change, so that the system converges to an invasive equilibrium instead of the oscillations of interest. Careful placement of polar origins are seen to fix this in the cases tested here. Future work is focusing on systematically identifying when stalling happens, and methods to prevent it.