0% found this document useful (0 votes)
29 views43 pages

Scilab 6.0.1 Lab Manual for DSP

The document is a lab manual for the Basic Simulation Lab at Vignana Bharathi Institute of Technology, focusing on Scilab 6.0.1 for scientific computing and signal processing. It covers the user interface, basic matrix operations, generation of various signals, and operations on signals including addition, multiplication, and scaling. The manual includes programming examples and graphical outputs for various signal processing tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views43 pages

Scilab 6.0.1 Lab Manual for DSP

The document is a lab manual for the Basic Simulation Lab at Vignana Bharathi Institute of Technology, focusing on Scilab 6.0.1 for scientific computing and signal processing. It covers the user interface, basic matrix operations, generation of various signals, and operations on signals including addition, multiplication, and scaling. The manual includes programming examples and graphical outputs for various signal processing tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

INTRODUCTION TO SCILAB 6.0.1

Scilab Overview

Scilab is a programming language associated with a rich collection of numerical


algorithms covering many aspects of scientific computing problems. Scilab is an
interpreted language. The Scilab language can dynamically compile and link other
languages such as Fortran and C: this way, external libraries can be used as if they
were a part of Scilab built-in features. Scilab also interfaces LabVIEW, a platform
and development environment for a visual programming language from National
Instruments.

The following is a short list of capabilities of Scilab :

• Linear algebra, sparse matrices,


• Polynomials and rational functions,
• Interpolation, approximation,
• Linear, quadratic and non linear optimization,
• Ordinary Differential Equation solver and Differential Algebraic Equations
solver,
• Classic and robust control, Linear Matrix Inequality optimization,
• Differentiable and non-differentiable optimization,
• Signal processing,
• Statistics.

We will focus on signal processing in the present laboratory session to accomplish


the Digital Signal Processing (DSP) experiments prescribed in the syllabus.

Introduction to the User Interface (UI)

The use of user interface icons to manage your work can help you become more
productive with Scilab. You can use Scilab predefined functions to perform the
equivalent of most of the features found in the UI icons. The following illustration
shows the default configuration of the Scilab UI. You can modify the appearance
in a way that pleases you. The user interface is on display in the next page.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Arranging the Console UI

These are some common ways to customize the User Interface (UI):
 Resize any particular browser (File Browser, Variable Browser, Command
History or the News feed) by dragging one of its edges.
 Dock or undock a tool outside of the UI by clicking the undock button in the
tool's title bar.
 Customize the UI by clicking the Scilab Preferences icon in the console
menu bar. The Scilab Preferences icon is located third from right of the
menu bar. Use the tool tip displayed as you move your mouse over the menu
bar to figure out the icon.

Scilab Demonstration icon

The Scilab Demonstration icon provides easy access to tools, demos, shortcuts.
Click the Scilab Demonstration icon to see the options.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Console Window and Command History

Console Window

Use the Command Window to enter variables and to run Scilab functions and
scripts. Scilab echoes the results. To avoid the echoing terminate the
command/function by semi-colon (;).
The results of last performed operation are by default stored in variable called ans.

Press the up arrow key ↑ to recall a statement you previously typed. Edit the
statement as needed, and then press Enter to run it. To get help about various
functions and toolboxes of Scilab use the “help” command. The syntax is provided
here: help <command>. This will result in popping up of help browser with
suitable documentation help.

Command History

Statements you enter in the console Window are logged with a timestamp in the
Command History. From the Command History, you can view and search for
previously run statements, as well as copy and execute selected statements. You
can also create a file from selected [Link] save the input and output from a
Scilab session to a file, use the diary function.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Getting Help

The various ways of finding help are discussed here. Click the help browser icon to
see the help browser pop. The icon is found on extreme right of the menu bar
showing question mark symbol (?). The help browser would look this:

The help browser is divided into two parts. The left half the help browser has two
icons at the top. The two icons are the table of contents icon and the search icon.
To the left half of the help browser window you have various nodes corresponding
to various capabilities of scilab. Expand the necessary node and look for
corresponding topic. Else you can click on search icon of the browser window and
give appropriate search string. By doing so you can see that the help browser
window will show the corresponding command/function and the suitable
navigation in the table of contents.

