A Building Block Method for Modeling and Small-Signal Stability Analysis of the Autonomous Microgrid Operation

The task of the whole microgrid state-space matrix creation is usually done in a preferred textual programming language, and it presents a complicated, time-consuming, and error-prone job for a researcher without good coding practices. To ease the modeling task, contribute to the adaptation of new microgrid structures, control algorithms, and devices, and to improve the flexibility of the model, a graphical element building block method is proposed in this paper. With the proposed approach model creation of the whole microgrid is reduced to the creation of the individual element state-space model that is linked with other elements in a logical way with a graphical connection. Elements are then grouped into meaningful wholes and encapsulated with the appropriate graphical user interface that enables easy parameter modification and model complexity change. More detailed DC/DC and DC/AC models of converters than those in the literature concerning microgrid stability are presented in this paper. Those converters are incorporated in a microgrid, whose model is created using the proposed approach in MATLAB/Simulink. The dynamic response examination of the model remains easy, just as with all Simulink models, while for the linear system analysis, a specialized toolbox is used.


Introduction
A large number of rural areas around the world require the use of Renewable Energy Sources (RESs) as the only solution for power supply. The autonomous microgrid imposes itself as an efficient and reliable solution in these conditions, where access to the main utility grid is unavailable or inefficient and costly. The electrification of such areas through a Low Voltage (LV) microgrid is achieved using the RESs as constitutive parts of distributive generation and Energy Storage Devices (ESDs). Compared to the main utility grid, the autonomous microgrid, due to the use of power converters as integrating devices for RESs and ESDs and the lack of synchronous generators, has low system inertia. The low system inertia, unpredictable nature of RESs, and fluctuations in consumption may cause frequency and voltage deviations, poor power-sharing ability among Distributed Generation Units (DGUs), and stability issues [1][2][3]. In the autonomous operation, microgrid should be able to remedy all these problems itself [4][5][6][7]. As the use of the RESs increase, the stability and control of microgrids have been a topic of great interest over various studies. In [8][9][10], the classification of microgrid stability is divided onto small-signal and transient stability.
The small-signal stability analysis, related to small-signal perturbation, is usually used to investigate the interaction effects between the DGUs and consumption in the defined steady-state Recognizing the importance of the detailed modeling of microgrid elements, the trend of growing microgrid complexity, and the error-prone and rigid job of classical matrix-based modeling, the authors are herein proposing a graphical modeling approach. With the proposed approach, modeling of the whole microgrid state-space matrix is not required, instead the focus is on the modeling of individual elements. The whole model is obtained with a graphical connection of appropriate signals in MATLAB/Simulink R2018b (Update 6). In this way, overall linear models of microgrids and the accompanying structures are more comfortable to obtain. Several models of the same element can be provided and selected for analysis only with proper signal routing. Flexibility and robustness of the modeling are improved with encapsulation of the group of elements into meaningful wholes with a Graphical User Interface (GUI) that enables fast change of element model or parameters in model with a check-box or input field. For an analysis of a linear model, MATLAB/Simulink Linear Analysis Toolbox (LAT) is used. It provides various analysis tools for linear models and the ability to export obtained linear models into MATLAB workspace for further manipulation. The effectiveness of the proposed modeling approach is demonstrated in the case of the microgrid with DGUs where typical control structures are modeled, but also for the same microgrid where DGUs are modeled in more detail. Detail model accounts for power-electronics-based converter dead-time effect, the control of DC-link voltage via boost converter with appropriate control structures, and the effects that are related to digitally implemented control algorithm. In summary, the main benefits and key features of this paper are as follows: • The presented modeling approach provides higher flexibility through modularity, less chance for error through a better model overview, and easier microgrid analysis with tested toolboxes compared to traditional state-space matrix obtainment. • When models are created using the graphical building blocks method, elements in it are connected with other elements in the way to imitate the physical layout of the microgrid; thus, more natural modeling of the complex network configuration with different types of sources and loads is possible. • More detailed AC/DC and DC/DC converter models than those available in the literature are presented and analyzed as a direct benefit of the proposed modeling approach.

•
To support scientific collaboration and microgrid research, MATLAB/Simulink models from this paper, with accompanying documentation, are published on this paper's MDPI webpage.
The rest of this paper is organized as follows: Section 2 gives the detailed linearized state-space models of each element of the microgrid. In Section 3, the proposed modeling approach is described along with the elements' implementation procedure in the Simulink. In the first part of Section 4, a comparison between the linearized model and the model built using the Simscape toolbox is presented in terms of dynamic response. In the second part of Section 4, eigenvalue analysis is conducted on the linear model built using the proposed approach, followed by the participation factor and the singular value decomposition analysis.

Autonomous Microgrid Small-Signal State-Space Modeling
The autonomous LV microgrid representation, including n-DGUs, k-nodes with the load in each node, and j-lines, is presented in Figure 1.
Energies 2020, 13, x FOR PEER REVIEW 3 of 28 • More detailed AC/DC and DC/DC converter models than those available in the literature are presented and analyzed as a direct benefit of the proposed modeling approach.

•
To support scientific collaboration and microgrid research, MATLAB/Simulink models from this paper, with accompanying documentation, are published on this paper's MDPI webpage.
The rest of this paper is organized as follows: Section 2 gives the detailed linearized state-space models of each element of the microgrid. In Section 3, the proposed modeling approach is described along with the elements' implementation procedure in the Simulink. In the first part of Section 4, a comparison between the linearized model and the model built using the Simscape toolbox is presented in terms of dynamic response. In the second part of Section 4, eigenvalue analysis is conducted on the linear model built using the proposed approach, followed by the participation factor and the singular value decomposition analysis.

Autonomous Microgrid Small-Signal State-Space Modeling
The autonomous LV microgrid representation, including n-DGUs, k-nodes with the load in each node, and j-lines, is presented in Figure 1. It is assumed in Figure 1 that the integration of the RESs in the microgrid is accomplished over DGUs composed of a DC/DC boost converter and a DC/AC Voltage Source Converter (VSC). The presumption is made for an operation regime in which all RESs have sufficient energy to supply the loads. To apply the building block method and perform small-signal stability analysis with LAT, an individual state-space models of each component in the microgrid needs to be modeled. Four subsystems with associated components are identified: • Boost converter subsystem (power model, voltage and current controllers, digital control emulator models); • VSC subsystem (VSC with LCL filter model, power controller with virtual impedance loop, voltage and current controllers, dead-time, digital control emulator models); • Network subsystem (a resistive/indictive nature of power lines); • Load mode subsystem (a resistive/inductive load model).

