Sei sulla pagina 1di 113

LABORATORY OBSERVATION BOOK

BASIC SIMULATION LAB


III SEMESTER
ECE

Name of the Student


Roll Number
Branch & Section

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY


(AUTONOMOUS)
Accredited by NAAC with ‘A’ Grade of UGC, and NBA Accredited (EEE, CSE, & ECE) Approved by AICTE,
New Delhi & Permanently Affiliated to JNTUA, Ananthapuramu
(Recognized by UGC under 2(f) &12(B) & ISO 9001:2008 Certified Institution)
Nandikotkur Road, Kurnool-518452
Basic Simulation Laboratory

Vision of the Department

To produce engineers with sound knowledge in electronics and communication related


domains with entrepreneurial skills to serve societal needs.

Mission of the Department

The department imparts quality technical education with professional competence, leadership
abilities and ethical values through effective teaching learning process.

Course Outcomes
At the end of the successful competition of the course, the student will be able to
1. Generate different signals and sequences using MATLAB
2. Perform correlation and convolution of signals and sequences
3. Find the Fourier and Laplace transform of the given functions
4. Plot the pole-zero map of the given transfer function in S& Z planes
5. Find mean and variance & check the wide sense stationary of the Stochastic process
6. Remove the noise by auto correlation / cross correlation in a given signal corrupted by
noise.

Department of Electronics and Communication Engineering


G.PULLAIAH COLLEGE OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
INDEX

Mr/Ms.__________________________________ Roll Number:___________________

Text
S.No Date Title of the Experiment Book- Page Marks Signature
Page No of the
No. staff
Part-A:
1 Introduction to Mat lab T1-1 1
Part-B: List of Experiments
(Any 16 programs can be executed)
1 Basic operations on matrices T1-25 9
Generation of various signals
2 T1-42 13
and sequences
Operations on signals and
3 T1-68 21
sequences
Finding even and odd
components & real and
4 T1-85 33
imaginary parts of a signal and
sequence
Verification of linearity property
5 T1-125 38
of a system
Verification of time invariance
6 T1-129 41
property of a system
Computation of unit impulse
7 and unit step response of a T1-145 44
system
Computation of frequency
8 T1-147 48
response of a system
Convolution between signals
9 T1-96 52
and sequences
Autocorrelation and cross
10 correlation between signals and T1-110 56
sequences
Finding the Fourier transform of
11 a given signal and plotting its T1-167 62
magnitude and phase Spectrum
Waveform synthesis using
12 T1-181 65
Laplace transform
13 Sampling theorem verification. T1-223 67
Generation of Gaussian noise
(Real and Complex),
computation of its mean,
14 T1-211 72
M.S.Value and its skew, kurtosis,
and PSD, Probability Distribution
Function.
Removal of noise by auto
correlation / cross correlation in
15 T1-234 79
a given signal corrupted by
noise.
Impulse response of a raised
16 T1-254 84
cosine filter.
Checking a Random Process for
17 T1-260 89
Stationary in Wide Sense
Verification of Wiener-
18 T1-268 92
Khintchine relations
Extraction of periodic signal
19 masked by noise using T1-244 95
correlation
Locating zeros and poles, and
plotting the pole-zero maps in s-
20 T1-189 99
plane and z-plane for the given
transfer function
Part C: Additional Experiment Beyond the Curriculum
21 Gibbs Phenomenon T1-158 101
Part- D
Lab Based Mini Project

TEXT BOOKS:
1.Basic Simulation Lab with MATLAB by Bhanu Bhaskara &Siddhartha Bhaskara,
TMH2011
2.Edward.W.Kamen & Bonnie.S.Heck, Fundamentals of Signals and Systems Using the
Web and MATLAB, 3e, Pearson 2014.
BASIC SIMULATION LABORATORY

PART-A INTRODUCTION TO
MATLAB

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY


(AUTONOMOUS)
Accredited by NAAC with ‘A’ Grade of UGC, and NBA Accredited (EEE, CSE & ECE)
Approved by AICTE, New Delhi & Permanently Affiliated to JNTUA, Ananthapuramu
(Recognized by UGC under 2(f) &12(B) & ISO 9001:2008 Certified Institution)
Nandikotkur Road, Kurnool-518452
Basic Simulation Laboratory

Part-A Module-1

Introduction to MATLAB

1. Introduction

SIMULATE means “create a representation or model of/ to appear to be real,/an act of /


Something made to resemble something else. “

Simulation is the imitation of the operation of a real-world process or system over time. The act
of simulating something first requires that a model be developed; this model represents the key
characteristics or behaviors/functions of the selected physical or abstract system or process.
The model represents the system itself, whereas the simulation represents the operation of
the system over time.

Simulation is used in many contexts, such as simulation of technology for performance


optimization, safety engineering, testing, training, education, and video games. Often, computer
experiments are used to study simulation models. Simulation is also used with scientific
modeling of natural systems or human systems to gain insight into their functioning. Simulation
can be used to show the eventual real effects of alternative conditions and courses of
action. Simulation is also used when the real system cannot be engaged, because it may not be
accessible, or it may be dangerous or unacceptable to engage, or it is being designed but not yet
built, or it may simply not exist.

1.1 History & Overview of MATLAB:

MATLAB full form is “Matrix laboratory”

MATLAB (matrix laboratory) is a numerical computing environment and fourth- generation


programming language.

Invented in the year 1970 by Cleve Moler, and was modified by Jack little and Steve bangert.

Mathworks was started in 1984.

MATLAB is originally designed to provide student’s access to LINPACK & EISPACK

without learning FORTRAN.

MATLAB is numerical computing environment and programming language, used for applied
mathematics.

MATLAB was first adopted by control design engineers and spread to many other domains; it is
particularly used in education field and Industry/Scientific/Military applications.

Department of Electronics and Communication Engineering 1


Basic Simulation Laboratory

MATLAB began with 80 functions, now it has over 8000 functions; MATLAB engineers
incorporated the LAPACK, BLAS libraries, embedding the state of the art software for matrix
computation.

MATLAB today has millions of users and a standard tool in both professional and academic use.

MATLAB has inbuilt TOOLBOXES ( Control Systems, Communications, Neural

Networks, Image-processing, Signal Processing, Bioinformatics………………etc.,)

MATLAB has a GUI based simulation tool (SIMULINK).

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.

MATLAB is used in Math and Computation, Algorithm development, Data acquisition,


Modeling, “Simulation “, Prototyping, Data analysis exploration visualization, Scientific and
engineering graphics, Application development.

MATLAB is interactive system whose basic data element is an array that does not

require dimensioning. This allows solving many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program in
a scalar non-interactive language such as C or FORTRAN.

MATLAB system is technically called an interpreter, which means that each

statement presented to the command line is translated into language the computer understand
better and then immediately carried out.

MATLAB is case-sensitive, which means that a + B is not the same as a + b. The

MATLAB prompt (») in command window is where the commands are entered. Mat lab is
capable to interpret and evaluate the numerical matrices expressions as

a) Directly from keyboard in command window. Or

b) on form of sequences of expressions which are saved in a text file, called m-file and execute
it in command window. Or

c)more rarely on form binary file which is called mex-files or file of extension .mex generated
from a C compiler

1.2 Procedure to open MATLAB:

1. Open the MATLAB, by double clicking the icon on desktop.

Department of Electronics and Communication Engineering 2


Basic Simulation Laboratory

2. Below window is launched with default layout.

3. The Default Layout consists of three parts. They are


A) Command Window
B) Command History
C) Current directory/Workspace, resp. as shown below

a) Command window: Here we enter the commands at the prompt symbol

Department of Electronics and Communication Engineering 3


Basic Simulation Laboratory

b) Command history: This window represents previously entered commands at


command prompt

c) Current directory/Workspace:

The Current directory window displayed the list of all the files and folders under the
current directory, which happens to be the ‘work’ sub-directory, by default, under the
MATLAB root directory. Since the ‘MATLAB’ directory will normally be in the hard disk C:
/ in your system, where all the application software packages are stored, you should
never use the default directory for saving your MATLAB Files.

Workspace represents all the variables that are declared in Command Window.

VARIABLES: A variable is a name that is assigned to a value stored in the


computer’s memory. The variable names in MATLAB must begin with a letter, and they
may be followed by any combination of letters, digits, and underscores.

EXPRESSIONS AND STATEMENTS: An expression may consist of numbers, variable


names and some pre-defined functions such as sin, cos, log etc., arithmetic operators
such as +,-,/ etc.,
Department of Electronics and Communication Engineering 4
Basic Simulation Laboratory

relational operators such as <, > etc., and some special characters such as space,
(semicolon, ] etc., Evaluation of the expression produces a matrix.

MATLAB has 6 relational operators to make comparisons between variables. These are

< is less than

<= is less than or equal to

> is greater than

>= is greater than or equal to

== is equal to

~= is not equal to

Typical commands:

1. Whos

2. who

3. clear

4. quit

5. save filename – filename.mat

6. load filename - retrieve

7. dairy filename - b4 and after ASCII text file

8. help

1.3 Built in Functions:

1.3.1 Scalar Functions:

Certain MATLAB functions are essentially used on scalars, but operate element-wise
when applied to a matrix (or vector). They are summarized below.

1. sin - trigonometric sine

2. cos - trigonometric cosine

3. tan - trigonometric tangent

Department of Electronics and Communication Engineering 5


Basic Simulation Laboratory

4. asin - trigonometric inverse sine (arcsine)

5. acos - trigonometric inverse cosine (arccosine)

6. atan - trigonometric inverse tangent (arctangent)

7. exp - exponential

8. log - natural logarithm

9. abs - absolute value

10. sqrt - square root

11. rem - remainder

12. round - round towards nearest integer

13. floor - round towards negative infinity

14. ceil - round towards positive infinity

