0% found this document useful (0 votes)
9 views

BS Lab Manual

This document provides an introduction to the GNU Octave software and Basic Simulation Lab manual. It discusses the history and features of Octave, including that it is an open-source alternative to MATLAB that is mostly compatible with MATLAB. The document then lists the table of contents for the lab manual, which includes 10 programs related to basic operations on matrices and signals, such as convolution, Fourier transforms, and sampling theory verification. Safety guidelines are also provided for the lab.

Uploaded by

najmuus786
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)
9 views

BS Lab Manual

This document provides an introduction to the GNU Octave software and Basic Simulation Lab manual. It discusses the history and features of Octave, including that it is an open-source alternative to MATLAB that is mostly compatible with MATLAB. The document then lists the table of contents for the lab manual, which includes 10 programs related to basic operations on matrices and signals, such as convolution, Fourier transforms, and sampling theory verification. Safety guidelines are also provided for the lab.

Uploaded by

najmuus786
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/ 59

LORDS INSTITUTE OF ENGINEERING AND

TECHNOLOGY
(AUTONOMOUS)
(Affiliated to Osmania University) Himayathsagar, Hyderabad, Telangana.

BASIC SIMULATION LAB MANUAL


By
MD TOUSEEF SUMER
Assistant Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

i
ii
S. No. CONTEN PAGE
TS No.
1 Vision of the Institution I
2 Mission of the Institution I
3 Vision of the Department II
4 Mission of the Department II
5 PEOs II
6 POs III
7 PSOs IV
8 Introduction to OCTAVE IV
9 General Guidelines & Safety instructions XXVII
PROGR
AMS
10 Program 1: Basic Operations on Matrices 1
11 Program 2: Generation of Various Signals and Sequences 2
12 Program 3: Operations on Signals and Sequences 3
13 Program 4: Finding the Even and Odd parts of Signals/Sequence 4
14 Program 5: Convolution for Signals and sequences 6
15 Program 6: Auto Correlation and Cross Correlation for Signals and 8
Sequences.
16 Program 7: Verification of Linearity and Time Invariance Properties of a 9
given Continuous/Discrete System.
17 Program 8: Finding the Fourier Transform of a given signal and plotting 10
its magnitude and phase spectrum.
18 Program 9: Locating the Zeros and Poles and plotting the Pole-Zero 11
maps in S-plane and Z-Plane for the given transfer function
19 Program 10: Sampling Theorem Verification 13
20 Annexure-I: Basic Simulation Lab- Syllabus 22

iii
LORDS INSTITUTE OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING

1.-VISION OF THE INSTITUTION

To be part of universal human quest for development and progress by


contributing high caliber, ethical and socially responsible engineers who meet the
global challenge of building modern society in harmony with nature.

2.MISSION OF THE INSTITUTION

• To attain excellence in imparting technical education from the undergraduate


through doctorate levels by adopting coherent and judiciously coordinated
curricular and co- curricular programs
• To foster partnership with industry and government agencies through
collaborative research and consultancy
• To nurture and strengthen auxiliary soft skills for overall development and
improved employability in a multi-cultural work space
• To develop scientific temper and spirit of enquiry in order to harness the latent
innovative talents
• To develop constructive attitude in students towards the task of nation building
and empower them to become future leaders
• To nourish the entrepreneurial instincts of the students and hone their business
acumen.
• To involve the students and the faculty in solving local community problems
through economical and sustainable solutions.

i
LORDS INSTITUTE OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

3. VISION OF THE DEPARTMENT


To provide State of Art facilities to impart Technical education and Research in order to
guide and motivate young Engineers in Electronics and Communication Engineering

4. MISSION OF THE DEPARTMENT


 DM1: To make engineering education an enjoyable learning experience through
challenging tutorials, mini projects, assignments and laboratory experiences.

 DM2: To impart training to students for good designing skills and exposure to Research
& Development and innovations by using modern tools in frontier areas of Engineering
and Project Management

 DM3: To promote overall development of graduates by developing their competencies


in order to prepare them to be successful engineers/ entrepreneurs making them useful to
society and also improve their ethical values.

Note: DM: Department Mission

5.PROGRAM OUTCOMES

PO1: Engineering knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems.

PO2: Problem analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs with
appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.

ii
PO4: Conduct investigations of complex problems: Use research-based knowledge
and research methods including design of experiments, analysis and interpretation of
data, and synthesis of the information to provide valid conclusions.

PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.

PO6: The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.

PO7: Environment and sustainability: Understand the impact of the professional


engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.

PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.

PO9: Individual and team work: Function effectively as an individual, and as a


member or leader in diverse teams, and in multidisciplinary settings.

PO10: Communication: Communicate effectively on complex engineering activities


with the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.

PO11: Project management and finance: Demonstrate knowledge and


understanding of the engineering and management principles and apply these to one‟s
own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
PO 12: Life-long learning: Recognize the need for, and have the preparation and ability
to engage in independent and life-long learning in the broadest context of
technological change.

iii
6. PROGRAM SPECIFIC OUTCOMES

PSO1: Work as Software Engineers for providing solutions to real world problems
using Structured, Object Oriented Programming languages and open source software.

PSO2: Function as Systems Engineer, Software Analyst and Tester for IT and ITeS.

iv
7. INTRODUCTION TO BASIC SIMULATION LAB

SOFTWARE:

GNU Octave is a high-level programming language like MATLAB and it is mostly


compatible with MATLAB. It is also used for numerical computations.
Matlab is software featuring a high-level programming language, primarily intended for
numerical computations. Octave helps in solving linear and nonlinear problems numerically,
and for performing other numerical experiments using a language that is mostly compatible
with MATLAB. It may also be used as a batch-oriented language. Since it is part of the GNU
Project, it is free software under the terms of the GNU General Public License.

History: The project was conceived around 1988. At first it was intended to be a companion
to a chemical reactor design course. Real development was started by John W. Eaton in 1992.
The first alpha release dates back to January 4, 1993 and on February 17, 1994 version 1.0
was released. Version 4.0.0 was released on May 29, 2015.
The program is named after Octave Leve spiel, a former professor of the principal author.
Leve spiel is known for his ability to perform quick back-of-the-envelope calculations.
MATLAB −has the following common features with Octave
 matrices are fundamental data type
 it has built-in support for complex numbers
 it has built-in math functions and libraries
 it supports user-defined functions
GNU Octave is also freely redistributable software. You may redistribute it and/or modify it
under the terms of the GNU General Public License (GPL) as published by the Free Software
Foundation.

MATLAB vs Octave
Most MATLAB programs run in Octave, but some of the Octave programs may not run in
MATLAB because, Octave allows some syntax that MATLAB does not.
For example, MATLAB supports single quotes only, but Octave supports both single and
double quotes for defining strings. If you are looking for a tutorial on Octave, then kindly go
through this tutorial from beginning which covers both MATLAB as well as Octave.
Compatible Examples
Almost all the examples covered in this tutorial are compatible with MATLAB as well as
Octave. Let's try following example in MATLAB and Octave which produces same result
without any syntax changes −
This example creates a 3D surface map for the function g = xe -(x2 + y2). Create a script file and
type the following code −
[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)
print -deps graph.eps
When you run the file, MATLAB displays the following 3-D map −

v
Non-compatible Examples
Though all the core functionality of MATLAB is available in Octave, there are some
functionality for example, Differential & Integration Calculus, which does not match exactly
in both the languages. This tutorial has tried to give both type of examples where they
differed in their syntax.
Consider following example where MATLAB and Octave make use of different functions to
get the area of a curve: f(x) = x2 cos(x) for −4 ≤ x ≤ 9. Following is MATLAB version of the
code −
f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));
When you run the file, MATLAB plots the graph −

vi
The following result is displayed
a=
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)

Area:
0.3326
But to give area of the same curve in Octave, you will have to make use of symbolic package
as follows −
pkg load symbolic
symbols
x = sym("x");
f = inline("x^2*cos(x)");

ezplot(f, [-4,9])
print -deps graph.eps

[a, ierror, nfneval] = quad(f, -4, 9);


display('Area: '), disp(double(a));

Steps to Perform Experiments:


1. Click on to the Icon.

2. Octave window will be started.

3. Click on to New, then New Script. New Editor Window will be opened.

4. Type the Program on Editor Window. Click on run to save file and run.
5. If any Errors in instruction line we can see in Command window.

vii
6. Change the Directory Path. Waveform will be generated in Figure1.

viii
Experiment:1
Basic Operations on Matrices.
AIM: To Verify the basic operations of matrices
Software Required:
OCTAVE with PC

