> 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/example-models/simulation-and-analysis/interfacing-simulink-models-with-sps.md).

# Interfacing Simulink Models with SPS

This example shows the interfaces between Simulink® and SPS Software to design a custom synchronous machine model. It also shows an example of a customized Synchronous Machine block.

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

## Description

In this example, we use the Synchronous machine blocks as an example to show the interfaces between Simulink and SPS. There are two similar circuits shown in parallel. The top circuit model shows the starting of a synchronous machine using blocks from the SPS Software library. The circuit below it is identical in all respects, but for a custom-built model of the Synchronous machine.

Click to look under the mask of the official Synchronous machine block, and find the core functionality of the block modeled in the 'Source' and the 'SM\_mechanics' subsystems. It is important to note that these subsystems are built up from either Simulink elements or basic SPS blocks. Users may need to change this representation to add their own functionality to the block, and meet their custom needs.

Now look under the mask of the custom-built Synchronous machine block (in the middle circuit), and observe the three subsystems. The 'Measurement System' in green, contains the voltage measurement blocks which convert the SPS' signals into Simulink signals. The 'Simulink System Model', contains the core functionality of the Synchronous machine block, comprising the 'Source' and the 'SM\_mechanics' subsystems, borrowed from the standard shipped block. It is here that users may customize and manipulate the extracted Simulink signals to any degree. Lastly, the 'Current Injection System', contains the controlled current source blocks which convert Simulink signals into SPS' signals.

In general, measurement blocks (voltage/current/impedance) serve as an interface between SPS Software and Simulink, and controlled source blocks (voltage/current) between Simulink and SPS Software. This is the recommended template for interfacing custom-built blocks in Simulink, with SPS Software.

## Simulation

Run the example to see that there is no differences between the two circuits.

### Conclusion

This model presents a model of the Synchronous machine block, but users may just as well employ and edit any standard block in SPS Software. Extending this further, using the recommended template, it is even possible to create any custom block not provided with SPS Software in Simulink, and then interface it seamlessly with a SPS Software circuit.

## Command

Example model name: power\_SLmodeling

{% code lineNumbers="true" %}

```matlab
open('power_SLmodeling')
```

{% endcode %}


---

# 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/example-models/simulation-and-analysis/interfacing-simulink-models-with-sps.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.