State-Space Model of the DC/DC Boost Converter Subsystem
In this paper, the boost converter regulates the DC-link voltage udc to a reference value. For a power input from RES, the voltage source is assumed. Figure 2 presents a complete block diagram of It is assumed in Figure 1 that the integration of the RESs in the microgrid is accomplished over DGUs composed of a DC/DC boost converter and a DC/AC Voltage Source Converter (VSC). The presumption is made for an operation regime in which all RESs have sufficient energy to supply the loads. To apply the building block method and perform small-signal stability analysis with LAT, an individual state-space models of each component in the microgrid needs to be modeled. Four subsystems with associated components are identified: In this paper, the boost converter regulates the DC-link voltage u dc to a reference value. For a power input from RES, the voltage source is assumed. Figure 2  The boost converter power model is shown in Figure 3 and includes an inductor (inductance Llb and resistance Rlb), DC-link capacitor (capacitance Cdc), the resistance of the switching device during its conduction Ronb, and the forward diode voltage drop UDb. It is represented as a combination of the turn-on and turn-off states [32]. Dynamic equations of input/output voltages and currents uinb, udc, iinb, idc that average one switching cycle can be written as in Equations (1) and (2), respectively [33].
In Equations (1) and (2) the duty cycle of the boost converter is represented with db. Linearizing the average model described with Equations (1) and (2) around the operating point, the small-signal state-space model of the boost converter can be obtained as in Equation (3).
In Equation (3), Db, Udc, and Iinb represent the steady-state duty cycle, output DC-link voltage, and input inductor current, respectively. A similar principle is applied throughout the paper, where

DC/DC Boost Converter Power Model
The boost converter power model is shown in Figure 3 and includes an inductor (inductance L lb and resistance R lb ), DC-link capacitor (capacitance C dc ), the resistance of the switching device during its conduction R onb , and the forward diode voltage drop U Db . It is represented as a combination of the turn-on and turn-off states [32]. The boost converter power model is shown in Figure 3 and includes an inductor (inductance Llb and resistance Rlb), DC-link capacitor (capacitance Cdc), the resistance of the switching device during its conduction Ronb, and the forward diode voltage drop UDb. It is represented as a combination of the turn-on and turn-off states [32]. Dynamic equations of input/output voltages and currents uinb, udc, iinb, idc that average one switching cycle can be written as in Equations (1) and (2), respectively [33].
In Equations (1) and (2) the duty cycle of the boost converter is represented with db. Linearizing the average model described with Equations (1) and (2) around the operating point, the small-signal state-space model of the boost converter can be obtained as in Equation (3).
In Equation (3), Db, Udc, and Iinb represent the steady-state duty cycle, output DC-link voltage, and input inductor current, respectively. A similar principle is applied throughout the paper, where the upper-case symbols after linearization stand for the operating point of the system. Dynamic equations of input/output voltages and currents u inb , u dc , i inb , i dc that average one switching cycle can be written as in Equations (1) and (2), respectively [33].
In Equations (1) and (2) the duty cycle of the boost converter is represented with d b . Linearizing the average model described with Equations (1) and (2) around the operating point, the small-signal state-space model of the boost converter can be obtained as in Equation (3).
Energies 2020, 13, 1492 5 of 28 In Equation (3), D b , U dc , and I inb represent the steady-state duty cycle, output DC-link voltage, and input inductor current, respectively. A similar principle is applied throughout the paper, where the upper-case symbols after linearization stand for the operating point of the system.

Voltage and Current Controllers
The outer voltage and inner current control loops with PI controllers are introduced to control the DC-link voltage. The voltage controller output provides the reference to the boost inductor current controller i * inb . It is described with the following set of equations: Voltage error between the reference DC-link voltage u * dc and measured u dc voltage, in Equation (4) is denoted as . φ b , while Equation (5) defines boost input current reference. The K pub and K iub coefficients are proportional and integral terms of the boost voltage controller. Linearization of Equations (4) and (5) provides the following small-signal state-space model of the voltage controller: The output of the inductor current controller is d b , obtained according to the following set of algebraic equations: The inductor current error . γ b between the reference input current i * inb and the measured i inb is presented in Equation (8), while Equation (9) defines the boost duty cycle d b . The K pib and K iib coefficients are proportional and integral terms of the boost current controller. By linearizing Equations (8) and (9) around the operating point, the small-signal state-space model of the current controller is obtained and presented in Equations (10) and (11) as:

Digital Control Emulator Model
The process of continuous-time analog signal conversion to a discrete-time signal is called sampling. It is defined with time and amplitude quantization characteristics. In contrast to time quantization, amplitude quantization does not preserve the system linearity and produces effects that cannot be treated using linear system analysis [34]. However, the time quantization of a digital system can be represented with a series connection of the ideal sampler, the Zero-Order Hold (ZOH) [35,36], Energies 2020, 13, 1492 6 of 28 and digital execution of the algorithm as a transport delay. Combination of sampling, ZOH, and digital execution will be called Digital Control Emulator (DCE) [37] with a transfer function: where T s is the equivalent sampling period delay, and Laplace complex variable is denoted with s. The Pade approximation of Equation (12), as presented in [38], is used for the creation of a linear state-space model. In the boost converter subsystem, the DCE transfer function is applied on all input signals of the current controller. Figure 4 presents a block diagram of a single three-phase, three-wire, two-level VSC and its control structure connected to the grid through an LCL filter. Presented models in this subsection account for the effects induced by the switching frequency and the dead-time of the physical converter controlled by continuous space vector modulation technique, LCL filter used for its connection to the microgrid, power controller, cascaded PI voltage and current controllers, and DCE. Modeling will be done in the synchronous reference frame.

