0% found this document useful (0 votes)
9 views106 pages

CL Experiments

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

CL Experiments

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

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

Department of Electronics and Communication Engineering 2


Basic Simulation Laboratory

 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.
Matlab is capable to interpret and evaluate the numerical matrices expressions as
a) Directly from keyboard in command window
b) Or on form of sequences of expressions which are saved in a text file, called m-file
and execute it in command window.
c) Or 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.
2. Below window is launched with default layout.

Department of Electronics and Communication Engineering 3


Basic Simulation Laboratory

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 4


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 5


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

Department of Electronics and Communication Engineering 6


Basic Simulation Laboratory

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:
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
11. qr -QR factorization
12. chol- Cholesky decomposition

Department of Electronics and Communication Engineering 7


Basic Simulation Laboratory

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 --- New---M-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

Experiment No.

Generation of Signals and Sequences


1
Regd 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 9


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 10


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 11


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 12


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 13


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 14


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 15


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.

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

Department of Electronics and Communication Engineering 16


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph Questions (2M)
10M) (2M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 17


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 18


Basic Simulation Laboratory

Experiment No.

Operations on Signals & Sequences


2 Computation of Energy & Average Power

Regd 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 19


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 20


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 21


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 22


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

Department of Electronics and Communication Engineering 23


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 24


Basic Simulation Laboratory

(B) 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)
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')

Department of Electronics and Communication Engineering 25


Basic Simulation Laboratory

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

Department of Electronics and Communication Engineering 26


Basic Simulation Laboratory

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

Department of Electronics and Communication Engineering 27


Basic Simulation Laboratory

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

Department of Electronics and Communication Engineering 28


Basic Simulation Laboratory

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 29


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 30


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 31


Basic Simulation Laboratory

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph Questions (2M)
10M) (2M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 32


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 33


Basic Simulation Laboratory

Experiment No.

Convolution between Signals & Sequences


3
Regd 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 34


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 35


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 36


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.

Department of Electronics and Communication Engineering 37


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph Questions (2M)
10M) (2M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 38


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 39


Basic Simulation Laboratory

Experiment No.
Autocorrelation & Cross Correlation

4 Between Signals and Sequences

Regd 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?
----------------------------------------------------------------------------------------------------------------

Department of Electronics and Communication Engineering 40


Basic Simulation Laboratory

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

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

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 41


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 42


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 43


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 44


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.

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

Department of Electronics and Communication Engineering 45


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph (2M) Questions (2M)
10M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 46


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 47


Basic Simulation Laboratory

Experiment No.

Verification of Linearity and Time


5 Invariance Properties of System Sequences

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

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

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

Department of Electronics and Communication Engineering 48


Basic Simulation Laboratory

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

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

(A )Program:

N=128;
f1=150;
f2=300;
fs=8000;
n=0:N-1;
x1=sin(2*pi*(f1/fs)*n);
x2=cos(2*pi*(f2/fs)*n);
y1=x1;
y2=x2;
figure(1);
subplot(3,3,1);
plot(n,x1);
grid;
title('signal x1(t)');
subplot(3,3,2);
plot(n,y1);
grid;
title('signal y1(t)');
subplot(3,3,3);
plot(n,x2);
grid;
title('signal x2(t)');
subplot(3,3,4);
plot(n,y2);
grid;
title('signal y2(t)');
%signal delay
x1d=[zeros(1,20),x1(1:N-20)];
subplot(3,3,5);
plot(n,x1d);
grid;
title('delayed x1d(n),[x1(n-20)]');

Department of Electronics and Communication Engineering 49


Basic Simulation Laboratory

y1d=x1d;
subplot(3,3,6);
plot(n,y1d);
title('delayed y1d(n),[y1(n-20)]');
x2d=[zeros(1,20),x2(1:N-20)];
subplot(3,3,7);
plot(n,x2d);
grid;
title('delayed x2d(n),[x2(n-20)]');
y2d=x2d;
subplot(3,3,8);
plot(n,y2d);
grid;
title('delayed y2d(n),[y2(n-20)]');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1=input('enter first input sequence');
x2=input('enter second input sequence');
y1=x1;y2=x2;
if[(x1+x2)==(y1+y2)]
disp('given sequence is additive');
else
disp('given sequence is non additive');
end
k=input('enter scaling value of k');
y3=k*x1;y4=k*x2;
if((k*x1+k*x2)==(k*y1+k*y2))
disp('given sequence is homegene');
else
disp('given sequence is not homegene');
end
%%%%%%%%
N1=length(x1);
n=0:1:N1-1;
subplot(3,3,1);stem(n,x1);
xlabel('n'),ylabel('x');
title('first input sequence x1[n]');
N2=length(x2);
m=0:1:N2-1;
subplot(3,3,2);stem(m,x2);

Department of Electronics and Communication Engineering 50


Basic Simulation Laboratory

xlabel('m'),ylabel('x');
title('second input sequence x2[n]');
x1d=[zeros(1,2),x1(1:N1-2)];
subplot(3,3,3),stem(n,x1d);
xlabel('n-2'),ylabel('x1[n-2]');
title('delayed input sequence x1[n-2]');
N3=length(x1);
n1=0:1:N3-1;
subplot(3,3,4);stem(n1,y1);
xlabel('n1'),ylabel('y1');
title('first output sequence y1[n]');
y1d=[zeros(1,2),y1(1:N3-2)];
subplot(3,3,5),stem(n1,y1d);
xlabel('n-2'),ylabel('y1[n-2]');
N4=length(y2);
n2=0:1:N4-1;
subplot(3,3,6);stem(n2,y2);
xlabel('n2'),ylabel('y2');
title('second output sequence y2[n]');
y2d=[zeros(1,2),y1(1:N4-2)];
subplot(3,3,7),stem(n2,y2d);
xlabel('n-2'),ylabel('y2[n-2]');
title('second delayed input sequence y1[n-2]');
%%%%%%%%%%%%%%
subplot(3,3,8),stem(n1,y3);
xlabel('n1'),ylabel('y3');
title('output sequence y3=k*x1');
subplot(3,3,9),stem(n2,y4);
xlabel('n2'),ylabel('y4');
title('output sequence y4=k*x2');
%%%%%%%%%%%%%
if(x1d==y1d)
disp('given sequence is an linear time invarient system');
else
disp('given sequence is not a linear time invarient system');
end

Department of Electronics and Communication Engineering 51


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 52


Basic Simulation Laboratory

(B) Program:

t=-10:0.1:10;
y1=sin(t);
y2=cos(t);
subplot(121),plot(t,y1),title('sinewave');grid on
subplot(122),plot(t,y2),title('coswave');grid on
%--------------------linearity property---------------%
y3=2*y1;
y4=3*y2;
y5=y3+y4;
y6=t.*y5;
y7=t.*y3;
y8=t.*y4;
y9=y7+y8;
e=(y6)-(y9);
figure,subplot(2,2,1),plot(t,y6),title('T[a1*x1(t)+a2*x2(t)]');grid on
subplot(2,2,2),plot(t,y9),title('a1*T[x1(t)]+a2*T[x2(t)]');grid on
%--------------------time invariant property---------------%
Y2=sin(t-2);
Y3=t.*Y2;
Y4=(t-2).*sin(t-2);
figure,plot(t,Y3,'b--'),title('time invariant');grid on ,text(10*10^5,20,'level2')
hold; plot(t,Y4,'r--'),legend('T[x(t-2)]','y(t-2)',-1)

Expected Graphs:

Department of Electronics and Communication Engineering 53


Basic Simulation Laboratory

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)

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

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

