# A linear State-Space Model for Distribution Grid

This repository contains the following material:

- Matlab code to obtain a linear model of distribution grid

- Matlab code to run time simulation of a distribution grid with the possibility to set up time resolution and duration

- Simulink model of an 11 bus network

- Matlab code to repeat the tests shown in paper [A state-space linear model for distribution grids]

You need an updated version of Matlab, possibly Matlab 2017 to run the Simulink model

## Instructions to build a linear model of a distribution grid

- Run in Matlab the file BuildModel.m

- If needed modify the parameters of the grid, inverters and loads in the file Dynamic_Model

- Select the grid with Nnodes (e.g. Nnodes = 10 selects the grid used in the paper)

## Instructions to run time simulation of a distribution grid

- Run in Matlab the file TimeSimulation.m

- If needed modify the parameters of the grid, inverters and loads in the file Dynamic_Model

- Select the grid with Nnodes (e.g. Nnodes = 10 selects the grid used in the paper)

- Select the time resolution of the simulation, by changing time_delta. I suggest at least 1e-4 and smaller for the best result,

time_delta may degrade the solution depending on the grid.

- Select the number of point in time to be simulated with Nt.

- If needed modify the parameters uncertainty of inputs (slack voltage Eo, Irradiance G, PQ set points),

this will create random phenomena of a certain amplitude that impact the status of the system..

## Insutructions to repeat the tests shown in paper [A state-space linear model for distribution grids]

- It will be needed to run the matlab simulations, based on the linear model; then run the same simulations in Simulink and finally compare the results.

- Run in Matlab the file TestPaper.m

- The type of files and parameters used are simular to the one mentioned for the previous two sections of instructions.

- In this case the default parameter are the same as the one used in the paper, so the simulation will take quite a long time (hours).

- For quicker simulation reduce time_delta to 1e-4 or 1e-3 (but larger unaccuracy may appear).

- Run the file Initialization.m

- Open the simulink file named Test11bus.slx

- you will find three color blocks, where some simple manual modifications are to be applied in order to obtain the 3 testing conditions of the paper.

- Run the simulation (by default 5 seconds with 1e-5 seconds of time resolution)

- The structures Scope_Idq and Scope_Vdq will be saved in your workspace.

- type (depending on what scenario you tested in Simulink)

- save 'ScopeOut_steady' Scope_Idq Scope_Vdq

- save 'ScopeOut_PQrampchange' Scope_Idq Scope_Vdq

- save 'ScopeOut_PQstepchange' Scope_Idq Scope_Vdq

- save 'ScopeOut_Vstepchange' Scope_Idq Scope_Vdq

- When all the tree scenarios have been tested and the m files ScopeOut_PQramptest, ScopeOut_PQsteptest, ScopeOut_Vsteptest have been saved run PlotPaper.m

- Matlab code for rectangular current distribution state estimation

- Matlab code for rectangular voltage distribution state estimation

- Matlab code to collect error metrics and calculate uncertainty of estimators

The code runs in Matlab environment

## Instructions to test the state estimator

- Run in Matlab the file test_steady_DSSE.m

## Copyright

...

...

@@ -76,7 +42,6 @@ For other licensing options please consult [Prof. Antonello Monti](mailto:amonti