System Identification Injector

The System Identification (Sys. Id.) Injector block superimposes an excitation signal, such as a pseudorandom binary sequence (PRBS), on a scalar user-code signal. The resulting excitation is used to estimate the frequency response between two signals of the system under test. The block is the user-code component of the imperix System Identification toolbox:

  • On imperix controllers, the experiment is configured and launched from the Cockpit System Identification module (PN306). The Scope module (PN301) records the data, from which Cockpit estimates and displays the frequency response.
  • In Simulink or PLECS simulations, the block records the experiment and estimates the frequency response at the end of the simulation run.

This page focuses on configuring the injector block in Simulink/PLECS. PN215 (parametric identification of a buck converter) and PN216 (controller tuning in the frequency domain) present application examples.

Experiments with Cockpit’s System Identification module can be scripted using Python. A dedicated set of methods is available in the Python library.

Principles of operation

An identification experiment, whether executed on hardware or in simulation, runs in two phases:

  1. Excitation and recording. The excitation is injected at the control task rate, and the numerator and denominator signals are recorded.
  2. Estimation. The recorded data is used to compute the frequency response from the denominator to the numerator signal. In most cases, the numerator is the output signal and the denominator is the input signal, but this is not always the case.

Excitation signal

The excitation \(p(t)\) is a pseudorandom binary sequence (PRBS), which is a deterministic, periodic binary signal whose spectrum resembles white noise. A single experiment therefore excites all frequencies at once. Each bit lasts one control period \(T_s\), so the sequence is clocked at the control task rate \(f_s = 1/T_s\).

The two binary levels of the PRBS sequence are separated by the peak-to-peak value \(A_\mathrm{pp}\).

Advanced PRBS settings. The order \(N\), the number of repetitions \(R\) and the pre-excitation time \(T_\mathrm{pre}\) set the duration and frequency resolution of the experiment. One PRBS period contains \(L\) samples:

\[ L = 2^N – 1 \]

The injected signal consists of a pre-excitation part of duration \(T_\mathrm{pre}\), followed by \(R\) complete periods. The pre-excitation brings the system into the periodic steady state induced by the PRBS. The main part continues the same binary sequence. The total excitation duration is:

\[ T_\mathrm{PRBS} = T_\mathrm{pre} + L \cdot R \cdot T_s \]

The frequency response is obtained on the frequency grid defined by the PRBS period, from the resolution \(\Delta f\) up to the Nyquist frequency:

\[ f_k = \frac{k}{L\,T_s}, \qquad k = 1, \dots, \frac{L-1}{2}, \qquad \Delta f = \frac{f_s}{L} \]

For example, with the default settings (\(N = 12\), \(R = 10\), \(T_\mathrm{pre} = L \cdot T_s\)) and \(f_s = 50\,\mathrm{kHz}\): \(L = 4095\), \(\Delta f \approx 12.2\,\mathrm{Hz}\) and \(T_\mathrm{PRBS} \approx 0.90\,\mathrm{s}\). Higher order improves resolution at the cost of a longer experiment, and more repetitions reduce noise.

Figure 1: Injected PRBS (pre-excitation followed by R periods) and the corresponding system response.

Injection modes

The block output depends on the injection mode, where \(p(t)\) is the excitation signal and \(\overline{in}\) is the average of the input signal over the last 10 ms before the injection starts:

\[ \mathrm{out}(t) = \begin{cases} \mathrm{in}(t) + p(t) & \text{pass mode, during injection} \\ \overline{in} + p(t) & \text{hold mode, during injection} \\ \mathrm{in}(t) & \text{otherwise} \end{cases} \]

  • Pass mode keeps any control loop running through the injector active during the experiment.
  • Hold mode opens any control loop running through the injector for the duration of the experiment. In this mode, the open block output is set to 1, which can be used to pause integrators upstream to prevent windup.

Both modes give identical results when the injector follows a constant signal, such as a reference. The hold mode should not be used when the opened loop is unstable, e.g. a loop containing an integrator.

Frequency response estimation

The frequency response is computed from the spectra of the numerator \(y\) and the denominator \(u\) at the excited frequencies.

With a PRBS excitation, the Empirical Transfer Function Estimate (ETFE) [1] is computed only from data recorded during the \(R\) complete periods; pre-excitation samples are discarded. The estimation proceeds in three steps:

  1. The recorded data is split into \(R\) segments of \(L\) samples, one per PRBS period.
  2. Discrete Fourier Transforms (DFT) of the numerator and denominator are computed for each segment.
  3. The ETFE is computed as the ratio of the average of the \(R\) numerator and denominator DFTs.

\[ \qquad Y_r(k) = \sum_{n=0}^{L-1} y_r[n]\, e^{-j 2\pi k n / L},\ \hat{Y}(k) = \frac{1}{R} \sum_{r=1}^{R} Y_r(k) \]

\[ \hat{G}(f_k) = \frac{\hat{Y}(k)}{\hat{U}(k)} \]

Each segment spans exactly one period of a periodic excitation. Therefore, no window is applied and no spectral leakage occurs, provided the system is in periodic steady state [2]. Averaging over \(R\) periods reduces the influence of uncorrelated noise. The estimate is valid only if the system behaves linearly around its operating point; saturation, including that of the Output safety limits, invalidates it.

Figure 2: The Bode plot of the frequency response estimated by the Sys. Id. Injector block from the data seen in Figure 1

