Sei sulla pagina 1di 17

SIGNAL PROCESSING

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.

Getting startedwith Scilab


We can start using Scilab by clicking the icon shown below on the desktop

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.

Signal Processing using Scilab


Scilab provides tools to visualize, analyze and filter signals in time and frequency domains:
 Signal generation
 Data windowing
 Power spectral density estimation
 Digital IIR and FIR filter design
 Analog filter design
 Signal transforms including fftw

196
Program – 1
Fast Fourier Transform
Date:

Aim:To Compute the DFT of a sequence using Fast Fourier Transform.


Requirements: Personal Computer with SCILAB5.5.2 software

Program:
clear all;
clc ;
close ;

//Taking the input sequence from the user


x = input('Enter the input sequence:x=') ;
X = fft (x , -1)
disp(x,' The input sequence is x=');

//Inverse FFT
x_inv = real (fft(X ,1) )
disp(X,'The DFT of the input is X=');

//Alternate Inverse FFT


disp(x_inv,'The inverse DFT is x=');
k=fft(X,1);
disp(k,'the inverse is ');

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:

Aim: To implement sampling rate conversion by a rational factor on a given sequence.

Requirements: Personal Computer with SCILAB 5.5.2 software

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:

Result:Henceimplementation of sampling rate conversion by a rational factor on a given


sequence is performed

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)

z=%z; // first create a variable


a=((z^2)+(1/4)*z);
b=(z^(2)-(3/8)*z-(2/3))
h = ldiv (a ,b ,10) ;
disp (h ,"h(n)=") ;
plot2d3(h);
xtitle('Impulse response','n-->','response');

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

Requirements: Personal Computer with SCILAB 5.5.2 software


Program:

// Low pass filter


clc;
clear all;
close;
fp=input('Enter the cutoff frequency in Hz fp=');
n=input('Enter the order of the filter n=');
F=input('Enter sampling frequency in Hz F=');
wc=fp/F;
hz=iir(n,'lp','butt',[wc 0],[0 0]);// for Butterworth design LP
//hz=iir(n,'hp','butt',[wc 0],[0 0]);// for Butterworth design HP
//hz=iir(n,'lp','cheb1',[wc 0],[.08 .03]); // for Chebyshev-1 design
//hz=iir(n,'lp','cheb2',[wc 0],[.08 .03]); // for Chebyshev-2 design
[hzm,fr]=frmag(hz,256);
plot2d(fr',hzm');
a=gca();
a.x_label.text="Frequency";
a.y_label.text="Magnitude";
xtitle('Discrete IIR filter low pass');
z=poly(0,'z'); //to express the result in terms of the delay operator q=z^-1
hzd=horner(hz,1/z); // delay operator q=z^1
disp(hzd,'The transfer function is');
INPUT:
Enter the cutoff frequency in Hz --fp=400Hz
Enter the order of the filter --n=10
Enter sampling frequency in Hz --F=5000Hz
OUTPUT:

204
205
Waveforms/Graphs:

Result:HenceLP/HP digital IIR filters are designed and frequency response is plotted.

206
Program – 5

Generation of DTMF signals

Date:

Aim: To generate DTMF signal tones.

Requirements: Personal Computer with SCILAB 5.5.2 software

Program:

row_f1 =[697 770 852 941]; // Row F r e q u e n c y


colum_f1 =[1209 1336 1477]; // Column F r e q u e n c y
fs =8192; // Sampling F r e q u e n c y
N =1:4000; // T o t al No . of Sample
mobile =[9 8 4 9 4 0 7 9 6 5];
temp =[]; // A r ray t h a t Co n tai n t o t a l s i g n a l f o r ea c h D i g i t

figure ;

for i =1: length ( mobile )


select mobile (i )
case 1
row_f =1;
colum_f =1;
case 2
row_f =1;
colum_f =2;
case 3
row_f =1;
colum_f =3;
case 4
row_f =2;
colum_f =1;
case 5
row_f =2;
colum_f =2;
case 6
row_f =2;
colum_f =3;
case 7
row_f =3;
colum_f =1;
case 8
row_f =3;
colum_f =2;
case 9

207
row_f =3;
colum_f =3;
case 0
row_f =4;
colum_f =2;
else
row_f =4;
colum_f =1;
end

y = sin (2*3.14*( row_f1 ( row_f )/ fs ) * N) +sin (2*3.14*(colum_f1 ( colum_f ) / fs ) * N) ;

temp =[temp y zeros(1 ,4000)];


end
sound ( temp , fs ) ;

Result: DTMF signal tones are generated.

208

Potrebbero piacerti anche