SS Manual Students
SS Manual Students
B. Tech.
SEM. IV (EC)
1. Introduction to Scilab 04
2. Signal Generation 22
3. Operation on Signals 26
7. Convolution 45
10. Z - transform 53
Department of Electronics & Communication, Faculty of Technology, Dharmsinh Desai University, Nadiad 2
EXPERIMENT – 1
INTRODUCTION TO SCILAB
SCILAB is one of the two major open-source alternatives to MATLAB, the other one being
GNU Octave. SCILAB is similar enough to MATLAB, however it puts less emphasis on
syntactic compatibility (bidirectional) with MATLAB than Octave does. Due to the open
source nature of the software, some user contributions have been integrated into the main
program.
a) Scilab Basic:
Start the Scilab program by double-clicking Scilab- (version based on availability) icon on the
desktop or Start button on the desktop >Programs>Scilab-(version based on availability).
SCILAB will automatically load Tools for managing files, variables and applications.
To end SCILAB, File > quit in the Scilab console or Type the command ‘quit’ at the prompt
the
i Scilab Console.
Help Features:
To open SCILAB help, click help icon (?) in the toolbar or type help at the command
prompt help command (help inv, help sum) (This is useful when the name of the function is
already Known). To obtain a list of Scilab functions corresponding to a keyword, the
command aproposfollowed by the keyword should be used. apropos eigenvalues<Enter>.
Description
diary(filename)function creates a log of keyboard input and the resulting text output.
+ Addition
- Subtraction
* Multiplication
/ Right Division (i.e. X / Y = X*Y-1)
\ Left Division (i.e. X \ Y =X-1*Y)
^ Power
** Power (same as ^)
‘ Transpose Conjugate
SCILAB as a Calculator:
--> x=8,y=4,z=10
x=
8.
y=
4.
z=
10.
a=
12.
b=
32.
--> c = x/y , d = x\y // note the answer in c and d to understand right and left
division c =
2.
d=
0.5
e=
100.
f =
100
In SCILAB, any line which ends with two dots is the start of a newcontinuation line.Any line
which begins with two slashes "//" is considered as comment and is ignored.More than one
command can be entered on the same line by separating the commands by semicolon (;) or
a comma (,).
In SCILAB, everything is a matrix. All real, complex, Boolean, integer, string, and polynomial
variables are matrices. It is an interpreted language, which implies that there is no need to
declare a variable before using it. Variables are created at the moment where they are first
set. In SCILAB “=“sign is called assignment operator.Variablenames may be as long as user
wants but only first 24 characters are taken into account. SCILAB is case sensitive – (i.e. - A
is not equal to a).
Predefined Variables:
%i 1 imaginary unit
%pi pi greek
%e Exponential of 1
%e precision (machine dependent)
ps
%in Infinity
f
%n NotANumber
an
%s s polynomial variable
%z zpolynomial variable
%t true Boolean variable
%f false Boolean variable
--> %i
%i =
--> %pi
%pi =
3.1415927
--> %e
%e =
2.7182818
-->exp(1)
ans =
2.7182818
--> %eps
%eps =
2.220D-16
--> %inf
%inf =
Inf
--> %nan
%nan =
Nan
--> %s
%s =
--> %f
ans =
General commands:
Clock: Provide clock time and date as a vector [year month day hour minute seconds]
--> clock
ans =
date
ans =
05-Dec-2019
-->ver
ans =
--> a = [1 2 3 6 8]
a=
1. 2. 3. 6. 8.
--> b= [6,4,2,9,7] // Another way of creating a row
vector b =
6. 4. 2. 9. 7.
c = [2;5;3;8;4]
c=
2.
5.
3.
8.
4.
one d =
1. 2. 3. 4. 5. 6.
--> f = 1:1:6
f=
1. 2. 3. 4. 5. 6.
--> g = 1:2:6
g=
1. 3. 5.
too h =
10. 8. 6. 4. 2. 0.
k = [2+3*%i, 4+1*%i, 3, 5, 6] //vector with complex
numbers k =
2. + 3.i 4. + i 3. 5. 6.
add =
7. 6. 5. 15. 15.
mul2 =
130.
l=
0. 2.6666667 5.3333333 8.
--> a =[ 1 4 6 3 10]
a=
1. 4. 6. 3. 10.
-->a(1:3)
ans =
1. 4. 6.
-->a(2)
ans =
4.
-->a(5:-1:1)
ans
10. 3. 6. 4. 1.
--> b =sum(a) //sum of all
elements b =
24.
elements c =
4.8
d=
5.
vector f =
10.
vector g =
720.
--> h = sign (a) //Returns 1 if the sign of an element is the vector is +ve, 0 if element
// is negative
h=
1. 1. 1. 1. 1.
q=
--> a =fix(q) //Rounds the elements of the vector q to the nearest integer
towards zero
a=
2. 3. -4. 7. -2.
--> b = floor(q) //
b=
2. 3. -5. 7. -3.
--> c = ceil(q)
c=
3. 4. -4. 8. -2.
--> d =round(q)
d=
3. 3. -5. 8. -2.
order e =
Entering a Matrix:
// use ; to terminate a
row
A
=
1 3 2 13.
6. . .
5. 1 11 8.
0 .
.
9. 6 7. 12.
.
4. 1 14 1.
5 .
.
B=
136.
34.
34.
34.
34.
D=
Matrix Addressing:
A
=
3 1 6 5
. 1 . .
.
4 7 1 2
. . 0 .
.
1 9 0 8
3 . . .
.
-->A(2,3)
ans =
10.
-->A(:,2)
ans =
11.
7.
9.
-->A(2,:)
ans =
4. 7. 10. 2.
-->A(9)
ans =
0.
-->A(1:2,1:2)
ans =
3. 11.
4. 7.
-->B=A(3:-1:1,1:4)
B
=
1 9 0 8
3 . . .
.
4 7 1 2
. . 0 .
.
3 1 6 5
. 1 . .
.
--
>A(1:3,4)=[]
A
=
3 1 6
. 1 .
.
4 7 1
. . 0
.
1 9 0
3 . .
.
-->eye(2,2)
ans =
1. 0.
0. 1.
-->ones(2,3)
a =
n
s
1 1 1
. . .
1 1 1
. . .
-->zeros(3,3)
ans =
0. 0. 0.
0. 0. 0.
0. 0. 0.
-->C=[A,B]
C=
1 2 2 3.
. . .
3 4 5 6.
. . .
-->A=rand(2,3)
A=
-->B=diag(A)
B=
1.
5.
9.
-->C=diag(A,1)
C=
2.
6.
-->D=diag(A,-1)
D=
4.
8.
-->det(A)
ans =
4.
-->rank(A)
ans =
2.
-->trace(A)
ans =
5.
-->B=inv(A)
B=
1. -0.5
0. 0.25
-->norm(A)
ans =
4.495358
-->C=A'
C=
1. 0.
2. 4.
Polynomials
--> x= poly(0,"x")
x=
p=
-1 -4x +2x3
If v is a vector,
● poly(v,"x",["roots"]) is the polynomial with roots the entries of v and "x" as
formal variable. (In this case, roots and poly are inverse functions).
--> p2 = poly([ 2 3],'x','roots')
p2 =
6 -5x +x2
● poly(v,"x","coeff") creates the polynomial with symbol "x" and with coefficients the
entries of v (v(1) is the constant term of the polynomial). (Here poly and coeff are
inverse functions).
--> p3 = poly(1:4,'x','coeff')
p3 =
1 +2x +3x2 +4x3
--> a = roots(p3) // to find roots of polynomial
p3 a =
-0.0720852 + 0.6383267i
-0.0720852 - 0.6383267i
-0.6058296
--> b = coeff(p3) // to find coefficient of polynomial
p3 b =
1. 2. 3. 4.
ASSIGNMENT 1:
ph5i +1 1.6180340
= √
2 --> 1/phi
ans:- ans =
phi=(sqrt(5)+1)/2
phi = 0.6180340
--> psi=(sqrt(5)-1)/2
psi =
0.6180340
--> 1/psi
ans =
1.6180340
--> psi=(sqrt(5)-1)/2
psi =
0.6180340
--> 1/psi
ans =
1.6180340
(2) (3) 4 256
(4) 2560:25 (5) tan(45) (6) tan-1(1)
(7) Define two vectors A,B with 1,5,8,19 and 19,8,5,1 elements respectively.
(8) In SCILAB, enter thVerify Euler's identity: Is eπi+ 1 close to zero?e following Matrices:
1
⎡ ⎤
⎢ 2 59
1 1 4 ⎥
A=⎢ ⎥ B = [ 5 2]C = [ ]
44
⎢3 4⎥ ⎣5 6⎦
⎢1 1⎥
1 23
Using SCILAB commands, compute each of the following, if possible and explain the
errors, ifany.
(a) A* C*C *A (b) 2 *C - 6 *A (c) (2 * C - 6 *A’) *B’ (d) (2 *C - 6 *A’) *C’
(9) Define a 3x3 matrix A with all elements equal to 1. Multiply 1st and 2nd row
with scalars, 3and 4 respectively, and determine the determinant of the resultant
matrix.
(10) Represent the following linear system as a matrix equation. Solve the system using
the inversemethod:
x + y + 2z - w = 3
2x + 5y – z - 9w = -3
2x + y - z + 3w = -11
x - 3y + 2z + 7w = -5
(11) Construct a polynomial with 3 repeated roots at 4 and 2 repeated roots at 0.Check the
roots of the derivative of this polynomial.
(12) Construct the polynomial with b = [1 4 5 2] as the coefficients. Determine the value of
polynomial as well as derivative of the polynomial at [ 3 5].
When several commands are to be executed, it may be more convenient to write these
statements into a file with Scilab editor instead of writing at Scilab Console. These are called
SCRIPT files. These file generally have the extension ":sce" or ":sci",depending on its
content. To execute the commands written in such a script file, the "exec" function can be
used, followed by the name of the script file or click on Save and Execute available under
Execute Tab or press F5.
Bothe ":sce" or ":sci" files may contain Scilab functions and/or User defined functions and
executing both type of files loads the functions into Scilab environment but":sce" files
containing functions are executed but ":sci" files containing functions are not executed.
Please note that if any variable is to be “watched” or monitored inside a function, then “disp”
is required.
Sample Program:
Create a Scilab Script file to display sum and product of two given matrix A and B.
// filename as s1.sce
A=[24;59]
B=[31;65]
s=A+B
dis
p(s
)
m=
A*
B
dis
p(
m
)
mprintf('sum = \n')
mprintf('\t%d %d\n',s)
mprintf('product = \n')
mprintf('\t%d %d\n',m)
Program Output:
5. 5.
11. 14.
30. 22.
69. 50.
sum =
55
11 14
product =
30 22
69 50
Functions are segments of codethat have well defined input andoutput as well as local
variables. The simplest way to define afunction is by using the command ‘function’ and
‘endfunction’
function<lhs_arguments>=<function_name><rhs_arguments>
<statements>
endfunction
Sample Program:
Create a Function file to calculate sum and product of two given matrix A and B.
//filename as s2.sce
function[x, y]=ddu(A, B)
x=A+B
y=A*B
endfunction
NOTE: Execute the program go to scilab console and at command prompt enter the
following
-> [x,y]= ddu([2 4;5 9],[3 1;6 5])
y=
30. 22.
69. 50.
x=
5. 5.
11. 14.
Plotting Graphs
Plot2d 2D plot
Syntax
plot(y,<LineSpec>)
plot(x,y,<LineSpec>)
plot(x1,y1,<LineSpec1>,x2,y2,<LineSpec2>,...xN,yN,<LineSpecN>
) where arguments
<LineSpec> This optional argument must be a string that will be used as a shortcut to
specify a way of drawing a line. We can have one LineSpec per y or {x,y}
previously entered. LineSpec options deals with LineStyle, Marker and
Color specifiers. Those specifiers determine the line style, mark style and
color of the plotted lines.
subplot virtually grids the figure and sets the plotting area to a
chosen cell Syntax
subplot(m,n,
p)
subplot(mnp
)
Where arguments
Output:
Using Subplot
// sine wave - 1khz and 4 v (p-p)
f1=1
000
v1=
4
t1=0:0.001/f1:2/f1
y1=v1*sin(2*%pi*f1*t1)
// cosine wave - 2khz and 3 v
(p-p) f2=2000
v2=3
t2=0:0.001/f2:4
/f2
y2=v2*cos(2*%pi*f2*t2)
subplot(2,1,1)
plot(t1,y1)
xlabel('time in
sec')
ylabel('amplitude in V')
title('sine wave')
subplot(2,1,2)
plot(t2,y2,'r')
xlabel('time in sec')
ylabel('amplitude
in V') title('cosine
wave')
Output:
(1) Create a scilab script file to display product of a matrix A and inverse of A. A = [1; 1; 1;-1]
(2) Create a function file to calculate sum and difference of any two numbers. The output
should be the sum and the difference of numbers.
(3) Create a function file to calculate the row-wise and column-wise mean and standard
deviation of a user defined matrix. Display the matrix, its mean and standard deviation in
output. (hint: mean(), stdev() )
(4) Create a function to sort the elements of a random vector in descending order. (hint:
gsort())
(5) Create a function to round off the elements of a vector [1.9, 2.3, -1.1, 50.5] to
thenearest integer. (hint: round())
(6) Write a script / function file to check if a given number n is less than or equal to 10, if
yes, display itssquare.(for n = 4; 13 and 10)
(7) Write a script / function file to check if a number is less than 10, if yes, then display `>
10', if it is greaterthan 10, then display `> 10', else display the number. (for n = 4; 13 and
10)
(8) Create a function file which provides the first n Fibonacci numbers.
(9) Create a function file which provides first n factorials as output.
(10) For the values of integera going from 1 to 10, using separately the methods of the if
syntax, find the values of C if:
C= a2
plot2d command to graphically show C.
(11) Plot the two curves y1=2x+3 and y2=4x+3 on the same graph.[take x=-5 to 5]
(12) Write two function files for the following functions:
y1(x) = 3x+2; y2(x) = (-x/3)+3; sketch these functions using plot .
(13) For the circuit shown in figure below, you can produce outputs of various shapes by
selecting specific value of RC. Using SCILAB examine the influence of the time constant
on the response of the circuit.
v C V
– 2 SIGNAL
GENERATION
OBJECTI
VES
(1) To generate basic elementary discrete signal used in Digital Signal Processing.
(2) To generate discrete exponential signal, sinusoidal signal and random signal
THEORY:
Signals are broadly classified into analog & discrete signals. An analog signal will be
denoted by x(t), in which the variable t can represent any physical quantity. A discrete signal
will be denoted by x(n), in which the variable n is integer valued and represents discrete
instances in time. Therefore, it is called a discrete time signal, which is a number sequence
and will be denoted by one of the following notations:
x(n)={…,x(-1),x(0),x(1),….}
SAMPLE PROGRAM:
cl
c;
cl
e
a
r;
xdel(winsid());
t=0:0.1:2
0; f=0.2;
pi=3.14;
Sine wave
x1=sin(2*pi*f*t);
//scf();
subplot(231)
;
plot(t,x1,'cya+','marker','d','markerfac','green','markeredg','red');
title('Sinewave','color','red','fontsize', 4);
//xtitle( 'Sinewave', 'Index', 'Amplitude') ;
xlabel("Index", "fontsize", 2,"color",
"blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Cosine wave
x2=cos(2*pi*f*t); //Cosine Wave
//scf();
subplot(232)
;
plot(t,x2,'cya+','marker','d','markerfac','red','markeredg','yel');
title('Cosinewave','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Impulse Signal
t1=-10:10;
x3=[zeros(1,10) 1 zeros(1,10)];
//scf();
subplot(233)
;
plot(t1,x3,'cya+','marker','d','markerfac','green','markeredg','red');
title('Impulse','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Ramp Signal
t4=0:10;
x4=t4;
//scf();
subplot(234)
;
plot(t4,x4,'cya+','marker','d','markerfac','green','markeredg','red');
title('Ramp Wave','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Exponetial Signal
t5=0:10;
x5=exp(t5);
//scf();
subplot(235)
;
plot(t5,x5,'cya+','marker','d','markerfac','green','markeredg','red');
title('Exponetial Wave','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Random Signal
x6=rand(1,100);
//scf();
subplot(236)
;
plot(1:length(x6),x6,'cya+','marker','d','markerfac','green','markeredg','red'
); title('Random Wave','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Impulse Sequence
n1=1,n0=50,n2=100;
if((n0<n1)|(n0>n2)|
(n1>n2))
error('arugument
incorrect'); end
n=[n1:n2];
x7=[(n-n0)==0,1];
scf()
subplot(121)
;
plot(n,x7(n1:n2),'cya+','marker','d','markerfac','green','markeredg','r
ed'); title('Impulse Sequence','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Step Sequence
n1=1,n0=50,n2=100;
if((n0<n1)|(n0>n2)|
(n1>n2))
error('arugument
incorrect');
end
n=[n1:n2
];
x8=[(n-n0)>=0,1];
subplot(122);
plot(n,x8(n1:n2),'cya+','marker','d','markerfac','green','markeredg','red');
title('Step Sequence','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue");
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
MODIFICATIO
NS:
(1) Modify the above Program which will generate under damped exponential signal.
(2) Modify the above Program which will generate signals for n = 20.
CONCLUSION
: EXERCISES:
OBJECTIVES
THEORY:
Various signal operations are used in achieving more complex signal operations.
The signal operation like flipping, shifting, addition, multiplication is used in
implementation of convolution, correlation like operations.
SAMPLE PROGRAM:
cl
c;
cl
e
a
r;
xdel(winsid());
x1=[1 6 7 4 5 2 3 7 8 9];
n1=[-3 -2 -1 0 1 2 3 4 5 6];
x2=[5 8 6 9 4 2 3 7 5 6 2 8 7];
n2=[4 5 6 7 8 9 10 11 12 13 14 15 16] ;
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))))=x1;
y2(find((n>=min(n2))&(n<=max(n2))))=x2;
y=y1+y2;
x=y1.*y2;
// Addition of Two Sequences //
scf();
subplot(311);
bar(n,y1,0.1,'red');
title('Sequence_1','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(312);
bar(n,y2,0.1,'yellow');
title('Sequence_2','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(313)
bar(n,y,0.1,'Green');
//
plot(n,y,'cya+','marker','d','markerfac','red','markeredg','yel'
); title('Addition of Sequences','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
scf();
subplot(311);
bar(n,y1,0.1,'r
ed');
title('Sequence_1','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(312);
bar(n,y2,0.1,'yellow');
title('Sequence_2','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(313)
bar(n,x,0.1,'Green');
//plot(n,y,'cya+','marker','d','markerfac','red','markeredg','yel');
title('Multiplication of Sequences','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3 0.3]);
ylabel("Amplitude", "fontsize", 2, "color", "blue");
OUTPUT:
Signal Flipping
cl
c;
cl
e
a
r;
xdel(winsid());
x2=input("Enter the Sequence :"); // [2 3 5 6 4
8 6]; x3=mtlb_fliplr(x2);
n3=1:length(x2
); n3=-
mtlb_fliplr(n3);
scf();
subplot(2,1,1);
bar(x2,0.1,'red'
);
title('Original Sequence','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(2,1,2);
bar(n3,x3,0.1,'green');
OUTPUT:
title('Folded Sequence','color','green','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3 0.3]);
ylabel("Amplitude", "fontsize", 2, "color", "blue");
Signal Shifting
cl
c;
cl
e
a
r;
xdel(winsid());
x2=input("Enter the Sequence :"); // [2 3 5 6 4 8 6];
factor=input("Enter the Shifting Factor :"); // Example : -2
or 2 a=[];
t=[];
for
i=1:length(
x2) t=[t (i-
factor)];
a=[a
x2(i)]; end
temp=[];
if(factor>0)
a=[a
zeros(1,factor)];
for j=1:factor
temp=[temp
t(length(t))+j]; end
t=[t
temp];
end
if(factor<
0)
a=[zeros(1,-factor)
a]; for j=1:-factor
temp=[temp j];
end
t=[tem
p t];
e
n
d
s
c
f(
);
subplot(2,1,
1);
bar(x2,0.1,'r
ed');
title('Original Sequence','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
title('Original Sequence');
subplot(2,1,2);
bar(t,a,0.1,'green');
title('Shfted Sequence','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]);
ylabel("Amplitude", "fontsize", 2, "color", "blue");
MODIFICATIONS:
CONCLUSION:
EXERCISES:
FILTER
The purpose of this experiment is to study the frequency response of analog filter. The frequency
response is a graph of frequency versus output voltage or voltage gain which indicates
characteristics of circuit or system. In RC circuit shown in Fig. 1, when frequency is zero then
capacitive reactance is infinite (eq. (1)), and accordingly the voltage is maximum and equal to supply
voltage,
Xc =
1
(1)
2π fc
As frequency is increased capacitive reactance decreases, and consequently voltage across the
capacitor gradually decreases. For very high frequency, the voltage across capacitor becomes to
zero. Hence, the circuit allows low frequencies to pass and attenuates high frequency components.
Such filters are known as low pass filters. We can arrange R, L, and C in the network to obtain other
kind of response as well. Frequency response of the circuit (Fig. 1) is calculated theoretically as
shown below.
Fig. 1 RC circuit
THEORICAL CALCULATIONS:
RC circuit:
By viewing the circuit as a voltage divider as shown in Fig. 1, the voltage across the capacitor is:
1
jwC
Vc = ×Vin = (2)
1
×Vin
R+ 1 1+ jwRC
jwC
Amplitude = 1
(1 2
(wRC)
Phase =−
−
tan 1(wRC)
A = Vc = 1
=
11+ sRC
v
V R
in s1
RC
Hence cut off frequency,
1
w=
1
&f= (3)
2π RC
RC
Task 1:
SAMPLE PROGRAM 1:
clc;
clear
all;
A=[ ];
Ad=[ ]
R=1000
; C=1e-
6;
f=0:100:8000;
for ii=1:length(f)
w=2*%pi*f(ii)
A=1/sqrt(1+(w*R*C)^2); // Equation for voltage gain of the filter.
disp(A)
Ad(ii)=20*log10(A);
end
plot(f, Ad);
OUTPUT:
SAMPLE PROGRAM 2:
r=1000;
c=0.000001;
f=0:100:10000;
for i = 1:length(f)
w(i)=2*%pi*f(i);
A(i)=1/(sqrt(1+(w(i)^2)*(r^2)*(c^2)));
db(i)=20*log10(A(i));
Angle(i)=atan(-w(i)*r*c,1);
end
subplot(2,2,1);
plot(w,A);
xlabel("w");
ylabel("A");
title("Gain");
subplot(2,2,2);
plot(w,db);
xlabel("w");
ylabel("db");
title("Gain(db)");
subplot(2,2,3)
;
plot(w,Angle);
xlabel("w");
ylabel("Angle");
title("Angle");
subplot(2,2,4);
s=poly(0,'s'); h=syslin('c',
(1)/(1+r*c*s));
bode(h,0.01,10000);
OUTPUT:
SAMPLE PROGRAM 3:
High Pass 1st order RC Filter:
clc;
A=[]
;
Ad=[];
r=350;
c=exp(-25);
f=1:10:10000;
for i=1:length(f)
w=2*%pi*f(i);
A=((w*r*c)/(sqrt(1+(w*r*c)^2)));
disp(A);
Ad(i)=20*log10(A);
end
plot(f, Ad);
OUTPUT:
MODIFICATION:
Modify the program for different order of low pass filter and plot its frequency response.
CONCLUSION:
EXPERIMENT – 05
OBJECTIVE: Verify step response of first and second order system using XCOS.
THEORY:
XCOS is a graphical editor to design hybrid dynamical systems models. Models can be
designed, loaded, saved, compiled and simulated. Time domain behavior of a system is an
important aspect in designing or describing a system. How quickly a system responds is
important. If you have a control system that's controlling a temperature of a heater, so how
long it takes the temperature to reach a new steady state is important.
Ability to extrapolate the details of how a system or circuit responds to specific input is
important when you design systems. First, we will apply step as a test signal and observe
the time domain plot. The shape of the step response helps the designer to conclude how
fast it occurs, how much it oscillates, etc. We will observe the time domain behavior of a first
order system and second order system respectively.
𝑑𝑡
y(t) = Response of the system, u(t) = Unit step Input to the system, τ = Time constant of
the system,
G = DC Gain of the system.
Systems those are characterized by differential equation (1), have a transfer function of the
form:
𝑌(𝑠) (2)
𝐺 =
(𝑠) 𝑐𝑆+1
Any system which can be described by a transfer function of the above form, Variation in Time
constant determine how quickly the system moves toward steady state and Variation
in DC gain (G) of the system determine the amplitude of steady state response when the input
settles out to a constant value.
EXAMPLE:
Comparing above equation with eq.(2), DC gain (G) of the system = 1, and time constant (τ)
= RC.
First Order System Model In XCOS:
Now We Take
Time constant of the system(τ) = 4
DC Gain of the system(G) =2
A second order system is very much important. They are the systems that exhibit
oscillations. The simplest second order system satisfies a differential equation of this form:
𝑑2(𝑡) 𝑑𝑦(𝑡)
+ 2ÇW𝑘 + W𝑘2𝑦(𝑡) = 𝐺. W𝑘2.(𝑡) (4)
2 𝑑𝑡
𝑑𝑡
Where,
y(t) = Response of the system, u(t)= Input to the system, ξ = Damping ratio, ώ n=
Undamped natural frequency, G = DC gain of the system.
Systems that can be represented in the form of eq.(5) have a transfer function of the form:
2 2
𝐺𝖶𝑛 𝑠 +2£𝖶𝑛+
2
𝖶𝑛
(5)
A block diagram representation of such a system is provided in Fig. 3.5
By varying the parameters, you find in a second order system determine various kinds of responses.
2. DC gain (G) of the system, will determine the size of steady state response when the
input settles out to a constant value.
3. Undamped natural frequency (ώn), will determine how fast the system oscillates
during any transient response.
4. Damping ratio (ξ), will determine how much the system oscillates as the response
decays toward steady state.
If the Damping ratio is less than one(ξ<1) then the step response contains a decaying
2
sinusoid with a damped natural frequency of ώ n (1 £) and the exponential envelope of
the decay ise 𝑛⋅𝑡. This system is called under-damped. Most of the control systems with
£w
the exception of robotic control systems are designed with damping ratio less than one. As ξ
increases, the response becomes progressively less oscillatory till it becomes unity.
If the Damping ratio is equal to unity (ξ=1) , then the step response become non-oscillatory
and system is called critically-damped. If the Damping ratio is greater then unity(ξ>1), then
the step response will contains two decaying exponentials and system is called over-
damped. If the Damping ratio is equal to zero(ξ=0) , then response of the system will
oscillate forever with its undamped natural frequency (ώn) and system is called undamped.
Example:
Construct second order system model described by eq.(6) in XCOS using the procedure
described in the following section and observe time domain response of the system by
varying ώn and ξ.
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1), R = 2,
2
Output:
By varying the value of R, observe its effect on time response of the system.
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1)
2
Table 3.1 Effect of R on Time Response
Example 1
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1),
2
Example 2
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1), R = 40
2
Example 3
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.01) ,R = 20
2
Example 4
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.01) ,R = 400
2
PROCEDURE:
(1) Run XCOS from menu of SCILAB. Create a new XCOS file by selecting ’File/New
Diagram’. You will see a blank programming window.
(2) From pallete, select a ’Sources/Step_function’ block and drag it to the blank
window. This will be a step input to the system. By default it is a unit step that
starts at t=0s. This can be changed by right clicking, or double clicking, on the
icon and selecting new parameters
(3) Add a transfer function block (system model) using ’Continuous time
systems/CLR’. Default value of the transfer function is ’1/(s+1)’. Modify transfer
function according to your requirement by double clicking on transfer function
block.
(4) Connect the step input to the transfer function block by clicking on a small arrow
at input of the transfer function block and dragging it to the step input.
(5) Create an output display using ’Sinks/Cscope’ and connect the output of the
transfer function block to the scope.
(6) For event handling of scope add Clock_c from event handeling and connect
toscope. At this point the system diagram should look like as shown in Figure.
(7) All the blocks can be configured as per requirement of observations.
(8) Implement the first and second order system transfer function provided in examples
and observe the time response of a system by changing parameters of transfer function.
Print and attach the output graph in your lab book
CONCLUSION:
EXERCISE:
(1) Generate sine wave of frequency 1 kHz using generator block and pass it through
‘transfer function block’ which represent low pass filter of 1 kHz observe the output on
scope.
(2) Repeat (1) with input square wave of frequency 1 kHz.
EXPERIMENT – 6
OBJECTIVE: To construct the square wave and triangular wave using Fourier series of these
waveforms.
THEORY:
Any periodic signal g(t) can be represented as a summation of sine and cosine components.
𝑔(𝑡) = 𝑎0 + ∑ [𝑎𝑛 cos(2𝜋𝑛𝑓0𝑡) + 𝑏𝑛sin( 2𝜋𝑛𝑓0𝑡)] (1)
𝑛=1
If Square wave has peak voltage of V, has no dc components and if it is even function of time then
a0
= 0, bn = 0 and only an will exists which can be found as
4𝑉
, 𝑛 = 1,5,9,13, …
𝑎𝑛 = { 𝑛𝜋 (6)
−4𝑉
, 𝑛 = 3,7,11,15, . .
𝑛𝜋
Fourier series expansion of this type of square wave can be represented by
𝑔(𝑡) = 4𝑉 (𝑐𝑜𝑠𝜔 𝑡 − 1 𝑐𝑜𝑠 3𝜔 𝑡 + 1 𝑐𝑜𝑠 5𝜔 𝑡 − 1 𝑐𝑜𝑠 7𝜔 𝑡 + 1 𝑐𝑜𝑠 9𝜔 𝑡) …
� 03 5 0 7 9 0
�
(7)
Imagine the surprise of many with such proposal stating that even discontinuous functions such
as square waves could be represented by beautifully/smooth sines and cosines! But if you see
closely the waveform obtained, the series doesn’t converge when there is a jump discontinuity. At
the point of discontinuity, the series takes the average value of the left-hand and right-hand limits
of the signal at the instant of discontinuity.
Similarly, If triangular wave has peak voltage V, has no DC component and if it is even function
of time, then a0 = 0, bn = 0 and only an can be found as:
8
𝑓𝑜𝑟 𝑛 𝑜𝑑𝑑
𝑎𝑛 = {𝑛2𝜋2
0 𝑓𝑜𝑟 𝑛 𝑒𝑣𝑒𝑛
Fourier series expansion of this type of triangular wave can be represented by,
𝑔(𝑡) = 8𝑉 (𝑐𝑜𝑠𝜔 𝑡 + 𝑐𝑜𝑠 3𝜔0𝑡 + 𝑐𝑜𝑠 5𝜔0𝑡 + 𝑐𝑜𝑠 7𝜔0𝑡 + 𝑐𝑜𝑠 9𝜔0𝑡) +…….
2 0
𝜋 3!
5! 7! 9!
SAMPLE PROGRAM:
cl
c;
cl
e
ar
;
cl
os
e;
v=
1;
w
=
1
5;
t=0:0.001:0.99;
// synthesis of square wave using different number of
harmonics x1=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3);
x2=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5);
x3=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-
cos(7*w*t)/7);
x4=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-cos(7*w*t)/7+cos(9*w*t)/9);
x5=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-cos(7*w*t)/7+cos(9*w*t)/9-
cos(11*w*t)/11);
x6=(4*v/%pi)*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-cos(7*w*t)/7+cos(9*w*t)/9-
cos(11*w*t)/11+cos(13*w*t)/13);
subplot(3,
2,1);
plot(x1);
title('Square Wave constructed with First 2 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,2)
plot(x2);
title('Square Wave constructed with First 3 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,3)
plot(x3);
title('Square Wave constructed with First 4 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,4)
plot(x4);
title('Square Wave constructed with First 5 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,5)
plot(x5);
title('Square Wave constructed with First 6 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude (V)');
subplot(3,
2,6);
plot(x6);
title('Square Wave Constructed with First 7 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude (V)');
Output:
CONCLUSION:
EXERCISE:
(1) Synthesize arbitrary wave using Fourier series.
(2) Synthesize ramp signal of the period 2π and amplitude 1.
EXPERIMENT –
CONVOLUTION
OBJECTIVES:
THEORY :
The convolution theorem says, roughly, the convolving two sequences is the same as
multiplying their Fourier transforms. In order to make this precise, it is necessary to pad the
two vectors with zeros and ignore round off error. Thus, if X=fft([x,zeros(1,length(y)-1)]) and
Y=fft([y,zeros(1,length(y)-1)]) then conv(x,y)=ifft(X.*Y).
If x[n] is input and h[n] is the system impulse response then system
x[k]h[n k] x[n k]h[k]
response y[n] = Σ =Σ
k=–∞ k= –∞
SAMPLE PROGRAM:
OUTPUT:
MODIFICATIONS:
(1) Modify the above program to show that convolution of x1(n) and x2(n) is
equal to convolution of x2(n) and x1(n)
CONCLUSION:
EXPERIMEN
T 8 DTFT
and DFT
OBJECTIV
ES:
(1) To obtain magnitude and phase of discrete signals with DTFT and DFT.
THEORY:
Fourier Transform is used to find spectrum of analog aperiodic signals. It is observed that the
spectrum of such signals is continuous and aperiodic. If the signal is Discrete Time, Discrete
Time Fourier Transform (DTFT) is applicable. DTFT gives the spectrum which is continuous
and periodic in frequency domain. To process the discrete time signals in frequency domain
using processors, we need its discrete version. This can be obtained by another transform
known is Discrete Fourier Transform (DFT). DFT computes N equally spaced frequency
samples of the one period of DTFT.
The expressions for FT, DTFT and DFT and their respective inverse transforms are given
below.
Fourier Transform and DTFT and Inverse DTFT: DFT and IDFT:
Inverse Transform:
Algorithms which reduce computations while evaluating above equations are known as Fast
Fourier Transform (FFT) algorithms.
SAMPLE PROGRAM 1:
DTFT
clc
;
cl
os
e;
cle
ar
;
fs=8000; //sampling rate
//10s duration (Increasing the value and observe spectrum)
//plot2d3(x)
x1=[1 1 1 1, 0 0 0 0]; //zero padding for better spectrum
resolution Xohm=[];
for
ohm=0:0.1:2*3.14*24000/80
00 yk=0
for n1=0:length(x1)-1
yk=yk+x1(n1+1)*exp(-
%i*ohm*n1);
end
Xohm=[Xohm
yk]
end
ohm=0:0.1:2*3.14*24000/8
000
f=ohm*8000/(2*3.14)
magx=abs(Xohm)
phasex=atan(imag(Xohm),real(Xoh
m)) subplot(211)
plot(f,mag
x)
subplot(21
2)
plot(f,phas
ex)
DFT
PROGRAM 1
clc;
x=[1 1 1 1 0 0 0 ];
y=fft(x)
stem(abs
(y));
title('dft');
xlabel('time');
ylabel('amplitud
e');
Output:
SAMPLE PROGRAM 2:
MODIFICATIONS:
(2) Obtain the spectrum of pulse and exponential function with different
resolution and with x axis a s actual frequency.
CONCLUSION:
EXERCISE:
(1) Write SCILAB code to find DFT without using inbuilt function fft.
EXPERIMENT – 9
DFT
OBJECTIVE:
To find convolution of two sequences using FFT/IFFT.
THEORY :
DFT provides an alternative approach to time domain convolution. It can be used to perform linear
filtering in frequency domain.
Thus,
Y(ω) = X(ω).H(ω) ⟷ y(n)
The problem in this frequency domain approach is that Y(ω), X(ω) and H(ω) are continuous function
of ω, which is not fruitful for digital computation on computers. However, DFT provides sampled
version of these waveforms to solve the purpose.
The advantage is that, having knowledge of faster DFT techniques likes of FFT, a computationally
higher efficient algorithm can be developed for digital computer computation in comparison with time
domain approach.
Consider a finite duration sequence
x(n)=0,for n < 0 and nL Which excites a linear filter with impulse response
From the convolution analysis, it is clear that, the duration of y(n) is L+M1. In frequency domain,
Y(ω)=X(ω).H(ω)
Now, Y() is a continuous function of and it is sampled at a set of discrete frequencies with number of distinct samples
Where, X(k) and H(k) are N-point DFTs of x(n) and h(n) respectively. x(n) & h(n) are padded with zeros up to the leng
DFT of output sequence y(n) is sufficient to represent y(n) in frequency domain and these facts infer
that the multiplication of N-point DFTs of X(k) and H(k), followed by the computation of N-point
IDFT must yield y(n).
This implies, N-point circular convolution of x(n) and H(n) with zero padding, equals to linear
convolution of x(n) and h(n).
SAMPLE PROGRAM:
cl
c;
cl
e
ar
;
cl
o
s
e;
//x=input('Enter the input sequence
x(n)=' ); x=[2 1 2 1]
//
lx=0:length(x)-
1 h=[3 2 1];
clin=conv(x,h)
//n=1:1:length(x)+length(y)-
1; xgrid;
subplot(4 ,1 ,1)
; a=gca() ;
a.x_location =
"origin";
a.y_location =
"origin";
a.foreground = 4;
//a.font_color = 5;
//a.font_style = 5;
plot2d3(x);
title ('Input Sequence x[n]' );
xlabel ('Samples n');
ylabel ('Amplitude' );
xgrid;
subplot(4 ,1 ,2)
; xgrid;
a=gca() ;
a.x_location =
"origin"; a.y_location
= "origin";
a.foreground = 4;
plot2d3(h);
title ('Impulse response
h[n]' ); xlabel ('Samples n');
ylabel ('Amplitude' );
xgrid;
subplot(4 ,1 ,3) ;
xgri
d;
a=gc
a() ;
a.x_location =
"origin"; a.y_location
= "origin";
a.foreground = 4;
plot2d3(clin);
title ('linear convolution of x[n] and
h[n]' ); xlabel ('Samples n');
ylabel ('Amplitude' );
xpad = [x zeros(1,length(x)+length(h)-1-
length(x))]; hpad= [h zeros(1,length(x)
+length(h)-1-length(h))]; ccirc =
ifft(fft(xpad).*fft(hpad));
xgrid;
subplot(4 ,1 ,4)
; xgrid;
a=gca() ;
a.x_location =
"origin"; a.y_location
= "origin";
a.foreground = 4;
plot2d3(ccirc);
title ('linear convolution of x[n] and h[n] using ifft' );
xlabel ('Samples n');
ylabel ('Amplitude' )
OUTPUT:
CONCLUSION:
EXERCISE:
(1) For h(n) = e-an u(n), where a>o, verify that impulse response is same as h(n).
(2) For h(n) = e-an u(n), where a>o, find out step response.
EXPERIMENT 10
Z-Transform
OBJECTIVES:
THEORY:
The Z-Transform is an important tool in DSP that is fundamental to filter design and system
analysis. It will help you understand the behavior and stability conditions of a system. The Z-
transform converts a discrete time-domain signal, which is a sequence of real or complex
numbers, into a complex frequency-domain representation. It can be considered as a
discrete equivalent of the Laplace transform.
𝑛=−
∞
The relation sometimes called the direct z-transform because it transforms the time-domain
signal x[n] into its complex-plane representation X[z].
SAMPLE PROGRAM:
h=syslin("d",[45.76+6*%z+2*%z^2;0.64*%z],[1+0.1*%z+%z^2;0.28+3.1*%z+%z^2
])
// compute poles and zeros and display
[z p k] = tf2zp(h);
disp('Zeros:');
disp(z);
disp('Poles:');
disp(p);
input('Hit <return> to continue...');
// compute and display factored form of G(z)
//[sos k] = zp2ss(z,p,k)
input('Hit <return> to continue...');
// generate pole-zero plot
plzr(h);
mtlb.zplane(z,p);
OUTPUT:
CONCLUSION:
EXERCISE:
(1) Write a program to find out inverse Z transform of the system.