State-Space Model of the DC/AC Voltage Source Converter Subsystem
where Ts is the equivalent sampling period delay, and Laplace complex variable is denoted with s. The Pade approximation of Equation (12), as presented in [38], is used for the creation of a linear state-space model. In the boost converter subsystem, the DCE transfer function is applied on all input signals of the current controller. Figure 4 presents a block diagram of a single three-phase, three-wire, two-level VSC and its control structure connected to the grid through an LCL filter. Presented models in this subsection account for the effects induced by the switching frequency and the dead-time of the physical converter controlled by continuous space vector modulation technique, LCL filter used for its connection to the microgrid, power controller, cascaded PI voltage and current controllers, and DCE. Modeling will be done in the synchronous reference frame.

Reference Frame Transformation
In order to analyze the microgrid with several DGUs, the synchronous reference frame of one DGU is declared as a common reference frame (D-Q) with frequency are needed. These transformations are widely discussed in [12,13] and can be represented as:

Reference Frame Transformation
In order to analyze the microgrid with several DGUs, the synchronous reference frame of one DGU is declared as a common reference frame (D-Q) with frequency ω g = ω gcom , and all other individual inverters are transformed to this reference frame. The transformation of the grid voltage in the Point of Common Coupling (PCC) from the common to the individual reference frame of the VSC u gDQ → u gdq and the transformation of the individual VSC output current to the common reference Energies 2020, 13, 1492 7 of 28 frame i gdq → i gDQ are needed. These transformations are widely discussed in [12,13] and can be represented as: where ∆δ is a small phase angle difference between the reference frame in discussion and the common reference frame. The steady-state phase angle difference is denoted with δ 0 .

Power Controller
A complete block diagram of a power controller is given in Figure 5. It consists of a block for power calculation, a first-order Low-Pass Filter (LPF), and the frequency and voltage reference calculation blocks.
Energies 2020, 13, x FOR PEER REVIEW 7 of 28 where Δδ is a small phase angle difference between the reference frame in discussion and the common reference frame. The steady-state phase angle difference is denoted with 0 δ .

Power Controller
A complete block diagram of a power controller is given in Figure 5. It consists of a block for power calculation, a first-order Low-Pass Filter (LPF), and the frequency and voltage reference calculation blocks. The instantaneous active p and reactive power q are calculated in the d-q reference frame, after amplitude-invariant Park's transformation using the capacitor voltage uc and the grid current ig as in [15]. LPF with a cutoff frequency ωc is used to obtain filtered active and reactive power P and Q corresponding to the fundamental component.
The applicability of the conventional P-ω/Q-V droop control method in microgrids with dominant active resistance is confirmed in [39]. The nominal voltage and frequency values are set within the P-ω/Q-V droop control strategy according to the following equations: where ωn, ωg, and ωgcom are frequencies during ideal no-load operation, when DGU is loaded with active power P, and the frequency of common reference frame, respectively. Und is the d voltage component setpoint and ' cd u , ' cq u are the output voltage d-q components when DGU is providing reactive power Q. The static droop gains for active power mp and reactive power nq are defined individually for every DGU according to its power capacity, allowed operating frequency range, and voltage deviation in the microgrid.
The small-signal model of the P-ω/Q-V controller in a state-space form is given in [15,16] as: The instantaneous active p and reactive power q are calculated in the d-q reference frame, after amplitude-invariant Park's transformation using the capacitor voltage u c and the grid current i g as in [15]. LPF with a cutoff frequency ω c is used to obtain filtered active and reactive power P and Q corresponding to the fundamental component.
The applicability of the conventional P-ω/Q-V droop control method in microgrids with dominant active resistance is confirmed in [39]. The nominal voltage and frequency values are set within the P-ω/Q-V droop control strategy according to the following equations: where ω n , ω g , and ω gcom are frequencies during ideal no-load operation, when DGU is loaded with active power P, and the frequency of common reference frame, respectively. U nd is the d voltage component setpoint and u cd , u cq are the output voltage d-q components when DGU is providing reactive power Q. The static droop gains for active power m p and reactive power n q are defined individually for every DGU according to its power capacity, allowed operating frequency range, and voltage deviation in the microgrid.
The small-signal model of the P-ω/Q-V controller in a state-space form is given in [15,16] as: Energies 2020, 13, 1492

Virtual Impedance
According to [39], a virtual resistance is introduced to eliminate the mismatch of DGU's feeder line resistance and improve the power-sharing performances of DGU's. In this paper, complex virtual impedance is used because of the real resistive/inductive nature of the lines. Figure 6 represents the equivalent block diagram of the virtual impedance algebraic approximation. To generate reference voltage components u * cd and u * cq an additional feedback loop to the droop output command voltages u cd and u cq is added. This loop consists of LPF and virtual impedance where R v and L v is virtual resistance and inductance, respectively.

Virtual Impedance
According to [39], a virtual resistance is introduced to eliminate the mismatch of DGU's feeder line resistance and improve the power-sharing performances of DGU's. In this paper, complex virtual impedance is used because of the real resistive/inductive nature of the lines. Figure 6 represents the equivalent block diagram of the virtual impedance algebraic approximation. To generate reference voltage components * where v R and v L is virtual resistance and inductance, respectively. To reduce the noise amplification, direct use of the virtual impedance algebraic approximation is avoided by adding the grid current filtering stage using LPF, as explained in [40]. The filtered grid current components gdq f i − are used in the virtual impedance loop with dynamic representation: ( ) The voltage controller reference voltages * cd u and * cq u are generated as: A linearized small-signal state-space model of virtual impedance with LPF based on Equations (20)-(23) can be derived as: * ' where the nominal synchronous frequency is denoted as g Ω .

VSC Voltage and Current Controllers
The capacitor voltage and the converter inductance current controller realization is presented in Figure 7a,b, respectively. Controllers are implemented as standard PI with appropriate decoupling To reduce the noise amplification, direct use of the virtual impedance algebraic approximation is avoided by adding the grid current filtering stage using LPF, as explained in [40]. The filtered grid current components i gdq− f are used in the virtual impedance loop with dynamic representation: The voltage controller reference voltages u * cd and u * cq are generated as: A linearized small-signal state-space model of virtual impedance with LPF based on Equations (20)-(23) can be derived as: where the nominal synchronous frequency is denoted as Ω g .

