Вы находитесь на странице: 1из 116

GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

DEPARTMENT OF
ELECTRONICS AND COMMUNICATIONS ENGINEERING

LAB MANUAL: STUDENT COPY

BASIC SIMULATION LAB


II Year B.Tech[ECE] - I Semester
Academic Year: 2016-17

Prepared By
BACHU SRINIVAS
Associate Professor
Department of ECE
D. NARESH
Assistant Professor
Department of ECE

Guru Nanak Institutions Technical Campus


School of Engineering and Technology
Ibrahimpatnam, R. R. District – 501 506
Telangana, India.

BASIC SIMULATION LAB 1


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

I. VISION, MISSION & QUALITY POLICY

The Vision of the Electronics and Communication Engineering department is:

To be a premier department of Electronics & Communication


Engineering in the region.

The Mission of the Electronics and Communication Engineering department is:

1. Nurture young individuals into knowledgeable, skillful and


ethical professionals in their pursuit of electronics and
communication engineering.

2. Nurture the faculty to expose them to world-class infrastructure.

3. Sustain high performance by excellence in teaching, research


and innovations.

4. Extensive partnerships and collaborations with foreign


universities for technology up gradation.

5. Develop Industry-Interaction for innovation and product


development.

The Quality policy of the Electronics and Communication Engineering


department is:

GNITC is committed to provide quality education through dedicated


and talented faculty, world class infrastructure, labs and updated
research center to the students. Quality teaching-learning process
and systems will help students to attain placements and prepare
them for higher studies.

II. ABOUT DEPARTMENT


ECE department of GNITC is flagship academic organ staffed by experienced,
highly qualified and dedicated faculty team. This department focuses on
imparting quality education so that the pass-outs are competent and readily
employable. There are constant efforts in this department to mould the
students to fit into global competitive scenario. Besides B. Tech program, it
also offers M. Tech in DECE and DSCE with an intake of 18 each.

BASIC SIMULATION LAB 2


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Besides focusing on robust fundamentals of the ECE, this department also


endeavors to train the students in communication and soft skills by a strict
insistence on seminar presentations right from the first year. More than 85%
of eligible students are placed into various organizations during the academic
year 2010-11. The department conducts short term advanced courses in the
fields of LAB View, MATLAB, and VHDL & Verilog, also in latest topics.

The Department excels in VLSI and Embedded Systems, Microwave


Engineering and Signal Processing and therefore undertakes research and
consultancy in these areas. The department has conducted an International
Conference entitled, SPVL- 2010 on 11th -13th June 2010. The department
also conducted a National Conference on “Recent Trends and Advances in
NANO Technology” in the month of July 2011.

The Dept. is also equipped with excellent infrastructure and state-of-the-art


equipment to explore technological advancements in the relevant fields. The
department has sufficient labs equipment and software required.

III. HIGHLIGHTS:
 Teaching methodology involves technical case studies, creative exercises,
online assignments & descriptive tests.
 E-Class rooms.
 Industry focused knowledge is imparted by R & D and Industry peer
members.
 Digital Library.
 Tie up with MNC companies and foreign Universities.
 State of art laboratories, sophisticated equipment and advanced
software.
 Library is equipped with National and International Journals, 50000
volumes and more than 7500 titles of books, NPTEL, SONET CDs and
internet lab for students and staff.
 IEEE online journals and IEL online journals through AICTE INDEST
CONSORTIUM.
 Wi-Fi campus with 12 Mbps bandwidth.
 MAT LAB, PSPICE, VHDL, TINAPRO and DSP software‟s are available.

BASIC SIMULATION LAB 3


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

 State of art English Language lab and 800 computers connected with
dedicated high- end servers.
 Scholarship and free books for meritorious students.
 Book Bank Scheme facility to the students.
 Most of the classrooms are fixed with LCDs and screens.
 All major professional societies‟ student chapters like ISTE, IETE and
IEEE etc.

IV. FACULTY
The faculty in the department consists of Senior and well experienced
Professors, Associate Professors and Assistant Professors with Ph. D. / M.
Tech qualifications. An experienced System Administrator and well-qualified
Lab staff support the conduct of Laboratories

PROGRAM ME EDUCATIONAL OBJECTIVES:


We, at GNITC are committed to ensure higher standards to educate enrich &
excel in imparting professional education by top quality faculty members,
endeavor to mould the students into quality professionals through teamwork
and research orientation.

PEO1. Graduates shall have the ability to apply knowledge across the
disciplines and in emerging areas of Electronics and Communications
Engineering for higher studies, research, employability and handle the
realistic problems.

PEO2. Graduates shall have good communication skills, possess ethical


conduct, sense of responsibility to serve the society, and protect the
environment.

PEO3. Graduates shall have strong foundation in academic excellence, soft


skills, managerial skills, leadership qualities and understand the need for
lifelong learning for a successful professional career.

PROGRAMME OUTCOMES

BASIC SIMULATION LAB 4


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

The following list of program outcomes describes what graduates are expected
to know and be able to do at the time of graduation. Graduates at graduation
will have:
A. An ability to apply knowledge of mathematics, science, and engineering
B. An ability to design and conduct experiments, as well as to analyze and
interpret data
C. An ability to design a system, component, or process to meet desired
needs within realistic constraints such as economic, environmental, social,
political, ethical, health and safety, manufacturability and sustainability.
D. An ability to function on multidisciplinary teams.
E. An ability to identify, formulate and solve engineering problems.
F. An understanding of professional and ethical responsibility.
G. An ability to communicate effectively.
H. The broad education necessary to understand the impact of engineering
solutions in a global, economic, environmental, and societal context.
I. An recognition of the need for, and an ability to engage in life-long
learning.
J. A knowledge of contemporary issues.
K. An ability to use the techniques, skills, and modern engineering tools
necessary for engineering practice.
L. An in-depth ability to use a combination of Software, Hardware and
experimental techniques practiced in circuits, physical electronics,
communication, networks, systems and programming.
MAPPING of PEOs and POs:
Progra Progrmme Outcomes
mme
Educa
tional A B C D E F G H I J K L
Object
ives
PEO 1 √ √ √ √

PEO 2 √ √ √ √ √ √

PEO 3 √ √ √ √ √ √ √ √ √ √

BASIC SIMULATION LAB 5


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

LIST OF EXPERIMENTS

Expt. Name of the Experiment (s) Page


No. No.
Basic Operations on Matrices.
1 12
Generation of Various Signals and Sequences (Periodic
and Aperiodic), such as Unit impulse, unit step,
2 17
square, saw tooth, triangular, sinusoidal, ramp, sinc.

Observations on signals and sequences such as


addition, multiplication, scaling, shifting, folding,
3 38
computation of energy and average power.

Finding the even and odd parts of signal/ sequence


4 and real and imaginary parts of signal. 51

Convolution between signals and sequences.


5 56
Autocorrelation and cross correlation between signals
6 and sequences. 59

Verification of linearity and time invariance properties


7 of a given continuous/discrete system. 64

Computation of unit sample, unit step and sinusoidal


responses of the given LTI s system and verifying its
8 70
physical realizability and stability properties.

Gibbs phenomenon.
9 73
Finding the Fourier transform of a given signal and
10 plotting its magnitude and phase spectrum. 75

Waveform synthesis using Laplace Transform.


11 78

BASIC SIMULATION LAB 6


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Ex Name of the experiment (s) Page


pt. no.
No.
Locating the zeros and poles and plotting the pole-zero
maps in S plane and Z-plane for the given transfer
12 81
function.

Generation of Gaussian noise (real and complex),


computation of its mean, M.S. Value and its Skew,
13 88
Kurtosis, and PSD, Probability Distribution Function.

Sampling theorem verification.


14 93
Removal of noise by autocorrelation / cross
15 correlation. 97

extraction of periodic signal masked by noise using


16 correlation 101

Verification of winer-khinchine relations.


17 104
Checking a random process for stationary in wide
18 sense. 107

ADDITIONAL PROGRAMS

1 Generation of discrete time signals 110

2 Raised cosine filter 112

3 To find DFT of given discrete time signal 114

BASIC SIMULATION LAB 7


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Introduction
MATLAB is a mathematical software package, which is used extensively in
academia and industry and stands for MATrix LABoratory. It is one of the
leading scientific and technical computing soft ware‟s, used by over 10,20,000
engineers and scientists in more than 100 countries, on all seven continents.

The primary developer, Professor Cleve Moler at the University of New


Mexico, eventually founded Mathworks, Inc,. to further develop and market
the product in a commercial setting. The first version of MATLAB was
produced in the mid 1970s as a teaching tool. The vastly expanded MATLAB
is now used for mathematical calculations and simulation in companies and
government lab ranging from aerospace, car design, signal analysis through
to instrument controlled & financial analysis. In industry, MATLAB is the tool
of choice for high productivity research, development and analysis.

 MATLAB is a high-performance language for technical computing. It


integrates computation, visualization, and programming in an easy-to-use
environment where problems and solutions are expressed in familiar
mathematical notation.
 It is one of the leading scientific and technical computing software.
 The name MATLAB stands for matrix laboratory
 In industry, MATLAB is the tool of choice for high-productivity research,
development, and analysis.
 As a matrix based system, it is a great tool for simulation and data
analysis.
 MATLAB is an indispensable Graphical User Interface(GUI) tool and can
be used it for proper understanding of concepts in several prescribed basic
and advanced subjects such as,
Mathematics
Signals and Systems
Probability Theory and Stochastic Processes

BASIC SIMULATION LAB 8


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Control Systems
Analog Communications
Digital signal Processing
VLSI Design
Digital Communications
Digital Image Processing
Satellite Communications
Wireless Communications
Embedded Systems
Artificial Neural Networks
 It provides several optional „toolboxes‟ such as statistical toolbox, Control
systems toolbox, Neural Networks toolbox, symbolic math tool box, Signal
Processing toolbox, etc., which are extremely useful for specific applications.
Each toolbox provides a set of functions written for a specific application

Fig. 1. MATLAB Desktop Layout

BASIC SIMULATION LAB 9


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Starting MATLAB
To start MATLAB, double-click the MATLAB shortcut icon on your Windows
desktop.
MATLAB Desktop
When you start MATLAB, the MATLAB desktop appears as shown inn figure
1, containing tools (graphical user interfaces) for managing files, variables,
and applications associated with MATLAB.

The Command Window


The command window is the place where you enter all the MATLAB
commands at the command prompt(>>)
The Command History Window
All the commands entered recently at the command prompt are stored in the
„command history‟ window,for future use,until you select and delete them
purposefully.

The Current Directory Window


The current directory window displays the list of all the files and folders
under the current directory, which happens to be the „work‟ subdirectory, by
default, under the MATLAB root directory.

Changing the Current directory


>>pathtool
A new window called „set path‟ window opens up. It shows all the directories
and subdirectories which are visible to MATLAB
Click on „Add folder‟
Click on up or down buttons until the E: drive appears. Select it by clicking
once on it
Click on „Make a new folder‟ and type „slab‟ in the folder window and say OK
Now the new directory is added to MATLAB search path
Click on „Save‟ and then „close‟

BASIC SIMULATION LAB 10


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Ensure first that the current directory is the one that is your own ,which can
be done either by typing the following command at the command prompt or
using the „view or change the current directory‟ option
>> cd E:\slab

MATLAB Editor and Debugger


