In order to use Xcos you need to install Scilab first. In this article we are going to discuss about the following topics:
- what is Xcos
- what is a Xcos library (palette)
- what is a Xcos block
- how to setup a Xcos block diagram
- how to setup the simulation parameters in Xcos
- how to run a simulation and visualize results
What is Xcos ?
Xcos is a Scilab toolbox for modeling and simulation of dynamic (continuous and discrete) systems. Although the main purpose is to simulate dynamic systems, Xcos can be used for signal generation, data visualization or simple algebraic operations.
When dealing with systems with interconnected continuous-time and discrete-time components, Xcos is the right tool for modeling and simulation.
Xcos provides a modular approach for complex system modeling, using a block diagram editor. Xcos models are compiled and simulated in a single run. The resulting mathematical equations are integrated by a numerical solver with configurable parameters.
With Scilab opened, you can launch Xcos in several ways:
- by clicking the toolbar icon
- from the menu bar, by clicking Applications -> Xcos
- by entering at the Scilab console:
What is a Xcos library (palette) ?
When Xcos is launched, two windows are opened by default:
- a palette browser
- an editing window
The Palette browser has two panes. The left pane contains the list of available predefined palettes (libraries). The right pane contains the available blocks for each palette. By clicking another palette in the left pane, a new set of blocks will appear on the right pane.
The editing window is the Xcos workspace for developing new models (diagrams). In order to add blocks in the diagram, select the block from the palette browser and drag & drop in the editing window. You can also add block to the diagram by right-clicking the block in the library and Add to -> “name of the diagram“.
What is a Xcos block ?
Blocks are the smallest Xcos entities. Any Xcos model (diagram) is a collection of blocks, interconnected to each other. In general, a block has an input port, an output port and one or more parameters. There are blocks with multiple input and output ports, or only with one input port(s) or output port(s).
The block above is a gain block. It can be found in the “Mathematical Operations” palette (library). It has one input, one output port and two parameters. We can access the parameter menu by double-clicking on the block.
The gain block is multiplying the value of the input signal with the value of the
Gain parameter. For example, if the value of the input signal is 2 and the
Gain is set to 10, the value of the output signal will be 20.
After the parameters are set as indented, the user has to click the “Ok” button so that the settings are saved.
How to setup a Xcos block diagram (model) ?
First step is to drag into the diagram all the necessary blocks for our model. After the block are in the diagram, they have to be ordered in an appropriate manner so that the connections of the ports will be easy to perform.
The connection of the block’s input/output ports is done is several steps:
- place the mouse pointer on the starting port until is going to be highlighted with a green box
- click and hold the left mouse button
- drag the line onto the end port until it will be highlighted with a green box
- release the mouse button
In the example below we are using a sine wave generator block (
GENSIN_f) to generate a sine signal. The signal value is amplified with the help of a gain block (
GAINBLK). The amplified sine wave is plotted (displayed) on a scope (
CSCOPE). The frequency at which the sine wave is displayed on the scope is set by the clock block (
After the blocks are connected as in the image above, we need to setup the parameters for each block. In the images below you can see the parameter settings for each block. Click on each image for a high resolution view.
After the diagram (model) is complete, save it with the desired name and location.
How to setup the simulation parameters in Xcos ?
After the Xcos model is setup (blocks connected) and the parameters are set, we need to set the simulation parameters. To access the simulation parameters menu we have to click in the menu bar: Simulation -> Setup. The following window will open:
For this example we are going to set only the
Final integration time to 30 seconds (
How to run a simulation and visualize the results ?
After the simulation parameters are setup, we are ready to run the simulation. The simulation can be launched in two ways:
- by clicking the Start button from the toolbar
- by clicking Simulation -> Start in the menu bar
At the end of the simulation the scope block will open, displaying the result. In our example we are going to see an amplified sine wave as in the image below.
With Xcos, the user can develop its own library of reusable models which can be reused in different projects. This feature is very useful when a large model contains modules developed by different project teams.
Xcos is more than a modeling and simulation environment. The user can optimize model parameters, validate models or generate automatically C code, using embedded Xcos functions.
For any questions or observations regarding this tutorial please use the comment form below.
Don’t forget to Like, Share and Subscribe!