Basic Simulation Laboratory Manual B.Tech (Ii Year - I Sem) (2021-22)
Basic Simulation Laboratory Manual B.Tech (Ii Year - I Sem) (2021-22)
Basic Simulation Laboratory Manual B.Tech (Ii Year - I Sem) (2021-22)
LABORATORY MANUAL
B.TECH
(II YEAR – I SEM)
(2021-22)
Prepared by:
Ms.D. Asha, Associate Professor
VISION
MISSION
QUALITY POLICY
BS LAB MANUAL ECE, MRCET
➢
Place the chairs properly.
➢
Turn off the system properly
➢
Turn off the monitor.
➢
Please check the laboratory notice board regularly for updates.
BS LAB MANUAL ECE, MRCET
CONTENTS
Finding the Even and Odd parts of Signal/Sequence and Real and
4. Imaginary parts of Signal 20
Locating the Zeros and Poles and plotting the Pole-Zero maps in S-
11. plane and Z- Plane for the given transfer function. 44
0
BS LAB MANUAL ECE, MRCET
Experiment No-1
1
BS LAB MANUAL ECE, MRCET
% Creating a matrix
>> m=[1 2 3;4 6 9;2 6 9]
m=
123
469
269
% Extracting sub matrix from matrix
>> sub_m=m(2:3,2:3)
sub_m =
69
69
% extracting column vector from matrix
>> c=m (:,2)
c=
2
6
6
% extracting row vector from matrix
>> d=m (3,:)
d=
269
% creation of two matrices a and b
>> a=[2 4 -1;-2 1 9;-1 -1 0]
a=
2 4 -1
-2 1 9
-1 -1 0
>> b=[0 2 3;1 0 2;1 4 6]
b=
023
102
146
2
BS LAB MANUAL ECE, MRCET
% matrix multiplication
>> x1=a*b
x1 =
308
10 32 50
-1 -2 -5
% element to element multiplication
>> x2=a.*b
x2 =
0 8 -3
-2 0 18
-1 -4 0
% matrix addition
>> x3=a+b
x3 =
262
-1 1 11
036
% matrix subtraction
>> x4=a-b
x4 =
2 2 -4
-3 1 7
-2 -5 -6
% matrix division
>> x5=a/b
x5 =
-9.0000 -3.5000 5.5000
12.0000 3.7500 -5.7500
3.0000 0.7500 -1.7500
% element to element division
>> x6=a./b
Warning: Divide by zero.
3
BS LAB MANUAL ECE, MRCET
x6 =
Inf 2.0000 -0.3333
-2.0000 Inf 4.5000
-1.0000 -0.2500 0
% inverse of matrix a
>> x7=inv(a)
x7 =
-0.4286 -0.0476 -1.7619
0.4286 0.0476 0.7619
-0.1429 0.0952 -0.4762
% transpose of matrix a
>> x8=a'
x8 =
2 -2 -1
4 1 -1
-1 9 0
RESULT: Matrix operations are performed using Matlab software.
VIVA QUESTIONS:-
1. Expand MATLAB? And importance of MATLAB?
2. What is clear all and close all will do?
3. What is disp() and input()?
4. What is the syntax to find the Eigen values and eigenvectors of the matrix?
5. Define scalar and vector?
4
BS LAB MANUAL ECE, MRCET
Experiment No-2
Generation of signals and sequences
AIM: Generate various signals and sequences (Periodic and aperiodic), such as Unit Impulse,
Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.
Software Required: Matlab software
Theory: If the amplitude of the signal is defined at every instant of time then it is called
continuous time signal. If the amplitude of the signal is defined at only at some instants of
time then it is called discrete time signal. If the signal repeats itself at regular intervals then it
is called periodic signal. Otherwise they are called aperiodic signals.
EX: ramp,Impulse,unit step, sinc- Aperiodic signals
square,sawtooth,triangular sinusoidal – periodic signals.
Ramp sinal: The ramp function is a unitary real function, easily computable as the mean of
the independent variable and its absolute value.This function is applied in engineering. The
name ramp function is derived from the appearance of its graph.
r(t)= t when
0 else
Unit impulse signal: One of the more useful functions in the study of linear systems is the
"unit impulse function."An ideal impulse function is a function that is zero everywhere but at
the origin, where it isinfinitely high. However, the area of the impulse is finite
Y(t)= 1 when t=0
=0 other wise
Unit step signal: The unit step function and the impulse function are considered to be
fundamental functions in engineering, and it is strongly recommended that the reader
becomes very familiar with both of these functions.
0 if t < 0
u(t)= 1 if t > 0
If t=0
5
BS LAB MANUAL ECE, MRCET
PROCEDURE:-
➢ Open MATLAB
➢ Open new M-file
➢ Type the program
➢ Save in current directory
➢ Compile and Run the program
➢ For the output see command window\ Figure window
PROGRAM:
% Generation of signals and sequences
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of unit impulse signal
t1=-1:0.01:1
y1=(t1==0);
subplot(2,2,1);
plot(t1,y1);
xlabel('time');
ylabel('amplitude');
title('unit impulse signal');
%generation of impulse sequence
subplot(2,2,2);
stem(t1,y1);
xlabel('n');
ylabel('amplitude');
title('unit impulse sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
BS LAB MANUAL ECE, MRCET
7
BS LAB MANUAL ECE, MRCET
ylabel('amplitude');
title('triangular wave sequence');
%generation of sinsoidal wave signal
y6=sin(2*pi*40*t);
subplot(2,2,3);
plot(t,y6);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title(' sinsoidal wave signal');
%generation of sin wave sequence
subplot(2,2,4);
stem(t,y6);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sin wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of ramp signal
y7=t;
figure;
subplot(2,2,1);
plot(t,y7);
xlabel('time');
ylabel('amplitude');
title('ramp signal');
%generation of ramp sequence
subplot(2,2,2);
stem(t,y7);
xlabel('n');
ylabel('amplitude');
title('ramp sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of sinc signal
t3=linspace(-5,5);
y8=sinc(t3);
subplot(2,2,3);
plot(t3,y8);
xlabel('time');
ylabel('amplitude');
title(' sinc signal');
%generation of sinc sequence
subplot(2,2,4);
stem(y8);
xlabel('n');
ylabel('amplitude');
title('sinc sequence');
8
BS LAB MANUAL ECE, MRCET
Output:
9
BS LAB MANUAL ECE, MRCET
10
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
1. Define Signal?
2. Define continuous and discrete Signals?
3. State the relation between step, ramp and Delta Functions?
4. Differentiate saw tooth and triangular signals?
5. Define Periodic and aperiodic Signal?
11
BS LAB MANUAL ECE, MRCET
Experiment No-3
Basic Operations on Signals and sequences
AIM: perform the operations on signals and sequences such as addition, multiplication,
scaling, shifting, folding and also compute energy and power.
Software Required: Matlab software.
Theory:
Signal Addition
Addition: any two signals can be added to form a third signal,
z (t) = x (t) + y (t)
Multiplication :
Multiplication of two signals can be obtained by multiplying their values at every instants . z
z(t) = x (t) y (t)
Time reversal/Folding:
Time reversal of a signal x(t) can be obtained by folding the signal about t=0.
Y(t)=y(-t)
Signal Amplification/Scaling : Y(n)=ax(n) if a < 1 attnuation
a >1 amplification
Time shifting: The time shifting of x(n) obtained by delay or advance the signal in time by
using y(n)=x(n+k)
If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal
12
BS LAB MANUAL ECE, MRCET
Energy:
Average power:
Program:
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% addition of signals
y1=x1+x2;
subplot(2,2,3);
plot(t,y1);
xlabel('time');
ylabel('amplitude');
title('addition of two signals');
% multiplication of signals
y2=x1.*x2;
subplot(2,2,4);
plot(t,y2);
xlabel('time');
ylabel('amplitude');
title('multiplication of two signals');
% scaling of a signal1
13
BS LAB MANUAL ECE, MRCET
A=2;
y3=A*x1;
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('input signal')
subplot(2,2,2);
plot(t,y3);
xlabel('time');
ylabel('amplitude');
title('amplified input signal');
% folding of a signal1
h=length(x1);
nx=0:h-1;
subplot(2,2,3);
plot(nx,x1);
xlabel('nx');
ylabel('amplitude');
title('input signal')
y4=fliplr(x1);
nf=-fliplr(nx);
subplot(2,2,4);
plot(nf,y4);
xlabel('nf');
ylabel('amplitude');
title('folded signal');
%shifting of a signal 1
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('time t');
ylabel('amplitude');
title('input signal');
subplot(3,1,2);
plot(t+2,x1);
xlabel('t+2');
ylabel('amplitude');
title('right shifted signal');
subplot(3,1,3);
plot(t-2,x1);
xlabel('t-2');
ylabel('amplitude');
title('left shifted signal');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14
BS LAB MANUAL ECE, MRCET
%operations on sequences
n1=1:1:9;
s1=[1 2 3 0 5 8 0 2 4];
figure;
subplot(2,2,1);
stem(n1,s1);
xlabel('n1');
ylabel('amplitude');
title('input sequence1');
s2=[1 1 2 4 6 0 5 3 6];
subplot(2,2,2);
stem(n1,s2);
xlabel('n2');
ylabel('amplitude');
title('input sequence2');
% addition of sequences
s3=s1+s2;
subplot(2,2,3);
stem(n1,s3);
xlabel('n1');
ylabel('amplitude');
title('sum of two sequences');
% multiplication of sequences
s4=s1.*s2;
subplot(2,2,4);
stem(n1,s4);
xlabel('n1');
ylabel('amplitude');
title('product of two sequences');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
BS LAB MANUAL ECE, MRCET
OUTPUT:
enter the input sequence[1 3 2 4 1]
energy of given sequence is
e1 = 31
energy of given signal is
e2 = 4.0388
power of given sequence is
p1 = 6.2000
power of given signal is
p2 = 0.3672
Result: Various operations on signals and sequences are performed.
16
BS LAB MANUAL ECE, MRCET
Output:
17
BS LAB MANUAL ECE, MRCET
18
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
1. Define Symmetric and Anti-Symmetric Signals?
2. Define scaling of a signal?
3. What are the Different types of representation of discrete time signals?
4. What are the Different types of Operation performed on signals?
5. What is System?
19
BS LAB MANUAL ECE, MRCET
Experiment No-4
Even and odd parts of signal and sequence & Real and imaginary parts of
Signal
AIM: Finding even and odd part of the signal and sequence and also find real and imaginary
parts of signal.
Program:
clc
close all;
clear all;
y=sin(-t)+cos(-t); % y(t)=x(-t)
subplot(2,2,2)
plot(t,y)
xlabel('t');
ylabel('amplitude')
title('input signal with t= -t')
20
BS LAB MANUAL ECE, MRCET
even=(x+y)/2;
subplot(2,2,3)
plot(t,even)
xlabel('t');
ylabel('amplitude')
title('even part of the signal')
odd=(x-y)/2;
subplot(2,2,4)
plot(t,odd)
xlabel('t');
ylabel('amplitude');
title('odd part of the signal');
21
BS LAB MANUAL ECE, MRCET
title('input signal');
subplot(3,1,2)
plot(t,real(x2));
xlabel('time');
ylabel('amplitude');
title('real part of signal');
subplot(3,1,3)
plot(t,imag(x2));
xlabel('time');
ylabel('amplitude');
title('imaginary part of siganl');
RESULT: Even and odd part of the signal and sequence, real and imaginary parts of signal
are computed.
Output:
22
BS LAB MANUAL ECE, MRCET
23
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
1. What is the formula to find odd part of signal?
2. What is Even Signal?
3. What is Odd Signal?
4. What is the formula to find even part of signal?
5. How to represent a signal with even and odd parts?
24
BS LAB MANUAL ECE, MRCET
Experiment No-5
Convolution between signals& sequences
Aim: Write the program for convolution between two signals and also between two
sequences.
Program:
clc;
close all;
clear all;
%program for convolution of two sequences
x=input('enter input sequence: ');
h=input('enter impulse response: ');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence')
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse response sequence')
subplot(3,1,3);
25
BS LAB MANUAL ECE, MRCET
stem(y);
xlabel('n');
ylabel('y(n)');
title('linear convolution')
disp('linear convolution y=');
disp(y)
%program for signal convolution
t=0:0.1:10;
x1=sin(2*pi*t);
h1=cos(2*pi*t);
y1=conv(x1,h1);
figure;
subplot(3,1,1);
plot(x1);
xlabel('t');
ylabel('x(t)');
title('input signal')
subplot(3,1,2);
plot(h1);
xlabel('t');
ylabel('h(t)');
title('impulse response')
subplot(3,1,3);
plot(y1);
xlabel('n');
ylabel('y(n)');
title('linear convolution');
Output:
enter input sequence: [1 3 4 5]
linear convolution y=
2 7 15 26 21 20
26
BS LAB MANUAL ECE, MRCET
27
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
1. Define Convolution?
2. Define Properties of Convolution?
3. What is the Difference between Convolution& Correlation?
4. Define impulse response?
5. What is Half Wave Symmetry?
28
BS LAB MANUAL ECE, MRCET
Experiment No-6
Auto correlation and Cross correlation
Aim: To compute Auto correlation and Cross correlation between signals and sequences.
It is a measure of the degree to which two sequences are similar. Given two real-valued
sequences x(n) and y(n) of finite energy,
1. Shifting
2. Multiplication
3. Addition
Cross correlation +
rx , y (l ) = x ( n) y ( n − l )
n = −
Autocorrelation
+
rx , x (l ) = x ( n) x ( n − l )
n = −
Program:
clc;
close all;
clear all;
29
BS LAB MANUAL ECE, MRCET
% cross correlation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t');
ylabel('z1(t)');
title('cross correlation ');
% auto correlation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t');
ylabel('z2(t)');
title('auto correlation ');
Result: Auto correlation and Cross correlation between signals and sequences is computed.
30
BS LAB MANUAL ECE, MRCET
31
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
1. Define Correlation? And its properties?
2. Define Auto-Correlation?
3. Define Cross-Correlation?
4. What is the importance of correlation?
5. What is the difference b/w correlation and convolution?
32
BS LAB MANUAL ECE, MRCET
Experiment No-7
Verification of Linearity of a Discrete System
AIM: Verify the Linearity of a given Discrete System.
Software Required:
Mat lab software 7.0 and above
Theory:
LINEARITY PROPERTY:
Any system is said to be linear if it satisfies the superposition principal. superposition
principal state that Response to a weighted sum of input signal equal to the corresponding
weighted sum of the outputs of the system to each of the individual input signals.
y(n)=T[x(n)]
x3=[a*x1(n) +b *x2(n) ]
Y3(n)= T [x3(n)]
Program:
% Verification of Linearity of a given System.
% a) y(n)=nx(n) b) y=x^2(n)
clc;
clear all;
close all;
n=0:40;
a1=input('enter the scaling factor a1=');
a2=input('enter the scaling factor a2=');
x1=cos(2*pi*0.1*n);
x2=cos(2*pi*0.4*n);
x3=a1*x1+a2*x2;
%y(n)=n.x(n);
y1=n.*x1;
y2=n.*x2;
y3=n.*x3;
yt=a1*y1+a2*y2;
yt=round(yt);
y3=round(y3);
if y3==yt
disp('given system [y(n)=n.x(n)]is Linear');
else
33
BS LAB MANUAL ECE, MRCET
Output:
enter the scaling factor a1=3
enter the scaling factor a2=5
given system [y(n)=n.x(n)]is Linear
given system is [y(n)=x(n).^2 ]non Linear
VIVA QUESTIONS:-
34
BS LAB MANUAL ECE, MRCET
Experiment No -8
Verification of Time Invariance of a Discrete System
A system is called time invariant if its input – output characteristics do not change with time
35
BS LAB MANUAL ECE, MRCET
Output:
VIVA QUESTIONS:-
36
BS LAB MANUAL ECE, MRCET
Experiment No-9
Unit sample, unit step and sinusoidal response of the given LTI system and verifying its
stability
AIM: Compute the Unit sample, unit step and sinusoidal response of the given LTI system
and verifying its stability
Software Required:
Theory:
A discrete time system performs an operation on an input signal based on predefined criteria
to produce a modified output signal. The input signal x(n) is the system excitation, and y(n) is
the system response. The transform operation is shown as,
If the input to the system is unit impulse i.e. x(n) = δ(n) then the output of the system is
known as impulse response denoted by h(n) where,
h(n) = T[δ(n)]
we know that any arbitrary sequence x(n) can be represented as a weighted sum of discrete
impulses. Now the system response is given by,
37
BS LAB MANUAL ECE, MRCET
Program:
% verifing stability
figure;
zplane(b,a);
38
BS LAB MANUAL ECE, MRCET
Result: The Unit sample, unit step and sinusoidal response of the given LTI system is
computed and its stability verified. Hence all the poles lie inside the unit circle, so system is
stable.
Output:
39
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
40
BS LAB MANUAL ECE, MRCET
Experiment No-10
Finding the Fourier Transform of a given signal and plotting its magnitude and phase
spectrum
AIM: To find the Fourier Transform of a given signal and plotting its magnitude and phase
spectrum.
Theory:
Fourier Transform:
The Fourier transform as follows. Suppose that ƒ is a function which is zero outside of some
interval [−L/2, L/2]. Then for any T ≥ L we may expand ƒ in a Fourier series on the interval
[−T/2,T/2], where the "amount" of the wave e2πinx/T in the Fourier series of ƒ is given by
Program:
clc;
clear all;
close all;
fs=1000;
N=1024; % length of fft sequence
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]);
grid;
xlabel('t');
ylabel('amplitude');
title('input signal');
% Fourier transformof given signal
x1=fft(x);
% magnitude spectrum
41
BS LAB MANUAL ECE, MRCET
k=0:N-1;
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag);
grid;
xlabel('t');
ylabel('amplitude');
title('magnitude of fft signal')
%phase spectrum
Xphase=angle(x1);
subplot(3,1,3);
plot(k,Xphase);
grid;
xlabel('t');
ylabel('angle');
title('phase of fft signal');
Output:
42
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:
43
BS LAB MANUAL ECE, MRCET
Experiment No-11
AIM: Write the program for locating poles and zeros and plotting pole-zero maps in s-plane
and z-plane for the given transfer function.
Theory:
Z-transforms
The Z-transform, like many other integral transforms, can be defined as either a one-sided or
two-sided transform.
Bilateral Z-transform
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z)
defined as
Unilateral Z-transform
Alternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or unilateral Z-
transform is defined as
Example:
44
BS LAB MANUAL ECE, MRCET
Program:
clc;
clear all;
close all;
%enter the numerator and denamenator cofficients in square brackets
num=input('enter numerator co-efficients');
den=input('enter denominator co-efficients');
Result: Pole-zero maps are plotted in s-plane and z-plane for the given transfer function.
Output:
enter numerator co-efficients[1 -1 4 3.5]
poles =
-2.4874
0.4937 + 0.9810i
0.4937 - 0.9810i
zeros =
0.8402 + 2.1065i
0.8402 - 2.1065i
-0.6805
45
BS LAB MANUAL ECE, MRCET
46
BS LAB MANUAL ECE, MRCET
VIVA QUESTIONS:-
47
BS LAB MANUAL ECE, MRCET
Experiment No-12
Sampling theorem verification
The maximum frequency component of g(t) is fm. To recover the signal g(t) exactly from its
samples it has to be sampled at a rate fs ≥ 2fm.
The minimum required sampling rate fs = 2fm is called ' Nyquist rate
Fig
ure 3: (a) sampling signal δ (t) ) (b) Spectrum δ (w)
48
BS LAB MANUAL ECE, MRCET
Figure 5: Recovery of signal by filtering with a fiter of width 2wm Aliasing ws < 2wm.
Aliasing leads to distortion in recovered signal. This is the reason why sampling frequency
should be atleast twice thebandwidth of the signal. Oversampling ws >2wm. This condition
avoid aliasing.
49
BS LAB MANUAL ECE, MRCET
Program:
clc;
clear all;
close all;
t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');
ylabel('x(t)');
title('continous time signal');
grid;
n1=-4:1:4;
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs<2fm');
hold on;
subplot(2,2,2);
plot(n1,x1);
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs=2fm');
hold on;
subplot(2,2,3);
plot(n2,x2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs>2fm')
hold on;
subplot(2,2,4);
50
BS LAB MANUAL ECE, MRCET
plot(n3,x3)
grid;
OUTPUT:
VIVA QUESTIONS:-
51