After launching MATLAB and changing the current directory use the toolbar
and select File-> New->M-file to open the MATLAB editor and debugger
Save the file
File-> Save

BASIC SIMULATION LAB 11


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 1
BASIC OPERATIONS ON MATRICES

Variables
>>x=3+4
Creates a variable and assigns a value 7 to it
Expressions and Statements
MATLAB can be used as a simple calculator
>>34/7
>>log(12)
>>y=sqrt(17)
>>a=3+ 4*j
>>b=abs(a)
Entering Matrices
•Separate the elements of a row with blanks or commas.
•Use a semicolon, ; , to indicate the end of each row.
•Surround the entire list of elements with square brackets, [ ].
To enter a matrix, simply type in the Command Window
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
MATLAB displays the matrix you just entered.
A=
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
Sum, Transpose, and diag

Try these commands


>>sum(A)
MATLAB replies with

BASIC SIMULATION LAB 12


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ans =
34 34 34 34
>>A‟
ans =
16 5 9 4
3 10 6 15
2 11 7 14
13 8 12 1
And
>>sum(A')'
produces a column vector containing the row sums
ans =
34
34
34
34
The sum of the elements on the main diagonal is easily obtained with the help
of the diag function, which picks off that diagonal.
>>diag(A)
produces
ans =
16
10
7
1
and
sum(diag(A))
produces
ans =
34
>>diag(A)

BASIC SIMULATION LAB 13


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Subscripts
The element in row i and column j of A is denoted by A(i,j). For example,
A(4,2) is the number in the fourth row and second column.
The Colon Operator
The colon, :, is one of MATLAB‟s most important operators. It occurs in
several
different forms. The expression
1:10
is a row vector containing the integers from 1 to 10
1 2 3 4 5 6 7 8 9 10
Operations on Vectors
Let a=[5 2 1 4 3] , b=[ 8 6 7]
MATLAB
Meaning Example
Function
min Smallest element min (a) = 1

max Largest element max (b) = 8


Total number of
length length (b) = 3
elements
Sum of all
sum sum (b) = 21
elements
Product of all
prod prod (a) = 120
elements
mean Average value mean (a) = 3
Standard
std std (a) = 1.5811
deviation
median Median value median (b) = 7

The magic Function


MATLAB actually has a built-in function that creates magic squares of almost

BASIC SIMULATION LAB 14


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

any size. Not surprisingly, this function is named magic.


B = magic(4)
B=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Arithmetic and Relational Operators

Arithmetic
Operator Operation
+ Addition
- Subtraction
* Matrix Multiplication
.* Array Multiplication
/ Division
^ Matrix Power
.^ Array Power

' Transpose

Relational Operators
= = Equal
~ = Not Equal
< Less Than
< = Less Than or Equal
> Greater Than
> = Greater Than or Equal
Matrix Functions
Eye Identity matrix
zeros Matrix of zeros
ones Matrix of ones

BASIC SIMULATION LAB 15


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

diag Diagonal matrix


rand Matrix with
random elements
triu Upper triangular part of matrix

tril Lower triangular part of matrix


magic Magic square matrix
size Size of matrix
length Length of vector
sum Sum of elements
inv Inverse of matrix
eig Eigen value
rank Rank of matrix
det Determinant of matrix
norm Norm of matrix
poly Characteristic polynomial
trace Trace of matrix
prod Product of elements
mean Average value

BASIC SIMULATION LAB 16


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 2
GENERATION OF VARIOUS SIGNALS AND SEQUENCES (PERIODIC
AND APERIODIC), SUCH AS UNIT IMPULSE, UNIT STEP, SQUARE,
SAW TOOTH, TRIANGULAR, SINUSOIDAL, RAMP, SINC
2(a) Unit Step Signal
Aim:
To generate unit step signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Unit Step sequence:
The unit step function is that type of elementary function which exists
only for positive side and zero for negative side.

1, n  0
Un   
0, otherwise

Program:
clc;
clear all;
close all;
n=[-5:0.5:5]; % Specifying the discrete time index n
x1=1;

BASIC SIMULATION LAB 17


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

x2=0;

u=x1.*(n>=0)+x2.*(n<0);

subplot(2,1,1);
stem(n,u,'b')
grid; % Sets the X Grid, Y Grid lines
axis([-5 5 -.2 1.2]); % sets scaling for the x- and y-axes
xlabel('time(n) ---->'); % adds text beside the X-axis
ylabel('U(n) ---->'); % adds text beside the Y-axis
title('Fig (a): Unit step sequence');

%% Unit step signal in continuous case


t=[-5:0.005:5]; % Specifying the time index n
x1=1;
x2=0;

u=x1.*(t>=0)+x2.*(t<0);

subplot(2,1,2);
plot(t,u,'b')
grid; % Sets the X Grid, Y Grid lines
axis([-5 5 -0.2 1.2]); % sets scaling for the x- and y-axes
xlabel('time(t) ---->'); % adds text beside the X-axis
ylabel('U(t) ---->'); % adds text beside the Y-axis
title('Fig (b): Unit step signal ');

Output:

Result:

BASIC SIMULATION LAB 18


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(b) Unit Ramp Signal


Aim:
To generate unit ramp signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Unit Ramp Signal:
The unit ramp signal is defined as:

n, n  0
R n   
0, otherwise

Program:
clc;
clear all;
close all;

n=[-5:0.5:5]; % Specifying the time index n


x1=n;
x2=0;

r=x1.*(n>=0)+x2.*(n<0);

stem(n,r,'*');
grid;
axis([-5 5 -0.2 1.2]);

BASIC SIMULATION LAB 19


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

xlabel('time(n) ---->');
ylabel('R(n) ---->');
title('Fig (a): Unit ramp sequence‟);

Output:

Result:

BASIC SIMULATION LAB 20


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(c) Unit Parabolic Signal


Aim:
To generate unit parabolic signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Unit Parabolic Signal:
The unit parabolic signal is defined as:

 n2

Pn    2 , n  0
0, otherwise

Program:
clc;
clear all;
close all;

n=[-5:0.5:10]; % Specifying the discrete time


index n

x1=((n.^2)/2);
x2=0;

p=x1.*(n>=0)+x2.*(n<0); % Generate the parabolic


sequence

stem(n,p,'k');
grid;

BASIC SIMULATION LAB 21


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

axis([-5 10 -0.2 60]);


xlabel('time(n) ---->');
ylabel('P(n) ---->');
title('Fig (a): Unit parabolic sequence');

Output:

Result:

BASIC SIMULATION LAB 22


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(d) Unit Impulse Signal


Aim:
To generate unit impulse signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Unit Impulse sequence:
In discrete time unit impulse function is also known as an unit-
sample signal. It is a signal that is zero everywhere, except at n=0
where it is a value is unity.

1, n  0
 n   
0, otherwise

Program:
clc;
clear all;
close all;
n=[-5:0.5:5]; % Specifying the discrete time index n
x1=1;
x2=0;

ui=x1.*(n==0)+x2.*(n>0)+x2.*(n<0);

stem(n,ui,'b');
grid;

BASIC SIMULATION LAB 23


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

axis([-5 5 -0.2 1.2]);


xlabel('time(n) ---->');
ylabel('P(n) ---->');
title('Fig (a): Unit Impulse sequence');

Result:

Output:

BASIC SIMULATION LAB 24


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(e) Signum Function


Aim:
To generate Signum function.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Signum Function:
The Signum function is defined as:

1, n  0

Sgnn   0, n  0
- 1, n  0

Program:

clc; clear all;close all;


n=[-5:0.5:5]; % Specifying the discrete time index n
x1=1;
x2=0;
x3=-1;

sig=x1.*(n>0)+x2.*(n==0)+x3.*(n<0);

stem(n,sig);
grid;
axis([-5 5 -1.2 1.2]);
xlabel('time(n) ---->');
ylabel('Sgn(n) ---->');

BASIC SIMULATION LAB 25


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

title('Fig (a): Signum Funcnion');

Result:

Output:

BASIC SIMULATION LAB 26


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(f) SinC Function


Aim:
To generate SinC function.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
SinC function:
The SinC function is defined as:

SinC(t)=Sin(π t)/
(π t)

Program:
clc;
clear all;
close all;
%% Sinc function (continuous case)
t=[-3:0.1:3];
x=sin(pi*t)./(pi*t);
subplot(1,2,1);
plot(t,x);
grid();
axis([-3 3 -0.4 1.2])
xlabel('----->time(t)');
ylabel('----->sinc(t)');
title('Fig a): Sinc function (continuous case)');

BASIC SIMULATION LAB 27


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

% Sinc function (discrete case)


n=[-3:0.1:3];
x=sin(pi*n)./(pi*n);
subplot(1,2,2);
stem(n,x);
grid();
axis([-3 3 -0.4 1.2])
xlabel('-----> discrete time(n)');
ylabel('----->sinc(n)');
title('Fig(b): Sinc function (discrete case)');
Output:

Result:

BASIC SIMULATION LAB 28


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(g) Generation of Periodic Signals

Aim: To generate the following periodic signals and sequences using MATLAB
software.
1. Sine 2. Saw tooth
3. Triangular 4. Square

Theory:
Sine Wave:
The sine wave or sinusoid is a mathematical curve that describes a smooth
repetitive oscillation. It is named after the function sine, of which it is the
graph as shown in Fig. 3(a). It‟s most basic form as a function of time (t) is:
X(t)=ASin(ωt)
Where, A is the Amplitude, is the peak deviation of the function from zero.
ω=2πf is the angular frequency is the rate of change of the function argument
in units of radians per second
f is the ordinary frequency, is the number of oscillations (cycles) that occur
each second of time.

Sine and Cosine Waves

Saw tooth Wave:


A saw tooth wave is an expression of waveform amplitude. A saw tooth wave
is a non-sinusoidal wave. It is also known as "saw wave" as shown in Fig.

BASIC SIMULATION LAB 29


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(b). As its name suggests, this waveform resembles the teeth of a saw. A saw
tooth wave generally goes upward like a hill and drops down sharply. It can
also go downwards and then rise up sharply. This form of wave is known as
"reverse saw tooth wave" or “inverse saw tooth wave”. A saw tooth wave
comprises infinite set of harmonically related sine waves. This wave is often
used in sound synthesis.

Saw-tooth Wave

Triangular Wave
A wave whose amplitude rises along a straight line to a given maximum, then
returns quickly to the baseline again following a linear path. Alternatively,
such a wave may rise quickly to a given peak, then drop gradually following a
linear path is as shown in Fig. 3(c).

Triangular Wave

Square Wave
A waveform that rises quickly to particular amplitude remains constant for a
time period and drops fast at the end as shown in Fig. 3(d). In digital systems,
square waves are the norm, because they represent a binary digit (0 or 1).

BASIC SIMULATION LAB 30


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Square waves can also be generated in musical synthesizers and have a raspy
sound.

Square Wave

Program: (i) To Generate Sinusoidal signal

clc;
clear all;
close all;
N = input('Enter the number of cycles ...:: ');
t = 0:0.05:N; % Set time index 0 to N

x = sin(2*pi*1*t); % generates the sinusoidal signal

subplot(1,2,1);
plot(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('a. Sinusoidal signal in continuous case');

subplot(1,2,2);
stem(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('b. Sinusoidal signal in discrete case‟');

Output:

Enter the number of cycles ...:: 2

BASIC SIMULATION LAB 31


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program: (ii) Generate Saw tooth Waveform

clc;

clear all;

close all;
N = input('Enter the number of cycles ...:: ');

t1 = 0:25;
t = [];

for i = 1:N,
t = [t,t1];
end;

subplot(2,1,1);
plot(t);
xlabel('---------> Time');ylabel('---------> Amplitude');
title('a.Sawtooth waveform in continuous case');

subplot(2,1,2);
stem(t);
xlabel('---------> Time');ylabel('---------> Amplitude');
title('b.Sawtooth waveform in discrete case ');
Output:

Enter the number of cycles ...:: 3

BASIC SIMULATION LAB 32


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program: (iii). Generate Triangular Waveform


clc;
clear all;
close all;
N = input('Enter the number of cycles .....:: ');

M = input('Enter the period ....:: ');

t1 = 0:0.1:M/2;

t2 = M/2:-0.1:0;

t = [];

for i = 1:N,
t = [t,t1,t2];
end;

subplot(1,2,1);
plot(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Triangular waveform');

subplot(1,2,2);
stem(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Triangular waveform');

Output:
Enter the number of cycles .....:: 3
Enter the period ....:: 4

BASIC SIMULATION LAB 33


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program: (iv) Generate Square waveform

clc;
clear all;
close all;
t = 0 : 0.0001 : 0.1;
y = square ( 2 * pi * 50 * t);
plot(t , y);
grid;
axis ( [ 0 0.1 -2 2 ] );
xlabel('Time index t');
ylabel('Amplitude');
title('Square Wave Signal');
Output:

BASIC SIMULATION LAB 34


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

2(h) Generation of Saw tooth and Triangular waves using Saw tooth
Function
Aim:
To generate saw tooth wave signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Repeating waveform that rises from zero to maximum value linearly drops
back to zero and repeats.
Program:
fs = 10000;
t = 0 : 1/fs : 1.5;
x = sawtooth (2 * pi * 100 * t);
plot( t , x ); axis ( [ 0 0.05 -1 1 ] );
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title ('Sawtooth Wave Signal Sequence');
Output:

Result:

BASIC SIMULATION LAB 35


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Aim:
To generate a triangular wave signal.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Program:
fs = 10000;
t = 0 : 1/fs : 1.5;
x = sawtooth (2 * pi * 50 * t , 0.5);
plot(t,x); axis ( [ 0 0.1 -1 1 ] );
xlabel('Time Index t (sec.)');
ylabel('Amplitude');
title('Triangular Wave Signal Sequence');
Output:

Result:

Viva Questions:

1. What is subplot(), stem(), plot()?


2. What is xlabel(), ylabel(), title()?
3. What do you mean by time scale?
4. Generate the following figures
Fig(a) Fig(b)

BASIC SIMULATION LAB 36


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Fig(c) Fig(d)

Fig(e)

***

BASIC SIMULATION LAB 37


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-3
OBSERVATIONS ON SIGNALS AND SEQUENCES SUCH AS
ADDITION, MULTIPLICATION, SCALING, SHIFTING, FOLDING,
COMPUTATION OF ENERGY AND AVERAGE POWER

3(a) Addition and Multiplication of Two Signals


Aim:
To perform the addition and multiplication of two signals
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Addition of continuous/discrete time signals:
The addition of two continuous time signals is performed by adding the
value of the two signals corresponding to the same instant of time.
The sum of two signals x 1 t  and x 2 t  is a signal yt  , whose value at any
instant is equal to the sum of the value of these two signals at that instant.
i.e., yt  = x 1 t  + x 2 t 

Multiplication of continuous/discrete time signals:

The multiplication of two continuous time signals is performed by


multiplying the value of the two signals corresponding to the same instant of
time.
The product of two signals x 1 t  and x 2 t  is a signal yt  , whose value at
any instant is equal to the product of the values of these two signals at that
instant.
i.e., yt  = x 1 t   x 2 t 

Program:

%% Addition and Multiplication of the two signals (sine and cosine signals)

BASIC SIMULATION LAB 38


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

clc;
clear all;
close all;

%% Generation of sine wave


fm=input('Enter the "fm" (Message freq) for the sine and cosine waves:');
fs=20*fm; % sampling frequency

Ts=1/fs;

t=0:Ts:.003;

x1=sin(2*pi*fm*t);

subplot(2,2,1);

stem(t,x1,'filled');grid;

axis([0 0.003 -1.5 1.5]);

xlabel('Time (sec) ---->')

ylabel('Amplitude ---->')

title('Fig(a): Sine wave')

%% Generation of cosine wave


x2=cos(2*pi*fm*t);

subplot(2,2,3);

stem(t,x2','filled');

grid;

axis([0 0.003 -1.5 1.5]);

xlabel('Time (sec)')

BASIC SIMULATION LAB 39


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ylabel('Amplitude')

title('Fig(b): Cosine wave')

%% Multiplication of the two signals and ploting the output


ym=x1.*x2;

subplot(2,2,2);

stem(t,ym,'*','r');grid();

axis([0 0.003 -1.5 1.5])

xlabel('Time (sec) ---->')

ylabel('Amplitude ---->')

title('Fig(c): Multiplication of Sine and Cosine waves')

%% Addition of the two signals and plotting the output


ya=x1+x2;

subplot(2,2,4);

stem(t,ya,'*','k');

grid;

axis([0 0.003 -1.5 1.5]);

xlabel('Time (sec) ---->')

ylabel('Amplitude ---->')

title('Fig(d): Addition of Sine and Cosine waves')

Output:

Enter the "fm" (Message freq) for the sine and cosine waves: 350

Result:

BASIC SIMULATION LAB 40


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(b) Amplitude/Time Scaling of a Signal


Aim:
To perform the amplitude/time scaling of a sine wave signal
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:

Scaling of a signal:

The two types of scaling continuous time signals are,


i. Amplitude scaling
ii. Time Scaling
i. Amplitude scaling:
The amplitude scaling is performed by multiplying the amplitude of the
signal by a constant.

Let x t  be a continuous time signal. Now A x t  is the amplitude scaled

version of x t  , where A is a constant.

When | A | 1 , then A x t  is the amplitude magnified version of x t  and

when | A | 1 , then A x t  is the amplitude attenuated version of x t  .

ii. Time Scaling:


The time scaling is performed by multiplying the variable time by a constant.
If x t  be a continuous time signal, then x Kt  is the amplitude scaled version

of x t  , where K is a constant.

When | K | 1 , then x Kt  is the time compressed version of x t  and

when | K | 1 , then x Kt  is the time expanded version of x t  .

BASIC SIMULATION LAB 41


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:

%% Generation of the sine wave signal with scaling (Amplitude / Time)

clc;
clear all;
close all;
fm=input('Enter the message frequency(fm) for generating sine wave is..::');
k=input('Enter the time scaling value(k)');
A=input('Enter the amplitude scaling value(A)');

fs=50*fm; % sampling frequency


Ts=1/fs; % sampling interval
t=0:Ts:4; % sampling instants
x1=sin(2*pi*fm*t);
x2=sin(2*pi*fm*k*t); % To generate the sine wave with time scaling
x3=A*sin(2*pi*fm*t); % To generate the sine wave with amplitude scaling

subplot(2,2,1);
plot(t,x1);
axis([0 .2 -2 2]);grid();
xlabel('Time(sec) ---->');
ylabel('Amplitude ---->');
title('Fig(a): Sine wave without scaling')

subplot(2,2,2);
plot(t,x2,'r');
axis([0 0.2 -2 2]);grid;
xlabel('Time(sec) ---->');
ylabel('Amplitude ---->');
title('Fig(b): Sine wave with time scaling');

BASIC SIMULATION LAB 42


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

subplot(2,2,4);
plot(t,x3,'r');
axis([0 .2 -A-1 A+1]);
grid;
xlabel('Time(sec) ---->');
ylabel('Amplitude ---->');
title('Fig(c): Sine wave with amplitude scaling');

Output:

Enter the message frequency (fm) for generating sine wave is...: 100

Enter the time scaling value (k): 0.5

Enter the amplitude scaling value (A): 6

Result:

BASIC SIMULATION LAB 43


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(d) Time Shifting (Right/Left side)


Aim:
To perform the time shifting operation on a signal/sequence
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:

Time Shifting:

The time shifting of a continuous time signal x t  is performed by replacing the

independent variable‟ t‟ by „t-m‟, to get the time shifted signal x t  m  , where


m represents the time shift in seconds.
In x t  m  , if m is +ve, then the time shift results in a delay by m seconds. The

delay results in shifting the original signal x t  to right, to generate the time

shifted signal x t  m  .

In x t  m  , if m is -ve, then the time shift results in an advance of the signal by

|m |seconds. The advance results in shifting the original signal x t  to left, to

generate the time shifted signal x t  m  .

Program:

%% Ttime shifting (Right/Left side) of a sequence

clc;
clear all;
close all;

n=0:1:5;
h=[2,3,-4,3,2,-5]; % Generate the impulse sequence

BASIC SIMULATION LAB 44


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

rst=input('Enter Right sided shifting time in +ve integer..:');


lst=input('Enter Left sided shifting time in -ve integer..:');

subplot(2,2,1)
stem(n,h); % plot the impulse sequence
grid;
xlabel('----> n');ylabel('----> h(n)');
title('Fig(a): Impulse sequence');

subplot(2,2,3)
stem(n+rst,h); % plot the right side shifted sequence
grid;
xlabel('----> n');ylabel('----> h(n)');
title('Fig(b): Right side shifted sequence');

subplot(2,2,4)
stem(n-lst,h); % plot the left side shifted sequence
grid;
xlabel('----> n');
ylabel('----> h(n)');
title('Fig(c): Left side shifted sequence');

Output:

Enter Right sided shifting time in +ve integer..: 6

Enter Left sided shifting time in -ve integer..: 48

Result:

BASIC SIMULATION LAB 45


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(e) Folding (Reflection or Transpose)


Aim:
To perform the folding operation on a signal/sequence
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:

Folding (Reflection or Transpose):

The folding of a continuous time signal x t  is performed by changing the sign

of time base t in the signal x t  .The folding operation produces a signal x  t 

which is a mirror image of the original signal x t  with respect to the time
origin t=0.

Program:

clc;
clear all;
close all;
t=[0:0.01:1];
A=4; % Assighn the apmlitude
f=5; % Create a 5 Hz sine wave lasting 1 sec

x=A*sin(2*pi*f*t);
lx=length(x);
tx=0:lx-1; % set arange for +ve X-axis

xf=fliplr(x); % perform the folding operation on the signal


tf=-fliplr(tx); % Fold the vector'nx' to get a mirror image vector 'nf'

BASIC SIMULATION LAB 46


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

subplot(2,1,1);
plot(tx,x);
xlabel('----> tx');
ylabel('---> Amplitude');
title('Fig(a): Original signal')

subplot(2,1,2);
plot(tf,xf);
xlabel('----> nf');
ylabel('---> Amplitude');
title('Fig(b): Folded signal')

Output:

Result:

BASIC SIMULATION LAB 47


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(f) Energy of a Signal


Aim:
To calculate the energy of a signal
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Energy of a signal:

A signal with finite energy is an energy signal. An exponentially decaying


signal that exists only for t > 0 is an energy signal. On the other hand, a
signal that has a finite and nonzero power is a power signal. The periodic
signals are power signals, and since these signals are everlasting, they have
infinite energy. Since the periodic signals have infinite energy, we calculate
the power delivered by them.

Program:

clc;clear all;close all;


n = 0:1:30;
x = (1/2) .^ n;
stem(n,x);
axis([-1 20 -1 2]);
E = sum(abs(x).^2)
disp( ' The calculated Energy E of the signal is ' );
disp(E);

Output:
The calculated Energy E of the signal is
1.3333

Result:

BASIC SIMULATION LAB 48


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

3(g) Power of a Signal


Aim:
To calculate the power of a signal
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Power of a signal:

Power by definition is the energy per second. To summarize, a power signal


has infinite energy and a finite power, and and an energy signal has a finite
energy and zero power, where the average power is computed as energy over
infinite time. It is clear that a signal cannot be both a power signal and an
energy signal. It has to be either of the two. But it is possible for a signal to be
neither of the two. For instance, a ramp signal is neither a power signal nor
an energy signal. A ramp signal has infinite power and infinite energy. Such a
signal exists in theory, but not in real world. If an everlasting exponential
signal is defined as exp(at), it is neither an energy signal nor a power signal,
as long as a is a positive or a negative real value. If the value of a is either
zero or imaginary, then the signal is a power signal. If the value of a is zero,
then the signal is a dc ignal, and if the value of a is imaginary, then the
signal is an alternating signal.

Program:

clc;
clear all;
close all;
N = 10;
t = -N : 0.0001 : N;
x = cos (2 * pi * 50 * t ) .^ 2;
P = sum(abs(x).^2)/length(x);
BASIC SIMULATION LAB 49
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

disp( ' The calculated Power P of the signal is ' );


disp(P);
plot(t,x);
axis ([0 0.1 0 1]);
title('Cosine wave with f=50hz')

Output:
The calculated Power P of the signal is
0.3750

Result:

Viva Questions:

1. What Operations can be performed on Signals and Sequences?


2. Define Causality and Stability?
3. Define Scaling property and give its importance.
4. Define Shifting property and give its importance.
5. Define Folding property and give its importance.
6. Give the expressions for finding the Energy of a Signal/Sequence?
7. Give the expressions for finding the Average Power of a
Signal/Sequence?
8. Perform all the operations on the following Sequences
a. x(n) = {1 1 1 1 1 1 1 0 0 0 0 0 0 } b) x(n) = {2 3 4 5 6 6 5 4 3 2 1}
9. Find the Energy and Average Power of a Signal defined
a. x(t) = 10*U(t) – 20*U(t – 2) b) x(t) = 1.5*t2U(t)

***

BASIC SIMULATION LAB 50


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-4
EVEN AND ODD PARTS OF SIGNAL/SEQUENCE & REAL AND IMAGINARY
PARTS OF SIGNAL
4(a) Even and Odd parts of Signal/Sequence

Aim:
To find the even and odd & real and imaginary of the given
signal/sequence
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
One of the characteristics of signal is symmetry that may be useful for signal
analysis. Even signals are symmetric around vertical axis, and Odd signals
are symmetric about origin.

Even Signal: A signal is referred to as an even if it is satisfies the following


condition;
x (t)=x(-t)
Statement: A signal is referred to as an even if it is identical to its time
reversed counterparts.

Odd Signal: A signal is referred to as an odd if it is satisfies the following


condition;
x (t) = - x(-t)
An odd signal must be zero at t=0, in other words, odd signal passes the
origin.
Using the definition of even and odd signal, any signal may be decomposed
into a sum of its even part, Xe (t ) and its odd part Xo (t ) , as follows:

X(t)  Xe (t)  Xo (t)

BASIC SIMULATION LAB 51


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)


1
X(t )  X(t ) 1 X(t )  X(t )
2 2

Where X e ( t ) 
1
X(t )  X(t ) , Xo (t )  1 X(t )  X(t )
2 2
Example: sine function is odd signal and cosine function is even signal.

Program:
clc;
clear all;
close all;
t=[-3:0.1:3];
x1=exp(2*t);
x2=exp(-2*t); % Generae the time folded signal

%% Check the given signal is Even or Odd


if(x2==x1)
disp('"The given signal is even signal"');
else if(x2==(-x1))
disp('"The given signal is odd signal"');
else
disp('"The given signal is neither even nor odd signal"');
end
end

%% Generate the even and odd parts


xe=(x1+x2)/2; % Comute even part
xo=(x1-x2)/2; % Comute odd part

ymin=min([min(x1), min(x2), min(xe), min(xo)]);


ymax=max([max(x1), max(x2), max(xe), max(xo)]);

subplot(2,2,1);
plot(t,x1);

BASIC SIMULATION LAB 52


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

axis([-3 3 ymin ymax]);


xlabel('-----> t');
ylabel('x1(t)');
title('Fig(a): Given Signal x(t)');

subplot(2,2,2);
plot(t,x2);
axis([-3 3 ymin ymax]);
xlabel('-----> t');
ylabel('x2(t)');
title('Fig(b):Time folded Signal x(-t)');

subplot(2,2,3);
plot(t,xe);
axis([-3 3 ymin ymax]);
xlabel('-----> t');
ylabel('xe(t)');
title('Fig(c):Even part of x(t)');

subplot(2,2,4);
plot(t,xo);
axis([-3 3 ymin ymax]);
xlabel('-----> t');
ylabel('xo(t)');
title('Fig(d):Odd part of x(t)');

Output:
"The given signal is neither even nor odd signal"

Result:

BASIC SIMULATION LAB 53


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

4(b) Real and Imaginary parts of Signal/Sequence

Aim: To find the Real and Imaginary parts of the Exponential signal
  1  
    i  t
x(t )  Ae   12  6 

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
A signal can be represented as a vector with real (Re) and imaginary (Im)
components recorded from the I and Q channels respectively. An
equivalent/alternative representation of the signal is as a complex number.

Signal = (Re, Im) = Re + i


Im
where i² = −1, the imaginary
unit. Its magnitude and
phase can be calculated by
simple trigonometry as
shown in Fig.
Fig. Representation of a signal in terms
of real and imaginary components.
Program:
clc;clear all;close all;

%% To generate the exponential function


c = -(1/12)+(pi/6)*i;
A = 2;
t = 0:2:35;

x = A*exp(c*t); %generating the exponential function

rx= real(x);
ix=imag(x);

BASIC SIMULATION LAB 54


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

subplot (2,1,1);
plot(t,rx); % Plot Real part
xlabel('time index n ----->');
ylabel('Amplitude ----->');
title('Fig(a): Real part of the given sequence');

subplot (2,1,2);
plot (t,ix); % Plot Imaginary part
xlabel('Time index n ----->');
ylabel('Amplitude ----->');
title('Fig(b): Imaginary part of the given sequence');

Output:

Result:

Viva Voce Questions:


1. Define Continuous time even signal
2. Define continuous time anti-symmetric signal
3. Define discrete time symmetric signal
4. Define discrete time odd signal
5. Which MATLAB command opens an empty graph window
6. When two even signals are subtracted, will the resultant signal be an
even signal or an odd signal
7. Define conjugate symmetric signal
8. Define conjugate asymmetric signal
9. Write MATLAB code to prove the following
10. The sum or product of two even signals is even
11. The sum of an even signal and an odd signal is neither even nor odd
12. The product of two odd signals is even

BASIC SIMULATION LAB 55


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-5
CONVOLUTION BETWEEN SIGNALS/SEQUENCES
Aim:
To find the output with linear convolution operation using MATLAB
software
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Discrete or Linear convolution:
The Discrete or Linear convolution of x1 n  and x 2 n  is defined as,

x 3 n  x1 n* x 2 n  x 2 n* x1 n



i.e., x 3 n    x k x n  k 
1 2
k  

or

x 3 n    x k x n  k 
2 1
k  

Where, x 3 n is the sequence obtained by convoluting x 1 n  and x 2 n 

K is a dummy variable
If the sequence x 1 n  has N 1 samples and x 2 n  has N 2 samples then the

output sequence x 3 n will be finite duration sequence consisting of “ N 1 + N 2 -1”

samples. The convolution results in a non-periodic sequence. Hence this


convolution is also called aperiodic convolution.
Procedure:
1. Change of index
2. Folding
3. Shifting
4. Multiplication
5. Summation

BASIC SIMULATION LAB 56


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:
%% Linear Convolution of two Signals using conv() function
clc;
clear all;
close all;

x=input('Enter the input sequence x(n) like [a c f - - -]= ');


h=input('Enter the Impulse sequence h(n) like [a c f - -]= ');
y=conv(x,h);
disp('The resultant sequence is: ');disp(y);
subplot(3,1,1);
stem(x);
xlabel('----> n');
ylabel('----> x(n)');
title('Fig(a): Input sequence');

subplot(3,1,2);
stem(h);
xlabel('----> n');
ylabel('----> h(n)');
title('Fig(b): Impulse sequence');

subplot(3,1,3);
stem(y);
xlabel('----> n');
ylabel('----> y(n)=x(n)*h(n)');
title('Fig(c): Resultant sequence of Linear convolution');

Output:
Enter the input sequence x(n) like [a c f - - -]= [-1 -2 -3 -4]
Enter the Impulse sequence h(n) like [a c f - -]= [1 2 3 4]

BASIC SIMULATION LAB 57


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

The resultant sequence is:


-1 -4 -10 -20 -25 -24 -16

Result:

Viva Voce Questioins:


1. Define convolution
2. What is the significance of convolution?
3. Which operator denotes the convolution between two signals?
4. Which mathematical equation represents the convolution between two
sequences?
5. What are the steps involved in the convolution operation?

BASIC SIMULATION LAB 58


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-6
AUTO CORRELATION AND CROSS CORRELATION BETWEEN SIGNALS
AND SEQUENCES
Aim:
To verify the auto correlation and cross correlation function
Software used:
1. Operating system-Windows XP
2. MATLAB 7.0.1v
Theory:
Correlation is a measure of similarity between two continuous or discrete
time signals. Mathematically, the correlation operation resembles that of
convolution to a very good extent. As in the case of convolution, a
mathematical operation is performed on two signals in correlation also to
form a third signal. However, the purpose for which convolution and
correlation are used is completely different. While convolution is used to
obtain the response of an LTI system to an arbitrary input signal, the main
objective of correlation is to measure the degree to which the two signals are
similar. Correlation is of two types, cross correlation, and auto correlation
which are defined as follows:

Auto Correlation Function and Cross Correlation Function:

The correlation of two different sequences x n  and yn  is defined as,


rxy k    xn yn - k 
n  

Where rxy k  is the correlation sequence obtained by correlation of x n  and

yn  and „k‟ is the variable used for time shift. The correlation of two different
sequences is called cross correlation and the correlation of a sequence with

BASIC SIMULATION LAB 59


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

itself is called auto correlation. Hence auto correlation of a discrete time


sequence is defined as,


rxx k    xn xn - k 
n  

If the sequence x n  has N 1 samples and sequence x n  has N 2 samples then

the cross correlation sequence rxy k  will be a finite duration sequence

consisting of „ N 1 + N 2 -1‟ samples. If the sequence x n  has N samples, then the

auto correlation sequence rxx k  will be a finite duration sequence consisting


of „ 2N - 1 ‟ samples.

In above expression the sequence x n  is un-shifted and the sequence yn  is


shifted by k units of time for correlation operation. The same results can be
obtained if the sequence yn  is un-shifted and the sequence x n  is shifted
opposite to that of earlier case by k units of time, hence the cross correlation
operation can also be expressed as,


rxy k    xn  k yn 
n  

Program:
(i). Auto Correlation of a signal
clc;clear all;
close all;
t = 0:0.01:2; % Declaration of the time interval.
x= cos(2*pi*t); % Generate the cosinusoidal signal
y= xcorr(x); % Generate the ACF of cosine signal

subplot(2,1,1);
plot(x); % Plot the cosinusoidal signal

BASIC SIMULATION LAB 60


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

xlabel('----> Samples');
ylabel('----> Amplitude');
title('Fig(a): Input Signal');

subplot(2,1,2);
plot(y); % Plot the generated ACF signal
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Fig(b): Output Signal (Auto correlated signal)');

Output:

BASIC SIMULATION LAB 61


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:

(ii). Cross Correlation of a signal


clc;
clear all;
close all;

x=input('Enter input sequence:');

h=input('Enter impulse sequence:');

subplot(3,1,1);

stem(x);

xlabel('n');

ylabel('x(n)');

title('Fig(a): Input signal');

subplot(3,1,2);

stem(h);

xlabel('n');

ylabel('h(n)');

title('Fig(b): Impulse signal');

y=xcorr(x,h);

disp('The resultant signal is:');

disp(y);

subplot(3,1,3);
BASIC SIMULATION LAB 62
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

stem(y);

xlabel('n');

ylabel('y(n)');

title('Fig(c): correlation signal');

Output:
Enter first sequence [1 2 3]

Enter second sequence [1 2 3 4]

The resultant signal is:

4.0000 11.0000 20.0000 14.0000 8.0000 3.0000 -


0.0000

Result:

Viva Questions:

1. What is Correlation?
2. What is the importance of Correlation?
3. What is the difference between Correlation and Convolution?
4. Define ACF and CCF?

BASIC SIMULATION LAB 63


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-7
VERIFICATION OF LINEARITY AND TIME INVARIANCE PROPERTIES OF
A GIVEN CONTINUOUS/DISCRETE SYSTEM

7(a) Verification of Linearity


Aim:
To verify the linear property of a system
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Linear and Non-linear systems:
A system is said to be linear, if it satisfies the superposition and
homogeneity principles, otherwise the system is said to be Non-linear system.
Consider two systems defined as follows:
y1 (t)  Hx1 (t)
Where H is a relaxed system

y 2 (t)  Hx 2 (t)


Then the continuous time system is linear, if

Ha 1x1 (t)  a 2 x 2 (t)  a1 y1 (t)  a 2 y 2 (t)

Here a1 and a 2 are arbitrary constants. This condition states that the

response of the linear combination of the inputs x1 (t) and x 2 (t) with arbitrary

constants a1 and a 2 is same as the sum of the individual responses due to

individual inputs with arbitrary constants.


Similarly, in discrete time system also

BASIC SIMULATION LAB 64


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Fig (a): Response of the system to linear combination of inputs

Fig (b): linear combination of outputs due to individual inputs

In mathematically,
For the system to be linear if,

y 3 (t)  y13 (t) For continuous time system

y 3 (n)  y13 (n) For discrete time system

If the system does not satisfy the above condition, it is called Non-linear
system.

Program:
clc;
clear all;
close all;
x1 = input (' type the samples of x1 ');
x2 = input (' type the samples of x2 ');
if (length(x1) ~= length(x2))
disp(' ERROR : Lengths of x1 & x2 are different ')

BASIC SIMULATION LAB 65


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

return;
end;
h = input (' type the samples of h ');
N = length(x1) + length(h) -1;
disp('length of the output signal will be ');
disp(N);
a1 = input (' The scale factor a1 is ');
a2 = input (' The scale factor a2 is ');
x = a1 * x1 + a2 * x2;
yo1 = conv(x,h);
y1 = conv(x1,h);
y1s = a1 * y1;
y2 = conv(x2,h);
y2s = a2 * y2;
yo2 = y1s + y2s;
disp ('Input signal x1 is '); disp(x1);
disp ('Input signal x2 is '); disp(x2);
disp ('Output Sequence yo1 is ');
disp(yo1);
disp ('Output Sequence yo2 is ');
disp(yo2);
if ( yo1 == yo2 )
disp(' yo1 = yo2. Hence the LTI system is LINEAR ')
end;

Output:

Result:

BASIC SIMULATION LAB 66


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

7(b) Verification of Time Invariance


Aim:
To verify the time invariance property of a system
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Time Invariant (TIV) and Time Variant (TV) systems:
A CTS is time invariant (TIV) if the time shift in the input signal, results in
corresponding time shift in the output.
It is characterized by the property that, if y(n) is the response to x(n) then
y(n - k) is the response to x(n - k) , where k is +ve or –ve integer i.e., if input is
delayed, output is also delayed by the same amount and the wave shape does
not change.
A relaxed system H is time invariant or shift invariant if and only if
H
x(n)  y(n)
It implies that,
H
x(n - k)  y(n - k) For every input signal and every time shift „k‟

Program:
x = input( ' Type the samples of signal x(n) ' );
h = input( ' Type the samples of signal h(n) ' );
y = conv(x,h);
disp( ' Enter a POSITIVE number for delay ' );
d = input( ' Desired delay of the signal is ' );

xd = [zeros(1,d), x];
nxd = 0 : length(xd)-1;

BASIC SIMULATION LAB 67


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

yd = conv(xd,h);
nyd = 0:length(yd)-1;

disp(' Original Input Signal x(n) is ');disp(x);

disp(' Delayed Input Signal xd(n) is ');disp(xd);

disp(' Original Output Signal y(n) is ');disp(y);

disp(' Delayed Output Signal yd(n) is ');disp(yd);

xp = [x , zeros(1,d)];
figure
subplot(2,1,1);
stem(nxd,xp); grid;
xlabel( ' Time Index n ' );
ylabel( ' x(n) ' );
title( ' Original Input Signal x(n) ' );

subplot(2,1,2);
stem(nxd,xd);
grid;
xlabel( ' Time Index n ' );
ylabel( ' xd(n) ' );
title( ' Delayed Input Signal xd(n) ' );

yp = [y zeros(1,d)];
figure
subplot(2,1,1); stem(nyd,yp); grid;
xlabel( ' Time Index n ' );ylabel( ' y(n) ' );
title( ' Original Output Signal y(n) ' );

BASIC SIMULATION LAB 68


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

subplot(2,1,2);
stem(nyd,yd);
grid;
xlabel( ' Time Index n ' );
ylabel( ' yd(n) ' );
title( ' Delayed Output Signal yd(n) ' );
Output:

Result:

Viva Voce questions:


1. How do you classify discrete time systems?
2. Define an LTI system? Give an example of an system which is linear in
nature?
3. State the principle of superposition in words. express mathematically the
principle of superposition applicable to discrete time systems.
4. What do you understand by unit impulse response of a discrete time
system.
5. Define a time invariant system. Give an example of TIS.can you really
work with time invariant systems in reality.
6. What are the advantages of LTI systems because of which they are very
popular?
7. Which MATLAB command appends five zeros to a row vector x so as to
increase its length by five?

***

BASIC SIMULATION LAB 69


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-8
COMPUTATION OF UNIT SAMPLE, UNIT STEP AND SINUSOIDAL
RESPONSES OF THE GIVEN LTI S SYSTEM

8(b) Impulse Response of an LTI system

Aim:
To find the impulse response of an LTI system
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Program:
num = input ('type the numerator vector ');
den = input ('type the denominator vector ');
N = input ('type the desired length of the output sequence N ');
n = 0 : N-1;
imp = [ 1 zeros(1, N-1) ];
h = filter ( num, den, imp );
disp('The impulse response of LTI system is'); disp(h);
stem(n,h)
xlabel ('time index n');
ylabel ('h(n)');
title ('Impulse Response of LTI system');

Output:

Result:

BASIC SIMULATION LAB 70


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

8(b) Step Response of an LTI system


Aim:
To find the step response of an LTI system
Software used:
1. Operating system-Windows XP
2. MATLAB 7.0.1v
Theory:
The step response of a system in a given initial state consists of the time
evolution of its outputs when its control inputs are Heaviside step functions.
In electronic engineering and control theory, step response is the time
behavior of the outputs of a general system when its inputs change from zero
to one in a very short time. The concept can be extended to the abstract
mathematical notion of a dynamical system using an evolution parameter.

From a practical standpoint, knowing how the system responds to a sudden


input is important because large and possibly fast deviations from the long
term steady state may have extreme effects on the component itself and on
other portions of the overall system dependent on this component. In
addition, the overall system cannot act until the component's output settles
down to some vicinity of its final state, delaying the overall system response.
Formally, knowing the step response of a dynamical system gives information
on the stability of such a system, and on its ability to reach one stationary
state when starting from another.

BASIC SIMULATION LAB 71


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:
num = input ('type the numerator vector ');
den = input ('type the denominator vector ');
N = input ('type the desired length of the output sequence N ');
n = 0 : 1 : N-1;
u = ones (1, N);
s = filter ( num, den, u );
disp('The step response of LTI system is'); disp(s);
stem(n,s)
xlabel ('time index n');
ylabel ('s(n)');
title ('Step Response of LTI system');
Output

Result:

Viva Voce Questions:


1. How do you classify LTI systems
2. Define FIR, I IR systems.
3. what is a casual system and its importance.
4. what is meant by off line signal processing.
5. what is a stable system
6. compare contrast stable and unstable systems.
7. what is a transfer function.
8. which classes of LTI system are physically realizable
9. define zeros and poles
10. what is a recursive system.

***

BASIC SIMULATION LAB 72


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-9

GIBBS PHENOMENON

Aim: To verify the Gibbs Phenomenon using MATLAB software.

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
The decomposition of non-periodic or aperiodic signals can also be done
using Fourier transform. When we decompose a signal in to a sum of
sinusoidal components using these powerful mathematical tools called
Fourier series or Fourier Transforms, we are basically resolving the signal
into its frequency components. This process is known as frequency analysis
or spectral analysis of signals.
Every periodic signal has a frequency spectrum consisting of harmonics
with different amplitudes. A harmonic is a signal whose frequency is an
integral multiple of the frequency of some reference signal. The first
harmonic is called the fundamental frequency.
When we add up all the corresponding sinusoidal harmonic components,
it is common sense that we should get back our original periodic signal.
This reconstruction process, which is just the reverse of frequency analysis,
is called Fourier synthesis.
In one such experiment, the American physicist JW Gibbs observed a
peculiar phenomenon like ripples or oscillatory behavior near the jump or
discontinuity of a square wave is known as Gibbs Phenomenon.

Definition: Gibbs Phenomenon is the oscillatory behavior observed near a


jump or discontinuity of a periodic signal, such as a square wave, when it is
reconstructed from a finite number of harmonics.

BASIC SIMULATION LAB 73


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:
clc;clear all;close all;

% Enter the number of sine wave harmonics

N=input('Enter the total number of harmonics :');

t=0:.001:1;

f=square(2*pi*t); % Generate the square wave signal[f(t)] of period T=1.

% plot the original square wave with a blue line and thickness of 2 units

plot(t,f,'b','linewidth',2);

% Adjust the scale of X and Y axes to have a clear view of signals

axis([0 1 -1.5 1.5]);

hold;

% Generate a vector of 1001 zeros to initialize the sq vector.


sq=zeros(size(t));

% Generate odd values for N beginning with 1, increment with 2

for n=1:2:N

sq=sq+(4/(pi*n))*sin(2*pi*n*t); % Generate the sythesized square wave

end;

plot(t,sq);

grid();

xlabel('t');

ylabel('ssq(t)');

title('Fig (a):Synthesized Square Wave Using Fourier Series')

Output:

BASIC SIMULATION LAB 74


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 10
FOURIER TRANSFORM AND IT’S FREQUENCY SPECTRUM

Aim:
To find the Fourier transform and its magnitude and phase spectrum of
the following signal x(n) = 0.8*Cos(2*pi*f*n), Assume f=150Hz and
n=0:1023 samples
Software used:
1. Operating System-Windows XP
2. MATLAB R2009b
Theory:
The Fourier representation of periodic signals has been extended to non-
periodic signals by letting the fundamental period T tend to infinity, and this
Fourier method of representing non-periodic signals as a function of
frequency is called Fourier Transform. This Fourier representation of signals is
also known as frequency domain representation. In general the Fourier series
representation can be obtained only for periodic signal, but the Fourier
transform technique can be applied to both periodic and non-periodic signals
to obtain the frequency domain representation of the signals.

The Fourier representation of signals can be used to perform frequency


domain analysis of signals, in which we can study the various frequency
components present in the signal, magnitude and phase of various frequency
components. The plot of magnitude versus frequency i9s called Magnitude
Spectrum. And the plot of phase versus frequency is called Phase Spectrum. In
general the plots are called frequency spectrum.

Fourier transform of f t  is defined as


Ff t   F    f t e  jt dt
-

BASIC SIMULATION LAB 75


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:
clc;clear all;close all;

f=150; % Fix the frequency of cosine wave at 150


Hz

fs=2000;

Ts=1/(fs); % Find the sampling interval

N=1024; % Let the DFT sequence N be 1024

n=[0:N-1]*Ts; % Set the scale of X-axis

x=0.8*cos(2*pi*f*n); % Generate the cosine wave with a


frequency of 150 Hz

plot(n,x); % Plot the generated cosine wave


grid;
axis([0 0.05 -1 1]); % Adjust scale of X and Y axis
title('Fig (a): Cosine signal of frquency f');
xlabel('time n (sec) -- >');
ylabel('x(n) -- >');

Xw=fft(x,N); % Compute the N-Point DFT using built-in


function 'fft'

w=0:N-1; % Set a range for the frequency index


variable w.

figure; % By itself, creates a new figure


window, and returns its handle.

Xmag=abs(Xw); % Compute the magnitude plot of Xw

subplot(2,1,1);
plot(w,Xmag);

BASIC SIMULATION LAB 76


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

grid;
xlabel('frquency index w -- >');
ylabel('Magnitude -- >');
title('Fig (a): Magnitude of Fourier transform');

Xphas e=angle(Xw); % Compute the phase plot of Xw

subplot(2,1,2);
plot(w,Xphase);
grid;
xlabel('frquency index w -- >');
ylabel('Phase -- >');
title('Fig (b): Phase of Fourier transform');

Output:

Viva Questions:

1. Give the expression for Fourier Transform?


2. Give the expression for Inverse Fourier Transform?
3. Find the Magnitude and Phase of x + i*y?
4. Find the Fourier Transform and find its Magnitude and Phase Spectrum
a) x(t) = U(t) b) x(t) = r(t)
c) x(t) = 2sin(10t)U(t) d) x(t) = exp(-|t|)U(t)