VSC Voltage and Current Controllers
The capacitor voltage and the converter inductance current controller realization is presented in Figure 7a,b, respectively. Controllers are implemented as standard PI with appropriate decoupling and capacitor voltage feed-forward terms as represented in Equations (27)-(28) and (32) The measured capacitor voltages cdq u are subtracted from the reference voltage components * cdq u , and the obtained error is passed to the appropriate PI controller. The set of equations that describe the voltage controller are: where Kpu and Kiu are proportional and integral gain of the voltage controller, respectively, while Cf represents the phase capacitance of the LCL filter. The voltage controller linearized state-space model based on Equations (26)- (28), can be written in the small-signal form as: The set of equations that describe the current controller are: In Equations (32) and (33), Kpi and Kii present the proportional and integral current gain, respectively, while Li corresponds to the converter side inductor. With linearization of Equations (31)-(33), the state-space model for the current controller in the small-signal form is obtained as: The measured capacitor voltages u cdq are subtracted from the reference voltage components u * cdq , and the obtained error is passed to the appropriate PI controller. The set of equations that describe the voltage controller are: where K pu and K iu are proportional and integral gain of the voltage controller, respectively, while C f represents the phase capacitance of the LCL filter. The voltage controller linearized state-space model based on Equations (26)- (28), can be written in the small-signal form as: The set of equations that describe the current controller are: Energies 2020, 13, 1492 10 of 28 In Equations (32) and (33), K pi and K ii present the proportional and integral current gain, respectively, while L i corresponds to the converter side inductor. With linearization of Equations (31)- (33), the state-space model for the current controller in the small-signal form is obtained as: The link between the DC voltage of the VSC u dc and d-q components of the output voltage u id and u iq can be established through the duty cycles d d and d q as: Linearized small-signal state-space model of Equation (36) is given in Equation (37) as: The relation between the DC-link current i dc and the d-q components of the VSC output current i id and i iq is achieved based on equality between the active power in DC-link p dc and active power at the output of the VSC p through: Small-signal state-space model of Equation (38) is obtained with linearization around the operating point as: Introduction of the dead-time model in VSC with continuous space vector modulation is presented in [31,41], where it was shown that dead-time creates a significant damping effect. Dead-time is modeled as a nonlinear function for d-q components of the VSC output current i id and i iq as: where T dt is the dead-time value, and T sw is the switching period. The LCL filter attenuates the high-order harmonics originating from power switches of the converter. A model of the LCL filter in the d-q reference frame is presented in Figure 8. Set of dynamic equations that account for the VSC dead-time effect when the combination of a continuous space vector modulation and the LCL filter is used, can be written as: Linearization of Equations (41)-(46) around the operating point gives the small-signal statespace model of the LCL-filter in the following form: where: Set of dynamic equations that account for the VSC dead-time effect when the combination of a continuous space vector modulation and the LCL filter is used, can be written as: Linearization of Equations (41)-(46) around the operating point gives the small-signal state-space model of the LCL-filter in the following form: where: Lg Ω g R f K dt I id I iq U dc 2.2.6. Digital Control Emulator for VSC DCE in the VSC subsystem is approximated the same way as for boost converter presented in Section 2.1.2. Equation (14). In the VSC subsystem, on all signals relevant to the current controller (reference current, measured current, and measured capacitor voltage), appropriate DCE function is applied.

State-Space Model of the Equivalent Power Line Subsystem
In general, mixed inductive/resistive nature of power lines is assumed. The equivalent power line model between two nodes in the d-q system is presented in Figure 9a,b, respectively. In general, a set of dynamic equations that describe d-q components of the current in the j th line, between the two nodes x and k in Figure 9 could be described according to Equations (48) and (49).

Digital Control Emulator for VSC
DCE in the VSC subsystem is approximated the same way as for boost converter presented in Section 2.1.2. Equation (14). In the VSC subsystem, on all signals relevant to the current controller (reference current, measured current, and measured capacitor voltage), appropriate DCE function is applied.

State-Space Model of the Equivalent Power Line Subsystem
In general, mixed inductive/resistive nature of power lines is assumed. The equivalent power line model between two nodes in the d-q system is presented in Figure 9a,b, respectively. In general, a set of dynamic equations that describe d-q components of the current in the j th line, between the two nodes x and k in Figure 9 could be described according to Equations (48) and (49).
A complete small-signal state-space model of the test network from Figure 1 can be derived based on Equation (50) as: The linearized state-space model based on Equations (48) and (49) in the small-signal form is: A complete small-signal state-space model of the test network from Figure 1 can be derived based on Equation (50) as: To define the voltage in each node of the network, a concept of the virtual resistor R n is applied. A symbolic form of node voltages is given in [12,13,42] as follows: where M conv , M load and M net are mapping matrices of converters, loads, and lines according to [12].

State-Space Model of the Load Subsystem
It is assumed that the consumption in the microgrid can be represented through the RL load model. Dynamic equations that describe the RL load model at the k th node of the microgrid are: Energies 2020, 13, 1492

of 28
The single load model in the small-signal state-space form based on Equations (53) and (54) is:

State-Space Model Creation
Analysis of a linear microgrid model in literature most commonly starts with the creation of the complete system state matrix A sys [12,13,[15][16][17][18][19][20]42]: It includes and combines the state matrices of aggregated converters state matrix, network state matrix, and complete loads state matrix. The creation of element state-space model and state-space matrix aggregation is usually done in some textual programming language, like MATLAB, R, or Python. This creates a matrix assembly job that is not easy, let alone the eventual debugging. Figure 10 shows the comparison between the VSC voltage controller matrix definition in the textual programing language and the proposed graphical approach. On this level, the proposed approach provides no clear advantage; someone might argue that the lack of coding is the advantage; others might say that the code is easier to read. An additional benefit of the graphical approach is the fact that along with the state-space matrix definition, presented in Figure 10a,b, the complete state-space model of the voltage controller is created. The advantage of the proposed approach can be seen in Figure 11. Here the comparison is made on the example of converter matrix creation. For a researcher inexperienced with matrix manipulation, the creation of a converter matrix in terms of matrix dimension fitting and debugging is a daunting task. Furthermore, if poor coding practices are applied, modification of the existing model can be a slow and error-prone process. The building block method showed in Figure 11b   The advantage of the proposed approach can be seen in Figure 11. Here the comparison is made on the example of converter matrix creation. For a researcher inexperienced with matrix manipulation, the creation of a converter matrix in terms of matrix dimension fitting and debugging is a daunting task. Furthermore, if poor coding practices are applied, modification of the existing model can be a slow and error-prone process. The building block method showed in Figure 11b enables:

