0% found this document useful (0 votes)
39 views76 pages

SS Manual Students

The document is a laboratory manual for Signals & Systems for B. Tech. students at Dharmsinh Desai University, covering various topics such as signal generation, convolution, and Z-transform using Scilab. It includes an introduction to Scilab, its basic functions, and commands for signal processing and numerical computations. The manual serves as a comprehensive guide for students to perform experiments and understand the application of Scilab in electronics and communication.

Uploaded by

joshnap02619
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views76 pages

SS Manual Students

The document is a laboratory manual for Signals & Systems for B. Tech. students at Dharmsinh Desai University, covering various topics such as signal generation, convolution, and Z-transform using Scilab. It includes an introduction to Scilab, its basic functions, and commands for signal processing and numerical computations. The manual serves as a comprehensive guide for students to perform experiments and understand the application of Scilab in electronics and communication.

Uploaded by

joshnap02619
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 76

Laboratory Manual for

Signals & Systems

B. Tech.

SEM. IV (EC)

Department of Electronics &


Communication Faculty of Technology
Dharmsinh Desai University
Nadiad
TABLE OF CONTENTS

PART- I LABORATORY MANUAL

Sr. No. Title Page No.

1. Introduction to Scilab 04

2. Signal Generation 22

3. Operation on Signals 26

4. Frequency Response of Filter 30

5. Step Response Using XCOS 33

6. Synthesis of Signals Using Fourier Series 42

7. Convolution 45

8. DTFT and DFT 47

9. Linear Filtering Using DFT 51

10. Z - transform 53

Department of Electronics & Communication, Faculty of Technology, Dharmsinh Desai University, Nadiad 2
EXPERIMENT – 1

INTRODUCTION TO SCILAB

OBJECTIVE: a) To study the basic function in Scilab


b) Creation of script & function file in Scilab.
THEORY:
SCILAB is an open source, cross-platform numerical computational package and a high-
level, numerically oriented programming language. It can be used for signal processing,
statistical analysis, image enhancement, fluid dynamics simulations, numerical optimization,
and modeling, simulation of explicit and implicit dynamical systems and symbolic
manipulations. SCILAB provides an interpreted programming environment, with matrices as
the main data type. By using matrix-based computation, dynamic typing, and automatic
memory management, many numerical problems may be expressed in a reduced number of
code lines, as compared to similar solutions using traditional languages, such as Fortan, C,
or C++. This allows users to rapidly construct models for a range of mathematical problems.
While the language provides simple matrix operations such as multiplication, the SCILAB
package also provides a library of high-level operations such as correlation and complex
multidimensional arithmetic.

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.

Fig. 1.1 SCILAB default console


-->pwd // to know the path of working

directory ans = C:\Users\sstdd\Documents

Quitting the Scilab program:

To end SCILAB, File > quit in the Scilab console or Type the command ‘quit’ at the prompt
the
i Scilab Console.

Fig. 1.2 SCILAB help browser

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>.

--> help diary

Description

diary(filename)function creates a log of keyboard input and the resulting text output.

diary(filename,'close') closes diary session(s) identified by 'filename'.


Table 1.1 Arithmetic operations

+ 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 = x+y, b = x*y

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 = z^2, f = z**2

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 (,).

Basic Elements of SCILAB:

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:

In SCILAB, certain variables are predefined and write-protectedas follows:

Table 1.2 Scilab 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 =

Some useful SCILAB Commands:

General commands:

Clock: Provide clock time and date as a vector [year month day hour minute seconds]

--> clock

ans =

2019. 12. 5. 4. 54. 0.0000047

Date: Current date a string


-->

date

ans =

05-Dec-2019

ver: Version information for SCILAB

-->ver

ans =

!Scilab Version: 6.0.1.1518683525 !

Table 1.3 Workspace commands

who Lists the variables currently in the SCILAB workspace


whos Same as who but provides more information on size, type
whos-type List the variables that can store real or complex constant
constants complex constant
whos- name a List all variables with name starting with the letter ‘a’
what Lists the SCILAB primitives
clear Kills the variables which are not protected
clear xyz Kills the variables specified in the command
Clc Clears screen
Clf Clears figure window
diary List of current session commands