***

BASIC SIMULATION LAB 77


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-11
WAVEFORM SYNTHESIS USING LAPLACE TRANSFORM
Aim:
To find the Laplace transform of a standard causal signals.
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
The Laplace transform is important mathematical tool which is used for the
analysis of signals and systems. In some cases, Laplace transform can be
used where Fourier transform cannot be used. The Laplace transforms can
be used to analyze continuous time problems involving signals that are not
absolutely integrable, such as the impulse response of unstable systems.

Unilateral Laplace transforms:



F S    f t e  st dt
0

Where S    j ,  is the real part of the „S‟ and


 is the imaginary part of the „S‟.
Bilateral Laplace transforms:

F S    f t e  st dt


Program:
clc;clear all;close all;

syms t w s;
a=2;

% Generation of trigonometric and exponential functions


ft1=sin (w*t);
ft2=cos (w*t);

BASIC SIMULATION LAB 78


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ft3=sinh (w*t);
ft4=cosh (w*t);
ft5=exp (a*t);
ft6=exp (-a*t);
ft7= (exp (a*t))*sin (w*t);
ft8= (exp (-a*t))*cos (w*t);

% Laplace transforms of Generated trigonometric functions


FS1=laplace (f1);
FS2=laplace (f2);
FS3=laplace (f3);
FS 4=laplace (f4);
FS 5=laplace (f5);
FS 6=laplace (f6);
FS 7=laplace (f7);
FS 8=laplace (f8);
disp ('(a). Laplace transforms of Sin (wt) is: ');disp(FS 1);
disp ('(b). Laplace transforms of Cos(wt) is: ');disp(FS 2);