•
The converter matrix creation only with an appropriate connection of consisted elements, in a physically logical way. It allows the complex system modeling through the creation of individual control and power stage blocks, and their appropriate graphical connection to form the models of the microgrid subsystems.

•
The easy debugging procedure, since the inspection of the variable of interest requires an only connection with a scope, as in any MATLAB/Simulink simulation. Greater clarity and monitoring of the model input/output signals in the blocks reduce the possibility of modeling errors.

•
The easy modification of the desired element and with it model complexity. Greater flexibility and modularity of the system modeling is allowed, and also the spent time is significantly reduced. It is possible to easily remove, modify, or insert new blocks of different complexity in a model.
(b) Figure 10. Comparison between voltage controller matrix definition: (a) textual language; (b) using the building block method.
The advantage of the proposed approach can be seen in Figure 11. Here the comparison is made on the example of converter matrix creation. For a researcher inexperienced with matrix manipulation, the creation of a converter matrix in terms of matrix dimension fitting and debugging is a daunting task. Furthermore, if poor coding practices are applied, modification of the existing model can be a slow and error-prone process. The building block method showed in Figure 11b enables: • The converter matrix creation only with an appropriate connection of consisted elements, in a physically logical way. It allows the complex system modeling through the creation of individual control and power stage blocks, and their appropriate graphical connection to form the models of the microgrid subsystems.

•
The easy debugging procedure, since the inspection of the variable of interest requires an only connection with a scope, as in any MATLAB/Simulink simulation. Greater clarity and monitoring of the model input/output signals in the blocks reduce the possibility of modeling errors.

•
The easy modification of the desired element and with it model complexity. Greater flexibility and modularity of the system modeling is allowed, and also the spent time is significantly reduced. It is possible to easily remove, modify, or insert new blocks of different complexity in a model. The previously presented voltage controller element is created in the same manner as the other elements presented in Section 2, using the building principle showed in Figure 12. Standard MATLAB/Simulink "Gain," "Integrator," and "Add" blocks present the foundation for the proposed modeling. All blocks are adopted for vector operations, enabling the creation of state-space matrices that mimic the matrices created in textual languages. The input of the required integrator is a vector sum of state signals multiplied by matrix A, and the input signals multiplied by matrix B. Signals at the integrator output represent element states. They are fed back to matrix A and forward into matrix C. At last, the input vector is multiplied with state-matrix D and summed with the output of statematrix C in order to obtain desired output signals.
(a) (b) Figure 11. Part of the converter state-space matrix creation: (a) textual language; (b) using the proposed method.
The previously presented voltage controller element is created in the same manner as the other elements presented in Section 2, using the building principle showed in Figure 12. Standard MATLAB/Simulink "Gain", "Integrator", and "Add" blocks present the foundation for the proposed modeling. All blocks are adopted for vector operations, enabling the creation of state-space matrices that mimic the matrices created in textual languages. The input of the required integrator is a vector sum of state signals multiplied by matrix A, and the input signals multiplied by matrix B. Signals at the integrator output represent element states. They are fed back to matrix A and forward into matrix C. At last, the input vector is multiplied with state-matrix D and summed with the output of state-matrix C in order to obtain desired output signals.
modeling. All blocks are adopted for vector operations, enabling the creation of state-space matrices that mimic the matrices created in textual languages. The input of the required integrator is a vector sum of state signals multiplied by matrix A, and the input signals multiplied by matrix B. Signals at the integrator output represent element states. They are fed back to matrix A and forward into matrix C. At last, the input vector is multiplied with state-matrix D and summed with the output of statematrix C in order to obtain desired output signals.

The Overview of the DGU model
The overview of the individual DGU model with available state-space elements is given in Figure 13. All blocks in one DGU belong to one of two unities: VSC or Boost converter. In the same figure, all signals are represented as small-signal variations around the linearization point. In the case of small-signal analysis, this is true. When microgrid time-domain simulation for dynamic response examination is wanted, all signals correspond to actual values that can be expected. Also, for dynamic response test, power calculation block and reference frame calculation blocks are implemented as nonlinear equations.

The Overview of the DGU Model
The overview of the individual DGU model with available state-space elements is given in Figure 13. All blocks in one DGU belong to one of two unities: VSC or Boost converter. In the same figure, all signals are represented as small-signal variations around the linearization point. In the case of small-signal analysis, this is true. When microgrid time-domain simulation for dynamic response examination is wanted, all signals correspond to actual values that can be expected. Also, for dynamic response test, power calculation block and reference frame calculation blocks are implemented as nonlinear equations.

Boost Converter Subsystem
The boost converter subsystem, according to Figure 13, consists of four building blocks and two selectors. The selector application allows easy enabling or disabling of an individual block of the model in the analysis. A voltage controller block 1 in the boost subsystem is based on Equations (6) and (7), with the reference voltage ∆u * dc as input and measured DC-Link voltage ∆u dc as feedback into the block. The output of the block in the form of the reference current ∆i * inb is forwarded together with the measured current ∆i inb to DCE block 2 . This block represents a unified model of the ideal sampler, zero-order hold and computational time delay models. Right after the digital control emulator block, a selector is implemented in order to enable or disable its usage in the boost subsystem model. To implement this block, a state-space representation of Equation (12) is needed. An application of MATLAB pade function for linear approximation and appropriate functions for state-space conversion creates matrices A dce , B dce , C dce , and D dce that model DCE [43]. The next building block in the boost subsystem model, according to Figure 13, is the current controller block 3 modeled based on Equations (10) and (11). The boost duty cycle reference ∆d b as output from the current controller block is together with the source voltage ∆u inb and DC-link current ∆i dc forwarded to the block that models physical boost converter 4 . The boost converter model block is formed based on the state-space Equation (3). Its outputs are the DC-link voltage ∆u dc and inductor current ∆i dc , which are used as feedback to the model. A selector next to this block gives a possibility to work with constant voltage ∆u dc by disabling the boost subsystem model from DGU or enabling it by forwarding the voltage ∆u dc to the VSC subsystem model. Based on the state of this selector, a boost subsystem model may or may not be included in the analysis.