Department of Electronics and Communication Engineering 54


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph Questions (2M)
10M) (2M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 55


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 56


Basic Simulation Laboratory

Experiment No.
Finding the Fourier Transform of A Given
Signal and Plotting Its Magnitude And
6 Phase Spectrum

Regd 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 57


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 58


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 59


Basic Simulation Laboratory

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 60


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 61


Basic Simulation Laboratory

Experiment No.
WAVEFORM SYNTHESIS USING LAPLACE
TRANSFORM
7
Regd 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 62


Basic Simulation Laboratory

(A ) Program:

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

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

Department of Electronics and Communication Engineering 63


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 64


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 65


Basic Simulation Laboratory

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

Regd 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 66


Basic Simulation Laboratory

4. Define probability distribution function. How is it differ 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 67


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 68


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

Department of Electronics and Communication Engineering 69


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 70


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 71


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 72


Basic Simulation Laboratory

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations Calculations Post-Lab Viva Total*(10M)
(Max.Marks- Questions (2M) &Graph (2M) Questions (2M)
10M) (2M) (2M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 73


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 74


Basic Simulation Laboratory

Experiment No.

9 Verification of Sampling Theorem

Regd 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 75


Basic Simulation Laboratory

(A )Program:

clear all;
clc;
t=-100:0.01:100;
fm=.02;
x=cos(2*pi*t*fm);
subplot(221),plot(t,x);title('continuous time signal')
fs1=.02;
n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(222),stem(n,x1,':'),title('discrete time signal with fs<2fm')
fs2=0.04;
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(223),stem(n1,x2),title('discrete time signal with fs=2fm')
hold on
subplot(223),plot(n1,x2,':')
n2=-50:50;
fs3=0.5;
x3=cos(2*pi*fm*n2/fs3);
subplot(224),stem(n2,x3);,title('discrete time signal with fs>2fm')
hold on
subplot(224),plot(n2,x3,':')
%%%%%%%%%%%%%%%%%%%
clear all;
t=-5:0.0001:5;
F1=3;F2=23;
x=cos(2*pi*F1*t)+cos(2*pi*F2*t);
figure(1);plot(t,x);
axis([-0.4 0.4 -2 2]);
xlabel('time t in sec');
ylabel('x(t)');
title('continuous time signal ');
Fs1=1.4*F2;ts1=1/Fs1;
n1=-0.4:ts1:0.4;
xs1=cos(2*pi*F1*n1)+cos(2*pi*F2*n1);
figure(2);stem(n1,xs1);

Department of Electronics and Communication Engineering 76


Basic Simulation Laboratory

hold on;plot(t,x,'r:');axis([-0.4 0.4 -2 2]);hold off


xlabel('time sample(n)');ylabel('amplitude');
title('discrete time signal');
legend('Fs<2Fmax');
Fs2=2*F2;ts2=1/Fs2;
n2=-0.4:ts2:0.4;
xs2=cos(2*pi*F1*n2)+cos(2*pi*F2*n2);
figure(3);stem(n2,xs2);
hold;plot(t,x,'r:');axis([-0.4 0.4 -2 2]);hold off
xlabel('time sample(n)');
ylabel('amplitude');
title('discrete time signal');
legend('Fs=2Fmax');
Fs3=7*F2;ts3=1/Fs3;
n3=-0.4:ts3:0.4;
xs3=cos(2*pi*F1*n3)+cos(2*pi*F2*n3);
figure(4);stem(n3,xs3);
hold;plot(t,x,'r:');
axis([-0.4 0.4 -2 2]);hold off
xlabel('time sample(n)');ylabel('amplitude');
title('discrete time signal');
legend('Fs>2Fmax');
%program to verify sampling theorem
clear all;
t=-100:0.01:100;
fm=0.02;
x=cos(2*pi*t*fm);
subplot(2,2,1);plot(t,x);
xlabel('time in sec');
ylabel('x(t)');
title('continuous signal');
fs1=0.02;
n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(2,2,2);stem(n,x1);
hold on;
subplot(2,2,2);plot(n,x1,':');
title('discrete time signal x(n) with fs<2fm');
xlabel('n');
ylabel('x(n)');

Department of Electronics and Communication Engineering 77


Basic Simulation Laboratory

fs2=0.04;
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(2,2,3);stem(n1,x2);
hold on;
subplot(2,2,3);plot(n1,x2,':');
title('discrete time signal x(n) with fs=2fm');
xlabel('n');
ylabel('x(n)');
n2=-50:50;
fs3=0.5;
x3=cos(2*pi*fm*n2/fs3);
subplot(2,2,4);stem(n2,x3);
hold on;
subplot(2,2,4);plot(n2,x3,':');
title('discrete time signal x(n) with fs>2fm');
xlabel('n');ylabel('x(n)');

Expected Graphs:

Department of Electronics and Communication Engineering 78


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 79


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 80


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 81


Basic Simulation Laboratory

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 82


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 83


Basic Simulation Laboratory

Experiment No.
Removal of Noise by Autocorrelation And Cross

10 Correlation

Regd 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?

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

Department of Electronics and Communication Engineering 84


Basic Simulation Laboratory

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

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

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

Department of Electronics and Communication Engineering 85


Basic Simulation Laboratory

plot(Rxx);
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 86


Basic Simulation Laboratory

Department of Electronics and Communication Engineering 87


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?

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

Department of Electronics and Communication Engineering 88


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 89


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 90


Basic Simulation Laboratory

Experiment No.

11 Impulse Response of Raised Cosine Filter

Regd 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 91


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:

Department of Electronics and Communication Engineering 92


Basic Simulation Laboratory

(B) Program:

%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 93


Basic Simulation Laboratory

Expected Graphs:

Department of Electronics and Communication Engineering 94


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 95


Basic Simulation Laboratory

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 96


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 97


Basic Simulation Laboratory

Experiment No.
Checking a Random Process for Stationary in Wide

12 Sense

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

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

Department of Electronics and Communication Engineering 98


Basic Simulation Laboratory

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

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

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

Department of Electronics and Communication Engineering 99


Basic Simulation Laboratory

Expected Graphs:

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.

Department of Electronics and Communication Engineering 100


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 101


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 102


Basic Simulation Laboratory

Experiment No.

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

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

Department of Electronics and Communication Engineering 103


Basic Simulation Laboratory

4. Does a square contain even harmonics?

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

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

(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 104


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?

Department of Electronics and Communication Engineering 105


Basic Simulation Laboratory

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.

Grading:

Date of
Submission
Marks Awarded Pre-Lab Observations(2 Calculations Post-Lab Viva Total*(1
(Max.Marks- Questions(2 M) &Graph (2M) Questions(2 (2M) 0M)
10M) M) M)

Remarks

Signature of the
Evaluator with
Date

Department of Electronics and Communication Engineering 106


Basic Simulation Laboratory

Notes:

Department of Electronics and Communication Engineering 107

You might also like