disp ('(c). Laplace transforms of Sinh(wt) is: ');disp(FS 3);

disp ('(d). Laplace transforms of Cosh(wt) is: ');disp(FS 4);

disp ('(e). Laplace transforms of exp(a*t) is: ');disp(FS 5);

disp ('(f). Laplace transforms of exp(-a*t) is: ');disp(FS 6);

disp('(g). Laplace transforms of [exp(a*t)]*[sin(w*t)] is: ');disp(FS 7);

disp ('(h). Laplace transforms of [exp(-a*t)]*[cos(w*t)] is: ');disp(FS 8);

Output:

BASIC SIMULATION LAB 79


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program: ii. To find the Inverse Laplace transform of signals

clc;clear all;close all;


syms t w s;
%% Generate the S-domain functions
FS1=1/(s + 2);
FS2=1/(s - 3);
FS3=w/(s^2 + w^2);
% Inverse Laplace transforms of S-domain functions
ft1=ilaplace (FS1);
ft2=ilaplace (FS2);
ft3=ilaplace (FS3);
disp ('(a). Inverse Laplace transforms of 1/(s + 2) is: ');disp(ft1);
disp ('(b). Inverse Laplace transforms of 1/(s + 2) is: ');disp(ft2);
disp ('(c). Inverse Laplace transforms of 1/(s + 2) is: ');disp(ft3);