1.3.2. Vector Functions:

Other MATLAB functions operate essentially on vectors returning a scalar value. Some
of these functions are given below.

1. max- largest component: get the row in which the maximum element lies

2. min -smallest component

3. length -length of a vector

4. sort -sort in ascending order

5. sum- sum of elements

6. prod -product of elements

7. median -median value

8. mean -mean value std standard deviation

1.3.3. Matrix Functions:

Department of Electronics and Communication Engineering 6


Basic Simulation Laboratory

Much of MATLAB’s power comes from its matrix functions. These can be further
separated into two sub-categories. The first one consists of convenient matrix building
functions, some of which are given below.

1. eye - identity matrix

2. zeros - matrix of zeros

3. ones - matrix of ones

4. diag - extract diagonal of a matrix or create diagonal matrices

5. triu - upper triangular part of a matrix

6. tril - lower triangular part of a matrix

7. rand - randomly generated matrix eg: diag ([0.9092; 0.5163;0.2661])

ans =

0.9092 0

0 0.5163 0

0 0.2661

commands in the second sub-category of matrix functions are

1. size- size of a matrix

2. det- determinant of a square matrix

3. inv- inverse of a matrix

4. rank- rank of a matrix

5. rref -reduced row echelon form

6. eig -eigenvalues and eigenvectors

7. poly- characteristic polynomial

8. norm- norm of matrix (1-norm, 2-norm, ∞ -norm)

9. cond -condition number in the 2-norm

10. lu -LU factorization

Department of Electronics and Communication Engineering 7


Basic Simulation Laboratory

11. qr -QR factorization

12. chol- Cholesky decomposition

13. svd -singular value decomposition

2. Procedure:

1. Open the Matlab software by double clicking the icon on desktop.

2. Open the Matlab Editor by using File Tab --- --- -File on the Menu.

3. Write the program in Matlab Editor

4. Click on save from File tab or press Ctrl+S Key

5. Click on Run Button Present on the Editor window or Press F5 Key

5. Perform error check if any, which is displayed on the Command window and Modify if
any.

6. Note-down the results or values on Command window or Workspace.

7. Check the waveforms which are displayed on Figure window and plot them.

Department of Electronics and Communication Engineering 8


BASIC SIMULATION LABORATORY

PART-B
LIST OF EXPERIMENTS

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY


(AUTONOMOUS)
Accredited by NAAC with ‘A’ Grade of UGC, Approved by AICTE, New Delhi
Permanently Affiliated to JNTUA, Ananthapuramu
(Recognized by UGC under 2(f) &12(B) & ISO 9001:2008 Certified Institution)
Nandikotkur Road, Kurnool-518452
Basic Simulation Laboratory

Experiment No.

Basic operations on matrices


1
Roll No:_______________ Date:_______________

Roll No:_____________
Date:______________

Objectives:

(A) To generate different matrices such as identity matrix, matrix with only zeros,
matrix with only ones and matrices with different sizes,

(B) To perform different operations such as addition, multiplication, determinant,


transpose and inverse.

Apparatus:
Computer loaded with windows7 and MATLAB software

1Pre-Lab Questions:

1. How can you generate identity matrix?

_________________________________________________________________

2. Which command is used to extract diagonal elements of a matrix?

__________________________________________________________________

3. Write MATLAB code to generate a random matrix of size 3x4.

__________________________________________________________________

4. Distinguish between element wise matrix multiplication and square of the matrix.

_________________________________________________________________

5. Give MATLAB commands to extract rows and columns from the matrices.

__________________________________________________________________

Department of Electronics and Communication Engineering 9


Basic Simulation Laboratory

Program:

>> a=magic(3) % generate a 3x3 matrix%

a=

8 1 6
3 5 7
4 9 2

>> sum(a) % find the sum of the elements in each column of matrix a%

ans =

15 15 15

>> b=a' % find the transpose of matrix a%

b=

8 3 4
1 5 9
6 7 2

>> diag (a) %find the diagonal elements of matrix a%

ans =

8
5
2

>> c=fliplr (a) % generate mirror image matrix of a%

c=

6 1 8
7 5 3
2 9 4

>> det (a) %find the determinant of matrix a%

ans =

Department of Electronics and Communication Engineering 10


Basic Simulation Laboratory

-360
>> inv (a) % find the inverse of matrix a%
ans =

0.1472 -0.1444 0.0639


-0.0611 0.0222 0.1056
-0.0194 0.1889 -0.1028

>> d=2*a %multiply matrix a by 2%


d=
16 2 12
6 10 14
8 18 4

>> e=a+d % find the sum of matrices a and d %


e=

24 3 18
9 15 21
12 27 6

>> f=a*b % find the product of two matrices a and b %


f=

101 71 53
71 83 71
53 71 101

>> g=a.*a % find the square of each element in matrix a %


g=
64 1 36
9 25 49
16 81 4

>> h=g(:,2:3) % extract 2&3 columns of matrix g %


h=
1 36
25 49
81 4
>> j=g(1:2,:) % extract 1&3 rows of matrix g %
j=
64 1 36
9 25 49
>> i=eye(3,3) % generate 3x3 identity matrix%

Department of Electronics and Communication Engineering 11


Basic Simulation Laboratory

i=
1 0 0
0 1 0
0 0 1

>> z=rand(4,3) % generate a random matrix of size 4x3 %


z=
0.8147 0.6324 0.9575
0.9058 0.0975 0.9649
0.1270 0.2785 0.1576
0.9134 0.5469 0.9706

Post Lab Questions

1. For a matrix ‘b’, what is the difference between b*b and b.*b?

_______________________________________________________________

_______________________________________________________________

2. Write a Mat Lab command to generate 4x4 identity matrix.

_______________________________________________________________

3. Write MATLAB code to find the square of the identity matrix of size 3x3.

______________________________________________________________

4. How can you find the sum of the elements in a column of matrix?

______________________________________________________________

Outcomes:

Upon completion of the experiment, the student will be able to

1. Perform different operations like inverse, transpose, flipping and extraction of


rows and columns for the given matrices.
2. Generate identity and random matrices
3. Find the sum, product and element wise multiplication of matrices

Department of Electronics and Communication Engineering 12


Basic Simulation Laboratory

Experiment No:

Generation of various signals and sequences


2
Roll No:_______________ Date:_______________

Objectives:

(A). To generate various signals such as Unit impulse, Unit step, Square, Saw tooth,
Triangular, Sinusoidal, Ramp, Sinc Function.
(B). To generate various sequences such as Unit impulse, Unit step, Square, Saw
tooth, Triangular, Sinusoidal, Ramp, Sinc Function.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. What does MATLAB stand for and which version of MATLAB did you use?

2. Why should you place a semicolon at the end of a command?

3. How do you convert a MATLAB command into a comment?

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 13


Basic Simulation Laboratory

4. How many toolboxes does MATLAB provide approximately? Name some of them.

----------------------------------------------------------------------------------------------------------------
5. Distinguish between continuous time and discrete time signals.

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

(A ) Program:

t=-20: 1:20
%--------------------Unit Impulse---------------------%
x=[zeros(1,20), 1,zeros(1,20)] %generate Unit Impulse Signal
figure(1), plot(t,x); % plot the generated Unit Impulse Signal
xlabel('t'); ylabel('x(t)'); title('Unit impulse Signal');
%------------------ Unit Step signal------------------%
y=[zeros(1,20), 1,ones(1,20)]
%y=[zeros(1,20),ones(20,1)] %generate Unit Step Signal
figure(2); plot(t,y); %Plot the generated unit step signal
xlabel('t'); ylabel('x(t)'); title('Unit Step Signal');
%---------------------- Ramp Signal------------------%
x1 = t;
x2 = 0;
x = x1.*(t>=0)+x2.*(t<0); %generate unit ramp signal
figure(3);plot(t,x); % plot the generated ramp signal
xlabel('t'); ylabel('x(t)'); title(' Ramp Signal');
%----------------------rectangular pulse------------%
t1=-10:0.01:10
a7=rectpuls(t1/10)
figure(4),plot(t1,a7), grid on,axis([-10 10 -2 2])
xlabel('time')
ylabel('magnitude')
title('rectangular pulse')
%-------------------- triangular pulse---------------%
t2=-10:0.1:10
a8=tripuls(t2)

Department of Electronics and Communication Engineering 14


Basic Simulation Laboratory

figure(5),plot(t2,a8), grid on
title('triangular pulse')
xlabel('time')
ylabel('magnitude')

%--------------- Sinc Signal----------------------%


x = sinc(t); %generate sinc signal
figure(6);plot(t,x); % plot the generated sinc signal
xlabel('t'); ylabel('x(t)'); title('sinc Signal');
%-----------------Sinusoidal Signal----------------%
T = 2; %declare time period
F = 1/T; %compute frequency
x = sin(2*pi*F*t); %generate sinusoidal signal
figure(7);plot(t,x); % plot the generated sinusoidal signal
xlabel('t'); ylabel('x(t)'); title('sinusoidal Signal');
%---------------- Sawtooth signal-----------------%
fs = 10000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t); %generate sawtooth signal
figure(8);plot(t,x); axis([0 0.2 -1 1]); %plot the generated sawtooth signal

xlabel('t'); ylabel('x(t)'); title('sawtooth Signal');


%----------------- square signal---------------------%
t=(0:0.001:10);
sq_wave=square(4*pi*t); %generate square signal
figure(9); plot(t,sq_wave); axis([0 5 -2 2]) %plot the generated square signal
xlabel('t'); ylabel('x(t)'); title('square signal');
%---------------------periodic triangle------------%
T=20;
x=linspace(0,5*T,10000);
y1=min(0.5,mod(x,T)/T);
y2=min(0.5,1-mod(x,T)/T);
figure(10),plot(x,y1+y2),grid on
xlabel('time')
ylabel('magnitude')
title('periodic triangle wave')

