> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/simulation-and-analysis/analyze-a-simple-circuit.md).

# Analyze a Simple Circuit

## Introduction

In this section you:

* obtain the state-space representation of your model with the power\_analyze command.
* compute the steady-state voltages and currents using the graphical user interface of the powergui block.
* analyze an electrical circuit in the frequency domain.

## Electrical state variables

The electrical state variables are the Simulink® states of your diagram associated to the capacitor and inductor devices of the SPS Software blocks. Inductors and capacitors elements are found in RLC-branch type blocks such as the Series RLC Branch block, Three-Phase Parallel RLC Load block, transformer models, the PI Section Line block, snubber devices of power electronic devices, etc.

Electrical state variables consist of the inductor currents and the capacitor voltages. Variable names for SPS Software electrical states contain the name of the block where the inductor or capacitor is found, preceded by the `Il_` prefix for inductor currents or the `Uc_` prefix for capacitor voltages.

## State-Space representation using power\_analyze

Compute the state-space representation of a model with the **power\_analyse command** at the MATLAB prompt, e.g.:

{% code lineNumbers="true" %}

```matlab
[A,B,C,D,x0,electrical_states,inputs,outputs] = power_analyze('power_gui')
```

{% endcode %}

This returns the state-space matrices A, B, C, and D for the power\_gui example model. x0 is the vector of initial conditions of the electrical states. The names of the electrical state variables, inputs, and outputs are returned in the corresponding outputs.

See the [power\_analyze](broken://pages/d801265c1522e6afbf2ba4e17fff41613db2781a) reference page for more details.

## Steady-state analysis

Open the power\_gui example model by typing:

Then open the **Powergui Steady-State Voltages and Currents Tool** to display steady-state phasor voltages measured by the voltage and current measurement blocks of the model.

* Each measurement output is identified by a character vector corresponding to the measurement block name.
* Phasor magnitudes correspond to the peak value of the sinusoidal voltages.

You can display steady-state values of the source voltage or the inductor currents and capacitor voltages by selecting the **Sources** or the **States** check box.

Refer to Measuring Voltages and Currents for details on sign conventions used for sources and electrical state variables listed in the Steady-State Tool window.

## Frequency analysis

The **SPS > Sensors and Measurements** library contains an [Impedance Measurement](broken://pages/5fb2aabf4263d0ddf87010f886a5181cff638eed) block that measures impedance between any two nodes of a circuit. Below are two methods to measure the impedance in the power\_gui model:

* automatic measurement using the Impedance Measurement block and the Powergui tool.
* calculation from the state-space model.

{% stepper %}
{% step %}

### Measuring impedance vs. frequency with the impedance measurement block

1. In the power\_gui example model, two Impedance Measurement blocks measure impedance at two points.\
   Delete Impedance B3 and reconnect Impedance B1 as required (refer to your model screenshots).

   <figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-10bb5e8a885124b66092281c149b510fa24306fa%2Fmeasure_impedance_frequency.png?alt=media" alt=""><figcaption><p><strong>Measuring Impedance vs. Frequency with the Impedance Measurement Block</strong></p></figcaption></figure>
2. In the **150 km Line** block, set **Number of pi sections** to 1 and click **OK**.
3. Open the Powergui dialog. In the **Tools** tab, select **Impedance Measurement**. A window opens showing the list of Impedance Measurement blocks available in the circuit.
4. Fill in the frequency range by entering: 0:2:5000 (zero to 5000 Hz by steps of 2 Hz).

   Select logarithmic scale to display Z magnitude.

   <figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-c147a8b0b96e5307b6363071837c48584e4ce545%2Fpowergui_imp_freq_block_ex.png?alt=media" alt="" width="528"><figcaption></figcaption></figure>
5. When calculation finishes, the window displays magnitude and phase as functions of frequency.
6. To see the effect of a higher-fidelity line model, open the **150 km Line** block dialog, set **Number of pi sections** to 10, then in the Powergui Impedance vs Frequency Measurement tool click **Update**. The dialog displays the new frequency response.

   <figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-abfe4caf9212d3169a09ace2f4d7c63f1d27eb69%2Fpowergui_imp_freq_block_exresults.png?alt=media" alt="" width="528"><figcaption></figcaption></figure>

{% endstep %}

{% step %}

### Obtaining the impedance vs. frequency relation from the state-space model

{% hint style="danger" %}
The following assumes Control System Toolbox™ is installed.
{% endhint %}

* Add an [AC Current Source](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/blocks-functions-tools/basics/sources/ac-current-source.md) block from **SPS > Sources** library to your model. Connect this source so it injects at the node of interest. Set the current source magnitude to zero and keep its frequency at 60Hz.

  <figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-08ec56f628f21c524995565d4582df0a852b940f%2Fex_ACsource_B2node.png?alt=media" alt=""><figcaption><p><strong>AC Current Source at the B2 Node</strong></p></figcaption></figure>
* Compute the state-space representation of the model with the folllowing command at the MATLAB prompt.

{% code lineNumbers="true" %}

```matlab
sys1 = power_analyze('power_gui','ss');
```

{% endcode %}

This returns a continuous-time state-space model representing the circuit.

* In the Laplace domain, impedance at the measured node is the transfer function between the current injected by the AC Current Source block and the voltage measured by the U2 Voltage Measurement block:

  $$Z2(s) = \frac{U2(s)}{ I2(s)}$$
* Obtain input and output names from the state-space model:

{% code lineNumbers="true" %}

```
sys1.InputName
ans =
    'U_Vs (60Hz)'
    'I_AC Current Source'
sys1.OutputName
ans =
    'U_Ub2'
    'U_Ub1'
```

{% endcode %}

The impedance at the measured node corresponds to transfer function from input 2 to output 1: sys1(1,2).

For the 0–5000 Hz range, calculate and display the frequency response:

{% code lineNumbers="true" %}

```matlab
freq = 0:5000;
w = 2*pi*freq;
bode(sys1(1,2), w);
```

{% endcode %}

* To compare single-section and 10-section line models:

  * Change the **PI Section Line** dialog box Number of sections from 1 to 10.
  * Compute the new state-space model and superimpose Bode plots:

    <pre class="language-matlab" data-line-numbers><code class="lang-matlab">sys10 = power_analyze('power_gui','ss');
    bode(sys1(1,2), sys10(1,2), w);
    </code></pre>
  * In the Bode plot property editor, select Frequency units in Hz using linear scale and Magnitude in absolute using log scale.

  The resulting plot shows that the single line section model is limited at high frequencies and the 10-section model provides a better approximation.

  <figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-5554c55a73c89e781a211c1adf24cc49fcb114aa%2Fex_imp_measurednode_fction_freq_results.png?alt=media" alt=""><figcaption><p><strong>Impedance at the Measured Node as Function of Frequency</strong></p></figcaption></figure>

{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/smart-power-simulation-software-sps/simulation-and-analysis/analyze-a-simple-circuit.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
