You are on page 1of 44

J D COLLEGE OF ENGINEERING & MANAGEMENT

An Autonomous Institute, Affiliated to DBATU, Lonere


At: Khandala, Post- Valni, Kalmeshwar Road, Near Fetri, Nagpur
Department of Electronics & Telecommunication Engineering

Course Name: Software Workshop Lab


Course Code : ET5L006
Sem /Branch : 5th Sem B.Tech in

ETC
Subject Teacher
Mr. Amol Dhankar
Vision and Mission of Department
VISION Assistant Professor, ETC
To be a Department providing high quality & globally competent knowledge of concurrent technologies in the field of
Electronics and Telecommunication.
MISSION
1. To provide quality teaching learning process through well developed educational environment and dedicated faculties.
2. To produce competent technocrats of high standards satisfying the needs of all stakeholders.
List of Experiments:
SCILAB
1 Introduction to SCILAB Environment
2 To study simple matrix and array manipulations using SCILAB
3 Programming using SCILAB
4 Calculus using SCILAB
5 To plot signals: discrete and continuous using SCILAB
6 Function programming and SCILAB
7 Signal Manipulation using SCILAB

Spice
1 Design and simulation of resistive circuit
2 Plotting of VI characteristics of diode
3 Plotting of VI characteristics of BJT/FET
4 Plotting of VI characteristics of UJT/SCR
5 Design and simulation of half wave & full wave rectifier
6 Design and simulation of clipper and clamper circuits
7 Simulation of frequency response of a transistorized RC coupled amplifier
Experiment No: 1 Introduction to SCILAB Environment

What is SCILAB?

(1) SCILAB is a freely distributed and open source scientific


software package.
(2) A powerful open computing environment for Engineering and
Scientific applications.
(3) Developed since 1990 by researchers from INRIA 2 (Institut
Nationale de Recherche en Informatique et en Automatique) and
ENPC (National School of Bridges and Roads).
(4) Now maintained and developed by Scilab consortium since
2003.
(5) Integrated into Digiteo foundation in July 2008.
(6) The current version is 6.1.1 (July 2021).
(7) Since 1994 it is distributed freely along with source code
through the Internet. (www.scilab.org )
8) Scilab users can develop their own module so that they can solve
their particular problems.
9) The Scilab language allows to 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.
10) Scilab also interfaces LabVIEW, a platform and development
environment for a visual programming language from National
Instruments.
Scilab’s Main Features:
1. A high-level programming language
2. Scilab is an interpreted language
3. Integarated object-oriented 2-D and 3-D graphics with animation
A dedicated Editor
4. An XML-based help system
5. Interface with symbolic computing packages (Maple and
MuPAD 3.0)
6. An interface with Tcl/Tk
7. Scilab works with most Unix systems including GNU/Linux and
on Windows (9X/NT/2000/XP/Vista/7), and Mac operating system.

Scilab coded Toolboxes


1. Linear algebra and Sparse matrices
2. Polynomials and Rational functions
3. 2-D and 3-D graphics with animation
4. Interpolation and Approximations
5. Linear, Quadratic and Nonlinear Optimization ODE solver and
DAE solver
6. Classical and Robust Control, LMI Optimization 8.
Differentiable and Non-differential Optimization
7. Signal Processing
8. Statistic
9. Scicos: A hybrid dynamic system modeler and simulator
10. Parallel Scialab using PVM
11. Metanet: Graphs and Networks
Typical uses
1. Educational Institutes, Research centers and companies
2. Math and computation
3. Algorithm development
4. Modeling, simulation, and visualization
5. Scientific and engineering graphics, exported to various
formats so that can be included into documents.
6. Application development, including GUI building
Desktop tool and development environment
Set of tools and facilities
Graphical UI : Scilab Console, Sciab editor, Scilab help bowser,
MATLAB to Scilab Translator
Mathematics Function Library
Collection of computational algorithm : sum, sine, matrix functions
Language
High-level matrix/array language with flow, functions, structure
Graphics
Extensive facilities for displaying vectors and matrices as graphs
High-level functions for 2-D and 3-D data visualization
External Interfaces
Allows to write C and Fortran programs that interact with SCILAB

Getting Started with Scilab


Stating the Scilab program
> Start the Scilab program by double-clicking Scilab-6.1.1 icon on
the desktop
> Start button on the desktop >Programs>Scilab -6.1.1>Scilab -6.1.1
Automatically loading Tools for managing files, variables and
applications
Quitting the Scilab program
> To end SCILAB, File > quit in the scilab console
> Type ‘quit’ in the Scilab Console
Scilab Default Console
Scilab Help Browser
Arithmetic Operations:
+ addition
-subtraction
* multiplication
/ right division i.e. X/Y = XY-1
\ left division i.e. X\Y = X-1Y
^ power i.e. XY
** power (same as ^)
' transpose conjugate
Scilab as a Calculator
-->6+5 ans = 11.
-->4+5/3+2 ans = 7.6666667
-->7+8/2 ans = 11.
-->5^3/2 ans = 62.5
(0.785)^7/(1*2*3*4*5*6*7) ans = 0.0000364
COND…
Any line which begins with two slashes "//" is considered by
Scilab as a comment and is ignored.
More than one command can be entered on the same line by
separating the commands by semicolon (;) or a comma (,).
Experiment No: 2 To study simple matrix and array manipulations
using SCILAB
Predefined Variables:
Certain variables are predefined and write-protected
Some useful Scilab Commands
Some useful Scilab Commands ........... contd
Some useful Scilab Commands ........... contd
Creating Arrays (Vectors and Matrices)