Table 1.4 Directory commands

pwd Provides SCILAB current working directory


copyfile Copies a file
mkdir Makes a a new directory/folder in the current directory

Table 1.5 Termination commands

Quit Quits SCILAB


Exit Same as quit command

Creating Arrays (Vectors and Matrices):

Create a row Vector:

--> 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.

Create a column Vector:

c = [2;5;3;8;4]

c=

2.

5.

3.

8.

4.

Creating a row vector with colon (:) operator:

Variable_name = m:q:n where m=first term, q=increment, n=last term

--> d = 1:6 // Default increment is

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.

--> h = 10:-2:0 // increment can be negative

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 = a+b

add =

7. 6. 5. 15. 15.

--> mul1 = a*b

Inconsistent row/column dimensions.

--> mul2 = a*b'

mul2 =

130.

--> l = linspace(0,8,4) //Generates a vector of 4 elements, 0 is the first element and


//8 is the last element

l=

0. 2.6666667 5.3333333 8.

Addressing a vector element:

--> 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.

--> c =mean(a) // Average of all

elements c =

4.8

--> d= length(a) //Number of elements in the vector

d=

5.

--> f = max(a) // maximum value in the

vector f =

10.

--> g = prod(a) // Product of elements in the

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 = [ 2.6 3.2 -4.6 7.5 -2.4]

q=

2.6 3.2 -4.6 7.5 -2.4

--> 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.

--> e =gsort(q) //Sorts the elements of q in descending

order e =

7.5 3.2 2.6 -2.4 -4.6

Entering a Matrix:

-->A=[16 3 2 13;5 10 11 8;9 6 7 12;4 15 14 1] //use space or , for row elements

// 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=sum(A) // Gives the sum of all the


elements

B=

136.

-->C=sum(A,'c') // Sum of the elements of


column C =

34.
34.

34.

34.

-->D=sum(A,'r') // Sum of the row elements

D=

34. 34. 34. 34.

Matrix Addressing:

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

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.

-->A=[1 2;3 4];


-->B=[2 3; 5 6];

-->C=[A,B]

C=

1 2 2 3.
. . .
3 4 5 6.
. . .
-->A=rand(2,3)

A=

0.849745 0.878216 0.56084


2 5 86
0.685731 0.068374 0.66235
0 0 69

-->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.

8.

-->A=[1 2;0 4];

-->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") is the seed for defining polynomials with symbol "x"

--> x= poly(0,"x")

x=

--> p = 1+ 2*x -x^2 +4* x^3

p=

1 +2x -x2 +4x3

--> p1 = 2*x^3 -4*x-1


p1 =

-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.

--> c = horner(p3,[1 2 5]) // to determine the value of p3 at 1, 2 and


5c=
10. 49. 586.

--> d= derivat(p3) // finding derivative of polynomial


p3 d =
2 +6x +12x2

ASSIGNMENT 1:

Solve the following examples on the SCILAB Console:

(1) Perform the following calculations on the scilab command line:

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.

(a) Calculate A*B-B*A


(b) Calculate A*A+B*B

(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].

b) Scripts & Functions File

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 opens a function


definition endfunction closes a
function definition
Description

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

x a real matrix or vector. If omitted, it is assumed to be the vector 1:n where


n is the number of curve points given by the y parameter.

y a real matrix or vector. y can also be a function defined as a macro or a


primitive.

<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

m,n,p positive integers

mnp an integer with decimal notation mnp


