ANN-based control of a three-phase inverter

Conventional model-based control in power electronics relies heavily on deriving precise mathematical models of the physical system. In contrast, data-driven control shifts this paradigm by estimating control laws directly from empirical data. A key example is Artificial Neural Network (ANN)-based control. ANNs serve as universal function approximators that extract complex input–output relationships directly from empirical or simulated datasets. Beyond mapping known parameters, ANNs generalize well, allowing them to accurately predict system behavior under unseen operating conditions. This robustness is particularly advantageous for managing systems with complex dynamics that defy explicit mathematical modeling. Additionally, their inherent structural flexibility makes them naturally suited for multi-variable systems [1]. While the foundational mathematics of ANNs were established in 1943, their application in power electronics has surged recently, becoming a dominant area of research [2].

This technical note replaces the traditional inner-loop discrete PI current regulator with a lightweight feedforward neural network (FNN), a supervised machine-learning approach. The FNN is designed to accurately reproduce the voltage-reference mapping within a standard grid-following current control structure. Finally, this approach is validated by implementing the ANN-based controller on a physical TPI8032 programmable inverter.

Classification of ANNs

Depending on the learning task, ANNs are generally categorized into two main groups: classification and regression. Classification handles discrete decisions, while regression handles continuous predictions. In power electronics, this distinction aligns perfectly with how the ANN drives the converter:

  • Direct control (Classification): The ANN directly generates the discrete gate signals (e.g., ON/OFF) for the semiconductor switches. As the outputs are discrete states, this is formulated as a classification problem.
  • Indirect control (Regression): The ANN calculates a continuous control variable, such as the voltage reference or duty cycle, which is then fed into a modulator. As the output is a continuous numerical value, this requires a regression model.

In this technical note, the ANN replaces a standard discrete PI current controller, meaning it needs to map a continuous voltage reference. Therefore, an indirect control strategy based on a regression ANN is implemented.

Beyond their learning task, ANNs can also be classified by their internal topology into feedforward and recurrent architectures. Feedforward neural networks (FNNs) process data strictly in one direction (see Fig. 1). As static, memoryless systems, FNNs lack an internal state and require past samples to be explicitly included in the input vector to account for historical data. Standard feedforward models include Multilayer Perceptrons, Radial Basis Function networks, and Convolutional Neural Networks. In contrast, recurrent networks, including LSTMs and GRUs, use feedback loops to retain an internal memory of past inputs (see Fig. 2), making them highly effective for modeling dynamic, time-dependent systems [3].

Among these ANN architectures, the Multilayer Perceptron (MLP) FNN is often used as a baseline because of its simplicity and efficient implementation, and it is widely used in industrial applications [1]. Therefore, this technical note selects the MLP-FNN for its strictly feedforward architecture, which ensures deterministic, low-latency execution required for a high-bandwidth controller. Additionally, its ability to approximate any function allows it to reproduce the PI controller’s input-output mapping accurately with minimal computational overhead.

Fig. 1: Feedforward neural network architecture with multiple hidden layers
Fig. 2: Recurrent neural network architecture

MLP-FNN architecture

An MLP-FNN architecture typically comprises an input layer, one or more hidden layers, and an output layer, each containing one or multiple interconnected neurons, as illustrated in Fig. 1. Within each neuron, incoming signals are multiplied by their respective connection weights (\(w\)), which represent the strength of the input, summed together, and then shifted by a bias term (\(b\)). Finally, the aggregated value passes through an activation function to produce the neuron’s output signal. This function can include non-linearity, allowing the network to learn and model complex patterns beyond simple linear relationships. By iteratively adjusting the weights and biases during training, the FNN encodes the learned relationships, enabling it to generalize accurately across its intended operating region [3].

Important concepts related to ANNs in general, and FNNs in particular, are detailed below:

Mathematical representation of FNN

Referring to Fig. 1, let the input vector be x=[x1​​⋯​xm​​]⊤∈Rmx=[x_1​​⋯​x_m​​]^⊤∈R^m, and the output vector be y=[y1​​⋯​yn​​]⊤∈Rn.y=[y_1​​⋯​y_n​​]^⊤∈R^n.

A typical mathematical expression for the output of neuron jj in layer ll:

yj(l)=N(l)(∑i=1nl−1wji(l)xi+bj(l))y_j^{(l)} = N^{(l)} \left( \sum_{i=1}^{n_{l-1}} w_{ji}^{(l)} x_i + b_j^{(l)} \right)