Department of Electronics and Communication Engineering 15


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 16


Basic Simulation Laboratory

(B) Program:

t=-20: 1:20
%--------------------Unit Impulse---------------------%
x=[zeros(1,20), 1,zeros(1,20)] %generate Unit Impulse Signal
figure(1), stem(t,x); % plot the generated Unit Impulse Signal
xlabel('t'); ylabel('x(t)'); title('Unit impulse Signal');
%------------------ Unit Step signal------------------%
y=[zeros(1,20), 1,ones(1,20)]
%y=[zeros(1,20),ones(20,1)] %generate Unit Step Signal
figure(2); stem(t,y); %Plot the generated unit step signal
xlabel('t'); ylabel('x(t)'); title('Unit Step Signal');
%---------------------- Ramp Signal------------------%
x1 = t;
x2 = 0;
x = x1.*(t>=0)+x2.*(t<0); %generate unit ramp signal
figure(3);stem(t,x); % plot the generated ramp signal
xlabel('t'); ylabel('x(t)'); title(' Ramp Signal');

Department of Electronics and Communication Engineering 17


Basic Simulation Laboratory

%----------------------rectangular pulse------------%
t1=-10:0.1:10
a7=rectpuls(t1/10)
figure(4),stem(t1,a7), grid on,axis([-10 10 -2 2])
xlabel('time')
ylabel('magnitude')
title('rectangular pulse')
%-------------------- triangular pulse---------------%
t2=-10:0.1:10
a8=tripuls(t2)
figure(5),stem(t2,a8), grid on
title('triangular pulse')
xlabel('time')
ylabel('magnitude')
%--------------- Sinc Signal----------------------%
x = linspace(-5,5);
y = sinc(x);
figure(6);stem(x,y)
xlabel('time');
ylabel('amplitude');
title('sincfunction');
%-----------------Sinusoidal Signal----------------%
T = 20; %declare time period
F = 1/T; %compute frequency
x = sin(2*pi*F*t); %generate sinusoidal signal
figure(7);stem(t,x); % plot the generated sinusoidal signal
xlabel('t'); ylabel('x(t)'); title('sinusoidal Signal');
%---------------- Sawtooth signal-----------------%
fs = 1000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t); %generate sawtooth signal
figure(8);stem(t,x); axis([0 0.2 -1 1]); %plot the generated sawtooth signal
xlabel('t'); ylabel('x(t)'); title('sawtooth Signal');
%----------------- square signal---------------------%
t=(0:0.01:10);
sq_wave=square(4*pi*t); %generate square signal
figure(9); stem(t,sq_wave); axis([0 5 -2 2]) %plot the generated square signal
xlabel('t'); ylabel('x(t)'); title('square signal');

Department of Electronics and Communication Engineering 18


Basic Simulation Laboratory

%---------------------periodic triangle------------%
T=20;
x=linspace(0,5*T,1000);
y1=min(0.5,mod(x,T)/T);
y2=min(0.5,1-mod(x,T)/T);
figure(10),stem(x,y1+y2),grid on
xlabel('time')
ylabel('magnitude')
title('periodic triangle wave')

Expected Graphs:

Department of Electronics and Communication Engineering 19


Basic Simulation Laboratory

Post Lab Questions:

1. What is the difference between ‘stem’ and ‘plot’ commands?

----------------------------------------------------------------------------------------------------------------

2. Write a MATLAB code for generation of sinusoidal signal with frequency 50HZ.

----------------------------------------------------------------------------------------------------------------

3. Write a MATLAB code for to generate a random signal.

----------------------------------------------------------------------------------------------------------------
4. Write a MATLAB code to plot a magnitude and phase of a complex exponential
signal.

----------------------------------------------------------------------------------------------------------------

5. Which MATLAB command divides the graphic space into six parts and select 5th part?

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to


1. Understood the ways of creating a MATLAB m-file, using the MATLAB Editor, run it
and view the results.
2. Understood the usefulness of different types of signals and sequences.
3. Write MATLAB code to generate any type of signals.

Department of Electronics and Communication Engineering 20


Basic Simulation Laboratory

Experiment No.

Operations on Signals & Sequences


3 Computation of Energy & Average Power

Roll No:_______________ Date:_______________

Objectives:

(A) To perform various operations on signals such as addition, multiplication,


subtraction, time-shifting, folding on signals and compute energy and power of signals.
(B) To perform various operations on sequences such as addition, multiplication,
subtraction, time-shifting, folding on signals and compute energy and power of signals

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. What is the difference between ‘energy’ and ‘power’ of a signal

2. Draw the schematic of a constant multiplier system.

Department of Electronics and Communication Engineering 21


Basic Simulation Laboratory

3. Draw the schematic of a time delay system that delays the signal x(n) by k samples.

----------------------------------------------------------------------------------------------------------------
4. What do you mean by scaling a signal? Where do you find the need for scaling

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------
5. Which operation shifts the signal towards right?

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

(A) Program:

%Program for addition and multiplication of signals


t = [0:.01:1]; % independent (time) variable
A = 8; % amplitude
f1 = 1;
s1 = A*sin(2*pi*f1*t); % create a 1 Hz sine wave
f2 = 2;
s2 = A*sin(2*pi*f2*t); % create a 2 Hz sine wave
figure
subplot(4,1,1)
plot(t, s1)
title('1 Hz sine wave')
ylabel('Amplitude')
%plot the 2 Hz sine wave in the middle panel
subplot(4,1,2) ;plot(t, s2)
title('2 Hz sine wave')
ylabel('Amplitude')
%plot the summed sine waves in the bottom panel
subplot(4,1,3) ;plot(t, s1+s2)
title('Summed sine waves')
ylabel('Amplitude')
xlabel('Time (s)')
xmult=s1.*s2;
subplot(4,1,4);plot(xmult);

Department of Electronics and Communication Engineering 22


Basic Simulation Laboratory

title('multiplication');
ylabel('Amplitude')
xlabel('Time (s)')
% Amplitude scaling
t = [0:.01:1]; % independent (time) variable
A = 8; % amplitude
f1 = 2; % create a 2 Hz sine wave lasting 1 sec
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
plot(s1);
xlabel('t');
ylabel('amplitude');
title('input signal');
s2=2*s1;
subplot(3,1,2)
plot(s2);
xlabel('t');
ylabel('amplitude');
title('amplified input signal');
s3=s1/2;
subplot(3,1,3)
plot(s3);
xlabel('t');
ylabel('amplitude');
title('attenuated input signal');
% Time scaling
t = [0:.05:pi]; % independent (time) variable
A = 8; % amplitude
f1 = 2; % create a 2 Hz sine wave lasting 1 sec
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
plot(s1);
xlabel('t');
ylabel('amplitude');
title ('sine signal')
s2=A*sin(2*2*pi*f1*t); % scaling by a=4
subplot(3,1,2)
plot(s2);
xlabel('t');
ylabel('amplitude');

Department of Electronics and Communication Engineering 23


Basic Simulation Laboratory

title ('scaled sine signal with a=4')


s3=A*sin(.5*pi*f1*t); % scaling by a=1/4
subplot(3,1,3);
plot(s3);
xlabel('t');
ylabel('amplitude');
title ('scaled sine signal with a=1/4');
%--------------------time shifting---------------%
Clc; clear all; close all
t = [0:.01:pi]; % independent (time) variable
A = 8; % amplitude
f1 = 2;
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
plot(t,s1)
xlabel('t');
ylabel('amplitude');
title('input signal')
subplot(3,1,2)
plot(t+10,s1)
xlabel('t');
ylabel('amplitude');
title('right shifted signal')
subplot(3,1,3)
plot(t-10,s1)
xlabel('t');
ylabel('amplitude');
title('left shifted signal')
%--------------------Folding (Time reversal) ---------------%
% Folding for signal
Clc; ; close all; clear all
t = [0:.01:1]; % independent (time) variable
A = 8; % amplitude
f1 = 2; % create a 2 Hz sine wave lasting 1 sec
x = A*sin(2*pi*f1*t);
lx=length(x);
nx=0:lx-1;
xf=fliplr(x);
nf=-fliplr(nx);
subplot(2,1,1);

Department of Electronics and Communication Engineering 24


Basic Simulation Laboratory

plot(nx,x);
xlabel('nx');ylabel('amplitude)');
title('original signal');
subplot(2,1,2);
plot(nf,xf);
xlabel('nf');
ylabel('amplitude');
title('folded signal');
%-------------------computation of energy and power---------------%
x=10*sin(10*pi*t);To=10
xsq=x.^2;
E = trapz(t,xsq);
P = E/(2*To);
disp([' Energy, E = ', num2str(E),' Joules']);
disp([' Power, P = ', num2str(P),' Watts'])

Expected Graphs:

Department of Electronics and Communication Engineering 25


Basic Simulation Laboratory

(B) Program:

%Program for addition and multiplication of signals


t = [0:.01:1]; % independent (time) variable
A = 8; % amplitude
f1 = 1;

Department of Electronics and Communication Engineering 26


Basic Simulation Laboratory

s1 = A*sin(2*pi*f1*t); % create a 1 Hz sine wave


f2 = 2;
s2 = A*sin(2*pi*f2*t); % create a 2 Hz sine wave
figure
subplot(4,1,1)
stem(t, s1)
title('1 Hz sine wave')
ylabel('Amplitude')
%plot the 4 Hz sine wave in the middle panel
subplot(4,1,2) ;stem(t, s2)
title('2 Hz sine wave')
ylabel('Amplitude')
%plot the summed sine waves in the bottom panel
subplot(4,1,3) ;stem(t, s1+s2)
title('Summed sine waves')
ylabel('Amplitude')
xlabel('Time (s)')
xmult=s1.*s2;
subplot(4,1,4);stem(xmult);
title('multiplication');
ylabel('Amplitude')
xlabel('Time (s)')
% Amplitude scaling
t = [0:.01:1]; % independent (time) variable
A = 8; % amplitude
f1 = 2; % create a 2 Hz sine wave lasting 1 sec
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
stem(s1);
xlabel('t');
ylabel('amplitude');
title('input signal');
s2=2*s1;
subplot(3,1,2)
stem(s2);
xlabel('t');
ylabel('amplitude');
title('amplified input signal');
s3=s1/2;
subplot(3,1,3)

