Sei sulla pagina 1di 15

:

Matlab-Scilab
Comparison

:


:



: "

: 1122


-
TECHNION - ISRAEL INSTITUTE OF TECHNOLOGY



Contents
Matlab Scilab Comparison
Introduction
Simulating Simple Linear Systems
Simulating Dynamic Systems Using Xcos
Differences in Workflow using Xcos compared to Simulink
Components Library
Connecting the Components
The Resulting Diagrams
Execution Time
DAQ using Scilab
Video Tracking using Scilab
Converting Matlab Code to Scilab
ATOMS
Introduction
In this project, our goal is to determine whether the Control Lab of the Electrical
Engineering Faculty of the Technion (and thereafter all labs of Electrical Engineering)
can gradually switch all lab experiments and projects to use Scilab instead of Matlab.
The reason that the faculty is considering this transformation is that it can save the
faculty great amount of money. At the current situation, the price of maintaining
Matlab and its additional needed toolboxes is becoming a great financial burden on
the faculty.
In order to test if this switch is possible within the near future, we decided to test
Scilab's performance in the following aspects:
1. Solve simple linear systems and calculate LQR gain
2. Simulate dynamic models built from block diagrams using Scilab's Xcos
(similar to Matlab's Simulink)
3. Interface with a DAQ card used in the Control Lab (used for various
experiments in the lab)
4. Replicate a video tracing algorithm using Scilab

In each of these aspects, we measured whether the results Scilab returned were
identical to those returned by Matlab; compared the execution times; and reviewed
how difficult the interaction with the program was.

Simulating Simple Linear Systems
For simple examples of linear systems, we chose to implement the project given in the
course "Control Systems 2".
First of all, we wanted to examine how Scilab deals with small projects (homework
assignments etc.).
The example we chose is a State Space System controlled by a LQR feedback
controller. In addition, we wanted to examine how Scilab deals with noise added to
the model. For example, here is the model we built in Xcos (with noise):


Scilab produced the same feedback controller and gave the same output as Matlab.
The execution time was also very similar to Matlab (with a small advantage to
Matlab).
It is very easy to convert a small project from Simulink to Xcos, because the UI and
parameter configuration are almost identical, as you can see in the following
screenshots:

MATLAB:



Scilab:


In conclusion, it is very easy to learn how to use Xcos for someone who has prior
knowledge in working with Simulink. We found that the learning curve of Xcos
should be the same as that of Simulink. In terms of number of components, we had all
we needed for producing this project. Therefore, the case should be similar for other
small projects and homework assignments in control systems.
Simulating Dynamic Systems Using Xcos
In order to test whether Xcos can serve as an alternative to Matlab's Simulink, we
decided to take a project which makes extensive use of Simulink and to replicate it in
Scilab. Unfortunately, there is no program that we found which can convert Simulink
files to files which Xcos can process. Therefore, the conversion had to be done
manually.
The project which we decided to test is called "Auto-Park", done by Limor Greenberg
and Yaniv Romano. Their Matlab code performs some initialization of variables and
then calls a Simulink simulation. The Matlab code was converted using an automatic
script included with Scilab. The Simulink diagram was built from scratch in Xcos.
Differences in Workflow using Xcos compared to Simulink
Components Library
Xcos has a smaller variety of components to choose from when creating a diagram.
However, for the project we chose, Xcos contained all the components we needed in
order to replicate the Simulink diagram. Adding new components to the diagram and
editing the properties of the components was simple and intuitive.
Other than the smaller variety of components, there was also a small difference in that
in Xcos, all components which are synchronous (To Workflow, Scope) have a
synchronization port, which needs to be connected to a clock component. In Simulink,
each of these components has an option of sample time, which may be inherited or
supplied manually.
In addition, Xcos does not have (so far) a simulation solver which can run with a
variable step. It simply runs using a fixed step clock, according to the one given by
the clock component in the diagram.
Connecting the Components
The difficulty we had, dealing with Xcos, was connecting the different components.
Connecting the components of the diagram usually involved many clicks and it was
difficult to select the end points of the lines (at the ports of the components). There
was much flexibility as to the shape of the lines (adding points to the line was simple)
however the lines usually did not turn-out straight and elegant. Alternatively, in
Simulink, there is a simple keyboard shortcut (Ctrl + Click) which allows connecting
components quickly and simply.
Furthermore, Xcos didn't have the feature of creating incomplete lines, whereas in
Simulink this feature exists and allows editing the connections in an easier manner.




The Resulting Diagrams
Original Matlab Diagram:

Corresponding Scilab diagram:





Simulation results in Matlab:
0 10 20 30 40 50 60
-15
-10
-5
0
5
10
15
Prallel Parking
X [m]
Y

[
m
]

Simulation results in Scilab:


Execution Time
The results of the simulation were identical in both MATLAB and Scilab. However,
the execution time of the simulation under Scilab was 22.9 times longer than that of
MATLAB, as you can see in the table below:

MATLAB Scilab
Execution Time [sec] 79.477 1820.969

DAQ using Scilab
Another aspect we wanted to examine is the use of the DAQ card used in the control
lab. Currently, the control lab performs many projects using the "NI PCI 6024E" card.
In order to communicate with the card, we tried searching for toolboxes for data
acquisition that use that card. We found some outdated toolboxes which use the driver
"NI DAQmx Base 2.x", but we didn't manage to compile the code of the toolbox,
since it is written for an old version of Scilab. Here is a link to the referred toolbox:
DATA ACQUISITION AND REAL-TIME - DAQ Toolbox
We also found a toolbox that deals with many drivers by communicating with a DAQ
program called "COMEDI". COMEDI supports many DAQ cards (including our
card), but it is written for a Linux environment. Therefore, the toolbox itself can only
run under Linux. We decided that due to the large learning curve of Linux, it is not
recommended to use this toolbox in the lab. In addition, this toolbox is also outdated,
and it would probably be difficult to use it in new version of Scilab. Here is a link to
the referred toolbox: SCICOS - COMEDI
After we found there are no suitable toolboxes for our purpose, we decided to create a
primitive interface between Scilab and the DAQ card, which includes simple reading
and writing functions. We built this interface in order to estimate how difficult it
would be to implement a fully-functional toolbox which interacts with the card.
In order to build this interface, we used the ability of Scilab to run external C
functions and use them to create appropriate Scilab functions. We decided to go in
this direction, since we found a C API for the driver "NI DAQmx" which our card
uses.
Our reading function, receives an integer which specifies how many samples to read
from the card. The output of the function is a Scilab vector containing the sampling
results.
Our writing function, receives a vector from Scilab, which is written to the card. The
result, in this case, is the activation of the device that is connected to the card.
We tested these functions on the "Flexible Robotic Arm" which has a motor and is
connected to the DAQ card. Using the reading function, we managed to receive a
signal specifying the angle of the robotic arm. Using the writing function, we
managed to move the robotic arm in different directions according to the vector we
sent the function.
According to our experience of implementing these simple functions, we assume that
implementing a fully-functional toolbox could be performed as part of a student
project in the Control Lab. It may also be possible to request from the company that
supports the card to build this toolbox for Scilab.
In addition, we found that Scilab can be easily extended through C/Fortran functions.
Video Tracking using Scilab
We wanted to examine how Scilab deals with video tracking.
The first problem we encountered is trying to read video files from Scilab. For this
action, there is a toolbox called SIVP (Scilab Image and Video Processing toolbox).
This toolbox has a function for reading ".avi" files called "aviopen". This function
relies on OpenCV. When trying to run this function under Windows, we were unable
to read simple avi files. We also ran the same function in a Linux environment
(Ubuntu) and managed to read video files, but this doesn't help us since we want to
test Scilab only in a Windows environment.
Because of this obstacle, we decided to focus our attention on the image processing
capabilities of Scilab. There are three main toolboxes for dealing with image
processing in Scilab:
SIP Scilab Image Processing Toolbox: This is a rather old toolbox, written
originally for Linux. It contains many useful functions (selecting ROI, dilation
and erosion etc.). It uses ImageMagick implementation of many of its
functions. A fork to Windows may be developed soon.
Image Processing Design Toolbox: This toolbox contains many useful image
processing functions (morphological filters, edge detection etc.). The toolbox
has a syntax which is different from that of similar Matlab functions.
Currently works only in a Windows environment.
SIVP: Contains many image and video editing functions. It is inspired by SIP,
but uses OpenCV instead of ImageMagick for its image processing
capabilities. Its video support is currently experimental and works only on
Linux. It also has a function that is not present in other image processing
toolboxes which is able to detect faces within an image.

Converting Matlab Code to Scilab
Scilab contains a script for converting ".m" files to ".sci" files (built into Scilab). We
used this script extensively in the project, and we found some places where it can be
improved.
The script does not detect some functions which can be easily converted,
especially those which are added by toolboxes installed.
Many temporary variables are added in the conversion, which makes the
converted code, in some cases, unclear.
Conversion of functions does not work if there is an "end" at the end of the
Matlab function.
Converting complex conditions from Matlab is sometimes incorrect.
In conclusion, this conversion script is not useful for projects which contain functions
that are not so common and complicated logic. However, this script will not have to
be used if the projects will be written in Scilab beforehand.
ATOMS
Since Scilab 5.2, adding external modules/toolboxes to Scilab has become simpler,
due to the addition of a new feature named ATOMS (AuTomatic mOdules
Management for Scilab). This new platform encourages developers to write their own
modules for ATOMS, which will then be added to the ATOMS portal website, and
will be available for download for all users. ATOMS support is built into Scilab, and
searching for new modules or updating existing modules can be done from within
Scilab very easily.
As we followed the progress of ATOMS, we learned that there is much progress in
this direction. Some old toolboxes are being rewritten to comply with ATOMS (and
therefore can be more easily installed on multiple platforms). Additionally, new
modules are constantly being added to the portal, and it is worth checking for new
modules in order to added capabilities and functions that may be useful for different
projects.
Conclusion
We found that it is rather easy to learn how to use Scilab and Xcos. For now it cannot
replace Matlab in all areas. However, in some cases for small projects Scilab can be a
good alternative. Once the video processing toolboxes will be available on windows,
it will probably be possible to build video tracking projects in Scilab. In order for the
"NI PCI 6024E" card to work fully on Scilab, an interface needs to be built which
communicates with the driver. We found this task to be possible to perform within the
scope of a student project. Finally, the execution time we found of a complex Xcos
model was much higher than that of an equivalent Matlab model. In order for Scilab
to become a worthy alternative in this aspect, the execution times must be reduced.

Potrebbero piacerti anche