BS Lab Manual
BS Lab Manual
TECHNOLOGY
(AUTONOMOUS)
(Affiliated to Osmania University) Himayathsagar, Hyderabad, Telangana.
i
ii
S. No. CONTEN PAGE
TS No.
1 Vision of the Institution I
2 Mission of the Institution I
3 Vision of the Department II
4 Mission of the Department II
5 PEOs II
6 POs III
7 PSOs IV
8 Introduction to OCTAVE IV
9 General Guidelines & Safety instructions XXVII
PROGR
AMS
10 Program 1: Basic Operations on Matrices 1
11 Program 2: Generation of Various Signals and Sequences 2
12 Program 3: Operations on Signals and Sequences 3
13 Program 4: Finding the Even and Odd parts of Signals/Sequence 4
14 Program 5: Convolution for Signals and sequences 6
15 Program 6: Auto Correlation and Cross Correlation for Signals and 8
Sequences.
16 Program 7: Verification of Linearity and Time Invariance Properties of a 9
given Continuous/Discrete System.
17 Program 8: Finding the Fourier Transform of a given signal and plotting 10
its magnitude and phase spectrum.
18 Program 9: Locating the Zeros and Poles and plotting the Pole-Zero 11
maps in S-plane and Z-Plane for the given transfer function
19 Program 10: Sampling Theorem Verification 13
20 Annexure-I: Basic Simulation Lab- Syllabus 22
iii
LORDS INSTITUTE OF ENGINEERING AND TECHNOLOGY
i
LORDS INSTITUTE OF ENGINEERING AND TECHNOLOGY
DM2: To impart training to students for good designing skills and exposure to Research
& Development and innovations by using modern tools in frontier areas of Engineering
and Project Management
5.PROGRAM OUTCOMES
PO2: Problem analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs with
appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
ii
PO4: Conduct investigations of complex problems: Use research-based knowledge
and research methods including design of experiments, analysis and interpretation of
data, and synthesis of the information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
iii
6. PROGRAM SPECIFIC OUTCOMES
PSO1: Work as Software Engineers for providing solutions to real world problems
using Structured, Object Oriented Programming languages and open source software.
PSO2: Function as Systems Engineer, Software Analyst and Tester for IT and ITeS.
iv
7. INTRODUCTION TO BASIC SIMULATION LAB
SOFTWARE:
History: The project was conceived around 1988. At first it was intended to be a companion
to a chemical reactor design course. Real development was started by John W. Eaton in 1992.
The first alpha release dates back to January 4, 1993 and on February 17, 1994 version 1.0
was released. Version 4.0.0 was released on May 29, 2015.
The program is named after Octave Leve spiel, a former professor of the principal author.
Leve spiel is known for his ability to perform quick back-of-the-envelope calculations.
MATLAB −has the following common features with Octave
matrices are fundamental data type
it has built-in support for complex numbers
it has built-in math functions and libraries
it supports user-defined functions
GNU Octave is also freely redistributable software. You may redistribute it and/or modify it
under the terms of the GNU General Public License (GPL) as published by the Free Software
Foundation.
MATLAB vs Octave
Most MATLAB programs run in Octave, but some of the Octave programs may not run in
MATLAB because, Octave allows some syntax that MATLAB does not.
For example, MATLAB supports single quotes only, but Octave supports both single and
double quotes for defining strings. If you are looking for a tutorial on Octave, then kindly go
through this tutorial from beginning which covers both MATLAB as well as Octave.
Compatible Examples
Almost all the examples covered in this tutorial are compatible with MATLAB as well as
Octave. Let's try following example in MATLAB and Octave which produces same result
without any syntax changes −
This example creates a 3D surface map for the function g = xe -(x2 + y2). Create a script file and
type the following code −
[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)
print -deps graph.eps
When you run the file, MATLAB displays the following 3-D map −
v
Non-compatible Examples
Though all the core functionality of MATLAB is available in Octave, there are some
functionality for example, Differential & Integration Calculus, which does not match exactly
in both the languages. This tutorial has tried to give both type of examples where they
differed in their syntax.
Consider following example where MATLAB and Octave make use of different functions to
get the area of a curve: f(x) = x2 cos(x) for −4 ≤ x ≤ 9. Following is MATLAB version of the
code −
f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));
When you run the file, MATLAB plots the graph −
vi
The following result is displayed
a=
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)
Area:
0.3326
But to give area of the same curve in Octave, you will have to make use of symbolic package
as follows −
pkg load symbolic
symbols
x = sym("x");
f = inline("x^2*cos(x)");
ezplot(f, [-4,9])
print -deps graph.eps
3. Click on to New, then New Script. New Editor Window will be opened.
4. Type the Program on Editor Window. Click on run to save file and run.
5. If any Errors in instruction line we can see in Command window.
vii
6. Change the Directory Path. Waveform will be generated in Figure1.
viii
Experiment:1
Basic Operations on Matrices.
AIM: To Verify the basic operations of matrices
Software Required:
OCTAVE with PC
Theory: If the amplitude of the signal is defined at every instant of time then it is called
continuous signal. If the amplitude of the signal is defined at only at some instants of time
then it is called discrete signal.
If the signal repeats itself at regular intervals then it is called periodic signal.
Otherwise they are called aperiodic signals.
1. Ramp sinal:
r(t)= t when t>=0
1
1.1 Basic Program for Addition, Subtraction, Multiplication, Division.
PROGRAM:
clear all;
close all;
clc;
A = input('Enter the Matrix A ::');
B = input('Enter the Matrix B ::');
%%%% Find the size of matrices
disp('The sise of Ma trix A is .... :: ');disp(size(A));
disp('The sise of Ma trix B is .... :: ');disp(size(B));
%%% Find the length of vector
P = length(A);
Q = length(B);
%%%% Addition of two ma trices
disp('Addition of A and B Matrices is .....:: ');
disp(A + B);
%%%%% Subtration of two matrices
disp('Subtraction of A and B Matrices is .....:: ');
disp(A - B);
%%%%% Multiplication (ELEMENT BY ELEMENT) of two matrices
disp('Multiplication of A and B Matrices is .....:: ');
disp(A.*B);
RESULT:
2
1.2. Basic Program for Determinant, Trace, Inverse, Rank of a Square Matrix.
PROGRAM:
clear all;
close all;
clc;
clear all;
close all;
clc;
A = input('Enter the Square Ma trix A ::');
% Finding the Rank of the matrix
disp('Rank of Matrix A is ::');disp(rank(A));
% Find the determinent of the matrix
disp('Determinent of Matrix A is ::'); disp(det(A));
% Find the trace of the matrix
disp('Trace of Matrix A is ::');disp(trace(A));
% Find the Inverse of the matrix
disp('Inverse of Matrix A is ::');disp(inv(A));
Result:
3
Experiment-2:
Generation of Various Signals and Sequences (Periodic and Aperiodic), such as Unit
Impulse, Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.
Software Required:
OCTAVE with PC
4
2.2.Generate Unit Impulse function
Program:
clear all;
close all;
clc;
x = ones(1,1);
y = zeros(1,2);
z = [y, x, y];
stem(z);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title(' Unit Impulse');
Result:
5
2.3.Generate Unit Step function
Program:
clear all;
close all;
clc;
x = ones(100);
subplot(2,1,1);
plot(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Step signal');
subplot(2,1,2);
stem(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Step signal');
OUTPUT
6
2.4 Generate Ramp Function:
Program:
clear all;
close all;
clc;
t = 0:25;
y = t;
subplot(1,2,1);
plot(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
subplot(1,2,2);
stem(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
OUTPUT
7
Experiment No. -3
AIM: perform the operations on signals and sequences such as addition , multiplication ,
scaling . shifting , folding and also compute energy and power.
Software Required:
OCTAVE with PC
.
Theory:
Signal Addition
Multiplication:
Multiplication of two signals can be obtained by multiplying their values at every instants .
z (t) = x (t) y (t)
Time reversal/Folding:
Time reversal of a signal x(t) can be obtained by folding the signal about t=0. Y(t)=y(-t)
If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal
Energy:
E=sum(abs(X).^2)
8
Average power:
P= (sum(abs(X).^2))/ length(x)
Program:
clear all;
close all;
clc;
x = input(' Enter sequence 1 :: ');
y = input(' Enter sequence 2 :: ');
M = length(x);
N = length(y);
subplot(2,2,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 1');
subplot(2,2,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
subplot(2,2,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');
9
title(' Addition of sequences 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
subplot(2,2,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of sequences 1 and 2');
OUTPUT:
Enter sequence 1 :: [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
Enter sequence 2 :: [5 6 7 8 9 9 8 7 6 5]
10
3.2 Scaling Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
a = input('Enter the scaling Factor ...:: ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i-1,a) == 0
s_scal = [s_scal,s(i)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel('---------> Time');
ylabel('---------> Amplitude');
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the scaling Factor ...:: 4
11
12
3.3 Shifting Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
a = input('Enter the length to be shifted ...:: ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' ---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');
ylabel('---------> Amplitude');
13
title('Shifted Sequence');
end;
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the length to be shifted ...:: 5
14
3.4. Folding Operation on a given Sequence
Program:
clear all;
close all;
clc;
s = input('Enter the sequence ......:: ');
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1, m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
Output:
Enter the sequence ......:: [1 2 3 4 5 6 7]
15
Experiment No. -4
AIM: perform the operations on signals and sequences such as addition , multiplication ,
scaling . shifting , folding and also compute energy and power.
Software Required:
. OCTAVE with PC
16
4.1. Addition and Multiplication of two Signals
Program:
clear all;
close all;
clear all;
close all;
clc;
t = 0:0.01:2;
x = sin(2*pi*t);
y = square(2*pi*t);
M = length(x);
N = length(y);
subplot(4,1,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signa l 1');
subplot(4,1,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signa l 2');
17
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
z = x + y;
subplot(4,1,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title(' Addition of signals 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
a = x.*y;
subplot(4,1,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of signals 1 and 2');
OUTPUT:
18
4.2. Scaling Operation on a given Signal
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the scaling Factor ...:: ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i,a) == 0
s_scal = [s_scal,s(i-1)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Scaled Sequence');
Output:
Enter the scaling Factor ...:: 3
19
20
4.3. Shifting Operation on a given Signal
Program:
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the length to be shifted ...:: ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' ---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');
21
ylabel('---------> Amplitude');
title('Shifted Sequence');
end;
Output:
Enter the length to be shifted ...:: 75
22
4.4 Folding Operation on a given Signal
Program:
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1, m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
Output:
23
4.5. Energy and Average Power on a given Signal
Program:
clc;
t = 0:0.01:4;
tes = cos(2*pi*t);
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M;
Output:
Energy of the given sequence is ..... ::
Energy =201
Average Power of the given sequence is ..... ::0.5012
24
Experiment No.-5
EVEN AND ODD PARTS OF SIGNAL AND SEQUENCE & REAL AND
IMAGINARY PARTS
AIM: Finding even and odd part of the signal and sequence and also find real and imaginary
parts of signal.
Software Required:
OCTAVE with PC
Theory:
Any signal x(t) can be expressed as sum of even and odd components I e
X(t)=xe(t)+xo(t)
25
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(-t)');
even =0.5*(x + y);
subplot(2,2,3);
stem(even);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Even part');
odd = 0.5*(x - y);
subplot(2,2,4);
stem(odd);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Odd part');
Output:
26
5.2. Even and Odd part of Sequence
Program:
clear all;
close all;
clc;
x = input('Enter the sequence :: ');
y = -x;
subplot(2,2,1);
stem(x);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(t)');
subplot(2,2,2);
stem(y);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Original signal f(-t)');
even =0.5*(x + y);
subplot(2,2,3);
stem(even);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('Even part');
odd = 0.5*(x - y);
subplot(2,2,4);
stem(odd);
xlabel('Time ----> ');
ylabel('Amplitude ---->');
title('O dd part');
Output:
Enter the sequence :: [1 2 3 4 3 2 1]
27
28
Experiment No.-6
CONVOLUTION BETWEEN SIGNALS& SEQUENCES
Aim: Write the program for convolution between two signals and also between two
sequences.
Software Required:
OCTAVE with PC
.
Theory:
If x(n)=h(n) [ impulse ) then output y(n) is known as impulse response of the system.
x(n)=δ(n)
y(n)=T[x(n)]
Thus output of LTI system is given by weighted sum of time-shifted impulse responses
Linear Convolution involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:
29
Program:
clc;
close all;
clear all;
%program for convolution of two sequences
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');ylabel('x(n)'); title('input signal')
subplot(3,1,2);
stem(h);
xlabel('n'); ylabel('h(n)');title('impulse response')
subplot(3,1,3);
stem(y);
xlabel('n');ylabel('y(n)'); title('linear convolution')
disp('The resultant signal is'); disp(y)
30
31
Experiment No. -7
AUTO CORRELATION AND CROSS CORRELATION
AIM: Write the program to compute Auto correlation and Cross correlation between signals
and sequences.
Software Required:
OCTAVE with PC
Theory:
Correlations of sequences:
It is a measure of the degree to which two sequences are similar. Given two real-
valued sequences x(n) and y(n) of finite energy,
1. Shifting
2. Multiplication
3. Addition
Program:
clc;
close all;
clear all;
stem(x);
xlabel('n'); ylabel('x(n)'); title('input sequence');
subplot(2,2,2);
stem(h);
32
xlabel('n'); ylabel('h(n)'); title('impulse signal');
% cross correlation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t'); ylabel('z1(t)'); title('cross correlation ');
% auto correlation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t'); ylabel('z2(t)'); title('auto correlation ');
Result: Auto correlation and Cross correlation between signals and sequences is
computed.
Output:
Enter input sequence [1 2 5 7]
33
34
Experiment No. -8
VERIFICATION OF LINEARITY OF A DISCRETE SYSTEM
Software Required:
OCTAVE with PC
Theory:
LINEARITY PROPERTY:
Any system is said to be linear if it satisfies the superposition principal. superposition
principal state that Response to a weighted sum of input signal equal to the corresponding
weighted sum of the outputs of the system to each of the individual input signals.
Y(n)=T[x(n)]
Y1(n)=T[X1(n)] : Y2(n)=T[X2(n)]
Y3(n)= T [x3(n)]
a) Linearity of a system
clear all;
close all;
clc;
n=0:0.01:2;
a= -3; b= 5;
x1=cos(2*pi*n);
x2=cos(3*pi*n);
x=a*x1+b*x2;
ic=[0 0];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
y=filter(num,den,x,ic);
yt=a *y1+b*y2;
35
d=y-yt;
subplot(3,1,1), stem(n,y);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' y = a*x1 + b*x2');
subplot(3,1,2), stem(n,yt);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' yt = a*y1 + b*y2');
subplot(3,1,3), stem(n,d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' difference of y and yt');
Result:
Program:
clear all;
close all;
clc;
n=0:0.05:4;
D=10;
x=3*cos(2*pi*n)-0.5*cos(4*pi*n);
xd=[zeros(1,D) x];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
ic=[0 0];
y=filter(num,den,x,ic)
36
yd=filter(num,den,xd,ic)
d=y-yd(1+D:41+D);
subplot(3,1,1), stem(y);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('y ');
subplot(3,1,2), stem(yd);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('yd');
subplot(3,1,3), stem(d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title(' difference of y and yd');
Result:
37
Experiment:9
Computation of Unit sample, Unit step and Sinusoidal responses of the given LTI
system and verifying its physical realiazability and stability properties.
Software Required:
OCTAVE with PC
Output:
38
ii. Step Response of an LTI system
Program:
clear all;
close all;
clc;
h = (-0.9).^[0:49];
subplot(2,2,1);
stem([0:49],h,'filled');
xlabel('Samples');
ylabel('Amplitude');
title(' h = (-0.9).^[0:49]');
u = ones(1,50);
subplot(2,2,2);
stem([1:50],u,'filled');
xlabel('Samples');
ylabel('Amplitude');
title('Step');
s = conv(u,h);
subplot(2,2,[3,4]);
stem([0:49],s(1:50));
xlabel('Samples');
ylabel('Amplitude');
title('Response for a step');
39
Output:
40
ylabel('Amplitude');
title('Response for a sine');
Output:
41
Experiment No-10
AIM: To find the Fourier Transform of a given signal and plotting its magnitude and phase
spectrum.
Software Required:
OCTAVE with PC
Theory:
Fourier Transform :
The Fourier transform as follows. Suppose that ƒ is a function which is zero outside of some
interval [−L/2, L/2]. Then for any T ≥ L we may expand ƒ in
a Fourier series on the interval [−T/2,T/2], where the "amount" of the wave e2πinx/T in the
Fourier series of ƒ is given by
By definition Fourier Transform of signal f(t) is defined as
Program:
clc;
clear all;
close all;
fs=1000;
N=1024; % length of fft sequence
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]); grid;
xlabel('t'); ylabel('amplitude'); title('input signal');
% magnitude spectrum
x1=fft(x);
k=0:N-1;
42
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag); grid;
xlabel('t'); ylabel('amplitude'); title('magnitude of fft signal')
%phase spectrum
Xphase=angle(x1)
subplot(3,1,3);
plot(k,Xphase); grid;
xlabel('t'); ylabel('angle in degrees'); title('phase of fft signal');
Output:
43
Experiment No-11
AIM: Finding the Laplace transform & Inverse Laplace transform of some signals.
Software Required:
OCTAVE with PC
Theory:
Program:
clc;
clear all; close
all;
%representation of symbolic variables
syms f t w s;
%laplace transform of t
f=t;
z=laplace(f);
disp('the laplace transform of f = '); disp(z);
% laplace transform of sin signal
f1=sin(w*t);
f2=sin(w*(t-1));
v1=laplace(f1);
disp('the laplace transform of f1 = '); disp(v1);
v2=laplace(f2);
disp('the laplace transform of f2 = '); disp(v2);
simplify(v2)
%inverse laplace transform
y1=ilaplace(z);
disp('the inverse laplace transform of z = '); disp(y1);
44
y2=ilaplace(v1);
disp('the inverse laplace transform of v1 = '); disp(y2);
y3=ilaplace(v2);
disp('the inverse laplace transform of v2 = '); disp(y3);
x1=11*s^3+52*s^2+86*s+72;
x2=4*s*(s+2)^2*(s+3);
x3=x1/x2;
y4=ilaplace(x3);
disp('the inverse laplace transform of x3 = '); disp(y4);
Output:
the laplace transform of f = 1/s^2
ans = -(-cos(w)*w+sin(w)*s)/(s^2+w^2)
45
Experiment no:12
EQUIPMENTS:
OCTAVE with PC
Sampling Theorem: The sampling theorem specifies the minimum-sampling rate at which
a continuous-time signal needs to be uniformly sampled so that the original signal can be
completely recovered or reconstructed by these samples alone. This is usually referred to as
Shannon's sampling theorem in the literature.
A band-limited signal can be reconstructed exactly if it is sampled at a rate at least twice the
maximum frequency component in it.
Program:
t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');ylabel('x(t)')
title('continous time signal')
grid;
n1=-4:1:4
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs<2fm')
hold on
subplot(2,2,2);
plot(n1,x1)
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs=2fm')
hold on
46
subplot(2,2,3);
plot(n2,x2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3);
xlabel('time');ylabel('x(n)')
title('discrete time signal with fs>2fm')
hold on
subplot(2,2,4);
plot(n3,x3)
grid;
Output:
Result: In this experiment the sampling theorem have been verified using MATLAB.
47
SYLLABUS
BASIC SIMULATION LAB
Course Code U21EC3L2
Course Objectives:
1. To impart the knowledge to write MATLAB codes for the generation of signals,
2. To perform different operations and to verify various transforms for converting time domain signal
to frequency domain signal.
Course Outcomes: Upon completion of the course, Students will be able to
1. Write MATLAB codes for the generation of signals
2. Apply various transforms on signals to find its Spectrum using MATLAB.
3. Correlate two signals and can remove noise using correlation.
4. Find the response of the system using convolution function in MATLAB.
5. Perform sampling of continuous time signals.
List of Experiments:
1. Basic Operation on Matrices
8. Finding the Fourier Transform of a given signal and plotting its magnitude and phase spectrum.
9. Locating the Zeros and Poles and plotting the Pole-Zero maps in S-plane and Z-Plane for the given
transfer function.
48