subplot(m,n,p) or subplot(mnp) breaks the graphics window into an m-by-n matrix of sub-
windows and selects the p-th sub-window for drawing the current plot. The number of a
sub- window into the matrices is counted row by row.
Sample Program: Create a script file to plot the two signals: sine wave of 1 kHz
frequency and peak to peak amplitude of 4 V & cosine wave of 2 kHz and 3 V peak to
peak on same graph as well as on two different using subplot.
Plot on same graph
// sine wave - 1khz and 4 v (p-
p) f1=1000
v1=4
t1=0:0.001/f1:2
/f1
y1=v1*sin(2*%pi*f1*t1)
plot(t1,y1)
xlabel('time in sec')
ylabel('amplitude in V')
title('sinusoidal
waveforms')
// 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)
plot(t2,y2,'r')
xlabel('time in sec')
ylabel('amplitude in
V')
h1=legend(['y1';'y2'
])

Output:

Fig. 1.3 Output result of sample program of plot Function

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:

Fig. 1.4 Output result of sample program of subplot Function


ASSIGNMENT 2:

(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

Assuming when switch is closed at t = 0, Vc (0) = 3 V. Given Vs= 10 V and RC = 1s.


a) Sketch a graph of Vc (t). Also plot the point on the graph when capacitor charges to
9V? Also use mprintfcommand to display the time when capacitor charges to 9 V in
all the cases.
b) Use function files to determine the voltage across capacitance considering RC as the
variable to be passed to function file and consider V c and Vs as global parameter. Plot
several curves of Vc (t) corresponding to: RC=1, RC= 5 and RC= 10. Determine from
the
graph which of these time constants results in the fastest approach of Vc(t) toward Vs?
—t —t
RC RC
Hint: use the formula: Vc (t) = Vc (0)e + Vc [1 e ]
EXPERIMENT

– 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),….}

Some of the discrete signals are generated using SCILAB.

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:

(1) Generate rect(n/2N) and for N=5.


(2) Generate tri(n/2N) for N=7.
EXPERIMENT – 3

OPERATIONS ON DISCRETE SIGNALS

OBJECTIVES

(1) To perform addition of two discrete signals.


(2) Multiplication of two discrete signals.
(3) To flip a discrete signal.
(4) Right shifting and left shifting of discrete signal.

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:

Signal Addition and Multiplication

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:

(1) Modify the above program to perform operation 2*x1(n) + 3*x2(n)..


(2) Modify the above program to multiply x1(n) and x2(n-3).

CONCLUSION:

EXERCISES:

Perform following operations.

(1) x(n)=2δ(n+2)-δ(n-4), -5<=n<=5;


(2) x(n)=n[u(n)-u(n-10)+exp(-0.3(n-10))[u(n-10)-u(n-20)], 0<=n<=20;
(3) x(n)=n[u(n)-u(n-10)+exp(-0.3(n-10))[u(n-10)-u(n-20)], 0<=n<=20;
(4) 2*x(n-5)-3*x(n+4).
EXPERIMENT – 4

FREQUENCY RESPONSE OF THE

FILTER

OBJECTIVE: To study and analyze frequency response of the filter.


THEORY:
The filter circuits are passing or stop the different range of frequency in circuit or system. Electronic
filters are electronic circuits which remove unwanted frequency components from the signal and
select the desired signal like in radio receiver. Implementations of linear filters are based on
combinations of resistors (R), inductors (L) and capacitors (C).

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:

Find frequency response of the filter using above equations.

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

Step Response of System using XCOS

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.

First Order System:


It is described by,
𝑑(𝑡)
𝑟 + 𝑦(𝑡) = 𝐺𝑢(𝑡) (1)

𝑑𝑡

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

A block diagram representation of such a system is provided in Fig. 3.1.

Fig. 3.1 First order system

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:

Fig. 3.2 RC Circuit

Transfer function of the circuit provided in Fig.3.2 is given by,


(𝑠) = 1 (3)
(𝑠) (𝑅𝐶)𝑆+1

Comparing above equation with eq.(2), DC gain (G) of the system = 1, and time constant (τ)
= RC.
First Order System Model In XCOS:

Fig. 3.3 First order system model in XCOS


Output:

Now We Take
Time constant of the system(τ) = 4
DC Gain of the system(G) =2

Fig. 3.4 First order system model in XCOS


Output:

Second Order System:

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

Fig. 3.5 Second order system

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:

Fig. 3.6 RLC Circuit


Transfer function of a circuit provided in Fig. 3.6 is given
by
(𝑠) = 1 (6)
2
(𝑠) 𝐿𝐶𝑠 +𝑅𝐶𝑠+1

Comparing above equation with eq.(5),


we get DC Gain of the system (G) = 1
Undamped natural frequency(ώn) = 1
𝐿𝑐
𝑅 𝑐
Damping ratio(Ԑ) =
2 𝐿

Second Order System Model In XCOS:

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

Fig. 3.7 Second order system model in XCOS

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

L = 1H, C = 0.01F, ώn = 10, ξ= 𝑅 (0.01)


2
By varying the value of R, observe its effect on time response of the
system.

Table 3.2 Effect of R on Time Response

Example 1
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1),
2

Fig. 3.8 Second order system model in XCOS


Output:

Example 2
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.1), R = 40
2