-->a=[1 2 3 4 5 6 7 8 9 10]Create a row vector a =


1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
-->a=[1,2,3,4,5,6,7,8,9,10] Another way of creating a row vector a =
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
-->a=[1;2;3;4;5;6;7;8;9;10] Create a column vector
a = 1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Vectors and matrices ……contd.
Matrix Addressing:

-->A=[3 11 6 5;4 7 10 2;13 9 0 8]


A =
3. 11. 6. 5.
4. 7. 10. 2.
13. 9. 0. 8.
-->A(2,3)
ans

=
10.
--
>A(:,
2)
ans

=
11.
Matrix Addressing:

-->A(2,:)
ans =

4. 7. 10.
2.

-->A(9)
ans =

0.

-->A(1:2,1:2)
ans =
3. 11.
4. 7.
Vectors and matrices ……contd.
-->B=A(3:-1:1,1:4)
B =
13. 9. 0.
8.
4. 7.
10. 2.
3. 11. 6.
5.
-->B=A(3:-1:1,1:4)
B =
13. 9. 0.
8.
4. 7.
10. 2.
4. 7. 10.
3. 11. 6.
13. 9. 5. 0.
-->A(1:3,4)=[]
A =
3.
Vectors and matrices ……contd.
-->eye(2,2)
ans =
1.
0.
0.