Output:

Result:

Viva Questions:
1. What is Waveform Synthesis?
2. What is the difference between Analysis and Synthesis?
3. Find the Inverse Laplace Transform of
a) 1/(s+2) b)1/s3
c) (s2 +2s +9)/(s(s2 +9)) d) 18/(s2(s2 + 9))
4. Find the Laplace Transform of
a) x(t) = (1 – e-2t)*U(t) b) x(t) = U(t) – U(t – 2)
c) x(t) = 10cos(t) – 20Sin(20t) d) x(t) = a2tU(t)

***

BASIC SIMULATION LAB 80


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 12
LOCATING THE ZEROS AND POLES AND PLOTTING THE POLE-ZERO
MAPS IN S PLANE AND Z-PLANE FOR THE GIVEN TRANSFER FUNCTION
Aim:
To locating the zeros and poles and plotting the pole-zero maps in s-plane

N S  S 2  3S  2
and z-plane for the following transfer function XS  
DS  S 2 1
[same TF for X(Z)] using MATLAB software

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
In Laplace transforms:
N S 
Any function in S-domain XS 
DS 

Where N(S) = Numerator polynomial, and D(S) = Denominator polynomial


The roots of the equation, N(S) = 0 correspond to the „zeros‟ of X(S)
The roots of the equation, D(S) = 0 correspond to the „poles‟ of X(S)

