You are on page 1of 4

EXPERIMENT 1: Basic Functions Using Scilab

Date : 8/1/2019
AIM:
To plot basic functions in scilab simulator : Sin, Cos, Tan, Unit Impulse, Unit Ramp,Unit Step,
Square Wave, Sawtooth wave, Triangular Wave.

THEORY:
Basic functions are plotted using either in-built function or by hardcoding algorithms.

FLOWCHART/ALGORITHM:
Note – Sin, Cos, Tan functions were plotted directly using the in-built functions of the scilab

Unit Step : The value on y-axis for (x >= 0) is set to 1 and 0 for (x < 0).
Unit Impulse : The value on y-axis is set to 1 for (x = 0) ; else set to 0.
Unit Ramp : for (x < 0) y = 0 ; else y = x
Square wave : Alternative sets of time periods (length 1 sec each), value of y axis were to set to
either 1 or 0 depending on the value of the variable “flag”
Sawtooth wave : for each set of time period (length 1 sec each), y = x was plotted.

PROGRAM:
t = -10 : 0.1 : 10; // domain
y1 = sin(t); //sin function
y2 = cos(t); //cos function
y3 = tan(t); //tan function
subplot(3,3,1)
plot(t,y1)
xlabel('time')
ylabel('sin')
subplot(3,3,2)
plot(t,y2)
xlabel('time')
ylabel('cos')
subplot(3,3,3)
plot(t,y3)
xlabel('time')
ylabel('tan')

//Unit Impulse
y4 = zeros(1,length(t));
for i = 1 : 1 : length(t)
if(t(i) == 0)
y4(i) = 1;
end
end
subplot(3,3,4)
plot(t,y4)
xlabel('time')

EC206 - Principle of Communication, Electronics engineering Department, SVNIT, Surat- Page 1


ylabel('impulse')

//Unit Step

y5 = zeros(1,length(t));
for i = 1 : 1 : length(t)
if(t(i) >= 0)
y5(i) = 1;
end
end
subplot(3,3,5)
plot(t,y5)
xlabel('time')
ylabel('unit step')

//Unit Ramp Function

y6 = zeros(1,length(t));
for i = 1 : 1 : length(t)
if(t(i) >= 0)
y6(i) = (i-100)/10;
end
end
subplot(3,3,6)
plot(t,y6)
xlabel('time')
ylabel('unit ramp')

// Square Wave

y7 = zeros(1,length(t));
flag = 1;
for i = 1 : 10 : length(t)
if(i < 201)

if(flag == 1)
for j = i : 1 : i+10
y7(j) = 1;
flag = 0;
end
else
for j = i : 1 : i+10
y7(j) = 0;
flag = 1;
end
end
end
end
subplot(3,3,7)
plot(t,y7)
xlabel('time')
ylabel('square')

// Saw-tooth wave

EC206 - Principle of Communication, Electronics engineering Department, SVNIT, Surat- Page 2


y8 = zeros(1,length(t));
for i = 1 : 10 : length(t)
if(i<length(t))
x1 = t(i);
for j = i : 1 : i+10
y8(j) = t(j) - x1;
end
end
end
subplot(3,3,8)
plot(t,y8)
xlabel('time')
ylabel('Saw-tooth')

// Triangular wave

y9 = zeros(1,length(t));
for i = 1 : 10 : length(t)
if(i<length(t))
x2 = t(i);
for j = i : 1 : i+5
y9(j) = 2 * t(j - (x2*10));
y9(j+5) = -y9(j);
end
end
end
subplot(3,3,9)
plot(t,y9)
xlabel('time')
ylabel('Triangular')

EC206 - Principle of Communication, Electronics engineering Department, SVNIT, Surat- Page 3


RESULT:

CONCLUSION: Basic Functions were successfully plotted.

EC206 - Principle of Communication, Electronics engineering Department, SVNIT, Surat- Page 4