Scilab 2 PDF
Scilab 2 PDF
on Open Source Software, PSG Tech, June 22nd,2007 – July 6th,2007
for
Digital Signal Processing
S Subathra
Project Engineer, NRCFOSS
AUKBC Research Centre
MIT Campus of Anna University
Chennai – 600 044
subathra@aukbc.org
Plan for Presentation
Tutorial Session
Signal Processing with Scilab 45mins (Tutor)
Lab Session
Installation Demo 10mins (Tutor)
Installation of Scilab 15mins (Participants)
Scilab Buildin Demo 50mins (Participants)
Handson Practise 60mins (Participants)
Free software
Numerical programming
Rapid Prototyping
Extensive libraries and toolboxes
Easy for matrix manipulation
Free software
Numerical programming
Ideal for Signal Processing
Rapid Prototyping
Extensive libraries and toolboxes
Easy for matrix manipulation
To create a vector and store it in a variable
>b=[1 2 3 5 1];
To extract the element 1 to 3 of the above vector
>b(1:3)
[1 2 3]
For multiplying transpose of matrix ‘a’ with itself
>a’*a
For elementwise multiplication and addition
>c=a.*b
>c=a.+b
dimensional plots 0.8
0.7
To generates a random
0.6
0.5
vector of length 10 and plots 0.4
the points with straight line 0.3
joining each points 0.2
0.1
0.0
>y=rand(1,10);
1 2 3 4 5 6 7 8 9 10
>plot(y); Fig. 1 Plot Function Sample 1
‘y’ – yellow 0.8
‘c’ – cyan 0.7
‘g’ – green 0.6
‘w’ – white 0.5
‘m’ – magenta 0.4
‘r’ – red 0.3
‘b’ – blue 0.2
‘k’ – black 0.1
0.0
1 2 3 4 5 6 7 8 9 10
>y=rand(1,10);
>plot(y,’r’); Fig. 2 Plot Function Sample 2
point 0.6
‘^’ – uses upward triangles at each 0.5
point
‘o’ – uses circle at each point
0.4
‘+’ – uses cross at each point 0.3
‘v’ – uses inverted triangle at each 0.2
point 0.1
0.0
>y=rand(1,10);
1 2 3 4 5 6 7 8 9 10
>plot(y,’r’);
Fig. 3 Plot Function Sample 3
This command takes three parameters as input, first two
parameters specifies the grid size, i.e. how many rows and
columns and the third parameter specifies the position of the plot
in the grid.
For e.g.,
subplot(3,2,2)
tells scilab that the figure window is divided as three rows, two
columns and the plot has to be placed in the second column of the
first row.
x1=rand(1,10);
0.7
0.7
0.6 0.6
0.4 0.4
plot(x1); 0.3
0.3
0.2
x2=rand(1,20);
0.2 0.1
0.1 0.0
1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20
subplot(2,2,2);
plot(x2); 0.9 1.0
0.8 0.9
x3=rand(1,15); 0.7
0.8
0.7
subplot(2,2,3);
0.6 0.6
0.5 0.5
subplot(2,2,4);
0.1 0.0
0 2 4 6 8 10 12 14 16 0 5 10 15 20 25
plot(x4);
Fig. 4 Plot Function Sample 4
To mark label, the function 1.0
‘gca’ returns the handle for 0.9
the current axes 0.8
0.7
0.6
t=1:1:50
amplitude
0.5
0.4
y=rand(1,50); 0.3
plot(t,y); 0.2
0.1
a=gca(); 0.0
0 5 10 15 20 25 30 35 40 45 50
a.x_label.text=“time”;
time
a.y_label.text=“amplitude”; Fig. 5 Plot Function Sample 5
Mesh plot can be
generated using plot3d
command.
1
Z
0
m=rand(5,7);
2
3 1
i=1:1:5;
4 2
5 3
Y
6 4
j=1:1:7;
X
7 5
plot3d(i,j,m);
Fig. 6 Plot Function Sample 6
t=0:0.01:3.14; 1.0
0.8
y=sin(2*3.14*t); 0.6
0.4
subplot(2,1,1); 0.2
Amplitude
a=gca(); 0.0
0.2
a.x_label.text="Time"; 0.4
a.y_label.text="Amplitude";
0.6
0.8
plot2d(t,y); 1.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
xtitle("Sine Wave Generation"); Time
Cosine Wave Generation
1.0
0.8
//cos wave 0.6
t=0:0.01:3.14;
0.4
0.2
y=cos(2*3.14*t);
Amplitude
0.0
0.2
subplot(2,1,2); 0.4
a=gca(); 0.6
0.8
a.x_label.text="Time"; 1.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
a.y_label.text="Amplitude"; Time
plot2d(t,y);
xtitle("Cosine Wave Generation"); Fig. 7 Signal generation
For proper sampling of analog signal Nyquist
Shannon sampling theorem should be satisfied, i.e.
sampling frequency should be a greater than twice
the maximum frequency of the input signal.
ft=input('Sampling frequency in hz='); 1.0
0.8
t=0:0.01:1; 0.6
T=1.0/ft;
0.4
0.2
x=sin(2*3.14*fo*t);
Amplitude
0.0
0.2
subplot(2,1,1); 0.4
a=gca();
0.6
0.8
a.x_label.text="Time"; 1.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
a.y_label.text="Amplitude"; Time
Sampled Signal
plot(t,x); 1.0
0.8
xtitle("Continuous signal"); 0.6
0.4
0.2
n=0:ft;
Amplitude
0.0
0.2
y=sin(2*3.14*fo*n*T); 0.4
subplot(2,1,2); 0.6
0.8
a=gca(); 1.0
0 5 10 15 20 25 30 35 40 45 50
a.x_label.text="Time"; Time
a.y_label.text="Amplitude";
plot2d3(n,y); Fig. 8 Sampling
xtitle("Sampled Signal");
The LTI system can be defined using the impulse response of the
system.
Convolution of the input signal and impulse response of the system
gives the output signal. This process is also called digital filtering.
Mathematically,
If both the input signals are one and the same, then it is called as auto
correlation
If both the input signals are different, then it is called as cross correlation
Correlation is used to measure the similarity between the two input signals at
that particular time.
Mathematically,
DFT decomposes the input signal into set of sinusoids
In DFT, we take a sequence of real numbers(sampled signal)
as input and it is transformed into a sequence of complex
numbers.
Mathematically,
Filter Used to remove the unwanted signal from the
useful signal.
For eg, removing noise from audio signal
Two types – Analog & Digital filters
Analog filters uses inductors, capacitors to produce
the required effects
Digital filter uses modern processors for doing the
same
Digital filters are classified as non recursive
filters(FIR) and recursive filters(IIR)
FIR Filter – the output will be dependent on the
current & previous input values
IIR Filter – dependent on previous output in
addition to the input values
Hz fp='); 1.2
n=input('Enter the order of the filter 1.0
n=');
F=input('Enter sampling frequency in Hz 0.8
F=');
Magnitude
wc=fp/F; 0.6
[coeffval,famp,ffreq]=wfir('lp',n,[wc 0], 0.4
'hm', [0 0]);
//frequency response of the filter 0.2
plot2d(ffreq,famp);
0.0
a=gca(); 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
Frequency
a.x_label.text="Frequency";
a.y_label.text="Magnitude";
xtitle("FIR low pass filter"); Fig. 9 FIR LPF
1.0
n=input('Enter the order of the filter
n=');
0.9
F=input('Enter sampling frequency in Hz
0.8
F=');
0.7
wc=fp/F;
0.6
Magnitude
0.5
[coeffval,famp,ffreq]=wfir('hp',n,[wc 0],
'hm', [0 0]);
0.4
0.3
//frequency response of the filter
0.2
plot2d(ffreq,famp); 0.1
a=gca(); 0.0
a.x_label.text="Frequency";
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
Frequency
a.y_label.text="Magnitude";
xtitle("FIR high pass filter"); Fig. 10 FIR HPF
fp='); 1.2
n=input('Enter the order of the filter n=');
F=input('Enter sampling frequency in Hz 1.0
F=');
wc=fp/F;
0.8
hz=iir(3,'lp','butt',[wc 0],[0 0]);
Magnitude
0.6
[hzm,fr]=frmag(hz,256);
plot2d(fr',hzm'); 0.4
a=gca();
a.x_label.text="Frequency"; 0.2
a.y_label.text="Magnitude";
xtitle('Discrete IIR filter low pass');
0.0
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
q=poly(0,'q'); //to express the result in terms of
Frequency
the ...
hzd=horner(hz,1/q) // delay operator q=z^1
Fig. 11 IIR LPF
n=input('Enter the order of the filter n=');
1.0
F=input('Enter sampling frequency in Hz
F='); 0.8
wc=fp/F
hz=iir(3,'hp','butt',[wc 0],[0 0]);
Magnitude
0.6
[hzm,fr]=frmag(hz,256);
plot2d(fr',hzm'); 0.4
a=gca();
a.x_label.text="Frequency";
0.2
a.y_label.text="Magnitude"; 0.0
xtitle('Discrete IIR filter high pass'); 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
Frequency
q=poly(0,'q'); //to express the result in terms of
the ...
hzd=horner(hz,1/q) // delay operator q=z^1
Fig. 12 IIR HPF
[2] Sanjit K. Mitra, “Digital Signal Processing a computer based approach” – Second edition.
[3] Scilab Documentation, Available at www.scilab.org
Scilab demonstration
http://www.scilab.org/doc/demos_html/index.html
Matlab and Scilab functions
http://www.scilab.org/product/dicmatsci/M2SCI_doc.htm
Signal Processing Information Base (SPIB)
http://spib.rice.edu/spib.html
DSP Online Classes
http://bores.com/index_dsp.htm
http://bores.com/index_online.htm