In Z-transforms:
N Z 
Any function in S-domain XZ 
DZ 
Where N (Z) = Numerator polynomial, and D (Z) = Denominator polynomial
The roots of the equation, N (Z) = 0 correspond to the „zeros‟ of X (Z)
The roots of the equation, D (Z) = 0 correspond to the „poles‟ of X (Z)
Program:

%% Clearing section
clc;clear all;
close all;

BASIC SIMULATION LAB 81


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

num=input(' Enter the numerator polynomial N(s) in square brackets ');


den=input(' Enter the denominator polynomial D(s) in square brackets ');

H=tf(num,den); % Find the transfer function H(s)


[p z]=pzmap(H); % Find the locations of poles(p) and
zeros(z).

disp('Zeros at z=');disp(z); % To diplay the zeros in command window


disp('Poles at p=');disp(p); % To diplay the poles in command window

subplot(2,1,1);

pzmap(H); % plot the pole-zero map in S-


domain

title('Fig(a): Pole-Zero map in S-domain');

subplot(2,1,2);

zplane(num,den); % plot the pole-zero map in Z-domain

title('Fig(b): Pole-Zero map in Z-domain');

Output:

Result:

BASIC SIMULATION LAB 82


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Aim:
Find the following:
i.Z-transform of the standard signals
ii.Inverse Z- transform of the given signals
iii.Residues and poles of the Z-domain signal
iv.Impulse response of discrete time system
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b

Program:

(i). To find the z-transform of some standard signals

% Program to find the z-transform of some standard signals


clc;
clear all;
close all;

syms n T a real; % let n,T,a be real variable


syms z complex; % let z be complex variable

x=n;
disp('(a). z-transform of "n" is :');
disp(ztrans(x));

x=a^n;
disp('(b). z-transform of "a^n" is :');
disp(ztrans(x));

x=n*(a^n);
BASIC SIMULATION LAB 83
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

disp('(c). z-transform of "n*(a^n)" is :');


disp(ztrans(x));

x=exp(-a*n*T);
disp('(d). z-transform of "exp(-a*n*T)" is :');
disp(ztrans(x));
Output:

Result:

Program:

(ii). Program to determine the inverse z-transform

% Program to determine the inverse z-transform


clc;
clear all;
syms n z;

Xz=1/(1-1.5*(z^(-1))+0.5*(z^(-2)));
disp('Inverse z-transform of');
disp(Xz);disp('is :');

Xz=iztrans(Xz,z,n);
xn=simplify(Xz);
disp(xn);

Output:

Result:

BASIC SIMULATION LAB 84


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:

(iii). Program to determine the residues and poles of z-domain signal

clc;
clear all;

H=tf('z');
Ts=0.1;
nc=input('Enter numerator coefficients like [1 2-4 5] :');
dc=input('Enter denominator coefficients like [0 4 5] :');

disp('The given transfer funtion is :');


H=tf([nc],[dc],Ts)

disp('The residues, poles and direct terms of given Tf are :');


disp('(r - Residues ; p - Poles ; k - Direct terms ;)');
[r,p,k]=residue(nc,dc)
disp('The num. and den. coefficients extracted from r,p,k');
[nc,dc]=residue(r,p,k)

Output:

Result:

BASIC SIMULATION LAB 85


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program: (iv). Impulse response of a system

clc;
clear all;
close all;

syms z n;

H=input('Enter system response[H(z)] in "z-domain" ::');


disp('System response[H(z)] is ::');disp(H);