VSC Subsystem
A complete small-signal state-space model of the VSC subsystem in Figure 13 is composed of ten building blocks and four selectors. The building block 1 represents the power controller model based on the state-space Equations (18) and (19). The inputs to the block are d-q components of the grid current ∆i gdq , capacitor voltage ∆u cdq , and frequency of the common reference frame ∆ω gcom . Its outputs are capacitor reference voltage ∆u cdq , its reference frame frequency ∆ω g , and phase angle difference ∆δ compared to the common reference frame; the first two of which are being forwarded to the virtual impedance block as inputs and third to the blocks 8 and 9 . The virtual impedance block 2 is modeled according to Equations (24) and (25), therefore the LPF and selector are placed between blocks 1 and 2 . The selector here enables or disables the LPF in the virtual impedance block model, so the grid current ∆i gdq filtering possibility exists. Another selector is used next to the virtual impedance block to enable or disable its usage in the VSC subsystem model. The next in line is the voltage controller block 3 with its input of capacitor voltage reference ∆u * cdq and feedback of measured ∆u cdq . A voltage controller block is implemented according to Equations (29) and (30) with the converter current reference ∆i * idq as output. A selector next to block 3 is used to enable or disable a voltage regulation in the model. Same as in the boost subsystem, the DCE block 4 together with a selector is used in the VSC subsystem model. A current controller block 5 provides a reference for the converter output voltage ∆u idq . This block is modeled according to Equations (34) and (35). Depending on the selector state, a reference ∆u idq could be forwarded to the power model of the converter block 6 or the LCL filter model block 7 . The power model of the converter is based on Equation (37) and represents the link with the boost converter subsystem taking a DC-link voltage as input ∆u dc . The LCL filter model block is modeled according to Equation (47) and links the DGU to the network model through blocks 8 and 9 . Blocks 8 and 9 , according to Equations (13) and (14), transform a grid voltage from an individual DGU reference frame to the common reference frame and grid current from a common reference frame to an individual DGU reference frame, respectively. The link between the VSC output current ∆i idq and the DC link current ∆i dc is made with block 10 according to Equation (39).

Network Subsystem
The small-signal state-space model of the whole network subsystem is represented in one block. The model is created according to the desired microgrid network topology, using Equations (51) and (52). The network subsystem is represented in Figure 14. The input of the network block is the state vector, which consists of the converter's grid current subvector ∆i convDQ , load's current subvector ∆i loadDQ , and frequency of the common reference frame ∆ω gcom . The output of the block is a node voltage vector ∆u netDQ .
The model is created according to the desired microgrid network topology, using Equations (51) and (52). The network subsystem is represented in Figure 14. The input of the network block is the state vector, which consists of the converter's grid current subvector convDQ i Δ , load's current subvector loadDQ i Δ , and frequency of the common reference frame ω Δ gcom . The output of the block is a node voltage vector netDQ u Δ . Figure 14. The network subsystem block.

Load Subsystem
The block model of the individual load at the k th node is formed according to the small-signal state-space Equation (55), and it is presented in Figure 15. The inputs of the block are voltage kD Q u Δ in the k th node of the network and frequency of the common reference frame ω Δ gcom , while the output is the k th node load current loadkDQ i Δ . Figure 15. The individual load subsystem model block.

Load Subsystem
The block model of the individual load at the k th node is formed according to the small-signal state-space Equation (55), and it is presented in Figure 15. The inputs of the block are voltage ∆u kDQ in the k th node of the network and frequency of the common reference frame ∆ω gcom , while the output is the k th node load current ∆i loadkDQ .
vector, which consists of the converter's grid current subvector convDQ i Δ , load's current subvector loadDQ i Δ , and frequency of the common reference frame ω Δ gcom . The output of the block is a node voltage vector netDQ u Δ . Figure 14. The network subsystem block.

Load Subsystem
The block model of the individual load at the k th node is formed according to the small-signal state-space Equation (55), and it is presented in Figure 15. The inputs of the block are voltage kD Q u Δ in the k th node of the network and frequency of the common reference frame ω Δ gcom , while the output is the k th node load current loadkDQ i Δ . Figure 15. The individual load subsystem model block.

A Complete Microgrid Model
The example of test microgrid from Figure 1 created using the building blocks method in MATLAB/Simulink environment is presented in Figure 16a. The provided GUI for each masked subsection (DGU, network, load) enables: • Fast parameter and control structure change, as can be seen from the example of DGU1 showed in Figure 16b. The example of test microgrid from Figure 1 created using the building blocks method in MATLAB/Simulink environment is presented in Figure 16a. The provided GUI for each masked subsection (DGU, network, load) enables: • Fast parameter and control structure change, as can be seen from the example of DGU1 showed in Figure 16b. • An easy selection of the elements and control structure blocks that should be included in the analysis. Model scalability is achieved through the simple selection of the desired elements.

•
The switch between the dynamic model and linear model by a simple selection in the GUI. The dynamic model can be compared to the model made of SimPowerSystem components. In this microgrid example, the frequency of the DGU1 is selected to be the common frequency of the microgrid system

Procedure for Small-Signal Model Analysis
As shown in Figure 16, provided the Simulink state-space model of the microgrid is encapsulated in appropriate blocks, each of them with appropriate GUI. Using the LAT, it is possible to perform a stability analysis of the whole system or its individual blocks in a simple way. By defining (selecting) of the input and output signals at the points of interest in the model, the desired analysis of the corresponding block is performed. The LAT gives different possibilities for stability In this microgrid example, the frequency of the DGU1 is selected to be the common frequency of the microgrid system ∆ω DGU1 = ∆ω com , and all other DGUs are translated to its reference frame.