Theory: If the amplitude of the signal is defined at every instant of time then it is called
continuous signal. If the amplitude of the signal is defined at only at some instants of time
then it is called discrete signal.

If the signal repeats itself at regular intervals then it is called periodic signal.
Otherwise they are called aperiodic signals.

EX: ramp,Impulse,unit step, sinc- Aperiodic signals


square,sawtooth,triangular sinusoidal – periodic signals.

1. Ramp sinal:
r(t)= t when t>=0

Unit impulse signal:


Y(t)= 1 only when t=0 =0
other wise

Unit step signal:


u(t)= 1 only when t>=0 =0
other wise
Sinc signal:
G(x)=(sinx)/x

1
1.1 Basic Program for Addition, Subtraction, Multiplication, Division.

PROGRAM:
clear all;
close all;
clc;
A = input('Enter the Matrix A ::');
B = input('Enter the Matrix B ::');
%%%% Find the size of matrices
disp('The sise of Ma trix A is .... :: ');disp(size(A));
disp('The sise of Ma trix B is .... :: ');disp(size(B));
%%% Find the length of vector
P = length(A);
Q = length(B);
%%%% Addition of two ma trices
disp('Addition of A and B Matrices is .....:: ');
disp(A + B);
%%%%% Subtration of two matrices
disp('Subtraction of A and B Matrices is .....:: ');
disp(A - B);
%%%%% Multiplication (ELEMENT BY ELEMENT) of two matrices
disp('Multiplication of A and B Matrices is .....:: ');
disp(A.*B);
RESULT:

2
1.2. Basic Program for Determinant, Trace, Inverse, Rank of a Square Matrix.

PROGRAM:
clear all;
close all;
clc;
clear all;
close all;
clc;
A = input('Enter the Square Ma trix A ::');
% Finding the Rank of the matrix
disp('Rank of Matrix A is ::');disp(rank(A));
% Find the determinent of the matrix
disp('Determinent of Matrix A is ::'); disp(det(A));
% Find the trace of the matrix
disp('Trace of Matrix A is ::');disp(trace(A));
% Find the Inverse of the matrix
disp('Inverse of Matrix A is ::');disp(inv(A));
Result:

3
Experiment-2:
Generation of Various Signals and Sequences (Periodic and Aperiodic), such as Unit
Impulse, Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.
Software Required:
OCTAVE with PC

2.1.Generate Sinusoidal signal