Results and analysis

While the overall process executes identically on real hardware or in simulation, the software environment differs. The table below summarizes how the results are displayed:

EnvironmentEstimation startsResults
CockpitWhen the Scope acquisition ends– Bode plot in Cockpit’s Sys. Id. module
– Time-domain data in the Scope module.
Snapshots and export options are available
SimulinkAt the end of the simulation run– Struct <injector name>_data in the MATLAB base workspace
– Bode plot displayed automatically
PLECSAt the end of the simulation run– system_response.csv auto-exported (time domain data)
– etfe_result.csv auto-exported (frequency domain data)
Both files are located in a folder named after the injector, next to the model file.

Quick settings

With the default settings, the PRBS amplitude is the only parameter that must be chosen. All other parameters are advanced and can be left at their defaults for a first experiment. With an imperix controller, an experiment takes four steps:

  1. Insert the block on the signal to perturb, name it, and add Probe blocks on the numerator and denominator signals. Build and deploy the model.
  2. Bring the system to the intended operating point and wait for steady state.
  3. In the Cockpit Sys. Id. module, select the injector, set the Peak-to-peak amplitude, and select the numerator and denominator.
  4. Press Inject excitation. The Bode plot is displayed once the Scope acquisition is complete.

In simulation, steps 3 and 4 are replaced by enabling Simulate system identification in the block mask, connecting the num and den ports, and setting the amplitude.

Block parameters

Injector parameters

  • Injector name: identifies the injector in the Cockpit Sys. Id. module and names the simulation outputs.
  • Output safety limits: optionally saturate the block output. They are disabled by default and serve only as a protection: if they are reached, the excitation is distorted, and the estimate is invalid.

Simulation parameters

The simulation parameters are revealed when the Simulate System Identification option is selected in the Simulation parameters tab. When this option is active, the block records the input model data and estimates the frequency response at the end of the simulation.

For a given Injector name (e.g. sys_id_injector), Simulink saves the system identification data in a struct variable with that name and a suffix “_data” (e.g. sys_id_injector_data) in the MATLAB base workspace. PLECS, on the other hand, saves two CSV files (system_response.csv and etfe_result.csv) in a folder with the same name as the injector next to the PLECS model file.

The simulation parameters include:

  • Injection mode: allows choosing between Hold and Pass modes.
  • Injection start time [s]: injection start time in the simulation; the system should be in steady state.
  • PRBS peak-to-peak: configures the difference between the high and low state values of the pseudorandom binary sequence.
  • Advanced PRBS settings:
    • PRBS order: sets the PRBS period length. For an order \(N\), the period length is \(L=2^N-1\).
    • Number of PRBS sequence repetitions: sets how many PRBS periods are injected. For \(R\) repetitions, the module estimates \(R\) frequency responses using recorded data. The module displays the final estimate, calculated as the average of these estimates.
    • Pre-excitation time [s]: sets the duration before the \(R\) full periods. The data recorded over this interval is disregarded.

In PLECS, an additional parameter, CPU task execution rate [Hz], must be configured. For a CLK0 frequency \(F_{\text{CLK0}}\) and a postscaler value configured in the CONFIG block this parameter should be set to \(F_{\text{CPU}} = F_{\text{CLK0}}\) / postscaler.

Signal specification

  • in is the block input signal, upon which the PRBS is injected
  • num and den inputs only appear if the Simulate system identification option is activated. They record the system’s response so that the transfer function can be estimated afterward.
  • out is the main block output. Its value depends on the injection mode:
    • PRBS + in, during injection in Pass mode;
    • PRBS + the estimated average of in, during injection in Hold mode;
    • in, otherwise.
  • The open signal is a binary signal designed to prevent integral windup in Hold mode by pausing the error accumulation during the injection. This output produces:
    • 1, during injection in Hold mode,
    • 0, otherwise.

Masks

Simulink block mask dialog
PLECS block mask dialog

C++ functions

#define DEFINE_INJECTOR(name)

Preprocessor macro that defines a Sys. Id. Injector. It creates the controller variables necessary to define an Injector recognizable by Cockpit and a SysIdInjector object called name that handles these variables.

The variables must have global scope, so the macro has to be used at file level, outside of any function or class. It should only be used once per name in a given .cpp file.

Parameters

  • name: name of the injector, written without quotes (e.g. #define DEFINE_INJECTOR(my_injector)). It identifies the injector in the Cockpit Sys. Id. module and is the name of the SysIdInjector object in the code, so it must be a valid C++ identifier not used by anything else at file level.
bool inject(float& input_signal) const;

Injects the excitation signal from Cockpit into a variable in the code. When the injection is initiated by Cockpit, depending on the mode selected in Cockpit, the variable is added to the excitation (closed-loop mode) or replaced by it (open-loop mode). Otherwise, the variable is left unchanged.

Should only be called in the interrupt routine.

Parameters

  • input_signal: variable to inject the excitation into. It is passed by reference and modified in place.

Return value

  • Returns true during open-loop injection, false otherwise.

References

[1] Lennart Ljung, System Identification: Theory for the User, Pearson Education, 1998,
ISBN: 978-0-132-44053-0
[2] R. Pintelon and J. Schoukens, System Identification: A Frequency Domain Approach, 2nd ed. Hoboken, NJ, USA: Wiley-IEEE Press, 2012.