Fig. 3.9 Second order system model in XCOS


Output:

Example 3
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.01) ,R = 20
2

Fig. 3.10 Second order system model in XCOS


Output:

Example 4
L = 1H, C = 0.01F, ώn = 10, ξ = 𝑅 (0.01) ,R = 400
2

Fig. 3.11 Second order system model in XCOS


Output :

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

SYNTHESIS OF SQUARE WAVE AND TRIANGULAR WAVE USING FOURIER SERIES

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

Where f0 is the fundamental frequency of periodic function g(t).

The Fourier coefficients a0, an and bn are calculated as shown below.


𝑎 = 1 ∫𝑡1+𝑇0 (2)
𝑔(𝑡)𝑑𝑡
0 𝑇0 𝑡1
𝑎 = 2 ∫𝑡1+𝑇0 (3)
𝑔(𝑡)cos(2𝜋𝑛𝑓 𝑡)𝑑𝑡
𝑛 𝑇0 𝑡1 0
𝑏 = 2 ∫𝑡1+𝑇0 (4)
𝑔(𝑡)sin(2𝜋𝑛𝑓 𝑡)𝑑𝑡
𝑛 𝑇0 𝑡1 0
for n = 1,2,3……

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)

where, 𝜔0 = 2𝜋𝑓0 is angular fundamental frequency, V is peak amplitude and n is number of


harmonics. Therefore, square wave can be represented as weighted sum of different cosine
waves. Infinite number of cosine wave addition makes ideal square wave.

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)');

// synthesis of square wave using different number of


harmonics x1=v*(cos(w*t)-cos(3*w*t)/3)/%pi;
x2=v*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5)/%pi;
x3=v*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-cos(7*w*t)/7)
/%pi
x4=v*(cos(w*t)-cos(3*w*t)/3+cos(5*w*t)/5-cos(7*w*t)/7+cos(9*w*t)/9)/%pi;
x5=v*(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)/%pi;
x6=v*(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)/%pi;

// synthesis of triangular wave using different number of harmonics