h=iztrans(H); % Comute the impulse response


hn=simplify(h);
disp('Impulse response h(n) is ::');disp(hn);

N=15;
nc=input('Enter numerator coefficients of above funtion H(z) ::');
dc=input('Enter denominator coefficients of above funtion H(z) ::');

[H,n]=impz(nc,dc,N); % Compute N samples of impulse


response

stem(n,H);
grid;
xlabel('--> n');
ylabel('---> h(n)');
title('Fig (a): Impulse response h(n)')

Output:

Result:

BASIC SIMULATION LAB 86


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Viva Questions:
1. What is the need of z-transform?
2. Define Inverse z-transform?
3. Define impulse response?
4. Define poles, zeros and residues?

***

BASIC SIMULATION LAB 87


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-13
GENERATION OF GAUSSIAN NOISE, COMPUTATION OF ITS MEAN, MEAN
SQUARE VALUE (MSV), AND ITS SKEW, KURTOSIS, AND PSD,
HISTOGRAM
Aim:
To generate the Gaussian noise and compute the Mean, MSV, Variance,
and its Skew, Kurtosis, PSD, Histogram using MATLAB software.

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Gaussian probability or Normal distribution:
A random variable X is called Gaussian, if its density function has the form

 x m 2
2
f x x  
1
.e 2 x
2 x2

Where m= mean of X,  x2 = Variance of X, and f x x is referred as

Gaussian/Normal Distribution, it can be denoted as N (m,  x2 ).

Mean: Mean is the average or mean value. For vectors, mean (R1) is the
mean value of the elements in random signal R1. Expectation is the name
given to the process of averaging when a random variable is involved. It can

denoted as X or E  X 
In Discrete random variable case:
n
EX    xi P  x i 
i 1

In Continuous random variable case:

BASIC SIMULATION LAB 88


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)


EX    xf x dx
 x

Mean Square Value: The second moment about the origin of the random
variable X is known as Mean Square Value (MSV) of X.

In Discrete random variable case:


n
EX 2  
   x i 2 P  xi 
i 1

In Continuous random variable case:

 
E X2 
 2

x fx xdx

Variance: The second central moment of a random variable X is called as

Variance of X. It can be denoted as,  x2 or  2 . Mathematically it can be

expressed as:

E  X  m     x  m  P x 
n
2 2
i i
i 1

i.e.,  
Var(X) = E X 2  EX 
2

Skew: The third central moment E  X  m  3


 of a random variable X is
defined as skew of its probability density function. It is a measure of the
asymmetry of the density function of a random variable about its mean (m).

The measure used to describe this asymmetry is called Coefficient of


Skewness. The normalized third central moment of a random variable X,

i.e.,

E  X  m 2  is referred to as Coefficient of Skewness.
 x3

BASIC SIMULATION LAB 89


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Kurtosis: kurtosis (R1) returns the sample kurtosis of the values in R1. For
a vector input, K is the fourth central moment of X, divided by fourth power
of its standard deviation.

PSD: PSD Power Spectral Density estimate. PSD has been replaced by
SPECTRUM objects.

Pwelch: pwelch is the Power Spectral Density estimate via Welch's method.

Hist:

hist(X) bins the elements of R1 into equally spaced container

Program:

clc;
clear all;
close all;

N= input(' Enter the number of samples ....:: ');

R1=randn(1,N);% Generate the Gaussian Random signal with 'N' samples

m=mean(R1); % Mean of the Gaussian random signal


disp('The mean value of the Gaussian random signal E[X] :');disp(m);

msq = sum(R1.^ 2 )/length(R1); % Mean square value estimation