Department of Electronics and Communication Engineering 27


Basic Simulation Laboratory

stem(s3);
xlabel('t');
ylabel('amplitude');
title('attenuated input signal');
% Time scaling
t = [0:.05:pi]; % independent (time) variable
A = 8; % amplitude
f1 = 2; % create a 2 Hz sine wave lasting 1 sec
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
stem(s1);
xlabel('t');
ylabel('amplitude');
title ('sine signal')
s2=A*sin(2*2*pi*f1*t); % scaling by a=4
subplot(3,1,2)
stem(s2);
xlabel('t');
ylabel('amplitude');
title ('scaled sine signal with a=4')
s3=A*sin(.5*pi*f1*t); % scaling by a=1/4
subplot(3,1,3);
stem(s3);
xlabel('t');
ylabel('amplitude');
title ('scaled sine signal with a=1/4')
%--------------------time shifting---------------%
clc
clear all
close all
t = [0:.01:pi]; % independent (time) variable
A = 8; % amplitude
f1 = 2;
s1 = A*sin(2*pi*f1*t);
subplot(3,1,1)
stem(t,s1)
xlabel('t');
ylabel('amplitude');
title('input signal')
subplot(3,1,2)

Department of Electronics and Communication Engineering 28


Basic Simulation Laboratory

stem(t+10,s1)
xlabel('t');
ylabel('amplitude');
title('right shifted signal')
subplot(3,1,3)
stem(t-10,s1)
xlabel('t');
ylabel('amplitude');
title('left shifted signal');

%--operation on sequences with input discrete values---%


clear all;
x=[1,2,1,2,1,3,2];
N1=length(x);
n=0:1:N1-1;
subplot(3,3,1),stem(n,x);
xlabel('n');ylabel('x');
title('input sequence x(n)');
y=2*x;
subplot(3,3,2),stem(n,y);
xlabel('n');ylabel('y');
title('multiply sequence y(n)=2*x(n)');
y1=x/3;
subplot(3,3,3),stem(n,y1);
title('divided sequence y1=x/3');
n1=-(N1-1):1:0;
x1=[2,3,1,2,1,2,1];
y2=x1;
subplot(3,3,4),stem(n1,y2);
title('time reversal or folded sequence y2=x(-n)');
y3=x+10;
subplot(3,3,5),stem(n,y3);
title('addition operation to x(n)');
x2=[1,2,1,2,1,3,2];
N2=length(x2);
n2=0:1:N2-1;
subplot(3,3,6),stem(n2-2,x2);
xlabel('n');ylabel('x');

Department of Electronics and Communication Engineering 29


Basic Simulation Laboratory

title('shifted delayed input sequence x(n-2)');


x3=[1,2,1,2,1,3,2];
N3=length(x3);
n3=0:N2-1;
subplot(3,3,7),stem(n3+2,x3);
xlabel('n');ylabel('x');
title('shifted advanced input sequence x(n+2)');
x4=[1,2,3,4,5];
n5=length(x4);
E=x4.*x4;
subplot(3,3,2),stem(E);
title('input sequence');
subplot(3,3,8);stem(E);
title('energy');
p=norm(E)^2/length(x4);
subplot(3,3,9);stem(p);
title('power');

Expected Graphs:

Department of Electronics and Communication Engineering 30


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 31


Basic Simulation Laboratory

Post Lab Questions:

1. Which operator is used for array multiplication?

----------------------------------------------------------------------------------------------------------------
2. Write a MATLAB code o multiply the following two vectors. Check manually if the
result is as desired. A=[1 2 3 4 5] B=[4 6 1 7 8]

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------
3. Write a MATLAB code for to generate a random signal.

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------
4. Which operation shifts the signal toward right?

----------------------------------------------------------------------------------------------------------------
5. When a signal is time advanced what type of a change occurs in it.

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Understood different types of operations that may be performed by a discrete time


system.
2. Write a MATLAB code for any other operation on signals.
3. Write a MATLAB code for finding the energy and power of real as well as complex
discrete time signals.

Department of Electronics and Communication Engineering 32


Basic Simulation Laboratory

Experiment No:

Finding even and odd components & real and


4 imaginary parts of signals

Roll No:_____________ Date:______________

Objectives:

(A) To find even and odd components of a given signal.

(B) To find real and imaginary parts of a signal

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:

1. Write the expression to find the odd component of a signal.

_________________________________________________________________

2. Which command is used to extract odd component of a signal?

__________________________________________________________________

3. Give the expression to find even component of a signal.

__________________________________________________________________

4. Which command is used to extract even component of a signal?


_______________________________________________________________

5. How can you find real and imaginary parts of a signal?

_______________________________________________________________

Department of Electronics and Communication Engineering 33


Basic Simulation Laboratory

Program (A):

n=-1:0.01:2;
s1=sin(2*pi*n)+cos(2*pi*n);
s2=sin(2*pi*(-n))+cos(2*pi*(-n));
figure(1)
subplot(2,1,1);
plot(n,s1);
title('signal s1');
xlabel('time');
ylabel('amplitude');
grid
subplot(2,1,2);
plot(n,s2);
title('signal s2');
xlabel('time');
ylabel('amplitude');
grid
x1=(s1+s2)/2;
x2=(s1-s2)/2;
figure(2)
subplot(2,1,1);
plot(n,x1);
title('even part');
xlabel('time');
ylabel('amplitude');
grid
subplot(2,1,2);
plot(n,x2);
title('odd part');title('signal s1');
xlabel('time');
ylabel('amplitude');
grid

Department of Electronics and Communication Engineering 34


Basic Simulation Laboratory

Expected Graphs

signal s1
2

1
amplitude

-1

-2 complex signal
11-1 -0.5 0 0.5 1 1.5 2
10 time
signal s2
9
2
48.5 49 49.5 50 50.5 51 51.5

1
amplitude

-1

-2
-1 -0.5 0 0.5 1 1.5 2
time

even part
1

0.5
amplitude

-0.5

-1
-1 -0.5 0 0.5 1 1.5 2
time
signal s1
1

0.5
amplitude

-0.5

-1
-1 -0.5 0 0.5 1 1.5 2
time

Department of Electronics and Communication Engineering 35


Basic Simulation Laboratory

Program (B):

x=-5:0.01:5;
a=sinh(x*0.1);
subplot(5,1,1);
plot(x,a), grid on %hyperbolic sine function%
title('hyperbolic sine function');
b=50+10i+sin(2*pi*x);
subplot(5,1,2);
plot(x,b);
title('second signal');
c=a+b;
subplot(5,1,3);
plot(c);
title('complex signal');
d=real(c);
subplot(5,1,4);
plot(d);
title('real part');
e=imag(d);
subplot(5,1,5);
plot(e);
title('imaginary part')

Expected Graphs

hyperbolic sine function


1
0
-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
second signal
51
50
49
-5 -4 -3 -2 -1 0 1 2 3 4 5
complex signal
11
10
9
48.5 49 49.5 50 50.5 51 51.5
real part
52
50
48
0 200 400 600 800 1000 1200
imaginary part
1
0
-1
0 200 400 600 800 1000 1200
Department of Electronics and Communication Engineering 36
Basic Simulation Laboratory

Post Lab Questions


1.

1. What is meant by ImX?

_____________________________________________________________

_______________________________________________________________

2. Explain the command ‘ReX’.

_______________________________________________________________

3. How to find the absolute value of complex signal?

______________________________________________________________

4. How to represent a signal as a combination of even and odd components?

Outcomes:

Upon completion of the experiment, the student will be able to

1. Find and plot even and odd components of a signal.


2. Find real and imaginary parts of a complex signal
3. Find the absolute value of a complex signal

Department of Electronics and Communication Engineering 37


Basic Simulation Laboratory

Experiment No.

Verification of Linearity Property of a System


5
Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for verification of linearity and time invariance


properties of system.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. How do you classify discrete time systems?

2. Define an LTI system.

3. What are advantages of LTI systems because of which they are very popular.

----------------------------------------------------------------------------------------------------------------

4. Give an example of linear systems.

Department of Electronics and Communication Engineering 38


Basic Simulation Laboratory

----------------------------------------------------------------------------------------------------------------

(A )Program:

x1=input('enter the value for first input');


x2=input('enter the value for second input')
a1=input('enter the weighting value for first input a1= ')
a2=input('enter the weighting value for second input a2= ')
f=menu('choose a function','cos(x)','2*x(n)') %choose the functions to verify linearity%
if f == 1 % defining system function y=cos(x)%
y1=a1*cos(x1)+a2*cos(x2);
y2=cos((a1*x1)+(a2*x2));
if y1==y2
disp('y=cos(x) is linear system')
else
disp('y=cos(x) is non-linear system')
end
else %defining y=2*x%
y1 = a1*2*x1+a2*2*x2;
y2 = 2*((a1*x1)+(a2*x2));
if y1==y2
disp('y=2*x is linear system')
disp('y=2*x is linear system')
else
disp('y=2*x is non-linear system')
end
end
enter the value for first input2
enter the value for second input3

x2 =
3
enter the weighting value for first input a1= 4
a1 =
4
enter the weighting value for second input a2= 3
a2 =

Department of Electronics and Communication Engineering 39


Basic Simulation Laboratory