y1=(8*v/%pi^2)*(cos(w*t)+cos(3*w*t)/3);
y2=(8*v/%pi^2)*(cos(w*t)+cos(3*w*t)/6+cos(5*w*t)/120); y3=(8*v/%pi^2)*(cos(w*t)
+cos(3*w*t)/6+cos(5*w*t)/120+cos(7*w*t)/5040);
y4=(8*v/%pi^2)*(cos(w*t)+cos(3*w*t)/6+cos(5*w*t)/120+cos(7*w*t)/5040+cos(9*w*t)/
362880);
y5=(8*v/%pi^2)*(cos(w*t)+cos(3*w*t)/6+cos(5*w*t)/120+cos(7*w*t)/5040+cos(9*w*t)/
362880+cos(11* w*t)/39916800);
y6=(8*v/%pi^2)*(cos(w*t)+cos(3*w*t)/6+cos(5*w*t)/120+cos(7*w*t)/5040+cos(9*w*t)/
362880+cos(11* w*t)/39916800+cos(13*w*t)/(6.22*10^9));
figure;
subplot(3,2
,1);
plot(y1);
title('Triangle Wave constructed with First 2 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,2)
plot(y2);
title('Triangle Wave constructed with First 3 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,3)
plot(y3);
title('Triangle Wave constructed with First 4 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,4)
plot(y4);
title('Triangle Wave constructed with First 5 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude
(V)'); subplot(3,2,5)
plot(y5);
title('Triangle Wave constructed with First 6 Components of Fourier Series');
xlabel('Samples');
ylabel('Amplitude (V)');
subplot(3,
2,6);
plot(y6);
title('Triangle 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:

To perform the convolution operation between two discrete sequences.

THEORY :

Convolution operation between two discrete sequences

Convolution and polynomial multiplication Algebraically, convolution is the same as operation


as multiplying the polynomials whose coefficients are the elements of u and v. Definition: Let
m=length (u) and n=length (v). Then w is the vector of length (m+n-1) whose kth element is
the sum over all the values of j which lead to legal subscripts for u(j) and v(k+1-j), specifically
j= max(1,k+1-n): min(k,m). When m=n, this gives
w(1) = u (1)*v (1)
w(2) = u (1)*v (2)+u(2)*v(1)
w(3)= u(1)*v(3)+u(2)*v(2)+u(3)*v(1)
:
w(n)= u(1)*v(n)+u(2)*v(n-1)+...+u(n)*v(1)
...
w(2*n-1)= u(n)*v(n)

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:

Convolution of Two Sequences


cl
c;
cl
e
a
r;
xdel(winsid());
x1=input("Enter the Sequence_1 :"); // [1 2 3 4 5];
x2=input("Enter the Sequence_2 :"); // [5
4 8]; n = length(x1);
m=
length(x2);
for k = 1:
(m+n-1)
w(k) = 0;
for j =max(1,k+1-m) : min(k,n)
w(k)= w(k)+(x1(j)*x2(k+1-j));
end
e
n
d
s
c
f(
);
subplot(3,1,1);
plot2d3(x1);
title('Sequence_1','color','red','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.6
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(3,1,2);
plot2d3(x2);
title('Sequence_2','color','red','fontsize'
, 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.6
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");
subplot(3,1,3);
plot2d3(w);
title('Convoled Sequence','color','green','fontsize', 4);
xlabel("Index", "fontsize", 2,"color", "blue",'position',[0.3
0.3]); ylabel("Amplitude", "fontsize", 2, "color", "blue");

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:

G(\omega)=\int g(t)e^{-j\omega t}dt\\\\


\\ g(t)=\int G(\omega)e^{j\omega t}dt \\
\\ G(\Omega)=\sum_{-\infty}^{\infty} g(n)e^{-j\Omega n}\\ \\
\\ g(n)=\sum_{-\infty}^{\infty} G(\Omega)e^{j\Omega n}\\

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:

Spectrum of the exponential function


fs=1; //sampling rate
n=0:1/fs:10 //10s duration (Increasing the value and
observe spectrum)x=exp(-n);
plot2d3(x)
//x1=[x, zeros(1,100)]; //zero padding for better spectrum
resolutiony=fft(x1);
plot2d3(abs(fftshift(y)

MODIFICATIONS:

(1) Increase frequency resolution in DTFT and DFT and plot

(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

LINER FILTERING USING

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

h(n)=0,for n<0 and nM


The output
𝑴−𝟏
𝒚(𝒏) = ∑ 𝒉(𝒌)𝒙(𝒏 − 𝒌)
𝒌=𝟎

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

DFT size = N L+M1


With 𝜔 = 2𝜋 𝑘
𝑁

Y(ω) = X(k).H(k), where k=0,1,….,N-1

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:

1. Find poles and zeros of the system.


2. Obtain response of the filter.

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 z-transform of a discrete-time signal x(n) is defined as the power series


𝑛=∞
𝑋[
𝑍]
Where z is a complex variable. =

𝑥[𝑛
]𝑧−
𝑛

𝑛=−

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:

Poles and Zeros


// compute and display poles and zeros
clf;
// initialize

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);

Response of the Filter

//r=input("enter the value of


r"); clc
cl
e
a
r
r
=
2;
f=0:0.001:2
close all;
z=r*exp(%i*2*%pi*f)
//H=1/
(z^2+z+1); for
i=1:1:length(f)
z1=r*exp(%i*2*
%pi*f(i))
H(i)=(z1)/(z1-.5)
//H(i)=1/(z1^2+z1+1);
end
omega=0:%pi/16:4*
%pi figure;
//n=1:1:100;
plot(8000*f,H);

OUTPUT:

CONCLUSION:

EXERCISE:
(1) Write a program to find out inverse Z transform of the system.

You might also like