where wjiw_{ji} is the weight connecting neuron ii in layer l−1l-1 to neuron jj in layer ll, bjb_j is an offset, nl−1n_{l-1} is the number of neurons in the preceding layer, and N(l)N_{(l)}( ⋅ ) is the activation function of layer ℓ\ell.

Activation functions

To enable the network to learn complex non-linear mappings, the neurons must utilize non-linear activation functions. To be compatible with standard network training algorithms, these activation functions must be differentiable or piecewise differentiable. Among the available options, the Rectified Linear Unit (ReLU) is the most commonly used because of its computational efficiency and effectiveness in mitigating gradient-related issues during training [4]. Fig. 3 illustrates some important activation functions commonly used in ANNs.

Fig. 3: Commonly applied activation functions.

Network topology and design flexibility

FNN offers a significant degree of design flexibility. While the input and output layer dimensions are typically determined by the physical system, the internal structure is largely user-defined. Key design choices include the number of hidden layers (depth), the number of neurons per layer (width), and the connectivity scheme (e.g., all-to-all vs. sparsified connections). Increasing depth lets the network learn complex, hierarchical abstractions, while increasing width lets it capture a broader range of features at each stage. However, excessive depth or width risks overfitting and needlessly inflates execution time. Ultimately, this architectural freedom lets the user balance model learning capacity against the strict computational constraints of the physical application [4].

Training algorithms

The training algorithm used to calculate the network’s weight matrix depends on the architecture’s complexity. For simple, single-layer networks with linear input-output relationships, analytical methods such as the Pseudo-inverse or LASSO can directly optimize the weights and biases. However, multi-layer ANNs that use non-linear activation functions require iterative optimization methods.

Central to this iterative process is the loss function, which quantifies the error between the model’s predictions and the actual target values. Its primary function is to guide the optimization process, which iteratively adjusts the network’s weights and bias to minimize the error and improve the model’s accuracy.

The process of minimizing the loss in MLP-FNNs relies on two complementary phases: calculating the error gradients and updating the network weights and biases:

  • Backpropagation is a computational algorithm that calculates the loss function’s gradients with respect to each weight by propagating error information backward through the layers using the chain rule.
  • Optimization algorithms use those calculated gradients to update the network parameters. While Stochastic Gradient Descent is a common first-order optimizer that takes steps in the direction of the steepest descent, second-order methods like the Levenberg-Marquardt algorithm are also widely used. Levenberg-Marquardt dynamically blends gradient descent with Gauss-Newton optimization, allowing for much faster convergence on moderate-sized problems.

Together, these mechanisms enable the network to learn from data. However, the speed and stability of this convergence depend heavily on the chosen hyperparameters. These hyperparameters are external configuration variables set before training begins, unlike parameters (weights and biases), which are learned during training. They govern the network’s structure (e.g., number of layers, number of neurons) and the learning process (e.g., learning rate, batch size) to optimize performance.

Data partitioning and validation

To ensure the model generalizes effectively to unseen operating conditions, the dataset is typically partitioned into three distinct subsets: training, validation, and testing. The algorithm uses the training data directly to update the network’s weights and biases. Hyperparameters must be fixed before a training run begins, but the validation data is used to evaluate performance under those settings, allowing the designer to tune the configuration across multiple independent runs. Finally, the test set provides a completely independent, unbiased evaluation of the final model to confirm its true performance on strictly unseen data.

During optimization, the training algorithm iterates through the data over several epochs, continuously adjusting the weights and biases to minimize the prediction error. This training process typically continues until the validation error reaches a threshold and begins to increase. Halting the process at this point, a technique known as early stopping, is crucial to prevent overfitting and ensure robust performance when deployed [4].

Challenges of ANN-based control

Implementing ANN-based control in converter applications presents several specific challenges:

  • Data dependencies: The controller’s performance depends on the quality and breadth of the training dataset. Obtaining large, well-balanced datasets that cover the entire operating region, including rare events like faults, is often costly and time-consuming. Underrepresentation of these edge cases can hurt generalization.
  • Design trade-offs and overfitting: Selecting the network architecture requires balancing accuracy against robustness. While increasing network depth and width enhances representational capacity, it raises computational costs and increases the risk of overfitting (learning noise rather than system dynamics). Cross-validation is essential to mitigate this risk [4].
  • Verification and interpretability: Unlike standard linear controllers, ANNs often function as “black boxes” lacking analytical stability proofs. Consequently, safety-critical deployment typically requires auxiliary safety mechanisms, such as output saturations, runtime monitors, and fallback logic.