3
f=
1
y=cos(x) is non-linear system

Post Lab Questions:

1. Draw the block diagram notation of a system representing its linearity property.

2. Write a MATLAB code for performing linearity property of arbitrary discrete time
systems.

3. Draw the block diagram of a discrete time system that represents the proof of its
linearity.
----------------------------------------------------------------------------------------------------------------

4. Write a MATLAB code to see if the system described by the following input-output
relationship is linear. Y(n)=x(n)-x(n-1)
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Clearly define linearity and time invariance properties of a discrete time system.
2. Write a MATLAB code for proving the linearity and time invariance property of
arbitrary discrete time systems.

Department of Electronics and Communication Engineering 40


Basic Simulation Laboratory

Experiment No.

Verification of Time Invariant Property of a


6 System

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for verification of linearity and time invariance


properties of system.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. How do you classify discrete time systems?

2. Define an LTI system.

3. What are advantages of LTI systems because of which they are very popular.

----------------------------------------------------------------------------------------------------------------

4. Give an example of time invariant discrete time systems.

Department of Electronics and Communication Engineering 41


Basic Simulation Laboratory

----------------------------------------------------------------------------------------------------------------

(A )Program:

x=input('enter the input applied to the system');


p=input('enter the time at which input arrived')
m= input('enter the time instant at which you want to calculate output')
k=m-p
x(p)=x;
f=menu('choose a function', 'cos(x)','n*x(n)' ) %choose a function to verify the property%
if f == 1 % define a system function y(n)=cos(x(n)) %
y1= cos (x(p))
y2= cos (x(m-k))
if y1==y2
disp('y(n)=cos(x(n)) is time invariant system')
else
disp('y(n)=cos(x(n)) is time varying system')
end
else %define y(n)=nx(n) %
y1=p*x(p)
y2=m*x(m-k)
if y1==y2
disp('y=n*x(n) is time invariant system')
else
disp('y(n)=n*x(n) is time varying system')
end
end
enter the input applied to the system2
enter the time at which input arrived3
p=
3
enter the time instant at which you want to calculate output5
m=
5
k=
2
f=

Department of Electronics and Communication Engineering 42


Basic Simulation Laboratory

1
y1 =
-0.4161
y2 =
-0.4161
y(n)=cos(x(n)) is time invariant system

Post Lab Questions:

1. Draw the block diagram notation of a system representing its time invariance
property.

2. Write a MATLAB code for performing the time invariance property of arbitrary
discrete time systems.

3. Draw the block diagram of a discrete time system that represents the proof of its
linearity.
----------------------------------------------------------------------------------------------------------------

4. Write a MATLAB code to see if the system described by the following input-output
relationship is time invariant. Y(n)=x(n)-x(n-1)

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to


1. Clearly define linearity and time invariance properties of a discrete time system.
2. Write a MATLAB code for proving the linearity and time invariance property of
arbitrary discrete time systems.

Department of Electronics and Communication Engineering 43


Basic Simulation Laboratory

Experiment No.

Computation of unit impulse and unit step


7 response of a system& to determine stability

Roll No:_____________ Date:______________

Objectives:

(A) To find unit impulse response of a given system

(B) To find unit step response of a system

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:

1. Define impulse response.

_________________________________________________________________

2. What do you mean by step response?

__________________________________________________________________

3. The command ‘sys’ indicates_____________________

__________________________________________________________________

4. Which command is used to plot impulse response?


_______________________________________________________________

5. Which command is used to plot step response?

Department of Electronics and Communication Engineering 44


Basic Simulation Laboratory

Program (A):

num=input('enter the numerator polynomial=--');


den=input('enter the denominator polynomial=--');
sys=tf(num,den) % system transfer function%
stp =step(sys);
figure(1);
plot(stp);
title('step response');
xlabel('time');
ylabel('amplitude');
grid

i=impulse(sys);
figure(2);
plot(i);
title('impulse response');
xlabel('time');
ylabel('amplitude');
grid
enter the numerator polynomial=--2
enter the denominator polynomial=--[2,3]

sys =

2
-------
2s+3

Continuous-time transfer function.

Department of Electronics and Communication Engineering 45


Basic Simulation Laboratory

Expected Graphs

step response
0.7

0.6

0.5

0.4
amplitude

0.3

0.2

0.1

0
0 20 40 60 80 100 120 140 160 180 200
time

impulse response
1

0.9

0.8

0.7

0.6
amplitude

0.5

0.4

0.3

0.2

0.1

0
0 20 40 60 80 100 120 140
time

Department of Electronics and Communication Engineering 46


Basic Simulation Laboratory

Program (B)

num=input('enter the numerator polynomial=--');


den=input('enter the denominator polynomial=--');
sys=tf(num,den) % system transfer function%
p=pole(sys);
P=real(p)
P1=max(P);
if P1>0
disp('the system is unstable')
else
disp('the system is stable')
end
enter the numerator polynomial=--[1]
enter the denominator polynomial=--[1,-1]
sys =
1
-----
s-1
Continuous-time transfer function.
P=
1
the system is unstable

Post Lab Questions

1. What is the difference between impulse and step response?

_______________________________________________________________

2. What are the different matrices in state model?

______________________________________________________________

3. The command ‘num’ represents_______________________________

4. Which command is used to specify denominator?

Outcomes:

Upon completion of the experiment, the student will be able to

1. Plot the impulse response of a system.


2. Plot the step response of system

Department of Electronics and Communication Engineering 47


Basic Simulation Laboratory

Experiment No.

Computation of frequency response of a system


8
Regd No:_______________ Date:_______________

Objectives:

(A) To find frequency response of a given system

(B) To plot real, imaginary parts of a given complex function

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:

1. Define frequency response.

_________________________________________________________________

2. How to find magnitude and phase of a complex function?

__________________________________________________________________

3. What is the relation between polar form and rectangular form of a complex

function?

__________________________________________________________________

4. Which command is used to plot frequency response?


_______________________________________________________________

Department of Electronics and Communication Engineering 48


Basic Simulation Laboratory

Program (A)

num=input('type the numerator vector');


den=input('type the denominator vector');
N=input('number of frequency points');
w=0:pi/N:pi;
H=freqz(num,den,w);
figure;
subplot(2,1,1);
plot(w/pi,real(H));
xlabel('\omega/\pi');
ylabel('Amplitude');
title('Real part');
subplot(2,1,2);
plot(w/pi,imag(H));
xlabel('\omega/\pi');
ylabel('Amplitude');
title('Imaginary part');
figure
subplot(2,1,1);
plot(w/pi,abs(H));
xlabel('\omega/\pi');
ylabel('Magnitude');
title('Magnitude Spectrum');
subplot(2,1,2);
plot(w/pi,angle(H));
xlabel('\omega/\pi');
ylabel('Phase(radians)');
title('Phase Spectrum');
type the numerator vector[.5 0 .5]
type the denominator vector1
number of frequency points512

Department of Electronics and Communication Engineering 49


Basic Simulation Laboratory

Expected Graphs
Real part
1

Amplitude 0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/
Imaginary part
0.5
Amplitude

-0.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/

Magnitude Spectrum
1
Magnitude

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/
Phase Spectrum
2
Phase(radians)

-1

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/

Department of Electronics and Communication Engineering 50


Basic Simulation Laboratory

Post Lab Questions

5. Define frequency response.

_______________________________________________________________

_______________________________________________________________

6. What is the difference between impulse and frequency response?

_______________________________________________________________

Outcomes:

Upon completion of the experiment, the student will be able to

3. Plot the frequency response of a system.


4. Find magnitude and phase of the given complex function.
5. Can convert complex function from rectangular to polar form.

Department of Electronics and Communication Engineering 51


Basic Simulation Laboratory

Experiment No.

Convolution between Signals & Sequences


9
Roll No:_______________ Date:_______________

Objectives:

Write a Matlab program for convolution between signals and sequences.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define convolution. What is the significance of convolution?

2. What are the steps involved in convolution operation?

3. Draw the block diagram representation of the input output relationship of an LTI
system.

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 52


Basic Simulation Laboratory

4. Compare and contrast convolution sum and convolution integral.

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------
5. Which mathematical equation represents the convolution between two sequences?

----------------------------------------------------------------------------------------------------------------

(A ) Program:

%------------------ Unit Step signal------------------%


t=-10:0.1:10;
x1 =1;
x2 = 0;
x = x1.*(t>=0)+x2.*(t<0); %generate Unit Step Signal
figure; plot(t,x); %Plot the generated unit step signal
xlabel('t'); ylabel('x(t)'); title('Unit Step Signal u(t)');
%------------------ Exponential signal------------------%
y=exp(-2*t).*(t>=0);
figure,plot(t,y);title('exponential signal exp(-2t)');
%------------------ convolution of two signals------------------%
h=conv(x,y);
n3=length(h);
t1=0:1:n3-1; %set time vector for h signal
figure,plot(t1,h),xlim ([0 600]);title('convolution between u(t) & exp(-2t)');

Expected Graphs:

Department of Electronics and Communication Engineering 53


Basic Simulation Laboratory

(B) Program:

clear all;
x=[1,2,1,2,1,3,2];
N1=length(x);
n=0:1:N1-1;
subplot(2,2,1),stem(n,x);
xlabel('n'),ylabel('x(n)');
title('input sequence x(n)');
h=[1,-1,2,-2,1,1];
N2=length(h);
n1=0:1:N2-1;
subplot(2,2,2),stem(n1,h);
xlabel('n');ylabel('h(n)');
title('impulse signal h(n)');
y=conv(x,h);
n2=0:1:N1+N2-2;
subplot(2,1,2),stem(n2,y);
xlabel('n'),ylabel('y(n)'); title('convolution of 2 sequences x(n) and h(n)');

Department of Electronics and Communication Engineering 54