Procedure for Small-Signal Model Analysis
As shown in Figure 16, provided the Simulink state-space model of the microgrid is encapsulated in appropriate blocks, each of them with appropriate GUI. Using the LAT, it is possible to perform a stability analysis of the whole system or its individual blocks in a simple way. By defining (selecting) of the input and output signals at the points of interest in the model, the desired analysis of the corresponding block is performed. The LAT gives different possibilities for stability analysis (pole-zero placement, Bode plot, Nyquist plot, Nichols plot). If the output currents signal of all load blocks is selected, one by one, using right-click and if the option "Linear Analysis-Complementary Sensitivity" is selected, LAT will be instructed to compute the closed-loop transfer function backward from those selected outputs. To ensure that all states are accounted for, common frequency should be selected as "Input Perturbation" with the previously described procedure. By navigating through tab "Analysis" in the Simulink window, then "Control Design-Linear Analysis . . . ", the LAT window will open. The overview of LAT with the example pole-zero map for the microgrid model presented in this paper is shown in Figure 17. In the "SETUP" section of the "LINEAR ANALYSIS" tab, an inspection of the model's inputs and outputs, model linearization at the arbitrarily operating point, and parameter variation can be done. The last one mentioned is of interest in the case of the inspection of how a variation of parameter, or a linear combination of parameters, influence the system. For the microgrid model pole-zero placement analysis in the complex plane, the option "Pole-Zero Map" should be selected from the "LINEARIZE" section of "LINEAR ANALYSIS" tab. Upon successful calculation of the model poles and zeros for the provided setup, a pole-zero map is provided in the main window and in "Linear Analysis Workspace" a state-space model of the microgrid is saved. If further manipulation of the state-space form model is required, it can be transferred to standard "MATLAB Workspace" by means of drag-and-drop. In the main window section, LAT will provide a graphical representation of the pole-zero map. With the mouse cursor hover over the pole or zero of interest, its precise location in the complex plane, damping ratio, overshoot, and frequency are shown.
Energies 2020, 13, x FOR PEER REVIEW 19 of 28 space model of the microgrid is saved. If further manipulation of the state-space form model is required, it can be transferred to standard "MATLAB Workspace" by means of drag-and-drop. In the main window section, LAT will provide a graphical representation of the pole-zero map. With the mouse cursor hover over the pole or zero of interest, its precise location in the complex plane, damping ratio, overshoot, and frequency are shown.

Demonstration of the Applied Methodology
This section shows the results of typical tests that are used for the microgrid analysis. The validation of the proposed state-space model is done in MATLAB/Simulink R2018b (Update 6) on the test microgrid model presented in Figure 1 (simulation file MicrogridEnergiesFULL.slx using parameters from LiveScript MicrogridEnergiesParam.mlx). In Simulink configuration parameters, a variable step solver with the ode23tb method is selected. For a reference model, the microgrid is created using power elements from the Simscape toolbox (Simscape -Electrical -Specialized Power Systems -Fundamental Blocks), with the control structures implemented in a discrete domain. Inside the necessary "powergui" block continuous simulation type is selected. Details of two state-space models of the test microgrid shown in Figure 1 are presented in Table 1.

Demonstration of the Applied Methodology
This section shows the results of typical tests that are used for the microgrid analysis. The validation of the proposed state-space model is done in MATLAB/Simulink R2018b (Update 6) on the test microgrid model presented in Figure 1 (simulation file MicrogridEnergiesFULL.slx using parameters from LiveScript MicrogridEnergiesParam.mlx). In Simulink configuration parameters, a variable step solver with the ode23tb method is selected. For a reference model, the microgrid is created using power elements from the Simscape toolbox (Simscape-Electrical-Specialized Power Systems-Fundamental Blocks), with the control structures implemented in a discrete domain. Inside the necessary "powergui" block continuous simulation type is selected. Details of two state-space models of the test microgrid shown in Figure 1 are presented in Table 1.  (41) and (42) In the later analysis, here presented order of model elements, with the order of states presented in appropriate subsection will be assumed. For a linear approximation of the DCE model, 3rd order Pade approximation is used.
In the following subsections, first, the dynamic response of the models are compared in order to test their validity. After that, the participation factor analysis for both state-space models is provided, to determine what states contribute to the creation of a specific eigenvalue of interest. In the last part of this section, singular value decomposition analysis is used in order to gain an insight into groups of states that might share similar characteristics.

Building Block Model Validation
The accuracy of the proposed microgrid model developed in the state-space form and implemented in Simulink was compared with the model created in Simulink using SimPowerSystem Toolbox. The system parameters are presented in Table 2, and the steady-state operating point of each DGU is given in Table 3. The authors optioned for a steady-state operating point obtainment from the model built using SimPowerSystem, as used in [18]. The impedances of the microgrid lines in Table 2 are taken from the cable catalog data considering expected load flow, power losses, and voltage drop.  Figure 18b with the comparison of capacitor voltage waveforms. As expected, during the steady-state operation, in all presented waveforms, there are no significant differences between the models I and II. As noted in Section 3.2, for dynamic response test, power calculation block and reference frame calculation blocks are implemented as nonlinear equations.

Eigenvalue Analysis Using LAT
Since in the complex plane the location of the model's transfer function poles is equivalent to the location of the model's state-space eigenvalues, the LAT tool can be directly used for eigenvalue analysis of the microgrid (done using MicrogridEnergiesSSM.slx with parameters from LiveScript MicrogridEnergiesParam.mlx). With the procedure described in Section 3.6 after the calculation of the microgrid model transfer function, the inbuild LAT tool can be used for pole (eigenvalue) obtainment.
The comparison of eigenvalue location of the model I and II for the parameters described in Table 2 and steady-state described in Table 3 is shown in Figure 19. Although it is noted that model I has 67 and model II has 247 states, due to the virtual impedance of the second DGU that is equal to zero, in all consequent analysis, two fewer states are shown (65 and 245). In the upper left part of Figure 19, the locations of all eigenvalues are shown. The boxed area denoted with 1 is presented in the lower-left part of Figure 19 and represents a zoomed-in part of the previous graph. The same principle is applied to all subsequent graphs.
implemented as nonlinear equations.

Eigenvalue Analysis Using LAT
Since in the complex plane the location of the model's transfer function poles is equivalent to the location of the model's state-space eigenvalues, the LAT tool can be directly used for eigenvalue analysis of the microgrid (done using MicrogridEnergiesSSM.slx with parameters from LiveScript MicrogridEnergiesParam.mlx). With the procedure described in Section 3.6 after the calculation of the microgrid model transfer function, the inbuild LAT tool can be used for pole (eigenvalue) obtainment. The comparison of eigenvalue location of the model I and II for the parameters described in Table 2 and steady-state described in Table 3 is shown in Figure 19. Although it is noted that model