Experimental implementation of an ANN-based control

As an application example, an indirect MLP-FNN is implemented to regulate the output current of a three-phase grid-following converter. This example replaces the inner-loop PI current regulator with an offline-trained MLP-FNN. The indirect FNN is deployed at the controller interface, as shown in Fig. 4. The PLL synchronization, modulation (SVM), and protections remain unchanged, while the FNN reproduces the PI controller’s voltage-reference generation behavior.

Fig. 4: Inputs and outputs of the FNN-based controller together with the standard vector current control scheme

Structure of FNN

Instead of learning the full converter dynamics, the FNN is trained to emulate the mapping performed by the discrete PI current controller. At each control step k, the FNN receives controller-relevant input signals and outputs the corresponding voltage reference in dq coordinates. The input vector is constructed such that it captures the useful information that could be helpful for FNN in mapping the input vector to the output vector.

  • Inputs (5 inputs): x(k)=[∑Kied(k),∑Kieq​(k),ed(k),eq(k),ω(k)]x(k)=[\sum{K_i e_d(k)}, \sum{K_i e_q​(k)},e_d (k),e _q (k), ω(k)], where the first two terms are the PI integrator states, ed​(k),eq​(k)e _d ​ (k),e _q ​ (k) are the error terms used by the discrete PI controller, and ω(k)\omega(k) is the measured grid angular frequency.
  • Hidden layers: two layers, containing 32 and 16 neurons, respectively.
  • Outputs (2 regression outputs): y(k)=[Eg,d​(k),Eg,q​(k)]y(k)=[E_{g,d} ​ (k),E_{g,q} ​ (k)].
  • Activation function: tansig is used in hidden layers, and a pure linear activation is used in the output layer (see Fig. 3).

This structure ensures that the FNN can replace the PI controller. It receives the same internal control signals as a discrete PI controller would receive, and produces the same voltage reference quantities.

Data collection and preprocessing

Training data is generated using a vector current control scheme by simulating the grid-following converter in Simulink across a range of operating conditions and reference variations, e.g., different profiles for idrefand iqref, different DC-link voltage, and grid voltage magnitudes. Training data should be gathered by manipulating the variables in such a way as to cover the desired solution space. For each simulation run, signals are logged and consolidated into a measurements array.

All experiments are concatenated into a single supervised dataset by stacking time samples from each run. In this case, the training dataset contains 345,632 samples. Invalid samples are then removed. This step matters when concatenating logs from many simulation runs, especially when protections can produce undefined values during transients or failed runs. To stabilize training and keep signals in comparable numeric ranges, fixed scaling factors are applied. This normalization is part of the controller definition: Simulink must reproduce the same scaling at inference time, and FNN outputs must be de-scaled before use.

Training and deployment

The Levenberg-Marquardt optimization algorithm is selected to train the FNN because it is effective for moderately sized networks and converges relatively quickly for small- to moderate multi-layer perceptron regression problems. Additionally, Mean Squared Error (MSE) is chosen as the loss function. Some of the key implemented hyperparameters are:

  • Maximum epochs (2000): The absolute limit on training iterations if the network does not reach convergence earlier.
  • Performance goal (1e-7): The target MSE; training halts successfully if the loss falls below this threshold.
  • Initial learning rate (1e-3): The optimizer’s starting step size for updating the network weights.
  • Minimum gradient (1e-8): The threshold at which weight updates become numerically insignificant. If the gradient drops below this value, the optimizer has reached a flat region and training stops.
  • Validation early stopping (max_fail = 20): The number of consecutive epochs the validation loss is permitted to worsen before training is terminated. This prevents overfitting while allowing for typical, temporary fluctuations in the loss curve.)

The data is divided into a standard 70/15/15 split (training/validation/test) to ensure robust learning and unbiased performance evaluation. Training yields a final network with optimized weights and biases. For deployment, the trained model can be integrated into Simulink by generating a callable MATLAB function with genFunction().