1.
-->ones(2,3)
ans =
1. 1.
1.
1. 1.
1.
-->zeros(3,3)
ans =
0. 0.
0.
0. 0.
3. 4. 0. 5.
0. 0. 6.
0.
-->A=[1 2;3
4]; B=[2 3; 5
Vectors and matrices ……contd.
-->A=rand(2,3)
A =
0.8497452 0.8782165 0.5608486
0.6857310 0.0683740 0.6623569

-->A=[1 2 3; 4 5 6;7 8 9];


-->B=diag(A)
B =
1.
5.
9.
-->C=diag(A,1)
C =
2.
6.
-->D=diag(A,-1)
D=
4.
THANK YOU
Experiment No: 3- Programming using SCILAB
SCILAB Programming, IO, and strings
Programming is the basic skill for implementing numerical
methods.
In this session I will describe the fundamental programming
constructs used in SCILAB and present examples of their
applications to some elementary numerical methods.
The second part of this session is dedicated at exploring
input/output functions provided by SCILAB including operations
with files.
Finally, manipulation of strings in SCILAB is presented.
SCILAB programming constructs
SCILAB provides the user with a number of programming
constructs very similar to those available in FORTRAN and other
high-level languages.
We present some of the constructs below:
Comparison and Logical Operators
SCILAB comparison operators are
== equal to
< less than
> greater than
<= less than or equal to
<> >= greater than or equal to
or ~= not equal to
SCILAB logical operators are
& And

| Or

~ Not

As an example, try the following commands in SCILAB:


3 < > 2 <enter> (2<1) | (3>1) <enter>
3 = = 3 <enter> (2<1) | (3>5) <enter>
(2>1)&(3>1) <enter> ~(2<1) <enter>
(2>1)&(3>5) <enter> ~(2>1) <enter>
(2<1)&(3>1) <enter> ~(2>1) | (3>5) <enter>
(2<1)&(3>5) <enter>
(2>1) | (3>1) <enter>
(2>1) | (3>5) <enter>
Loops in SCILAB
SCILAB includes For and While loops.
The For loop is similar to the DO loop in FORTRAN or the
FOR..NEXT loop in Visual Basic.
The basic construct for the For loop is:
for index = starting_value : increment : end_value, …
statements…, end for index = starting_value : end_value, …
statements…, end
If no increment is included it is supposed to be
equal to 1.
 For example, enter the following For loops in
SCILAB:
r = 1; for k = 1:0.5:4, r = r+k, end <enter>
xs = -1.0; dx = 0.25; n = 10; for j = 1:n, x = xs +
(j-1)*dx, end <enter>
for m = 1:10, a(m) = m^2, end <enter>
for j = 1:10, disp(j), if j>5 then break, end, end
<enter>
The basic construct for the While loop is:
while condition, …statements…, end
For example, try the following while loop:
s = 100; while s>50, disp(s^2), s = s - 5, end <enter>
For and while loops can be terminated with the command break,
for example, try the following:
for j = 1:10, disp(j), if j>5 then break, end, end <enter>
Conditional constructs in SCILAB
In the example above we used an if… then…end construct.
There are two type of conditional constructs in SCILAB, one is
the if-then-else-end construct (as in the example above) and the
second one is the select-case conditional construct.
Different forms of the if-then-else construct are:
if condition then statement, end
if condition then statement, else statement, end
if condition then statement, elseif condition then statement, else
statement, end
Try the following examples:
x = 10; y = 5; if x> 5 then disp(y), end <enter>
x = 3 ; y = 5; if x>5 then disp(y), else disp(x), end <enter>
x = 3; y = 5; z = 4; if x>5 then disp(x), elseif x>6 then disp(y), else
disp(z), end <enter>
The general form of the select-case construct is:
select variable, case n1, statement, case n2,
statement, …, end
Try the following examples:
x = -1; select x, case 1, y = x+5, case -1, y = sqrt(x),
end <enter>
r = 7; select r, case 1, disp( r), case 2, disp(r^2), case
7, disp(r^3), end <enter>
Functions in SCILAB
Functions are procedures that may take input
arguments and return zero, one or more values.
Functions are defined either on line, using the deff
command, or as a separate file that needs to be
Following some examples of functions are presented:
deff('[z]=Euler(r,theta)','z=r*exp(%i*theta)')
<enter> Euler(1.0,-%pi/2) <enter>

deff('[r,theta]=cartpol(x,y)',['r=sqrt(x^2+y^2)';
'theta=atan(y,x)']) <enter> [radius,angle] = cartpol(3., 4.)
<enter>
Global and local variables
A global variable is one define in the main SCILAB environment,
while a local variable is one defined within a function.
If a variable in a function is not defined, or is not among the input
parameters, then it takes the value of a variable of the same name
that exist in the calling environment.
This variable remains local in the sense that modifying it within
the function does not alter its value in the calling environment
unless the command resume is used.
For example, using the function sphercart, try the following:
function [x, y, z]=sphecart(r, theta,
rho) x = r*cos(rho); y =
r*cos(rho)*sin(theta); z = r*sin(rho);
endfunction

To execute the function write in


console
sphecart(3,45,1)
ans =
1.6209069
--> [x,y,z] = sphecart(3,45,1)
x =
1.6209069
y =
1.3792354
z =
2.5244130
Experiment No: 4- To Plot Graph Using Scilab
Script for a simple plot
A simple 2D plot of a sine function
with the abscissa x = 0 ... 10,
and amplitude A = increases with x
The function itself is y(x)

x = [0:.1:10]; // Let x is a row vector


A = 0.5*x; // Modulated amplitude, row vector
y = A.*sin(2*x); // Element-by-element multiplication
plot(y) // Plot command

Multiplication by the Dot Operator (.*) is necessary to tell Scilab


it should multiply the vectors element-by-element.
Change to ordinary multiplication (*) and you’ll get this error
message on the Console.
1. Plotting 2D Graphs
x= linspace(1,10,5)
y=linspace(1,20,5)
plot(x,y)
xset('window',1) // To open empty plot window
plot2d(x,y,style=3)
title("My Plot")
xlabel("x")
ylabel("y")
xtitle("My Plot","x axis","y axis")
2. Exponential Plot
x=linspace(1,10,50)
y1=x.^2
plot(x,y1, "o-")
y2=2*x.^2
plot(x,y2,"+-")
xtitle("My plot","x axis","y axis")
legend("x^2","2*x^2")

3. Subplots
plot2d()
subplot(2,2,1)
plot2d()
subplot(2,2,2)
plot2d()
subplot(2,2,3)
plot2d()
subplot(2,2,4) plot2d()
4. Saving Plots
x=linspace(-3*%pi,3*%pi,100)
plot(x,sin(x))
save fig()
save fig(sine.png)

Exercise :
Qus: Draw two plots for given form
1) First plot is a parabola of the form Y = 4x2
2) Second plot is a straight line of the form Y = 2x+3 in the range -5
to 5.
3) Use legend to indicate each plot.
x=linspace(-5,5,10)
plot(x,4*(x^2))
plot(x,(2*x+3))
legend("y=4*(x^2)","y=2*x+3")
Plot the Bode plot for the function

Program:
clc,clf;
w = logspace(-1,3,100); // Define log scale for w
s = %i*w; // Define imaginary s
G = 100../((s-10).*(s-90)); // Define G(s)
y = 20*log10(abs(G)); // Define dB scale for y
plot2d(w,y,5,logflag='ln') // Plot y=f(w)
xtitle("Bode plot for G(s)=100/((s-10)(s-90))","w,...
log scale","y, dB scale")
xgrid() // Add grid
where s = iω and the angular frequency ω = 0.1 … 1000.
Note double dots 100../(s-10) in the G command. First dot is a
decimal point, then comes the Dot Operator.
Put the logarithmic ω-axis horizontally and the decibel scale
y=20log(|G(ωi)|) vertically.
Polar Plot :
Polar coordinates are used frequently in some areas of
engineering, e.g. to present antenna lobe diagrams.
Plotting in polar coordinates is done by the command polarplot().

Program:
clc,clf;
x = 0:0.07:2*%pi;
polarplot(x,1-cos(x),style=[-3]) // r = 1 - cos(x), for x = 0...2pi /
legend('y = 1-cos(x)',4)

The program shows the simple script for,


y = 1-cos(x), and its plot
Note the markers related to the style= [-3] argument .

You might also like