clear all;
close all;
clc;
N = input('Enter the number of cycles ...:: ');
t = 0:0.05:N;
x = sin(2*pi*t);
subplot(1,2,1);
plot(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinusoidal');
subplot(1,2,2);
stem(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinusoidal');
Result:
Enter the Number of Cycles: :2

4
2.2.Generate Unit Impulse function
Program:
clear all;
close all;
clc;
x = ones(1,1);
y = zeros(1,2);
z = [y, x, y];
stem(z);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title(' Unit Impulse');
Result:

5
2.3.Generate Unit Step function

Program:
clear all;
close all;
clc;
x = ones(100);
subplot(2,1,1);
plot(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Step signal');
subplot(2,1,2);
stem(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Step signal');

OUTPUT

6
2.4 Generate Ramp Function:
Program:

clear all;
close all;
clc;
t = 0:25;
y = t;
subplot(1,2,1);
plot(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
subplot(1,2,2);
stem(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
OUTPUT

7
Experiment No. -3
AIM: perform the operations on signals and sequences such as addition , multiplication ,
scaling . shifting , folding and also compute energy and power.
Software Required:

OCTAVE with PC
.
Theory:

Signal Addition

Addition: any two signals can be added to form a third signal,

z (t) = x (t) + y (t)

Multiplication:
Multiplication of two signals can be obtained by multiplying their values at every instants .
z (t) = x (t) y (t)

Time reversal/Folding:
Time reversal of a signal x(t) can be obtained by folding the signal about t=0. Y(t)=y(-t)

Signal Amplification/Scaling : Y(n)=ax(n) if a < 1 attnuation


a >1 amplification
Time shifting: The time shifting of x(n) obtained by delay or advance the signal in time by
using y(n)=x(n+k)

If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal

Energy:
E=sum(abs(X).^2)

8
Average power:
P= (sum(abs(X).^2))/ length(x)

3.1 Addition and Multiplication of two Sequences

Program:
clear all;
close all;
clc;
x = input(' Enter sequence 1 :: ');
y = input(' Enter sequence 2 :: ');
M = length(x);
N = length(y);
subplot(2,2,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 1');
subplot(2,2,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
subplot(2,2,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');

9
title(' Addition of sequences 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
subplot(2,2,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of sequences 1 and 2');

OUTPUT:
Enter sequence 1 :: [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
Enter sequence 2 :: [5 6 7 8 9 9 8 7 6 5]

10
3.2 Scaling Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
a = input('Enter the scaling Factor ...:: ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i-1,a) == 0
s_scal = [s_scal,s(i)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel('---------> Time');
ylabel('---------> Amplitude');
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the scaling Factor ...:: 4

11
12
3.3 Shifting Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
a = input('Enter the length to be shifted ...:: ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' ---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');
ylabel('---------> Amplitude');

13
title('Shifted Sequence');
end;
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the length to be shifted ...:: 5

Enter the sequence ......:: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]


Enter the length to be shifted ...:: -5

14
3.4. Folding Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1, m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7]

15
Experiment No. -4

AIM: perform the operations on signals and sequences such as addition , multiplication ,
scaling . shifting , folding and also compute energy and power.
Software Required:
. OCTAVE with PC

Energy and Average Power on a given Sequence


Program:
clear all;
close all;
clc;
tes = input('Enter the sequence ...:: ');
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M
Output:
Enter the sequence ...:: [1 2 3 4 5 4 3 2 1]
Energy of the given sequence is ..... ::
Energy=85
Average Power of the given sequence is ..... ::
Average_Power=9.444

16
4.1. Addition and Multiplication of two Signals
Program:
clear all;
close all;
clear all;
close all;
clc;
t = 0:0.01:2;
x = sin(2*pi*t);
y = square(2*pi*t);
M = length(x);
N = length(y);
subplot(4,1,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signa l 1');
subplot(4,1,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signa l 2');

17
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
z = x + y;
subplot(4,1,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title(' Addition of signals 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
a = x.*y;
subplot(4,1,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of signals 1 and 2');
OUTPUT:

18
4.2. Scaling Operation on a given Signal
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the scaling Factor ...:: ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i,a) == 0
s_scal = [s_scal,s(i-1)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Scaled Sequence');
Output:
Enter the scaling Factor ...:: 3

19
20
4.3. Shifting Operation on a given Signal
Program:
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the length to be shifted ...:: ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' ---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');

21
ylabel('---------> Amplitude');
title('Shifted Sequence');
end;
Output:
Enter the length to be shifted ...:: 75

22
4.4 Folding Operation on a given Signal
Program:
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1, m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
Output:

23
4.5. Energy and Average Power on a given Signal
Program:
clc;
t = 0:0.01:4;
tes = cos(2*pi*t);
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M;
Output:
Energy of the given sequence is ..... ::
Energy =201
Average Power of the given sequence is ..... ::0.5012

24
Experiment No.-5
EVEN AND ODD PARTS OF SIGNAL AND SEQUENCE & REAL AND
IMAGINARY PARTS

AIM: Finding even and odd part of the signal and sequence and also find real and imaginary
parts of signal.

Software Required:
OCTAVE with PC

Theory:

EVEN AND ODD PART OF A SIGNAL:

Any signal x(t) can be expressed as sum of even and odd components I e
X(t)=xe(t)+xo(t)

5.1. Even and Odd part of Signal


Program:
clear all;
close all;
clc;
t = 0:10;
x = 2*sin(t);
y = -(4 * x);
subplot(2,2,1);
stem(x);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(t)');
subplot(2,2,2);
stem(y);

25
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(-t)');
even =0.5*(x + y);
subplot(2,2,3);
stem(even);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Even part');
odd = 0.5*(x - y);
subplot(2,2,4);
stem(odd);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Odd part');
Output:

26
5.2. Even and Odd part of Sequence
Program:
clear all;
close all;
clc;
x = input('Enter the sequence :: ');
y = -x;
subplot(2,2,1);
stem(x);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(t)');
subplot(2,2,2);
stem(y);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(-t)');
even =0.5*(x + y);
subplot(2,2,3);
stem(even);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Even part');
odd = 0.5*(x - y);
subplot(2,2,4);
stem(odd);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('O dd part');
Output:
Enter the sequence :: [1 2 3 4 3 2 1]

27
28
Experiment No.-6
CONVOLUTION BETWEEN SIGNALS& SEQUENCES

Aim: Write the program for convolution between two signals and also between two
sequences.

Software Required:
OCTAVE with PC
.

Theory:

If x(n)=h(n) [ impulse ) then output y(n) is known as impulse response of the system.
x(n)=δ(n)

y(n)=T[x(n)]=h(n) similarly δ (n-k)= h(n-k)


x(n) cab represented as weighted sum of impulses such as

y(n)=T[x(n)]

T[δ(n)=h(n) then T[ δ (n-k)] = h(n-k)

---------------- Linear Convolution equation

Thus output of LTI system is given by weighted sum of time-shifted impulse responses
Linear Convolution involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:

29
Program:

clc;
close all;
clear all;
%program for convolution of two sequences
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');ylabel('x(n)'); title('input signal')
subplot(3,1,2);
stem(h);
xlabel('n'); ylabel('h(n)');title('impulse response')
subplot(3,1,3);
stem(y);
xlabel('n');ylabel('y(n)'); title('linear convolution')
disp('The resultant signal is'); disp(y)

%program for signal convolution


t=0:0.1:10;
x1=sin(2*pi*t);
h1=cos(2*pi*t);
y1=conv(x1,h1);
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('t');ylabel('x(t)'); title('input signal')
subplot(3,1,2);
plot(t,h1);
xlabel('t'); ylabel('h(t)');title('impulse response')
subplot(3,1,3);
plot(y1);
xlabel('n');ylabel('y(n)'); title('linear convolution');

RESULT: convolution between signals and sequences is computed.


Output:

enter input sequence[2 4 6 8]


enter impulse response[1 3 9 6]
The resultant signal is2 10 36 74 102 108 48

30
31
Experiment No. -7
AUTO CORRELATION AND CROSS CORRELATION

AIM: Write the program to compute Auto correlation and Cross correlation between signals
and sequences.

Software Required:
OCTAVE with PC

Theory:
Correlations of sequences:

It is a measure of the degree to which two sequences are similar. Given two real-
valued sequences x(n) and y(n) of finite energy,

Convolution involves the following operations.

1. Shifting
2. Multiplication
3. Addition

These operations can be represented by a Mathematical Expression as follows:

Program:
clc;
close all;
clear all;

% two input sequences


x=input('enter input sequence');
h=input('enter the impulse suquence');
subplot(2,2,1);

stem(x);
xlabel('n'); ylabel('x(n)'); title('input sequence');
subplot(2,2,2);
stem(h);

32
xlabel('n'); ylabel('h(n)'); title('impulse signal');

% cross correlation between two sequences


y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n'); ylabel('y(n)'); title(' cross correlation between two sequences ');

% auto correlation of input sequence


z=xcorr(x,x);
subplot(2,2,4);
stem(z);
xlabel('n'); ylabel('z(n)'); title('auto correlation of input sequence');

% cross correlation between two signals


% generating two input signals
t=0:0.2:10;
x1=3*exp( -2*t);
h1=exp(t);
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('t');ylabel('x1(t)'); title('input signal');
subplot(2,2,2);
plot(t,h1);
xlabel('t'); ylabel('h1(t)');title('impulse signal');

% cross correlation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t'); ylabel('z1(t)'); title('cross correlation ');

% auto correlation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t'); ylabel('z2(t)'); title('auto correlation ');

Result: Auto correlation and Cross correlation between signals and sequences is
computed.
Output:
Enter input sequence [1 2 5 7]

Enter the impulse sequence [2 6 0 5 3]

33
34
Experiment No. -8
VERIFICATION OF LINEARITY OF A DISCRETE SYSTEM

AIM: Verify the Linearity of a given Discrete System.

Software Required:
OCTAVE with PC

Theory:

LINEARITY PROPERTY:
Any system is said to be linear if it satisfies the superposition principal. superposition
principal state that Response to a weighted sum of input signal equal to the corresponding
weighted sum of the outputs of the system to each of the individual input signals.

X(n) -----------input signal


Y(n) ---------output signal

Y(n)=T[x(n)]

Y1(n)=T[X1(n)] : Y2(n)=T[X2(n)]

x3=[a X1(n)] +b [X2(n) ]

Y3(n)= T [x3(n)]

= T [a X1(n)] +b [X2(n) ] = a Y1(n)+ b [Y


Let a [Y1(n)]+ b [X2(n) ] =Z 3(n)

a) Linearity of a system
clear all;
close all;
clc;
n=0:0.01:2;
a= -3; b= 5;
x1=cos(2*pi*n);
x2=cos(3*pi*n);
x=a*x1+b*x2;
ic=[0 0];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
y=filter(num,den,x,ic);
yt=a *y1+b*y2;

35
d=y-yt;
subplot(3,1,1), stem(n,y);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' y = a*x1 + b*x2');
subplot(3,1,2), stem(n,yt);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' yt = a*y1 + b*y2');
subplot(3,1,3), stem(n,d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' difference of y and yt');
Result:

i. Time Invariance of a system

Program:
clear all;
close all;
clc;
n=0:0.05:4;
D=10;
x=3*cos(2*pi*n)-0.5*cos(4*pi*n);
xd=[zeros(1,D) x];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
ic=[0 0];
y=filter(num,den,x,ic)

36
yd=filter(num,den,xd,ic)
d=y-yd(1+D:41+D);
subplot(3,1,1), stem(y);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('y ');
subplot(3,1,2), stem(yd);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('yd');
subplot(3,1,3), stem(d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' difference of y and yd');

Result:

37
Experiment:9
Computation of Unit sample, Unit step and Sinusoidal responses of the given LTI
system and verifying its physical realiazability and stability properties.

Software Required:
OCTAVE with PC

i. Impulse Response of an LTI system


Program:
clear all;
close all;
clc;
h = (-0.9).^[0:49];
subplot(2,2,1);
stem([0:49],h,'filled');
xlabel('Samples');
ylabel('Amplitude');
title(' h = (-0.9).^[0:49]');
u = ones(1);
subplot(2,2,2);
stem(u,'filled' );
xlabel('Samples');
ylabel('Amplitude');
title('Impulse');
s = conv(u,h);
subplot(2,2,[3,4]);
stem([0:49],s(1:50));
xlabel('Samples');
ylabel('Amplitude');
title('Response for an impulse');

Output:

38
ii. Step Response of an LTI system
Program:
clear all;
close all;
clc;
h = (-0.9).^[0:49];
subplot(2,2,1);
stem([0:49],h,'filled');
xlabel('Samples');
ylabel('Amplitude');
title(' h = (-0.9).^[0:49]');
u = ones(1,50);
subplot(2,2,2);
stem([1:50],u,'filled');
xlabel('Samples');
ylabel('Amplitude');
title('Step');
s = conv(u,h);
subplot(2,2,[3,4]);
stem([0:49],s(1:50));
xlabel('Samples');
ylabel('Amplitude');
title('Response for a step');

39
Output:

iii. Sinusoidal Response of an LTI System


Program:
clear all;
close all;
clc;
t = 1:0.04:2;
h = (-0.9).^t;
subplot(2,2,1);
stem(t,h,'filled');
xlabel('Samples');
ylabel('Amplitude');
title(' h = (-0.9).^t');
u = sin(2*pi*t);
subplot(2,2,2);
stem(t,u,'filled');
xlabel('Samples');
ylabel('Amplitude');
title('Sine');
s = conv(u,h);
subplot(2,2,[3,4]);
stem([0:49],s(1:50));
xlabel('Samples');

40
ylabel('Amplitude');
title('Response for a sine');
Output:

41
Experiment No-10

FINDING THE FOURIER TRANSFORM OF A GIVEN SIGNAL AND


PLOTTING ITS MAGNITUDE AND PHASE SPECTRUM

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

Software Required:
OCTAVE with PC

Theory:

Fourier Transform :

The Fourier transform as follows. Suppose that ƒ is a function which is zero outside of some
interval [−L/2, L/2]. Then for any T ≥ L we may expand ƒ in
a Fourier series on the interval [−T/2,T/2], where the "amount" of the wave e2πinx/T in the
Fourier series of ƒ is given by
By definition Fourier Transform of signal f(t) is defined as

Iverse Fourier Transform of signal F(w) is defined as

Program:
clc;
clear all;
close all;
fs=1000;
N=1024; % length of fft sequence
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]); grid;
xlabel('t'); ylabel('amplitude'); title('input signal');

% magnitude spectrum
x1=fft(x);
k=0:N-1;

42
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag); grid;
xlabel('t'); ylabel('amplitude'); title('magnitude of fft signal')
%phase spectrum
Xphase=angle(x1)
subplot(3,1,3);
plot(k,Xphase); grid;
xlabel('t'); ylabel('angle in degrees'); title('phase of fft signal');

Result: Magnitude and phase spectrum of FFT of a given signal is plotted.

Output:

43
Experiment No-11

LAPLACE TRANSFORMS & INVERSE LAPLACE TRANSFORMS

AIM: Finding the Laplace transform & Inverse Laplace transform of some signals.

Software Required:
OCTAVE with PC

Theory:

Bilateral Laplace transforms:

The Laplace transform of a signal f(t) can be defined as follows:

Inverse Laplace transform

The inverse Laplace transform is given by the following formula :

Program:

clc;
clear all; close
all;
%representation of symbolic variables
syms f t w s;
%laplace transform of t
f=t;
z=laplace(f);
disp('the laplace transform of f = '); disp(z);
% laplace transform of sin signal
f1=sin(w*t);
f2=sin(w*(t-1));
v1=laplace(f1);
disp('the laplace transform of f1 = '); disp(v1);
v2=laplace(f2);
disp('the laplace transform of f2 = '); disp(v2);
simplify(v2)
%inverse laplace transform
y1=ilaplace(z);
disp('the inverse laplace transform of z = '); disp(y1);

44
y2=ilaplace(v1);
disp('the inverse laplace transform of v1 = '); disp(y2);

y3=ilaplace(v2);
disp('the inverse laplace transform of v2 = '); disp(y3);

x1=11*s^3+52*s^2+86*s+72;
x2=4*s*(s+2)^2*(s+3);
x3=x1/x2;
y4=ilaplace(x3);
disp('the inverse laplace transform of x3 = '); disp(y4);

Output:
the laplace transform of f = 1/s^2

the laplace transform of f1 = w/(s^2+w^2)

the laplace transform of f2 = cos(w)*w/(s^2+w^2)-sin(w)*s/(s^2+w^2)

ans = -(-cos(w)*w+sin(w)*s)/(s^2+w^2)

the inverse laplace transform of z = t

the inverse laplace transform of v1 = sin(w*t)

the inverse laplace transform of v2 = sin(w*t)*cos(w)-cos(w*t)*sin(w)

the inverse laplace transform of x3 = -5/2*t*exp(-2*t)+5/4*exp(-3*t)+3/2

45
Experiment no:12

Aim: Verify Sampling theorem.

EQUIPMENTS:

OCTAVE with PC

Sampling Theorem: The sampling theorem specifies the minimum-sampling rate at which
a continuous-time signal needs to be uniformly sampled so that the original signal can be
completely recovered or reconstructed by these samples alone. This is usually referred to as
Shannon's sampling theorem in the literature.

A band-limited signal can be reconstructed exactly if it is sampled at a rate at least twice the
maximum frequency component in it.

Program:

t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');ylabel('x(t)')
title('continous time signal')
grid;
n1=-4:1:4
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs<2fm')
hold on
subplot(2,2,2);
plot(n1,x1)
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs=2fm')
hold on

46
subplot(2,2,3);
plot(n2,x2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs>2fm')
hold on
subplot(2,2,4);
plot(n3,x3)
grid;
Output:

Result: In this experiment the sampling theorem have been verified using MATLAB.

47
SYLLABUS
BASIC SIMULATION LAB
Course Code U21EC3L2
Course Objectives:
1. To impart the knowledge to write MATLAB codes for the generation of signals,
2. To perform different operations and to verify various transforms for converting time domain signal
to frequency domain signal.
Course Outcomes: Upon completion of the course, Students will be able to
1. Write MATLAB codes for the generation of signals
2. Apply various transforms on signals to find its Spectrum using MATLAB.
3. Correlate two signals and can remove noise using correlation.
4. Find the response of the system using convolution function in MATLAB.
5. Perform sampling of continuous time signals.
List of Experiments:
1. Basic Operation on Matrices

2. Generation of Various Signals and Sequences

3. Operations on Signals and Sequences

4. Finding the Even and Odd parts of Signals/Sequence

5. Convolution for Signals and sequences.

6. Auto Correlation and Cross Correlation for Signals and Sequences.

7. Verification of Linearity and Time Invariance Properties of a given Continuous/Discrete System.

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

9. Locating the Zeros and Poles and plotting the Pole-Zero maps in S-plane and Z-Plane for the given

transfer function.

10. Sampling Theorem Verification.

48

You might also like