Tips to improve the ANN performance

  • It is recommended to excite the system with reference steps and parameter variations that span the full expected operating condition (grid strength, VdcV_{dc}​ , VgV_g​, frequency drift, etc.). Include transients, not just the steady state.
  • Use fixed scaling (per-unit or rated values). Analyze the data before training. Look for extreme outliers and remove them before scaling to avoid training dominated by rare events or spikes.
  • Choose an input vector carefully to reflect control causality, and avoid inputs that add noise without information.
  • Increasing the number of fully connected layers and neurons might improve performance, but it also increases the risk of overfitting.
  • During training, monitor the validation loss. If it stops improving for a set number of epochs, stop training manually to avoid overfitting the training set.
  • If your loss isn’t moving, check your learning rate first. It’s usually either way too high, causing exploding gradients, or too low, making progress invisible.

Implementation of FNN-based controller

Experimental setup

The setup (see Fig. 5) used to validate the proposed ANN-based control of the output current of the converter includes the following imperix products:

  • TPI8032, 22kW all-in-one programmable inverter
  • ACG SDK toolbox for automated generation of the controller code from Simulink

and additional components:

  • 1x DC power supply
  • Three-phase grid connection or three-phase power amplifier
Fig. 5: Test setup used for experiments

Downloads

The full Simulink model, as shown in Fig. 6, with a trained neural network whose parameters are saved as nn_parameters.mat, is available for download using the link below:

Fig. 6: Implementation of data-driven control in Simulink

Experimental results

To experimentally validate the FNN-based controller’s performance, it is implemented alongside the vector current controller in the Simulink model, as shown in Fig. 7.


Fig. 7: FNN-based controller implementation in Simulink

The experimental performance of the TPI8032 was evaluated at a switching and control frequency of 20 kHz with a line-to-neutral grid voltage of 230 V at the point of common coupling (PCC). To assess control robustness, a dynamic test scenario was configured in which the DC link voltage is programmed to drop from approximately 700 V to 600 V, right after the application of a input step of 30A in the d-axis current reference. This DC link voltage drop, therefore, coincides with a step change in the d-axis output current reference (Ig,d∗​) from 0 A to 30 A at t =5ms.

As shown in Fig. 8, the FNN-based controller demonstrates tracking performance similar to a PI controller. Despite the varying DC link voltage, a dynamic condition that was notably excluded from the training dataset, the FNN response (blue trace) closely tracks the reference and exhibits a transient response that nearly replicates the conventional PI-based vector current control scheme (dashed orange trace). This confirms that the FNN has generalized its learning to unseen operating conditions. Furthermore, the implementation is computationally efficient; running the FNN algorithm on the B-Board PRO embedded platform of TPI8032 consumes 35%-45% of the available cycle time at 20 kHz, keeping the computational load well within the CPU’s capacity.

Fig. 8: Controller performance comparison between the PI current controller and the ANN-based current controller

Conclusion

The example implementation demonstrates that a shallow ANN can effectively emulate the mapping of a discrete PI current controller in a grid-following converter while maintaining the deterministic, low-latency execution required for a real-time embedded target. However, the approach’s success depends strictly on the quality and breadth of the training dataset. While the ANN-based controller can generalize to conditions like varying DC-link voltages not explicitly included in training, insufficient data coverage or limited training time remains a primary factor that can lead to subpar performance during unexpected transients. Rigorous cross-validation and auxiliary safety mechanisms are essential to mitigate instability risk. Contrary to the assumption that ANNs require heavy computing power, this implementation proves that shallow ANNs can be effective and sufficient for power electronics control applications.

References

[1] M. R. G. Meireles, P. E. M. Almeida and M. G. Simoes, “A comprehensive review for industrial applicability of artificial neural networks,” in IEEE Transactions on Industrial Electronics, vol. 50, no. 3, pp. 585-601, June 2003.

[2] S. Zhao, F. Blaabjerg and H. Wang, “An Overview of Artificial Intelligence Applications for Power Electronics,” in IEEE Transactions on Power Electronics, April 2021.

[3] B. K. Bose, “Neural Network Applications in Power Electronics and Motor Drives—An Introduction and Perspective,” in IEEE Transactions on Industrial Electronics, Feb. 2007.

[4] S. Brunton, and J. Nathan Kutz, “Data-driven science and engineering: Machine learning, dynamical systems, and control“, Cambridge University Press, 2022.

To go further from here…

More information on controlling the TPI8032 as a grid-forming inverter can be found in TN167. The following are some of the other notes that can be useful:

PN190: Getting started with th TPI8032
TN166: Active front end (AFE)