Participation Factor Analysis
In detail modeled microgrids, it is useful to quantify the contribution of each element of the state matrix to a specific eigenvalue. The usual mathematical tool for this quantization, called the participation factor, relies on the unique properties of left and right eigenvectors [44]. Participation factor obtainment cannot be done directly in LAT. Instead, a state-space model of the microgrid has to be exported to the MATLAB workspace where this additional analysis is conducted (done using MicrogridEnergiesPF.m file). Normalized participation of each state in every eigenvalue of the model I and II are presented in Figure 20a,b, respectively. matrix to a specific eigenvalue. The usual mathematical tool for this quantization, called the participation factor, relies on the unique properties of left and right eigenvectors [44]. Participation factor obtainment cannot be done directly in LAT. Instead, a state-space model of the microgrid has to be exported to the MATLAB workspace where this additional analysis is conducted (done using MicrogridEnergiesPF.m file). Normalized participation of each state in every eigenvalue of the model I and II are presented in Figure 20a,b, respectively.  In Figure 20, the order of eigenvalue numeration is from the leftmost to the right. A pattern can be noticed in Figure 20a that the first state-space element of all Power Controllers (PCs) influences a wide number of eigenvalues. In general, its influence increases as the eigenvalues of interest are closer to the imaginary axis of the complex plane. Also, the influence of Virtual Impedance (VI) on some low-frequency eigenvalues can be noticed. Loads participate in the forming on the eigenvalues in the middle spectrum. For this selection of values, LCL filters have small importance, mostly on the medium-frequency eigenvalues. Voltage and current controllers (VC and CC, respectively) have an impact on the medium-frequency eigenvalues.
The participation factor analysis of the microgrid model II is shown in Figure 20b, mostly for demonstrative purposes. The detailed overview of the boxed sections of interest is shown in Appendix A. On this paper's MDPI website supplementary material is published that includes presented figures built-in MATLAB for detailed inspection. What can be concluded is that DCE has a significant contribution to the forming of a large number of eigenvalues.

Singular Value Decomposition Analysis
Frequently used for compression and low-dimensional representation of high-dimensional matrices in data science, singular value decomposition (done using MicrogridEnergiesSVD.m file) is also a valuable tool for the analysis of "belongings" or "concepts" hidden in the original matrix [45]. Namely, columns of left singular vectors can provide an insight into what state-space variables can be grouped under similar "concepts," no matter how abstract that group might be. Values of the matrix that contain left singular vectors are graphically showed in Figure 21 for model I. The clustering of the matrix shows the first cluster that can be formed on concepts 1 to 12 and that it dominantly includes state-space variables of the microgrid network and DGU's LCL filter models. The second cluster formed on concepts 13 to 18 groups state-space variables of all LCL filters. In addition to state-space variables of the first and the second, the third cluster of concepts (from 19 to 34) includes most of the state-space variables from power controllers. The third group (35 to 45) consists mainly of the load state-space variables. The next group (46 to 51) consists of current controller state-space variables, followed by the virtual impedance (52 to 56), voltage controllers with load model (57 to 62), and the rest of the state-space variables from the power controllers (63 to 65).
impact on the medium-frequency eigenvalues.
The participation factor analysis of the microgrid model II is shown in Figure 20b, mostly for demonstrative purposes. The detailed overview of the boxed sections of interest is shown in Appendix A. On this paper's MDPI website supplementary material is published that includes presented figures built-in MATLAB for detailed inspection. What can be concluded is that DCE has a significant contribution to the forming of a large number of eigenvalues.

Singular Value Decomposition Analysis
Frequently used for compression and low-dimensional representation of high-dimensional matrices in data science, singular value decomposition (done using MicrogridEnergiesSVD.m file) is also a valuable tool for the analysis of "belongings" or "concepts" hidden in the original matrix [45]. Namely, columns of left singular vectors can provide an insight into what state-space variables can be grouped under similar "concepts," no matter how abstract that group might be. Values of the matrix that contain left singular vectors are graphically showed in Figure 21 for model I. The clustering of the matrix shows the first cluster that can be formed on concepts 1 to 12 and that it dominantly includes state-space variables of the microgrid network and DGU's LCL filter models. The second cluster formed on concepts 13 to 18 groups state-space variables of all LCL filters. In addition to state-space variables of the first and the second, the third cluster of concepts (from 19 to 34) includes most of the state-space variables from power controllers. The third group (35 to 45) consists mainly of the load state-space variables. The next group (46 to 51) consists of current controller state-space variables, followed by the virtual impedance (52 to 56), voltage controllers with load model (57 to 62), and the rest of the state-space variables from the power controllers (63 to 65).

Conclusions
A building block modeling method based on MATLAB/Simulink is proposed in this paper. The main results can be considered from two aspects.
From the first aspect, the proposed method enables complex system modeling through the creation of individual block elements, and their appropriate graphical connection. In this way, a more

Conclusions
A building block modeling method based on MATLAB/Simulink is proposed in this paper. The main results can be considered from two aspects.
From the first aspect, the proposed method enables complex system modeling through the creation of individual block elements, and their appropriate graphical connection. In this way, a more flexible system modeling is achieved. Available elements complexity and control structures are easily changeable through GUI that encapsulates subsystems. The proposed method leverages the additional toolbox that enables fast linear system analysis.
From the second aspect, the detailed models of elements from the literature are synthesized and extended in this paper. As an illustration of the proposed building block method, two models are investigated. Typically considered elements for the microgrid modeling are grouped as the first model. The second model extends the first with an additional boost controller subsystem and digital control emulator. The dynamic response is used for these model validations, and it is shown that, of the tested models, the second model has a higher resemblance to the model build using Simscape. Participation factor analysis shows that the dynamic control emulator has a contribution to the creation of a high number of eigenvalues. Future work will include expansion of the model capabilities in order to analyze hybrid microgrids, microgrids with rotating machines, and the effects of secondary control on the stability.

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

Appendix A
The detailed overview of the boxed area presented in Figure 20b is shown in Figure A1.