Basic Simulation Laboratory

Expected Graphs:

Post Lab Questions:

1. Which operator denotes the convolution between two signals?


---------------------------------------------------------------------------------------------------------------
-
2. Which MATLAB command computes the convolution between two sequences a
and b?

3. Given two sequences a and b, is the operation conv(a,b) same as conv(b,a).


----------------------------------------------------------------------------------------------------------------
4. When do you get h(n) at the output of an LTI system.

Outcomes:

Upon completion of the experiment, the student will be able to


1. Define convolution operation between two signals and sequences and the
significance of such an operation.
2. Compute output of an LTI system manually for a given signal.
3. Write a MATLAB code for performing convolution operation without built in
function.

Department of Electronics and Communication Engineering 55


Basic Simulation Laboratory

Experiment No.
Autocorrelation & Cross Correlation

10 between Signals and Sequences

Roll No:_______________ Date:_______________

Objectives:

(A). To generate various signals such as Unit impulse, Unit step, Square, Saw tooth,
Triangular, Sinusoidal, Ramp, Sinc Function.
(B). To generate various sequences such as Unit impulse, Unit step, Square, Saw
tooth, Triangular, Sinusoidal, Ramp, Sinc Function.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define correlation and auto correlation.

2. Compare convolution and correlation.

3. What are the steps involved in the computation of correlation? How do they differ
when compared with those of convolution?
----------------------------------------------------------------------------------------------------------------

4. Which MATLAB command computes auto correlation and cross correlation.

Department of Electronics and Communication Engineering 56


Basic Simulation Laboratory

----------------------------------------------------------------------------------------------------------------

5. Which mathematical equation represents cross correlation.

--------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------

(A ) Program:

% ---------------------Cross Correlation of two Signals-------------------------%


clear all;
close all;
clc;
t = 0:0.01:2;
a = cos(2 * pi * t);
b = sin(2 * pi * t);
res = xcorr2(a,b);
subplot(2,2,1);
plot(a);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input signal(1)');
subplot(2,2,2);
plot(b);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input Signal(2)');
subplot(2,2,[3,4]);
plot(res);
xlabel('----> Samples');
ylabel('----> Amplitude');title('Output Signal');

Department of Electronics and Communication Engineering 57


Basic Simulation Laboratory

% ---------------------Auto Correlation of two Signals-------------------------%


N=1024;
f1=1;
Fs=200;n=0:N-1;
x=sin(2*pi*f1*n/Fs)
t=[1:N]*(1/Fs);
subplot(2,1,1);
plot(t,x);
title('sinwave of frequency 1000hz(Fs=800hz)');
xlabel('time[s]');
ylabel('amplitude');
grid;
Rxx=xcorr(x);
subplot(2,1,2);
plot(Rxx);
title('auto correlation of sinwave');
xlabel('lags');ylabel('autocorrelation');

Expected Graphs:

Department of Electronics and Communication Engineering 58


Basic Simulation Laboratory

(B) Program:

%auto correlation of a sequence


clear all;
x=[1,2,3,4,5];
disp('x values are');
y=xcorr(x,x);
subplot(2,1,1),stem(x);
title('input sequence');
xlabel('a(n)------------->');
ylabel('amplitude');
subplot(2,1,2);stem(y);
title('output sequence');
xlabel('c(n)----->');
ylabel('amplitude');
disp('the result is');
% cross correlation of a sequence
clear all;
x=[1,2,3,4,5];
y=[2,1,4,5,1]

Department of Electronics and Communication Engineering 59


Basic Simulation Laboratory

disp('x values are');


disp('y values are');
z=xcorr(x,y);
subplot(1,3,1),stem(x);
title('input sequence1');
xlabel('a(n)------------->');
ylabel('amplitude');
subplot(1,3,2),stem(y);
title('input sequence2');
xlabel('b(n)------------->');
ylabel('amplitude');
subplot(1,3,3);stem(z);
title('output sequence');
xlabel('c(n)----->');
ylabel('amplitude');
disp('the result is');

Expected Graphs:

Department of Electronics and Communication Engineering 60


Basic Simulation Laboratory

Post Lab Questions:

1. How do you compute cross correlation between x and y using the ‘conv’ command?

2. Write MATLAB program to prove that the auto correlation between two discrete
time signals, without using the built-in ‘xcorr’ command.

3. Write MATLAB code for computing the cross correlation of two periodic sequences,
each of period N.
----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to


1. Distinguish between cross correlation and auto correlation.
2. Compute the cross correlation between two given discrete time signals manually
with a thorough knowledge of the operations involved in the computation process.

Department of Electronics and Communication Engineering 61


Basic Simulation Laboratory

Experiment No.
Finding the Fourier Transform of a given
Signal and Plotting its Magnitude and
11 Phase Spectrum

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for finding the Fourier Transform of a given signal and
plot its Magnitude and phase spectrum.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Distinguish between the Fourier series and Fourier transform.

2. Express the Fourier transform in the equation form.

3. What is frequency spectrum?

----------------------------------------------------------------------------------------------------------------
4. Which equation specifies the magnitude and phase of spectral components of FT?

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 62


Basic Simulation Laboratory

5. Which MATLAB command computes the FT of a signal?

----------------------------------------------------------------------------------------------------------------

(A ) Program:

%-----------Given function f(t)=e-a|x| ------------------------------------%


clc;
a = sym(1);
t=0:.0002:100;
syms x
syms t
f = exp(-a*abs(x));
figure (1),subplot(1,3,1),ezplot((f))
r= (fourier(f))
xr=real(r);
xi=imag(r);
X=sqrt(xr^2+xi^2);
subplot(1,3,2),ezplot(X),title('magnitude spectrum');
P=(-atan(xi/xr));
subplot(1,3,3),ezplot(P),title('phase spectrum');

Expected Graphs:

Department of Electronics and Communication Engineering 63


Basic Simulation Laboratory

Post Lab Questions:

1. What is the significance of FT in signal processing?

2. What type of symmetry does the magnitude and phase spectra of FT possess?

3. Which MATLAB commands compute the magnitude and phase of FT?

----------------------------------------------------------------------------------------------------------------
4. Write a MATLAB program to find the Fourier transform of sinusoidal signal having
frequency 100Hz.

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Define the Fourier transform and Inverse Fourier transform.


2. Compute Fourier transform of any given arbitrary aperiodic signal manually and
plots magnitude and phase spectra.

Department of Electronics and Communication Engineering 64


Basic Simulation Laboratory

Experiment No.

WAVEFORM SYNTHESIS USING LAPLACE


TRANSFORM
12
Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for Wave form Synthesis using Laplace transform

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. What is the need of Laplace transform?

2. Express the Laplace transform in equation form.

----------------------------------------------------------------------------------------------------------------
3. Define Region of Convergence (ROC).

----------------------------------------------------------------------------------------------------------------

4. Write any three properties of ROC.


----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 65


Basic Simulation Laboratory

(A ) Program:

H = tf( {-5 } , {[1 -1 2] })


%perform laplace transform
x_a=sym('sin(a*t)+cos(b*t)');
x_a=laplace(x_a);
disp(['(a)x_a(s)=',char(x_a),'=',char(simplify(x_a))]);
%perform inverse laplace trasform
x_b=sym('(a*s^2)/(s^2+b^s)');
x_b=ilaplace(x_b);
disp(['(b)x_b(t)=',char(x_b),'=',char(simplify(x_b))]);

Expected Output:

-5
-----------
s^2 - s + 2
(a)x_a(s)=a/(s^2+a^2)+s/(s^2+b^2)=(a*s^2+a*b^2+s^3+s*a^2)/(s^2+a^2)/(s^2+b^2)
(b)x_b(t)=a*ilaplace(s^2/(s^2+b^s),s,t)=a*ilaplace(s^2/(s^2+b^s),s,t)

Post Lab Questions:

1. Which MATLAB command is used to find the Laplace transform of a signal.

2. Write a MATLAB code to plot pole zero map in S-domain.

3. Which MATLAB command is used to display the text in command window.


----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to


1. Know the utility of Laplace transform in the analysis of continuous time LTI system.
2. Explain the effect of different type of poles on the behavior of continuous time LTI
systems.

Department of Electronics and Communication Engineering 66


Basic Simulation Laboratory

Experiment No.

13 Verification of Sampling Theorem

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for verification of sampling theorem.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define sampling theorem.

----------------------------------------------------------------------------------------------------------------
2. What do you understand by uniform sampling?

3. What is aliasing?

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 67


Basic Simulation Laboratory

(A )Program:

f=input('enter the signal frequency');


fs= input('enter the sampling frequency');
t=0:1:fs+f-1;
if fs>=2*f
disp('sampling theorem is satisfied');
% plotting sinusoidal signal%
n=0:1/fs:pi;
x=sin(2*pi*f*n);
figure(1);
plot(n,x);
title('sinusoidal signal');
xlabel('time ');
ylabel('amplitude ');
% plotting spectrum of sinusoidal signal%
s1=0:1/f:1-1/f;
s2=(1-1/f)-s1;
w1=[s2,zeros(1,(fs))];
w2=[zeros(1,(fs-f)),s1,s2];
figure(2);
plot(t,w1, 'r',t,w2, 'b');
title('frequency plot');
xlabel('frequency ');
ylabel('amplitude ');
legend('original signal, LSB&USB ')
else
disp('sampling theorem is not satisfied');
s1=0:1/f:1-1/f;
s2=(1-s1);
w1=[s2,zeros(1,(fs))];
w2=[zeros(1,(fs-f)),s1,s2];
plot(t,w1, 'r',t,w2, 'b');
title('frequency plot');
xlabel('frequency ');
ylabel('amplitude ');
legend('original signal, LSB&USB ');
end

Department of Electronics and Communication Engineering 68


Basic Simulation Laboratory