Variable Browser

The Scilab UI consists of variables browser. The variable browser houses variables
defined during a Scilab session and stored in memory. You add variables to the
variable browsers by using functions, running function and script files. The view of
the browser when undocked would look this way. It displays variable name, type
of variable and memory occupied in system.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

To delete variables from the variable browser, select the variables, and then right
click on the variable and choose delete <variable name>. Alternatively, use clear
function in console window.

Using the Folder Browser to Manage Files

The Current Folder browser is a key tool for managing files. Open the Folder
where your pieces of code are placed click the ‘select a directory’ icon in file
browser. Then a pop box would appear which would help you choose the folder.
The screen shot of the pop box that would appear is on display in the next page.
The necessary commands are explained as and when required.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

[Link] Operation on Matrices

Aim: To perform basic operation on matrices

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Pre-requisites: Basic understanding of matrix operation.
Theory: Basic operation of matrix is calculated. Predefined functions are discussed
below. Functions discussed here will not be discussed to avoid redundancy.
Inbuilt functions used in this piece of code
Clc Clear the console window
Clear Clear variables in variable browser
Close Close all graphic windows if open.
Disp Display variables

Program:
clc;
clear;
close;
A = [1 2 3 4 5 6 7 8 9];
disp('Elements of Matrix A');
disp(A);
disp('Transpose of A is :');
disp(A');
B = A(:,$:-1:1);
disp('Flipping Elements of A');
disp(B);
C = eye(3,3);
disp('Defining a Identity Matrix of 3 by 3');
disp(C)
D = [3 4 5;1 6 5;2 5 9];
disp('Elements of Matrix D');
disp(D);
E = inv(D);
disp('Inverse of Matrix D');
disp(E);
disp('Determinant of Matrix of D');
Prepared by [Link] Shekar
Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

F = det(D);
disp(F);
disp('Accessing only first Two rows of Matrix D');
disp(D(1:2,1:$));
disp('Accessing only first two Columns of Matrix D');
disp(D(:,1:2));
a = [1 2;3 4];
b = [3 4;1 2];
disp('Product Matrix');
c = a*b;
disp(c);
e = a./b;
disp('Elements wise division');
disp(e);
disp('Eelment wise division of a/b');
f = a.\b;
disp(f);

Result: The basic operations on matrices are performed.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

[Link] Of Various Signals and Sequences, such as Unit Impulse, Unit


step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc

Aim: To generate various Signals and Sequences, such as unit impulse, unit step,
Square, Saw tooth, Triangular, Sinusoidal, Ramp and Sinc.
Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Pre-requisites: Mathematical relations of various signals.
Inbuilt functions used in this piece of code
Subplot Used for partitioning the given graph
Plot Interpolated version of the curve is plotted using this function
Plot2d3 Plain graph is plotted.
Xtitle Used to set the labels and titles for the graph
Gca Returns object of axis used to set axis properties.
Squarewave Used to generate square signal of period 2*π

Program:
clc;
clear;
close;
t = 0:0.1:10;
x1 = 1;
y1 = x1.*(t>=0);
subplot(5,1,1);
plot(t,y1);xgrid(color("green"));
//plot2d3(t,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Unit Step Signal','t Axis','U(t)')
y2 = t;
subplot(5,1,2);
plot(t,y2);xgrid(color("green"));
//plot2d3(t,y2);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Ramp Signal','t Axis','R(t)');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(5,1,3);
plot(t,cos(t));xgrid(color("green"));
//plot2d3(t,cos(t));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Cos Signal','t Axis','Cos(t)')

t2 = -10:0.1:10;
y4 = zeros(1,length(t2));
for k = 1:1:(length(t2)-1)
y4(k) = (sin(t2(k))/t2(k));
end;
subplot(5,1,4);
plot(t2,y4);xgrid(color("green"));
//plot2d3(t2,y4);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sinc Curve','t Axis','Sinc(t)')

t = -10:1:10;
y5 = x1.*(t==0);
subplot(5,1,5);
//plot(t,y5);xgrid(color("green"));
plot2d3(t,y5);xgrid(color("green"));

Graph

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

clc;
clear;
close;
t = (0:0.001:10*%pi);
subplot(3,1,1);
plot((7*t/44),squarewave(t,50));xgrid(color("green"));
//plot2d3((7*t/44),squarewave(t,50));xgrid(color("green"));
a = gca();a = gca();a.x_location = "origin";a.y_location = "origin";a.data_bounds =
[0,-2;5,2];
xtitle('Square Signal','t Time','Amplitue');
t = -1:0.001:1;
n = 1:1:length(t);
y = [1,zeros(1,length(t)-1)]
for n = 1:length(t)
if t(n)<=0
y(n) = 1 + t(n);
end
if t(n)>=0
y(n) = 1 - t(n);
end
end
subplot(3,1,2);
plot(t,y);xgrid(color("green"));
//plot2d3(t,y);xgrid(color("green"));
a = gca();a.x_location = "origin"; a.y_location="origin";
xtitle('Triangular Signal','t Time','Amplitue' );
t = -5:0.001:5;
y = t - floor(t);
subplot(3,1,3);
plot(t,y);xgrid(color("green"));
//plot2d3(t,y);xgrid(color("green"));
a = gca();a.x_location = "origin"; a.y_location="origin";
xtitle('Sawtooth Signal','t Time','Amplitude');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Graph:

Result: Generation various signals is accomplished and graph plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

3. Operation on Signals and Sequences such as Addition, Multiplication,


Scaling, Shifting, Folding, Computation of Energy and Power

Aim: To perform basic operation of Addition, Multiplication, Scaling, Shifting,


Folding on Signals and Computation of Energy and Power of Signals.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Pre-requisites: Understanding of basic operation of Addition, Multiplication,
Scaling, Shifting, Folding of signals and their mathematical relations. Basic
formulae for calculating energy and power of signals.

Program:
clc;
clear;
close;
t = 0:0.1:10;
y1 = ones(1,length(t));
subplot(5,1,1)
plot(t,y1);xgrid(color("gray"));
//plot2d3(t,y1);xgrid(color("gray"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Unit Step Signal','t Axis','U(t)')

y2= ones(1,length(t));
subplot(5,1,2);
plot(t,y2);xgrid(color("green"));
//plot2d3(t,y2);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Unit Step Signal','t Axis','U(t)');

y3 = y1 + y2;
subplot(5,1,3);
plot(t,y3);xgrid(color("green"));
//plot2d3(t,y3);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sum Of Signals','t Axis','y1 + y2');

y4 = t;

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

y5 = y4.*y1;
subplot(5,1,4);
plot(t,y5);xgrid(color("green"));
//plot2d3(t,y5);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Multiplication Of Signals','T Axis','Ramp signal');

a = 0.5;
t1 = (1/a)*t;
subplot(5,1,5);
plot(t1,y1);xgrid(color("green"));
//plot2d3(t1,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Scaling Of Signal','t1 Time','Amplitude');

Graph

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

clc;
clear;
close;
t = 0:0.1:10;
y1 = ones(1,length(t));
subplot(4,1,1)
plot(t,y1);xgrid(color("gray"));
//plot2d3(t,y1);xgrid(color("gray"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Unit Step Signal','t Axis','U(t)')
t1 = t + 1
subplot(4,1,2);
plot(t1,y1);xgrid(color("green"));
//plot2d3(t1,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Delayed Version','T Time Axis','U(t-1)');
t2 = t - 1;
subplot(4,1,3);
plot(t2,y1);xgrid(color("green"));
//plot2d3(t2,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Advanced Version','T Time Axis','U(t-1)');
tp = t(:,$:-1:1);
tp = -1*tp;
y1 = y1(:,$:-1:1);
subplot(4,1,4);
plot(tp,y1);xgrid(color("green"));
//plot2d3(tp,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Folding Operation','t Time','Amplitude');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Graph

clc;
clear;
close;
n = 0:1:5;
x = [0 1 2 3 4 5];
plot2d3(n,x);xgrid(color("green"));
xtitle('Input Signal','n Time','Amplitude');
En=0;
for l = 1:length(x)
En = En + x(l)*conj(x(l));
end
disp('The energy of the signal is = ');
disp(En);
disp('The power of the signal is = ');
disp(En/length(x));

Result: Basic operations on Signals are performed and the average energy and
power of a signal are calculated.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

4. Finding the Even and Odd Parts of Signal/Sequence and Real and
Imaginary Parts of Signal

Aim: To decompose the given signal into even and odd parts, real and imaginary
parts.
Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Pre-Requisites: Basic understanding of even and odd signals.

Theory: Any signal can be decomposed into even and odd parts. Let us consider a
signal x(t) which we can decompose as x e(t) and xo(t), denoting even and odd part
of the signal. So

x(t)= xe(t) + xo(t).

The relations for even and odd parts are given below

xe(t) = 0.5*{ x(t) + x(-t)}


xo(t) = 0.5*{ x(t) - x(-t)}
Program

clc;
clear;
close;
x = [0 1 2 3 4 5 6 7 8 9 10];
xn = [zeros(1,length(x)-1),x];
n = -(length(x)-1):1:length(x)-1;
subplot(4,1,1);
//plot2d3(n,xn);xgrid(color("green"));
plot(n,xn);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Input Signal','n Time','Amplitude');
xnf = xn(:,$:-1:1);
subplot(4,1,2);
//plot2d3(n,xnf);xgrid(color("green"));
plot(n,xnf);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Folded Signal','n Time','Amplitude');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

xe = 0.5*(xn + xnf);
subplot(4,1,3);
//plot2d3(n,xe);xgrid(color("green"));
plot(n,xe);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Even Part','n Time','Amplitude');
xo = 0.5*(xn - xnf);
subplot(4,1,4);
//plot2d3(n,xo);xgrid(color("green"));
plot(n,xo);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Odd Part','n Time','Amplitude');

Graph

clc;
clear;
close;
x = [0 1 2 3 4 5 6 7 8 9 10];
n = 0:1:length(x)-1;
subplot(3,1,1);
Prepared by [Link] Shekar
Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

//plot2d3(n,x);xgrid(color("green"));
plot(n,x);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Input Signal','n Time','Amplitude');
xn = hilbert(x);
xr = real(xn);
subplot(3,1,2);
//plot2d3(n,xr);xgrid(color("green"));
plot(n,xr);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Real Part of Signal','n Time','Aplitude');
xi = imag(xn);
subplot(3,1,3);
//plot2d3(n,xi);xgrid(color("green"));
plot(n,xi);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Imaginary Part','n Time','Amplitude');

Graph

Result: Given signal is decomposed to even and odd parts, real and imaginary
parts.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

5. Convolution of Signals and Sequences

Aim: To find the convolution of two signals.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Theory: The time domain relation between input x(n), impulse response h(n) and
output y(n), is given by convolution. The convolution relation can only be applied
to linear time invariant (LTI) systems only. The relation is provided below.

y(n) = ∑x(k)h(n-k) k varying from –infinity to +infinity


or
y(n) = ∑x(n-k)h(k) k varying from –infinity to +infinity

Inbuilt functions used in this piece of code


Convol Used to find convolution between signal and impulse response

Program
clc;
clear;
close;
x = [1 1 1 1 1 1 1 1 1 1 1];
h = [1 1 1 1 1 1 1 1 1 1 1];
n1 = 0:1:(length(x)-1);
n2 = 0:1:(length(h)-1);
n3 = 0:1:(length(x)+length(h)-2);
subplot(3,1,1);
plot(n1,x);xgrid(color("green"));
//plot2d3(n1,x);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Input Squence','n Axis','x(n)');
subplot(3,1,2);
plot(n2,h);xgrid(color("green"));
//plot2d3(n2,h);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle("Impulse Respone",'n Axis','h(n)');
y = convol(x,h);
subplot(3,1,3);
Prepared by [Link] Shekar
Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

plot(n3,y);xgrid(color("green"));
//plot2d3(n3,y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Convolution Output','n Axis', 'y Axis');

Graph

Result: The convolution between signal and impulse response is calculated and
plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

6. Auto Correlation and Cross Correlation for Signals and Sequences

Aim: To find auto correlation and cross correlation for signals and sequences.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Theory: The similarity between two signals is given by correlation expression. If
the measure of similarity is between same signals then it is auto correlation and if it
is between two different signals it is called cross correlation. The mathematical
relation is given below.

y(k) = ∑x(n)h(n+k) n varying from –∞ to +∞


or
y(k) = ∑x(n+k)h(n) n varying from –∞ to +∞

Inbuilt functions used in this piece of code


Xcorr Used in calculation of cross correlation between signals.

Program:
clc;
clear;
close;
x = [1 1 1 1 1 1 1 1 1 1 1];
h = [1 1 1 1 1 1 1 1 1 1 1];
xc = [1 2 3 4 5 6 7 8 9 10 11]
n1 = 0:1:(length(x)-1);
n2 = 0:1:(length(h)-1);
n3 = 0:1:(length(x)+length(h)-2);
subplot(4,1,1)
//plot2d3("gnn",n1,x);xgrid(color("green"));
plot(n1,x);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Input Squence','n Axis','x(n)');
subplot(4,1,2);
//plot2d3(n2,h);xgrid(color("green"));
plot(n2,h);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
Prepared by [Link] Shekar
Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

xtitle("Impulse Respone",'n Axis','h(n)');


y = xcorr(x,h);
subplot(4,1,3)
//plot2d3(n3,y);xgrid(color("green"));
plot(n3,y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Auto Correlation','n Axis', 'y Axis');
y = xcorr(x,xc);
subplot(4,1,4)
//plot2d3(n3,y);xgrid(color("green"));
plot(n3,y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Cross Correlation','n Axis', 'y Axis');

Graph

Result: The auto correlation and cross correlation between two signals is
calculated and corresponding graph plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

7. Verification of Linearity and Time Invariance Properties of a Given System

Aim: To verify if the given system is linear and time invariant (LTI)

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Theory: For a system to be linear it should be additive and homogeneous. For a
system to time invariant the output produced by shift in input should be similar to
shift in the output alone.
Program:
//Program for linearity check.
clc;
clear;
close;
h=[1 1 1 1 1 1 1 1 1 1];
x=[1 1 1 1 1 1 1 1 1 1];
y = convol(x,h);
n = 0:1:(length(x)+length(h)-2);
x1 = [1 1 1 1 1 1 1 1 1 1];
x1 = 2*x1;
y1 = convol(x1,h);
y1e = y1-2*y;
if (y1e == 0) then
disp('System is Homogeneous');
else
disp('System is Non Homogeneous');
end
x2 = x + x;
y2 = convol(x2,h);
y2e = y2 - (y+y);
if (y2e == 0) then
disp('System is Additive');
else
disp('System is Non Additive');
end

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

if ((y1e == 0) && (y2e == 0)) then


disp('System is Linear');
else
disp('System is Non Linear');
end

Check for Time invariance


clc;
clear;
close;
x = [1 2 3 5 6 7 8 9 10];
h = [1 2 1 3 5 6 2 4 5];
n = 0:1:length(x)+length(h)-2;
y = convol(x,h);
subplot(2,1,1);
plot(n,y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Usual Signal','t Time','Amplitude');
x1 = [0 x];
n1 = 0:1:length(x1)+length(h)-2;
y1 = convol(x1,h);
subplot(2,1,2)
plot(n1,y1);xgrid(color("green"));
a=gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Delayed Signal Output','t Time','Amplitude');

Result: The linearity and time invariance check for a given system is performed.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

[Link] of Unit Sample, Unit step and Sinusoidal response of the given
LTI system and verifying its physical realiazability and stability properties

Aim: To find the unit sample, unit step and sinusoidal response of a given system,
and check if the given system is physically realizable, stable.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite: Through understanding of basic convolution relation between


signal and impulse response of the system.

Inbuilt functions used in this piece of code


Csim Used for calculation of response of system to various inputs.

Program
clc;
clear;
close;
t = 0:0.01:10;
s = %s;
num = 1;
den = s+1;
tf = syslin('c',num,den);
I1 = sin(t);
y1 = csim("impulse",t,tf);
y2 = csim("step",t,tf);
y3 = csim(I1,t,tf);
subplot(4,1,1)
plot(t,y1);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Impulse Response of the System','t Time','Amplitued');
subplot(4,1,2);
plot(t,y2);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Step Response of the System','t Time','Amplitued');
Prepared by [Link] Shekar
Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(4,1,3);
plot(t,y3);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location="origin";
xtitle('Sinusoidal Response of the System','t Time','Amplitued');
subplot(4,1,4);
plzr(tf);

Graph

Result: The response of the system to various signals is plotted. Stability of the
system can be predicted from the location of ploes and zeros. Since the systems are
causal they are realizable.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

9. Gibbs Phenomenon Simulation

Aim: To observe the Gibbs Phenomenon

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite : Through understanding of the principle of Fourier series is must


for performing the experiment. Here we consider an odd square signal of period
four units. The Fourier series is given below.

F(t) = (4/)*∑ (1/n)*sin(n*π*t/(T/2)) n takes values 1,3,5,7…….


Program:
clc;
clear;
close;
t = 0:(1/10):(8*%pi);
x = sin(t);
xfs = 0;
for k = 1:2:80
xfs = xfs + (4/%pi)*(1/k)*sin(k*%pi*t/2);
end
plot(t,xfs);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
a.data_bounds = [0,-2;30,2];
xtitle('Gibbs Phenomenon','t Time','Amplitude');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Graph

Result: The Gibbs phenomenon is observed in the given graph.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

10. Finding the Fourier Transform of a given signal and plotting its
magnitude and phase spectrum

Aim: To find the Fourier Transform of a given signal and plotting its magnitude
and phase spectrum

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite: Through understanding of Fourier Transform and plotting


magnitude and phase spectrum.

Inbuilt functions used in this piece of code


Fft Used to find the Fourier Transform of the given signal.
Abs Used to find the magnitude of the given signal.
Atan Used to find the phase associated with given coefficient.

Program
clc;
clear;
close;
sample_rate=8000;
N = 1024;
t = (0:N-1)*1/(sample_rate);
s=sin(2*%pi*100*t);
subplot(3,1,1);
plot(t,s);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sine Signal','t Axis','sin(t)');
y=fft(s);
f=sample_rate*(0:(N-1))/N;
n=size(f,'*')

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(3,1,2);
plot(f,abs(y(1:n)));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Magnitude Spectrum','f Frequency','|y| Magnitude')
subplot(3,1,3);
plot(f,(180/%pi)*atan(real(y(1:n)),imag(y(1:n))));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Phase Spectrum','f Frequency','<y Phase Angle');

Graph

Result: The Fourier Transform of given signal is calculated and its magnitude and
phase spectrum plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

11. Waveform Synthesis using Laplace Transform

Aim: To synthesis time domain waveform of signal, given its Laplace Transform

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite: Through understanding of Laplace Transform and its inverses.

Program
clc;
clear;
close;
t = 0:0.01:10;
s = %s;
num = 1;
den1 = s;
tf1 = syslin('c',num,den1);
y1 = csim('impulse',t,tf1);
subplot(3,1,1);
plot(t,y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Unit Step Signal', 't Time','Amplitude');
den2 = s^2 + 1;
tf2 = syslin('c',num,den2);
y2 = csim('impulse',t,tf2);
subplot(3,1,2)
plot(t,y2);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sinusoidal Signal', 't Time','Amplitude');
y3 = csim('step',t,tf1);

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(3,1,3);
plot(t,y3);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Ramp Signal', 't Time','Amplitude');

Graph

Result: The various waveforms are synthesized using Laplace Transform.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

12. Locating the Zeros and Poles and Plotting the Pole-Zero Maps in S-Plane
and Z-Plane for the given transfer function.

Aim: To plot pole-zero plot of given function in Laplace and Z domains.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Theory: The point where the given function turns to zero is zero of the function. A
point where the function turns to infinity is called pole. The zero value could be
found by equation the numerator to zero. The pole is found by equating the
denominator to zero.

Inbuilt functions used in this piece of code


Plzr Used to plot the pole-zero plot for the given transfer function.

Program

clc;
clear;
close;
s = %s;
z = %z;
num = 1 + s;
den = (s+2)*(s+3);
p = syslin('c',num,den);
pd = syslin('d',1,z-0.5);
disp(pd);
subplot(2,1,1);
plzr(p);
a = gca();a.x_location = "origin";a.y_location = "origin";

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(2,1,2);
plzr(pd);
a = gca();a.x_location = "origin";a.y_location = "origin";

Graph

Result: The pole-zero plot of a given transfer is plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

13. Generation of Gaussian noise, Computation of its mean, Mean Square,


Skew, Kurtosis and PSD Probability Distribution Function

Aim: To generate Gaussian noise and measure its statistical parameters and its
PSD and Probability Distribution Function

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.
Pre-Requisite : Through understanding of concepts of Random Variables and
mathematical relations for the calculations of statistical parameters.

Inbuilt functions used in this piece of code


Rand Used for generation of random numbers
Histplot Used for plotting the histogram for the data
Mean Used for calculating the mean
Variance Used for calculating the variance.

Program
clc;
clear;
close;
rand('normal');
x = rand(1,1000);
y = 10*x + 5;
subplot(2,1,1);
histplot(20,y);;xgrid(color("green"));
a=gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Histogram','x Axis','y Gaussian Density Function');
disp(mean(y));
z = variance(y);
disp('The standard deviation is : ')
disp(z^0.5);
l = mean(y)*ones(1,length(x));
m = (y - l).^3;
sk = mean(m)

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

disp('The value of skew is : ');


disp(sk);
n = (y-l).^4;
kur = mean(n);
disp('The Kurtosis is :');
disp(kur);
acy = xcorr(y);
ffacy = fft(acy);
subplot(2,1,2);
plot(abs(ffacy));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('PSD Of Gaussian Noise','','');

Graph

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Program
clc;
clear;
close;
mu = 0;sigma = 1.0;
x = [-5:0.1:5];
y = exp(-x.^2 /2) ./ sqrt(2.*%pi);
subplot(2,1,1);
plot(x,y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Gaussian Density Function','x','f(x)');
F = zeros(1,length(x));
for i = 1:length(x)
F(i) = cdfnor('PQ',x(i),mu,sigma);
end
subplot(2,1,2)
plot(x,F);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Distribution Funciton','x','F(x)')

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

Graph

Result: Gaussian statistical parameters are calculated and its density and
distribution function found and its graph plotted.

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

14. Verification of Sampling Theorem

Aim: To verify the sampling theorem.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite: Through understanding of Sampling Theorem. It iterates that the


signal sampled at rate twice the highest frequency of the signal can be used for
faithful reconstruction of the signal itself.

Program
//Sampling Theorem Program
clc;
clear;
close;

t = 0:0.01:10;
x = 4*sin(2*%pi*1*t);
subplot(4,1,1)
plot(t,x);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Simple Signal','T Axis','Sinusoidal Signal');

//Under Sampling The Signal


fs1 = 1.6*1;
ts1 = 1/fs1;
n1 = 0:ts1:10;
x1 = 4*sin(2*%pi*1*n1);
subplot(4,1,2)
plot2d3(n1,x1);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Under Sampled','T Axis','x1 Signal');

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

//Nyquist Sampling The Signal


fs2 = 2*1;
ts2 = 1/fs2;
n2 = 0:ts2:10;
x2 = 4*sin(2*%pi*1*n2);
subplot(4,1,3)
plot2d3(n2,x2);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Critical Sampling','T Time Axis','x2 Signal');
//Over Sampling The Signal
fs3 = 4*1;
ts3 = 1/fs3;
n3 = 0:ts3:10;
x3 = 4*sin(2*%pi*1*n3);
subplot(4,1,4)
plot2d(n3,x3);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Over Sampling','T Time Axis','x2 Signal');

Graph

Result: The Sampling Theorem is verified

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

15. Verification of Weiner-Khinchine Relation

Aim: To Verify Weiner-Khinchine Relation.

Software: Scilab 6.0.1 and system loaded with Linux flavor of Ubuntu 16.04 LTS.

Pre-Requisite: Through understanding of Random Process and mathematical


relation of Weiner-Khinchine

Program
clc;
clear;
close;
sample_rate=1000;
N = 1024;
t = (0:N-1)*1/(sample_rate);
s=sin(2*%pi*50*t) + sin(2*%pi*100*t);
subplot(3,1,1);
plot(t,s);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sine Signal','t Axis','sin(t)');
//Generating 1024 equally spaced points between 0 and 1000;
//Distance between the points is (1000/1024)
f=sample_rate*(0:(N-1))/N;
n=size(f,'*')
y=fft(s);
subplot(3,1,2);
plot(f,abs(y(1:n)));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Magnitude Spectrum','f Frequency','|y| Magnitude');
scorr = xcorr(s,s);
maxData = max(scorr);
[i,j] = find(scorr==maxData);
scorr = scorr(j:$);
fscorr = fft(scorr);

Prepared by [Link] Shekar


Vignana Bharathi Institute of Technology Basic Simulation Lab Manual

subplot(3,1,3);
plot2d(f,(abs(fscorr).^2));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Magnitude Spectrum','f Frequenc','|y| Magnitude');

Graph

Result: The Weiner-Khinchine Relation is verified.

Prepared by [Link] Shekar

Common questions

Powered by AI

Scilab facilitates learning and experimentation with DSP concepts through its extensive suite of functions and tools for signal generation, analysis, and transformation. Features such as demos, help browser, and robust mathematical libraries allow students and practitioners to simulate and analyze real-world DSP scenarios tailored to educational curriculums. This hands-on approach helps users grasp complex theories by visualizing and manipulating signals directly within the Scilab environment .

The Command History feature in Scilab logs all statements entered in the Console window, along with timestamps. Users can search, view, copy, execute, or save past commands, which enhances task management by providing easy access to previous work, minimizing the need to retype lengthy commands and facilitating continuity in computational tasks .

Scilab's integration with LabVIEW, a visual programming platform, enhances its utility by allowing it to leverage LabVIEW's graphical capabilities for designing complex control and data acquisition systems. This integration benefits users by combining Scilab's computational power with LabVIEW's graphical interface, making it easier to visualize and implement data-driven applications in industries requiring robust testing and measurement solutions .

Scilab's User Interface (UI) can be improved in productivity through customization options such as resizing browsers, docking or undocking tools, and changing preferences via the Scilab Preferences icon. These adjustments allow users to tailor the interface to their workflow needs, reduce unnecessary interface elements, and focus on their tasks more efficiently .

Scilab handles the computation and visualization of the Fourier Transform using functions like 'fft' to calculate the transform and 'abs' for magnitude. These transformations are plotted for both magnitude and phase spectra. This approach allows users to analyze frequency components of signals graphically, offering insights into the signal properties and behaviors, which is critical for signal analysis and processing .

The primary mathematical operations and functionalities highlighted in Scilab for scientific computing include linear algebra, interpolation, optimization (linear, quadratic, and non-linear), ordinary differential equation solving, control systems, and signal processing. These features support complex computational tasks by providing a breadth of built-in algorithms that can be directly applied to various scientific problems .

Verifying linearity and time invariance properties in a system is crucial because these properties determine the predictability and stability of system responses to inputs. A linear, time-invariant (LTI) system operates under the principles of superposition and time consistency, which are essential for designing reliable control systems. Scilab facilitates this verification through simulations that demonstrate how systems respond to variances in input, which is important for both theoretical understanding and practical implementation of signal processing tasks .

The Variable Browser in Scilab is significant as it displays variables created during a session and the memory they occupy, providing a snapshot of current data points in use. Users can effectively manage variables by adding, viewing, or deleting them directly through the browser, aiding in organizing and optimizing memory usage, thus allowing streamlined manipulation of data sets .

Scilab's demonstration feature provides users with easy access to a collection of demos, tools, and shortcuts. By clicking the Scilab Demonstration icon, new users can explore a variety of examples that showcase different functionalities and capabilities of Scilab, which serve as a practical introduction to the software and help users learn how to implement Scilab features in real projects .

Scilab allows for dynamic compilation and linking with other languages such as Fortran and C, enabling the use of external libraries as if they were built-in features. This capability allows for expanded functionality and integration with existing codebases, making Scilab a powerful tool in scientific computing by leveraging established algorithms and systems from other languages .

You might also like