Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
USING SCILAB
INTRODUCTION TO SCILAB
Scilab is free and open source software for numerical computation providing a
powerful computing environment for engineering and scientific applications
From the software point of view, Scilab is an interpreted language. This generally
allows to get faster development processes, because the user directly accesses a high-level
language, with a rich set of features provided by the library. The Scilab language is meant to
be extended so that user-defined data types can be defined with possibly overloaded
operations. Scilab users can develop their own modules so that they can solve their particular
problems.
Scilab includes hundreds of mathematical functions. It has a high-level programming
language allowing access to advanced data structures, 2-D and 3-D graphical
functions. A large number of functionalities is included in Scilab:
Maths& Simulation
For usual engineering and science applications including mathematical operations and
data analysis.
2-D & 3-D Visualization
Graphics functions to visualize, annotate and export data and many ways to create and
customize various types of plots and charts.
Optimization
Algorithms to solve constrained and unconstrained continuous and discrete
optimization problems.
Statistics
Tools to perform data analysis and modeling
Control System Design & Analysis
Standard algorithms and tools for control system study
Signal Processing
Visualize, analyze and filter signals in time and frequency domains.
Application Development
Increase Scilab native functionalities and manage data exchanges with external tools.
Xcos - Hybrid dynamic systems modeler and simulator
Modeling mechanical systems, hydraulic circuits, control systems, etc.
Whatever our platform is (i.e. Windows, Linux or Mac), Scilab binaries can be
downloaded directly from the Scilab homepage http://www.scilab.org or from the Download
193
area http://www.scilab.org/download. Scilab binaries are provided for both 32 and 64-bit
platforms so that they match the target installation machine.
There are several ways of using Scilab and the basic two methods are:
Using the console in the interactive mode
Using the exec function against a file
The console
The first way is to use Scilab interactively, by typing commands in the console, analyzing
the results and continuing this process until the final result is computed.
The editor
Scilab,from version 5.2 provides a new editor which allows to edit scripts easily.The
editor can be accessed from the menu of the console, under the Applications > Editor menu,
or from the console, as presented below.
--> editor ()
194
This editor allows to manage several files at the same time, as presented in figure below
There are many features but commonly used features are under the Execute menu.
Load into Scilab allows to execute the statements in the current file, as if wedid a
copy and paste. This implies that the statements which do not end withthe semicolon
";" character will produce an output in the console.
Evaluate Selection allows to execute the statements which are currently selected.
Execute File into Scilab allows to execute the file, as if we used the execfunction. The
results which are produced in the console are only those whichare associated with
printing functions, such as disp for example.
We can also select a few lines in the script, by right clicking and get the context menu as
presented below:
195
Using exec
When several commands are to be executed, it may be more convenient to writethese
statements into a file with Scilab editor. To execute the commands located in such a file, the
exec function can be used, followed by the name of the script. This file generally has the
extension.sce or .sci, depending on its content:
Files having the .sci extension contain Scilab functions and executing themloads the
functions into Scilab environment (but does not execute them)
Files having the .sce extension contain both Scilab functions and
executablestatements.
Executing a .scefile has generally an effect such as computing several variables and
displaying the results in the console, creating 2D plots, reading or writing into a file, etc.
196
Program – 1
Fast Fourier Transform
Date:
Program:
clear all;
clc ;
close ;
//Inverse FFT
x_inv = real (fft(X ,1) )
disp(X,'The DFT of the input is X=');
INPUT:
Enter the input sequence:x=[1 2 3 4 4 3 2 1]
OUTPUT:
The input sequence is x= 1. 2. 3. 4. 4. 3. 2. 1.
The DFT of the input is X= 20. - 5.8284271 - 2.4142136i 0 - 0.1715729 - 0.4142136i
0 - 0.1715729 + 0.4142136i 0 - 5.8284271 + 2.4142136i
The inverse DFT is x= 1. 2. 3. 4. 4. 3. 2. 1.
The inverse is 1. 2. 3. 4. 4. 3. 2. 1.
Result: The DFT of a sequence using Fast Fourier Transform is computed
197
Program – 2
Implementation of I/D sampling rate converters
Date:
Program
clc;
clear all;
close;
t=0:0.05:1;
x=sin(10*t);
I=input('Enter the Interpolation factor:');
D=input('Enter the Decimation factor:');
scf(0);
plot2d3(x);
xlabel("$0\le t\le 1$","fontsize",4,"color","red");
ylabel("$x(t)={sin(10t)}$","fontsize",4,"color","red");
title("Input signal","color","red","fontsize",4);
y=intdec(x,I/D);
scf(1);
plot2d3(y);
xlabel("$0\le t\le 1$","fontsize",4,"color","red");
ylabel("$y(t)={x(2t/3)}$","fontsize",4,"color","red");
title("I/D sampled signal","color","red","fontsize",4);
INPUT:
Enter the Interpolation factor:2
Enter the Decimation factor:3
PLOTS:
INPUT SIGNAL
198
I/D SAMPLE RATE CONVERSION OUTPUT
199
Waveforms/Graphs:
200
Program – 3
Impulse response of first order and second order systems
Date:
Aim: To Calculate Unit Impulse Response (Unit Sample) of the givenLTI system.
Requirements: Personal Computer with SCILAB 5.5.2 software
Program:
// Continuous time System
clc;
close;
clear all;
s=%s; // first create a variable
num=36;
den=36+3*s+s^2;
//create a scilab continuous system LTI object
TF=syslin('c',num,den);
//TF = 36/ (36 + 3s + s^2);
ty=typeof(TF);// type of object is rational
t=linspace(0,5,500);
imp_res=csim('imp',t,TF);
plot(t,imp_res);
xgrid();
xtitle('Impulse response','time','response');
201
// Discrete time System
clc;
clear all;
close;
//Given 2nd order system
//y(n)=(3/8)y(n-1)+(2/3)y(n-2)+x(n)+(1/4)x(n-1)
OUTPUT:
h(n)=
1.
0.625
0.9010417
0.7545573
0.8836534
0.8344082
0.9020054
0.8945242
0.9367835
0.9476432
202
Waveforms/Graphs:
Result:Henceimpulse response of second order continuous and discrete time LTI systems are
found and plotted.
203
Program – 4
Implementation of LP/HP IIR filter
Date:
Aim: To design
i)Butterworth Lowpass IIR filter
ii)Chebyshev-I Highpass IIR filter
204
205
Waveforms/Graphs:
Result:HenceLP/HP digital IIR filters are designed and frequency response is plotted.
206
Program – 5
Date:
Program:
figure ;
207
row_f =3;
colum_f =3;
case 0
row_f =4;
colum_f =2;
else
row_f =4;
colum_f =1;
end
208