The output
case(1)
enter the signal frequency20
enter the sampling frequency50
sampling theorem is satisfied
case(2)
enter the signal frequency20
enter the sampling frequency30
sampling theorem is not satisfied

Expected Graphs:

sinusoidal signal
1

0.8

0.6

0.4

0.2
amplitude

-0.2

-0.4

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3 3.5
time

Case(1): fs>2f

Department of Electronics and Communication Engineering 69


Basic Simulation Laboratory

frequency plot
1
original signal, LSB&USB
0.9

0.8

0.7

0.6
amplitude

0.5

0.4

0.3

0.2

0.1

0
0 10 20 30 40 50 60 70
frequency

Case(2): fs<2f

frequency plot
1
original signal, LSB&USB
0.9

0.8

0.7

0.6
amplitude

0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25 30 35 40 45 50
frequency

Department of Electronics and Communication Engineering 70


Basic Simulation Laboratory

Post Lab Questions:

1. When does aliasing occur? How do you overcome it?

2. What does a sampler do?

3. What is an anti aliasing filter? Why is it called so?

----------------------------------------------------------------------------------------------------------------

4. What is meant by quantization?

---------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Explain the sampling process and the concept of aliasing.


2. Write a Matlab code for verifying Sampling theorem.

Department of Electronics and Communication Engineering 71


Basic Simulation Laboratory

Experiment No.
Generation of Gaussian Noise, Computation of its
Mean, M.S.Values and Its Skew, Kurtosis
14 And Psd, Probability Distribution Function

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for generation of Gaussian noise, and computation of its mean,
mean square values, and its psd, probability distribution function.

Apparatus:

Computer loaded with Windows 7


MATLAB software.

Pre Lab Questions:

1. What is noise? How is it generated in electronic circuits?

2. What is white Gaussian noise? How do you compare it with white uniform noise?

3. How do you define mean? What does it represent in a signal?

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 72


Basic Simulation Laboratory

4. Define probability distribution function. How is it differing from probability density


function?

----------------------------------------------------------------------------------------------------------------

5. Define skew and kurtosis

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

(A ) Program:

%generation of gaussian noise


t=0:0.001:0.1;
x=sin(2*pi*50*t);
subplot(2,1,1);plot(x);
title('original value');
xlabel('time');
ylabel('amplitude');
%y=x+2*randn(size(t));
y=awgn(x,10);
subplot(2,1,2);plot(y);
%plot(1000*t(1:50),y(1:50))
title('signal corrupted with noise');
xlabel('time');
ylabel('amplitude');
%%%%%%%%%%%%%%%%%%%%
x=-10:10;
pdfuniform=unifpdf(x,-5,5);
subplot(3,3,1);plot(x,pdfuniform);
title('uniform probability function');
x1=-15:0.1:25;
mu=3;
sigma=4;
pdfnormal=normpdf(x1,mu,sigma);
subplot(3,3,2);plot(x1,pdfnormal);
title('normal probalbility function');
pdfuniform1=rand(1,10000);

Department of Electronics and Communication Engineering 73


Basic Simulation Laboratory

subplot(3,3,3);hist(pdfuniform1);
title('uniform probability histogram');
subplot(3,3,4);hist(pdfuniform1,100);
title('uniform probability ,100.bin histogram');
pdfmean=5;
pdfstd=7;
pdfnormalss=randn(1,10000)*(pdfstd+pdfmean);
subplot(3,3,5);hist(pdfnormalss);
title('normal distrubution with mean=5,std=7');
subplot(3,3,6);hist(pdfnormalss,100);
title('normal distrubution with mean=5,std=7');
%%%%%%%%%%%%%%%%%%%%%%%%%
x=randn([5 4])
k=kurtosis(x);
k1=skewness(x);
subplot(3,3,1);stem(k);
title('skew');
subplot(3,3,2);stem(k);
title('kurtosis');
%mean
x=normrnd(0,1,100,5);
xbar=(mean(x));
subplot(3,3,3);stem(xbar);
title('mean');
%median
xodd=1:5;
modd=median(xodd)
subplot(3,3,4);stem(modd);
title('odd median');
xeven=1:4;
meven=median(xeven)
subplot(3,3,5);stem(meven);
x=normrnd(0,1,100,6);
title('even median');
%standerd deviation
y=std(x)
subplot(3,3,6);stem(y);
title('standard deviation');
[n,p]=size(x);
x=x-ones(n,1)*mean(x);

Department of Electronics and Communication Engineering 74


Basic Simulation Laboratory

y=x'*x/(n-1);
title('standard deviation');
%correlation
x=randn(30,4);
x(:,4)=sum(x,2);
[r,p]=corrcoef(x)
subplot(3,3,7);stem([r,p]);
title('correlation');
[i,j]=find(p<0.05);
[i,j]
%varience
x=[-1 1];
w=[1 3]
v1=var(x);
subplot(3,3,8);stem(v1);
title('varience');
%%%%%%%%%%%%%%%
Fs=1000;
t=0:1/Fs:1;
M=length(t);
w=randn(1,M);
x=cos(2*pi*200*t)+w;
h=spectrum.welch;
psd(h,x,'Fs',Fs);

Expected Graphs:

Department of Electronics and Communication Engineering 75


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 76


Basic Simulation Laboratory

Post Lab Questions:

1. What is power spectral density? How is it related to the Fourier transform?

2. How does the mean and standard deviation affect the shape of Gaussian
distribution?

Department of Electronics and Communication Engineering 77


Basic Simulation Laboratory

3. What do you understand by SNR? Should it be in general low or high? Why?

----------------------------------------------------------------------------------------------------------------

4. Write a MATLAB code to generate real and complex Gaussian noise.

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Know the concept of noise and its relevance in signal processing.


2. Clearly define white Gaussian noise and its probability distribution function.

Department of Electronics and Communication Engineering 78


Basic Simulation Laboratory

Experiment No.
Removal of Noise by Autocorrelation and Cross
15 Correlation

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for removal of noise by autocorrelation & cross correlation

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define cross correlation between two discrete time periodic signals?

2. Which command is used to generate a random signal?

3. State the formula for determining the signal to noise ratio in decibels?

----------------------------------------------------------------------------------------------------------------

4. What is the reason due to which the noise is removed by autocorrelation?

Department of Electronics and Communication Engineering 79


Basic Simulation Laboratory

----------------------------------------------------------------------------------------------------------------

(A ) Program:

N=1024;
f=1;
Fs=200;
n=0:N-1;
x=sin(2*pi*f*n/Fs);
y=x+10*randn(1,N);
subplot(3,1,1);plot(x);
title('pure sinewave');
grid;
subplot(3,1,2);plot(y);
title('y(n), puresinewave + noise');
grid;
Rxy=xcorr(x,y);
subplot(3,1,3);plot(Rxy);
title('cross correlation Rxy');
grid;
%%%%%%%%%%%%%%%%%%%%%%%
N=1024;
f1=1;
Fs=100;
n=0:N-1;
x=sin(2*pi*f1*n/Fs);
subplot(3,1,1);plot(x);title('pure sine wave');
grid;
x1=x+(10*randn(1,N));
subplot(3,1,2);
plot(x1);
title('pure sinewave + noise');
grid;
Rxx=xcorr(x,x1);
subplot(3,1,3);
plot(Rxx);

Department of Electronics and Communication Engineering 80


Basic Simulation Laboratory

title('auto correlation Rxx');


%%%%%%%%%%%%%%%%%%%
clc;
%-----------generate sinusoidal signal-------------------------%
t=0:0.1:10;
x = sin(2*pi*t); %generate sinusoidal signal
figure,plot(t,x);title('sinusoidal signal')
%-----------generate gaussian noise-------------------------%
% Y = WGN(1, 201, 10, 'complex');
Y = WGN(1, 101, 10, 'real');
%-----------generate (sinusoidal+noise) signal-------------------------%
X=x+Y;
figure(2),plot(t,X),title('sinusoidal signal+gaussian noise')
s = xcorr2(x,X);
figure(3),plot(s),title('Extraction of sinusoidal signal');

Expected Graphs:

Department of Electronics and Communication Engineering 81


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 82


Basic Simulation Laboratory

Post Lab Questions:

1. When does the cross correlation between two signals become nearly zero?

2. Why can’t we filter out noise from noisy signal? Why should you use correlation to
do so?What are the steps involved in convolution operation?

3. Which MATLAB command is used to generate a white Gaussian noise?


----------------------------------------------------------------------------------------------------------------

4. What is the auto correlation of white noise?


----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Write a MATLAB code for removing noise from a noisy periodic signal and calculate
its period.

Department of Electronics and Communication Engineering 83


Basic Simulation Laboratory

Experiment No.

16 Impulse Response of Raised Cosine Filter

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for impulse response of raised cosine filter

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define the raised cosine filter.

2. State the purpose for which the raised cosine filters are normally used.

3. How the ‘raised cosine’ is different from a normal cosine function.

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 84


Basic Simulation Laboratory

4. What do you understand by the ‘bandwidth’ of the filter?

----------------------------------------------------------------------------------------------------------------

(A ) Program:

[y,t]=rcosflt(ones(10,1),1,8,'fir',.5,6);
%delay=6samples
[y1,t1]=rcosflt(ones(10,1),1,8,'fir',.5,8);
plot(t,y,t1,y1,'--');
peak=t(find(y==max(y)));
peak1=t1(find(y1==max(y1)));
pt=[min(peak),min(peak1)];

Expected Graphs:

(B) Program:
Department of Electronics and Communication Engineering 85
Basic Simulation Laboratory