disp('The mean square value of the Gaussian random signal E[X.^2]
:');disp(msq);

v=var(R1); % Variance estimation


disp('The variance of the Gaussian random signal Var[X] :');disp(v);

BASIC SIMULATION LAB 90


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

s=skewness(R1); % skewness estimation


disp('The skewness of the Gaussian random signal:');disp(s);

k=kurtosis (R1); % kurtosis estimation


disp('The kurtosis of the Gaussian random signal :');disp(k);

p=periodogram(R1); % Periodogram estimation

x=pwelch(R1); % Power Spectral Density estimation

subplot(2,2,1);
plot(R1);
xlabel('Sample Number');
ylabel('Amplitude');
title('Fig (a): Normal [Gaussian] Distributed Random Signal');
subplot(2,2,2);
hist(R1); % bins the elements of R1 into equally spaced container
xlabel('Sample Number');
ylabel('Total');
title('Fig (b): Histogram [Pdf] of a normal Random Signal');

subplot(2,2,[3,4]);
plot(x);
xlabel('Sample Number');
ylabel('Amplitude');
title('Fig (c): PSD of a Normal Random Signal');

Output:

BASIC SIMULATION LAB 91


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Result:

Viva Questions:
1. Define Gaussian Noise?
2. Define Mean, Variance and Skew?
3. Define kurtosis and PSD?
4. Define CDF and PDF?
5. What is the difference between CDF and PDF?

***

BASIC SIMULATION LAB 92


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT-14
VERIFICATION OF SAMPLING THEOREM
Aim:
To verify the sampling theorem using MATLAB software.

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
Sampling Theorem:

A continuous-time signal (band limited) can be completely represented in its


samples and recovered back, if the sampling frequency f s is greater than (or)

equal to the twice of the highest frequency component f m of the message

signal.
Sampling is performed by taking samples of continuous time signal at definite
intervals of time. Usually, the time interval between two successive samples will
be same and such type of sampling is called periodic or uniform sampling.

i.e, f s  2 f m

Let, xa t  = Analog/Continuous time signal.

x n  =Discrete time signal obtained by sampling xa t  .

Mathematically the relation between x n  and xa t  can be expressed as,

n 
x n  = xa t  | t  nTs = x a nTs  = xa   ; for n in the range   n  

 fs 

Where, Ts =Sampling period or interval in seconds.


f s =Sampling rate or sampling frequency in Hertz‟s.

BASIC SIMULATION LAB 93


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Program:

%% Verification of sampling theorem by considering the co-sine signal with T=3


clc;
clear all;
close all;

t=-5:.01:5;
T=3; % Assighn Time period
fm=1/T; % Estimate frequency(fm)

x=cos(2*pi*fm*t); % Generate the co-sine signal with 0.33 Hz

subplot(2,1,1);
plot(t,x); % Plot the generated Co-Sine wave
xlabel('--> time');
ylabel('x(t)');
title('Fig(a): Continuous time signal');
grid;

fs1=0.6*fm; % Assume the fs1, as per fs1<2fm

ts1=1/fs1; % Estimate Sampling period ts1

n1=-5:ts1:5;

x1=cos(2*pi*fm*n1);

subplot(2,1,2);
stem(n1,x1,'p');
grid;
xlabel('--> time');
ylabel('x1(n)');
title('Fig(b): discrete time signal with fs<2fm');

legend('fs<2fm'); % put the string as label on the current plot.


BASIC SIMULATION LAB 94
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

figure; % by itself, creates a new figure window, and


returns its handle.

fs2=2*fm; % Assume the fs2, as per fs2=2fm

ts2=1/fs2; % Estimate Sampling period ts2

n2=-5:ts2:5; % Specify the time index in discrete case

x2=cos(2*pi*fm*n2);

subplot(2,1,1);
stem(n2,x2,'m');
xlabel('--> time');ylabel('x2(n)');
title('Fig(c): discrete time signal with fs=2fm');
legend('fs=2fm');
grid;

fs3=36*fm; % Assume the fs3, as per fs3>2fm

ts3=1/fs3; % Estimate Sampling period ts3

n3=-5:ts3:5;

x3=cos(2*pi*fm*n3);

subplot(2,1,2);
stem(n3,x3,'.');
xlabel('--> time');
ylabel('x3(n)');
title('Fig(d): discrete time signal with fs>2fm');
legend('fs>2fm');
grid;

BASIC SIMULATION LAB 95


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Output:

Result:

Viva Questions:

1. Define Sampling Theorem?


2. Define Replication property?
3. What is Impulse train?

***

BASIC SIMULATION LAB 96


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 15
REMOVAL OF NOISE BY AUTO CORRELATION / CROSS CORRELATION
Aim:
Removal of noise by autocorrelation / cross correlation
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
The cross correlation between two discrete time periodic signals x n  and
yn  is defined as,

1 N 1
R xy k    xn yn - k 
N n 0

Where R xy k  is the correlation sequence obtained by correlation of x n  and

yn  and „k‟ is the variable used for time shift.

A signal is uncorrelated with any periodic signal. If st  periodic signal

and n t  is a noise signal then,


 /2
 st nt   dt  0 for all 
1
Lim 
     / 2
R sn    Cross correlation function of st  and n t  then R sn    0

Detection of Noise by Auto Correlation:

st  = periodic signal (Transmitted), mixed with a noise signal n t  .


Then f t  is received signal is [ st  + n t  ]

Let R ff   =ACF of f t  ; R ss t  =ACF of st  ; R nn t  =ACF of n t  ;


 /2
R ff    Lim   f t  f t   dt
1
     / 2

BASIC SIMULATION LAB 97


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

 /2
 st   nt st     nt   dt
1
 Lim
    / 2

R ff    R ss    Rnn    R snf    Rns  

The periodic signal st  and n t  are uncorrelated.

 R sn    R ns    0

Then R ff    R ss    R nn  

The Auto correlation function of aperiodic signal is periodic of the same


frequency and the ACF of a non-periodic signal is tends to zero for large
value of  , since st  is a periodic signal and n t  is a non-periodic signal,

so R ss   is a periodic where as R nn   becomes small for large values of .

Therefore for sufficiently large values of  , R ff   is equal to R ss   .

Program:

% clearing section
clc;clear all;close all;

t = 0:0.1:pi*4; % Declaration of the time interval.


s= sin(t); % Generate the sine wave s(t)
k=2;

subplot(3,1,1)
plot(s);
xlabel('----> Time (t)');
ylabel('----> Amplitude');
title('Fig (a): Sine signal');

n=rand([1 126]); % Generate noise(Random signal) n(t)

f=s+n; % Generate Receieved signal f(t)

subplot(3,1,2)
plot(f);
xlabel('----> Time (t)');

BASIC SIMULATION LAB 98


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ylabel('----> Amplitude');
title('Fig (b): Receieved signal f(t)=s(t)+n(t)');

as=xcorr(s,s);

subplot(3,1,3)
plot(as);
xlabel('----> Time (t)');
ylabel('----> Amplitude');
title('Fig (c): Autio Correlation of s(t)');

figure;
an=xcorr(n,n);

subplot(3,1,1)
plot(an);
xlabel('----> Time (t)');
ylabel('----> Amplitude');
title('Fig (d): Autio Correlation of n(t)');

af=xcorr(f,f);

subplot(3,1,2)
plot(af);
xlabel('----> Time (t)');
ylabel('----> Amplitude');

title('Fig (e): Autio Correlation of f(t)');

hh=as+an;

subplot(3,1,3)
plot(af);
xlabel('----> Time (t)');
ylabel('----> Amplitude');
title('Fig (f): Addition of ACF of s(t)and ACF of n(t))');

BASIC SIMULATION LAB 99


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Output:

Result:

Viva Questions:

1. Define Sampling Theorem?


2. Define Replication property?
3. What is Impulse train?

***

BASIC SIMULATION LAB 100


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 16
EXTRACTION OF PERIODIC SIGNAL MASKED BY NOISE USING
CORRELATION

Aim:
To extract the periodic signal masked by noise using correlation
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Program:
clc; clear all;
M = 256;
n = 0 : M-1;
x = cos(16*pi*n/M) + sin(32*pi*n/M);
snr = input( ' Type the desired SNR ' );
px = var(x)
w = sqrt(12) * (rand( 1 , M ) - 0.5);
an = sqrt(px * (10 ^ ( (-1 * snr) / 10) ))
w = w .* an;
pn = var(w)
SNRdb = 10 * log10(px / pn)
y = x + w;
N = M / 8;
L = floor( M / N );
d = zeros( 1 , M );
for i = 1 : M
if rem(i-1,N) == 0
d(i) = 1;
end;
end;

BASIC SIMULATION LAB 101


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Cyd = ifft( fft(y,M) .* fft(d,M)) / M;


r = Cyd * ( M / L );
figure(1);
plot( n , x , 'b' ); axis( [ 1 80 -3 3 ] )
xlabel( 'n' ); ylabel( 'x(n)' );
title( ' Periodic Signal x(n) ' )
figure(2);
subplot(2,1,1); plot( n , y , 'r' );
grid; axis( [ 1 96 -3 3 ] );
xlabel( 'n' ); ylabel( 'y(n)' );
title( ' Noisy Signal y(n) ' )
subplot(2,1,2); stem( n , d );
grid; axis( [ 1 96 -0.5 1.5 ] );
xlabel( 'n' ); ylabel( 'd(n)' );
title( ' Impulse Train d(n) ' )
figure(3);
plot( n , r , 'k' ); axis( [ 1 80 -3 3 ] )
xlabel( 'n' ); ylabel( 'r(n)' );
title('Extracted Periodic Signal r(n)')
figure(4);
plot( n , x , 'b' ); hold on;
axis( [ 1 80 -3 3 ] )
plot( n , r , 'r:' ); hold off;
axis( [ 1 80 -3 3 ] )
legend( 'x(n)' , 'r(n)' )
Output:

Result:

BASIC SIMULATION LAB 102


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Viva voce Questions:


1.Why cant we filter out noise from a noisy signal?Why should you use
correlation to do so?
2.What do you think is the purpose of (a)band pass filter
(b)band reject filter and (c)high pass filter
3.When does the correlation between two signals become nearly zero?
4.What does the MATLAB command „floor‟ do?
5.Which MATLAB command rounds the result towards plus infinity?

***

BASIC SIMULATION LAB 103


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 17
VERIFICATION OF WIENER-KHINCHINE RELATION

Aim:
To verify the wiener-khinchine relation
Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:
The Wiener-khinchine (also known as the Wiener-khintchine theorem
and sometimes as the wiener-khinchin-Einstein theorem) states that the
power spectral density of a wide-sense-stationary random process is the
Fourier transform of the corresponding autocorrelation function. The
theorem is useful for analyzing linear time-invariant systems, LTI
systems, when the inputs and outputs are not square integrable, so
their Fourier transforms do not exist. Mathematically it is expressed as:

Continuous case:


S xx  f    rxx  e  j 2f d


Where rxx    E[ xt x * t   ]

is the auto correlation function defined in terms of statistical expectation.


The asterisk denotes complex conjugate, and can be omitted if the
random process is real-valued.

Discrete case:


S xx  f    rxx k e  j 2kf
k  

BASIC SIMULATION LAB 104


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Where rxx k   E[ xnx* n  k ]

and where is the power spectral density of the function with discrete
values.

Program:

clc;
clear all;
close all;

t=0:0.1:2*pi; % Declaration of Time interval

x=sin(2*t); % Generation sine wave

subplot(3,2,1);
plot(x); % plot the sine wave
title('Sine Wave')

auc=xcorr(x,x); % Generation Auto Correlation Function of sine wave


subplot(3,2,2);
plot(auc); % plot the ACF of sine wave
title('ACF of Sine Wave')

v=fft(auc); % Obtain FFT of ACF

subplot(3,2,3);
plot(abs(v)); % Magnitude plot the FFT of ACF of the sine wave
title('Magnitude plot the FFT of ACF of the sine wave')

fw=fft(x);

subplot(3,2,4);
plot(fw);
title('FFT of Sine Wave')

BASIC SIMULATION LAB 105


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

fw2=(abs(fw)).^2; % Generation Energy spectral density

subplot(3,2,5);
plot(fw2);
title('Energy spectral density of Sine Wave')

Output:

Result:

***

BASIC SIMULATION LAB 106


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXPERIMENT 18
CHECKING A RANDOM PROCESS FOR STATIONARY IN WIDE SENSE

Aim:

To verify a Random Process for Stationary in Wide Sense using MATLAB


software.

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Theory:

A random process is said to be stationary if all its statistical properties do


not change with time, other processes are called non-stationary.
A stationary random process (or strictly) is a stochastic process whose joint
probability distribution does not change when shifted in time or space.
Two processes X(t) and Y(t) are statistically independent, if the random
variable group X(t1), X(t2)…… X(tN) is independent of the group Y(t11),
Y(t21)……. Y(tN1) for any choice of times t1,t2,…tN, t11, t21 ,….. tN1.
Independence requires that the joint density be factorable by groups:

f xy  x1, x2 ,... xN ; y1, y2 ,... y N ; t1, t2 ,....t N ; t11, t12 ,....t1N 


 


 f x  x1, x2 ,... xN ; t1, t2 ,....t N   f y y1, y2 ,... y N ; t11, t12 ,....t1N
 

Wide sense stationary random processes(WSS RP):
If the statistical properties of a random process, such as the mean, standard
deviation, variance, etc., are invariant to the translation of the time axis ,
such a process is called stationary or strict sense stationary (SSS) random
process. Since SSS condition almost never satisfied in practice, a somewhat
weaker type of stationary called as wide sense stationary (WSS) process is
commonly employed in most of the signal processing applications.

BASIC SIMULATION LAB 107


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

WSS Random Processes Conditions:


1. μ x n   EXn   μ (a constant)   n  
This says that the mean value does not depend on the time origin.
2. The auto covariance function C xx t1, t 2 and the auto correlation

function Rxx t1, t 2 should depend only on the time difference   t 2  t1

between the time indices t1 and t2.


C xx t1, t 2  C xx  
R xx t1, t 2  R xx  

Program:

clc;
clear all;
close all;

syms x ;

z = input('Enter the function ..... :: ');


Max = input('Max limit ....:: ');
Min = input('Min limit ....:: ');

mean_value = int(z,Min,Max)

y = subs(z,x,x+5);

Auto_correlation = int(z*y,Min,Max)

disp('If the mean value is constant .....');


disp('and');
disp('Auto Correlation is not a function of x variable ....');
disp('then ');
disp('The Random Process is Wide Sense stationary.');

Output:

BASIC SIMULATION LAB 108


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Result:

Viva Questions:

1. Define Random Variable and Random Process?


2. Define Mean, Median and Mode?
3. Define Auto Correlation?
4. What are the types of Random Process?
5. What is a Stationary Process?
6. What are the conditions for the Random Process to be WSS?
7. What are the conditions for the Random Process to be SSS?

***

BASIC SIMULATION LAB 109


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ADDITIONAL PROGRAMES
EXP.NO: 1
GENERATION OF DICRETE TIME SIGNALS

Aim: To Generate Elementary Discrete-Time signals/Sinusoidal waveform


based on recursive difference equation.

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Program:
%Impluse
clc;clear all;close all;
n=-10:1:10;
impluse=[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(3,3,1);stem(n,impluse);axis([-10 10 0 1.2]);
xlabel('discrete time n');ylabel('amplitude');
title('unit impluse sequence');
%Unit step
n=-10:1:10;
step=[zeros(1,10),ones(1,11)];
subplot(3,3,2);stem(n,step);
xlabel('discerte time n');ylabel('amplitude');title('unit step sequence');
%Ramp
n=0:1:10
ramp=n;
subplot(3,3,3);stem(n,ramp);
xlabel('discrete time');ylabel('amplitude');
title('ramp signal');

BASIC SIMULATION LAB 110


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Output:

Result: Thus the discrete time signals are generated.

BASIC SIMULATION LAB 111


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXP.NO: 2
RAISED COSINE FILTER

Aim: To design a raised cosine filter

Software used:
1. Operating system-Windows XP
2. MATLAB R2009b
Program:
clc;
clear all;
t = linspace(-30,30,1000);
b= 0.2;
T=1;
h1 = (sin(pi*t/T))./(pi*t/T);
h2 = (cos(pi*b*t/T))./(1-(2*b*t/T).^2);
h = h1.*h2;
figure(1);
plot(t,h);
Output:

Result:

BASIC SIMULATION LAB 112


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

Viva-voce:
1. Define the raised cosine filter?
2. State the purpose for which the raised cosine filters are normally used?
3. What is inter symbol interference?
4. What do you understand by pulse shaping?
5. Draw the frequency responses plot for
(a) high pass filter, (b) low pass filter,
(c)band pass filter, (d) band reject filter?
6.What do you understand by the „bandwidth‟ of filter?

BASIC SIMULATION LAB 113


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

EXP.NO: 3
TO FIND DFT OF GIVEN DISCRETE TIME SIGNAL

Aim: To find DFT of a given Discrete Time signal

Software used:
1. Operating system-Windows XP
2. MATLAB R20009b
Theory:
The discrete Fourier Transform of sequence is Periodic and we are
interested in frequency range 0 to 2π there are infinitely many ω in this
range. If we use a digital computer to compute N equally spaced points over
the interval 0≤ ω<2π then the N points should be located at
ωk = (2π/N)k; k=0,1,2……,N-1;
These N equally space frequency samples of the DTFT are known as DFT
denoted by X(k) is
X(k) = X(ejω)|ω k = (2π/N)k; 0≤k≤N-1.
The formulas for DFT are

DFT 0 ≤ k ≤ N-1.

For notation purpose


= DFT [ ]
Program:

%DFT function
function X=dft( x, N);
L=length(x);
if(N<L)
error('N must be >=L')
end
x1=[x zeros(1,N-L)];
for k=0:1:N-1;

BASIC SIMULATION LAB 114


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

for n=0:1:N-1;
p=exp(-i*2*pi*n*k/N);
x2(k+1,n+1)=p;
end
end
X=x1*x2;
%to find DFT of given sequence

clc
clear all
close all
x=ones(1,4);
N1=8;
Y1=dft(x,N1);
k=0:1:N1-1;
subplot(2,2,1);
stem(k,abs(Y1));
xlabel('k');
ylabel('|Y1(k)|');
title('')
subplot(2,2,3);
stem(k,angle(Y1));
xlabel('k');
ylabel('arg(Y1(k))');
title('')
N2=31;
Y2=dft(x,N2);
k=0:1:N2-1;
subplot(2,2,2);
stem(k,abs(Y2));
xlabel('k');

BASIC SIMULATION LAB 115


GURU NANAK INSTITUTIONS TECHNICAL CAMPUS (GNITC)

ylabel('|Y2(k)|');
title('')
subplot(2,2,4);
stem(k,angle(Y2));
xlabel('k');
ylabel('arg(Y2(k))');
title('')

Output:

Result:

BASIC SIMULATION LAB 116

Вам также может понравиться