%parametres
delay=3;
dataL=20;
R=0.5;
Fs=8;Fd=1;
PropD=0;
%generate random data at time 0,1Fd,2/Fd....
x=randsrc(dataL,1,[],1245);
tx=[PropD:PropD+dataL-1]./Fd;
%plot data
stem(tx,x);
xlabel('time');ylabel('amplitude');
%set axis&labels
axis([0 30 -1.5 1.5]);
%%%%%%%%%%%%%%%%%%%%%%%
clc;
t=-10:0.1:10;
%--------------------Unit Impulse---------------------%
x1=1;
x2=0;
x =x1.*(t==0); %generate Unit Impulse Signal
subplot(121), plot(x); % plot the generated Unit Impulse Signal
xlabel('t'); ylabel('x(t)'); title('Unit impulse Signal');
%--------------impulse response of raised cosine filter-----------%
y = rcosflt(x,1,8,'fir'); % Same as original example
% y = rcosflt(x,1,8,'fir/sqrt'); % FIR square-root RC filter
% y = rcosflt(x,1,8,'iir'); % IIR raised cosine filter
% y = rcosflt(x,1,8,'iir/sqrt'); % IIR square-root RC filter
% y = rcosflt(x,1,8,'fir'); subplot(122),plot(y)

Department of Electronics and Communication Engineering 86


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 87


Basic Simulation Laboratory

Post Lab Questions:

1. Which MATLAB command returns the impulse response of an FIR type RCF? What is
its syntax?

2. What is the so special about the impulse response of a raised cosine filter?

3. How do you obtain the width of the transition band?

----------------------------------------------------------------------------------------------------------------

4. Have you heard about ‘root raised cosine filter’? How is it related to RCF?

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Represent the frequency response and the impulse response of raised cosine filter.
2. Define raised cosine filter and explain the applications in which it is used.

Department of Electronics and Communication Engineering 88


Basic Simulation Laboratory

Experiment No.
Checking a Random Process for Stationary in Wide

17 Sense

Roll No:_______________ Date:_______________

Objectives:

Write a matlab program for checking of Wide Sense Stationary.

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define random process and distinguish between random variable and random
process

2. What is an ergodic random process?

3. How do you classify the random process.


----------------------------------------------------------------------------------------------------------------

4. What condition must be satisfied for a random process to be called WSS?

----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 89


Basic Simulation Laboratory

(A ) Program:

%wide sense of stationary random process


X=[1 2 3 4 5 6];
M=mean(X);
subplot(3,3,1);stem(M);
title('mean of given sequence');
X1=fliplr(X);
y=xcorr(X);
subplot(3,3,2);stem(y);
title('auto correlation');
yneg=fliplr(y);
subplot(3,3,3);stem(yneg);
title('folded auto correlation');
if(y==yneg)
disp('given sequence is Wss');
end
z=(y*M);
%z=Xcorr(yneg);
subplot(3,3,4);stem(z);
title('product of mean autocorrelation');
subplot(3,3,5);stem(X1);
title('given folded input sequence');
subplot(3,3,6);stem(X);
title('given input sequence');
M1=mean(X1);
subplot(3,3,7);stem(M1);
title(' mean of flipped sequence');

Expected Graphs:

Department of Electronics and Communication Engineering 90


Basic Simulation Laboratory

Post Lab Questions:

1. Prove that the Gaussian random process generated using randn command is a WSS
process using MATLAB.
----------------------------------------------------------------------------------------------------------------
2. Which MATLAB command is used to fold the signal.

3. What is the difference between the average and time average?


----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Develop a MATLAB code for checking if a given random process is wide sense
stationary.
2. Classify the random processes.

Department of Electronics and Communication Engineering 91


Basic Simulation Laboratory

Experiment No.

18 Verification of Wiener-Khintchine Relations

Roll No:_____________ Date:______________

Objectives:

(A) To verify Wiener-Khintcine relations.

(B) To plot power spectrum and power spectral densities.

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:

5. Define Wiener-Khintchine relations.

_________________________________________________________________

6. Define fft.

__________________________________________________________________

7. What is the relation between autocorrelation and power spectral density?

_________________________________________________________________

Department of Electronics and Communication Engineering 92


Basic Simulation Laboratory

Program (A)

Fs=100;
t=0:1/Fs:10;
x=sin(2*pi*15*t)+sin(2*pi*30*t);
N=512;
X=fft(x,N);
f=Fs*(0:N-1)/N;
Power=X.*conj(X)/N;
figure(1)
plot(f,Power)
title('Power Spectrum through fft');
xlabel('frequency f');
ylabel('power');
figure(2)
rxx=xcorr(x,x);
Sxx=fft(rxx,512);
plot(f, abs(Sxx))
title('Fourier transform of autocorrelation');
xlabel('frequency f');
ylabel('abs(Sxx)');

Expected Graphs

Power Spectrum through fft


120

100

80
power

60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
frequency f

Department of Electronics and Communication Engineering 93


Basic Simulation Laboratory

4
x 10 Fourier transform of autocorrelation
3.5

2.5

abs(Sxx) 1.5

0.5

0
0 10 20 30 40 50 60 70 80 90 100
frequency f

Post Lab Questions

7. What is the significance of Wiener-Khintchine theorem?

_______________________________________________________________

_______________________________________________________________

8. How to plot the power spectral density?

_______________________________________________________________

Outcomes:

Upon completion of the experiment, the student will be able to

6. Verify Wiener-Khintchine relations


7. Find the power spectral density of the signal.

Department of Electronics and Communication Engineering 94


Basic Simulation Laboratory

Experiment No.

19 Extraction of Periodic signal masked by Noise

Roll No:_____________ Date:______________

Objectives:

(A) To generate noise signal, adding noise to an arbitrary signal

(B) To extract signal masked by noise

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:

1. Define cross correlation.

_________________________________________________________________

2. Define Gaussian noise.

__________________________________________________________________

Program (A)

M=256;

n=0:M-1;

x=cos(16*pi/M)+sin(32*pi*n/M);

snr=input('Type the desired SNR');

px=var(x)

Department of Electronics and Communication Engineering 95


Basic Simulation Laboratory

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

for i=1:M

if rem(i-1,N)==0

d(i)=1

end;

end;

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

Department of Electronics and Communication Engineering 96


Basic Simulation Laboratory

title('Noisy signal y(n)');

subplot(2,1,2);

stem(n,d);

grid; axis ([1 96 -0.5 0.5]);

xlabel('n');

ylabel('d(n)');

title('pulse 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)')

Department of Electronics and Communication Engineering 97


Basic Simulation Laboratory

periodic signal x(n)


3

1
x(n)

-1

-2

-3
10 20 30 40 50 60 70 80
n

Noisy signal y(n)

2
y(n)

-2

10 20 30 40 50 60 70 80 90
n

0.5

1. Distinguish
0 between auto correlation and cross correlation.
0 0.1 0.2 0.3 0.4 0.5 0.6
________________________________________ 0.7 0.8 0.9 1

2. Define white noise.

Department of Electronics and Communication Engineering 98


Basic Simulation Laboratory

Experiment No.

20 Locating poles and zeros in Z-plane &S-plane

Roll No:_____________ Date:______________

Objectives:

(A) To locate poles and zeros in the z-plane

(B) To plot the pole-zero diagram in the z-plane

Apparatus:

Computer loaded with windows7 and MATLAB software

1 Pre-Lab Questions:
1. Define transfer function.

_________________________________________________________________

2. Define poles and zeros.

_________________________________________________________________

Program

zer = -0.5;
pol = 0.9*exp(j*2*pi*[-0.3 0.3]');
[b,a] = zp2tf(zer,pol,1);
fvtool(b,a);
figure(1);
fvtool(b,a,'Analysis','polezero')
figure(2);
zplane(b,a)

Expected Graphs

Department of Electronics and Communication Engineering 99


Basic Simulation Laboratory

Pole/Zero Plot

0.5

Imaginary Part
0

-0.5

-1
-1.5 -1 -0.5 0 0.5 1 1.5
Real Part

1. Distinguish between s-plane and z-plane.

_______________________________________________________________

_______________________________________________________________

2. Define transfer function

______________________________________________________________

Outcomes:

Upon completion of the experiment, the student will be able to

1. plot the poles and zeros in z-plane


2. Find the transfer function of the system.

Department of Electronics and Communication Engineering 100


Basic Simulation Laboratory

Experiment No.

21 Gibbs Phenomenon

Regd No:_______________ Date:_______________

Objectives:

Write a MATLAB program to verify Gibbs phenomenon

Apparatus:

Computer loaded with Windows 7


MATLAB

Pre Lab Questions:

1. Define Gibbs phenomenon.

2. What do you understand by a ‘discontinuity’ in a signal?

3. State the difference between the two words ‘analysis’ and ‘synthesis’, in general
terms.

----------------------------------------------------------------------------------------------------------------

4. Does a square contain even harmonics?

Department of Electronics and Communication Engineering 101


Basic Simulation Laboratory

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

(A ) Program:

t=linspace(-2,2,2000);
u=linspace(-2,2,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
K=2;
N=[1,3,7,19,49,70];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*K*sin(m*pi/2)/(m*pi)];
end;
fN=K/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n);
plot(u,sq,'r','LineWidth',2);
hold on;
plot(t,fN,'LineWidth',2);
hold off;
axis([-2 2 -0.5 2.5]);
grid;
xlabel('time');
ylabel('y_N(t)');
title(['N=',nq]);
end;

Department of Electronics and Communication Engineering 102


Basic Simulation Laboratory

Expected Graphs:

Post Lab Questions:

1. Which MATLAB command is used to convert integer to string?

2. What is the reason for Gibbs phenomenon occurrence?

3. State atleast three important observations that you made by observing all the
synthesized square-wave graphs?

----------------------------------------------------------------------------------------------------------------

Outcomes:

Upon completion of the experiment, the student will be able to

1. Write MATLAB code for observing the Gibbs phenomenon in graphical form.

Department of Electronics and Communication Engineering 103

Potrebbero piacerti anche