BS Lab 2021-22
BS Lab 2021-22
BS Lab 2021-22
(AUTONOMOUS)
MEDBOWLI, MEERPET, RANGA REDDY
DEPARTMENT OF ECE
NAME:
ROLL NO:
II B.Tech ECE-A
2021-22
LIST OF EXPERIMENTS
2|BSLAB DepartmentofECE
INTRODUCTION TO MATLAB
The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to provide
easy access to matrix software developed by the LINPACK (linear system package) and EISPACK (Eigen
system package) projects.
MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming environment. Furthermore, MATLAB is a modern programming language
environment, it has sophisticated data structures, contains
built-in editing and debugging tools, and supports object-oriented programming. These factors make
MATLAB an excellent tool for teaching and research.
MATLAB has many advantages compared to conventional computer languages (e.g., C,
FORTRAN) for solving technical problems. MATLAB is an interactive system whose basic data element
is an array that does not require dimensioning. The software package has been commercially available
since 1984 and is now considered as a standard tool at most universities and industries worldwide.
It has powerful built-in routines that enable a very wide variety of computations. It also has easy to
use graphics commands that make the visualization of results immediately available. Specific applications
are collected in packages referred to as toolbox. There are toolboxes for signal processing, symbolic
computation, control theory, simulation, optimization, and several other fields of applied science and
engineering.
Matlab Window:
After logging into your account, you can enter MATLAB by double-clicking on the MATLAB
shortcut icon (MATLAB 2013a) on your Windows desktop. When you start MATLAB, a special window
called the MATLAB desktop appears. The desktop is a window that contains other windows. The major
tools within or accessible from the desktop are...
The Command Window
The Command History
The Workspace
The Current Directory
The Help Browser
The Start button
3|BSLAB DepartmentofECE
Specialities of MATLAB:
Matrices Representation:
1. row matrix:
Elements in a row are separated either by using white spaces or commas e.g.: a=[1 2 4 5]
2. column matrix:
Elements which differ by a column are separated by enter or semi column e.g.: b=[1; 2; 3]
4|BSLAB DepartmentofECE
default 1.
Ans: d= [0 1 2 3 4 5 6 7]
• The default increment can be changed (to 0.1) by using increment field in between as
e= [0:0.1:1]
Ans: e=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
• g(1:2:9) look with increment 2
Ans: g=[1 3 5 7 9]
Operators:
1. + addition
2. - subtraction
3. * multiplication
4. ^ power
5. ' transpose
6. \ left division
7. / right division
• Remember that the multiplication, power and division operators can be used in conjunction with a
period to specify an element-wise operation.
Typical commands:
1. clc - to clear the command window.
2. close all - to close the previous program figures.
3. clear all - to clear the work space.
4. quit or exit - to close the MATLAB
5. save filename - filename.mat
6. load filename - retrive
7. dairy filename - b4 and after ascii text file
8. help - to search required query.
Built in Functions:
1. Scalar Functions:
• Certain MATLAB functions are essentially used on scalars, but to 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
5|BSLAB DepartmentofECE
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
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
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
Few more commands:
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 -eigen values 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
13. svd -singular value decomposition
6|BSLAB DepartmentofECE
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
7|BSLAB DepartmentofECE
TKR COLLEGE OF ENGINEERING AND TECHNOLOGY
Experiment No-1
SOFTWARE REQURIED:-
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:-
clc;
close all;
clear all;
a=[1 2 -9;2 -1 2;3 -4 3];
b=[1 2 3;4 5 6;7 8 9];
disp('The matrix a= ');a
disp('The matrix b= ');b
% to find sum of a and b
c=a+b;
disp('The sum of a and b is ');c
% to find difference of a and b
d=a-b;
disp('The difference of a and b is ');d
%to find multiplication of a and b
e=a*b;
disp('The product of a and b is ');e
% to find element-by-element multiplication
f=a.*b;
disp('element to element multiplication of a and b is');f
%to find division of a and b
g=a/b;
disp('The of division a and b is');g
%to find element to element division of a and b
h=a./b;
disp('element to element division of a and b is');h
RESULT:-
Finding of addition, subtraction, multiplication using Matlab was
Successfully completed
OUTPUT:-
The matrix a=
a=
1 2 -9
2 -1 2
3 -4 3
The matrix b=
b=
1 2 3
4 5 6
7 8 9
Experiment No-02
AIM: -
Generate the various signals such as unit impulse, unit step, sine, sawtooth, square,
triangle, sinc function both in continuous and in discrete manner by using MATLAB.
SOFTWARE REQUIRED:-
clc;
clear all;
close all;
%unit impulse generation for discrete signal
t1=-2:1:2;
y1=[zeros(1,2),ones(1,1),zeros(1,2)];
stem(t1,y1,'r','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('unit impulse for discrete signal');
figure;
%unit impulse generation for continious signal
T=15;%input('enter the time interval=');
t2=-T:0.01:T;
a1=length(t2);
y2=[zeros(1,(a1-1)/2),ones(1,1),zeros(1,(a1-1)/2)];
plot(t2,y2,'r','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('unit impulse for continious signal');
figure;
%unit step generation for discrete and continious signal
n=15;%input('enter the value of n=');
t3=0:1:n-1;
y3=ones(1,n);
subplot(2,1,1);
stem(t3,y3,'m','linewidth',2);
xlabel('t(n)');
ylabel('amplitude');
title('unit step generation for discrete signal');
subplot(2,1,2);
plot(t3,y3,'r','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('unit step generation for continious signal');
figure;
%Ramp signal generation for discrete and continious signal.
m=15;%input('enter the input sequences of ramp=');
t4=0:m;
subplot(2,1,1);
stem(t4,t4,'r','linewidth',2);
xlabel('t(n)');
ylabel('amplitude');
title('Ramp signal generation for discrete sequence');
subplot(2,1,2);
plot(t4,t4,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('Ramp signal generation for continious signal');
%Sine signal generation for continious and discrete signal.
a5=3; %amplitude in db
f=2; %frequency 10 hz
t5=0:1/f:50; %0 and 10 are the time limits
y5=a5*sin(2*pi*1/10*t5);
subplot(2,1,1);
plot(t5,y5,'g','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('Continious sine wave generation');
grid on;
subplot(2,1,2);
stem(t5,y5,'m','linewidth',1);
xlabel('t(n)');
ylabel('amplitude');
title('Discrete sine signal generation');
grid on;
figure;
%square wave signal generation for continious and discrete manner.
a6=5; %amplitude of the signal
fs1=1000; %signal frequency
t6=0:1/fs1:2;
y6=a6*square(2*pi*8*t6);
subplot(2,1,1);
plot(t6,y6,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('Square wave signal generation');
grid on;
subplot(2,1,2);
stem(t6,y6,'m','linewidth',0.5);
xlabel('t(n)');
ylabel('amplitude');
title('Discrete square signal generation');
grid on;
figure;
%sawtooth wave signal generation for continious and discrete manner.
a7=5; %amplitude of the signal
fs2=100; %signal frequency
t7=0:1/fs2:2;
y7=a7*sawtooth(2*pi*5*t7);
subplot(2,1,1);
plot(t7,y7,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('continious Sawtooth signal generation');
grid on;
subplot(2,1,2);
stem(t7,y7,'m','linewidth',0.5);
xlabel('t(n)');
ylabel('amplitude');
title('Discrete sawtooth signal generation');
grid on;
figure;
%triangular wave signal generation for continious and discrete manner.
a8=5; %amplitude of the signal
fs3=100; %signal frequency
t8=0:1/fs3:2;
y8=a8*sawtooth(2*pi*5*t8,0.50); %0.50 is angle
subplot(2,1,1);
plot(t8,y8,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('continious triangle signal generation');
grid on;
subplot(2,1,2);
stem(t8,y8,'m','linewidth',0.5);
xlabel('t(n)');
ylabel('amplitude');
title('Discrete triangle signal generation');
grid on;
figure;
%generation of sinc signal in continious and discrete domain.
a9=7; %signal amplitude
t9=linspace(-5,5);
y9=sinc(t9);
subplot(2,1,1);
plot(t9,y9,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('continious sinc signal generation');
grid on;
subplot(2,1,2);
stem(t9,y9,'r','linewidth',1);
xlabel('t(n)');
ylabel('amplitude');
title('Discrete sinc signal generation');
grid on;
Results:
Generation of various signals and sequences in continuous and also in discrete domain
are observed.
Graphs:
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
n
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
-15 -10 -5 0 5 10 15
time
0.8
amplitude
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14
t(n)
unit step generation for continious signal
2
1.5
amplitude
0.5
0
0 2 4 6 8 10 12 14
time
2
amplitude
-2
-4
0 10 20 30 40 50
time
Discrete sine signal generation
4
2
amplitude
-2
-4
0 10 20 30 40 50
t(n)
-5
0 0.5 1 1.5 2
time
Discrete square signal generation
5
amplitude
-5
0 0.5 1 1.5 2
t(n)
-5
0 0.5 1 1.5 2
time
Discrete sawtooth signal generation
5
amplitude
-5
0 0.5 1 1.5 2
t(n)
-5
0 0.5 1 1.5 2
time
Discrete triangle signal generation
5
amplitude
-5
0 0.5 1 1.5 2
t(n)
0.5
-0.5
-5 0 5
time
Discrete sinc signal generation
1
amplitude
0.5
-0.5
-5 0 5
t(n)
Experiment No-03
SOFTWARE REQURIED :-
MATLAB R2013a (8.1 Version).
. .
PROCEDURE:-
• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
THEORY: • For the output see command window\ Figure window
➢ 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).
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
Programme:
clc;
close all;
clear all;
a=2; %amplitude
t=0:0.001:1;
L=length(t);
f1=1; %frequency for 1st sin signal
f2=3; %frequency for 2nd sin signal
%programme for addition of two signals
x1=a*sin(2*pi*f1*t);
subplot(3,1,1);
plot(t,x1,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('the signals x1(t) and x2(t)');
grid on;
x2=a*sin(2*pi*f2*t);
subplot(3,1,2);
plot(t,x2,'r','linewidth',2);
grid on;
x3=x1+x2;
subplot(3,1,3);
plot(t,x3,'g','linewidth',2);
grid on;
figure;
title('the sum of x1(t) and x2(t)');
grid on
%programme for multiplication of two signals
y1=a*sin(2*pi*f1*t);
subplot(3,1,1);
plot(t,y1,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('the signals y1(t) and y2(t)');
grid on;
y2=a*sin(2*pi*f2*t);
subplot(3,1,2);
plot(t,y2,'r','linewidth',2);
grid on;
y3=y1.*y2;
subplot(3,1,3);
plot(t,y3,'m','linewidth',2);
grid on;
figure;
title('the multiplication of y1(t) and y2(t)');
grid on;
%programme for folding of signals
z1=a*sin(2*pi*f1*(-t));
subplot(2,1,1);
plot(t,z1,'b','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('the folding of z1(t)and z2(t)');
grid on;
z2=a*sin(2*pi*f2*(-t));
subplot(2,1,2);
plot(t,z2,'r','linewidth',2);
grid on;
figure;
%shifting of signals
w=[zeros(1,200),x2(1:(L-200))];
plot(t,w,'r','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('the shifting of w');
grid on;
figure;
%squaring of signals
w1=x1.^2;
subplot(2,1,1);
plot(t,w1,'r','linewidth',2);
xlabel('time');
ylabel('amplitude');
title('the squaring of x1(t)and x2(t)');
grid on;
w2=x2.^2;
subplot(2,1,2);
plot(t,w2,'g','linewidth',2);
xlabel('time');
ylabel('amplitude');
grid on;
%Basic operations for Discrete sequences
n1=1:1:9;
s1=[1 2 3 4 5 6 2 3 1]; %1st sequence s1
subplot(4,1,1);
stem(n1,s1,'r','linewidth',2);
xlabel('t(n1)');
ylabel('amplitude');
title('input sequence');
n2=-2:1:6;
s2=[1 1 0 0 2 3 1 1 0]; %2nd sequence s2
subplot(4,1,2);
stem(n2,s2,'g','linewidth',2);
xlabel('n2');
ylabel('amplitude');
title('input sequence');
s3=s1+s2; % addition of s1 & s2 sequences
subplot(4,1,3);
stem(n2,s3,'m','linewidth',2);
xlabel('n2');
ylabel('amplitude');
title('input sequence');
subplot(4,1,4);
s4=s1.*s2; % multiplication of s1 & s2 sequences
stem(n2,s4,'y','linewidth',2);
xlabel('n2');
ylabel('amplitude');
title('input sequence');
figure;
%program for folding sequence
n3=0:1:10;
x=0.5.*n3;
lx=length(x);
nx=0:lx-1;
xf=fliplr(x);
nf=-fliplr(x);
subplot(2,1,1);
stem(nx,x,'r','linewidth',2);
xlabel('nx');
ylabel('x(nx)');
title('original sequence');
subplot(2,1,2);
stem(nf,xf,'g','linewidth',2);
xlabel('nx');
ylabel('x(nx)');
title('folded sequence');
figure;
%program for amplitude scaling sequence
n4=0:1:6;
s1=[5 15 10 5 5 10 5];
subplot(3,1,1);
stem(s1,'r','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('input sequence');
s2=5.*s1;
subplot(3,1,2);
stem(s2,'b','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('amplified input sequence');
s3=s1./5;
subplot(3,1,3);
stem(s3,'m','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('attenuated input sequence');
figure;
%program for time shifting sequence
n=0:1:4;
h=[1 1 1 -1 2];
subplot(3,1,1);
stem(n,h,'r','linewidth',2);
xlabel('n');
ylabel('h(n)');
title('input sequence');
subplot(3,1,2);
stem(n+2,h,'b','linewidth',2);
xlabel('n');
ylabel('h(n)');
title('right shifted sequence');
subplot(3,1,3);
stem(n-2,h,'m','linewidth',2);
xlabel('n');
ylabel('h(n)');
title('left shifted sequence');
Result:
Hence the various basic operations of basic signals in continuous and discrete manner
are observed.
-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time
-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-2
0 0.2 0.4 0.6 0.8 1
time
-2
0 0.2 0.4 0.6 0.8 1
-5
0 0.2 0.4 0.6 0.8 1
Folding of Signals:
the folding of z1(t)and z2(t)
2
1
amplitude
-1
-2
0 0.2 0.4 0.6 0.8 1
time
-1
-2
0 0.2 0.4 0.6 0.8 1
Shifting of Signals:
the shifting of w
2
1.5
0.5
amplitude
-0.5
-1
-1.5
-2
0 0.2 0.4 0.6 0.8 1
time
0
1 2 3 4 input se5quence 6 7 8 9
4 t(n1)
amplitude
0
-2 -1 0 1 2 3 4 5 6
input sne2quence
amplitude
10
5
0
-2 -1 0 1 2 3 4 5 6
n2
input sequence
amplitude
20
10
0
-2 -1 0 1 2 3 4 5 6
n2
1
0
0 2 4 6 8 10
nx
folded sequence
5
4
3
x(nx)
2
1
0
-5 -4 -3 -2 -1 0
nx
Amplified/Attenuated signals:
input sequence
20
amplitude
10
0
1 2 3 4 5 6 7
n
amplified input sequence
100
amplitude
50
0
1 2 3 4 5 6 7
n
attenuated input sequence
4
amplitude
0
1 2 3 4 5 6 7
n
-2
0 0.5 1 1.5 2 2.5 3 3.5 4
n
right shifted sequence
2
h(n)
-2
2 2.5 3 3.5 4 4.5 5 5.5 6
n
left shifted sequence
2
h(n)
-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
n
EXPERIMENT NO-4
AIM:
Finding even and odd part of the signal and sequence and also find
real and imaginary parts of signal and energy, power signals.
SOFTWARE REQUIRED:
THEORY:
Even and odd part of a signal:
Any signal x(t) can be expressed as sum of even and odd components e
X(t)=xe(t)+xo(t)
Energy:
E=sum(abs(X).^2)
Average power:
P= (sum(abs(X).^2))/ length(x)
PROGRAMME:
%programme for energy signal using sequence.
clc;
clear all;
close all;
x=[1 2 3 2];
n=length(x);
e1=0;
for i=1:n;
e1=e1+(x(i)*x(i));
end
%program for energy of a signal
t1=0:pi:10*pi;
z2=cos(2*pi*50*t1).^2;
e2=sum(abs(z2).^2);
%programme for power signal using sequence.
p1=(sum(abs(x).^2))/length(x);
%program for power of a signal
p2=(sum(abs(z2).^2))/length(z2);
%Even and odd parts of a signal
t2=0:.005:4*pi;
x=sin(t2)+cos(t2); % x=sint(t2)+cos(t2)
subplot(2,2,1)
plot(t2,x,'r','linewidth',2);
xlabel('t');
ylabel('amplitude')
title('input signal')
y=sin(-t2)+cos(-t2); % y=x(-t2)
subplot(2,2,2)
plot(t2,y,'g','linewidth',2);
xlabel('t2');
ylabel('amplitude')
title('input signal with t=-t2')
z=x+y;
subplot(2,2,3)
plot(t2,z/2,'m','linewidth',2)
xlabel('t');
ylabel('amplitude')
title('even part of the signal')
p=x-y;
subplot(2,2,4)
plot(t2,p/2,'y','linewidth',2)
xlabel('t');
ylabel('amplitude');
title('odd part of the signal');
figure;
%Even and odd parts of a sequence
z=[0,2+j*4,3+j*2,5-j*1,-2-j*4,-j*3,0];
n=-3:3;
subplot(2,1,1);
stem(n,real(z),'g','linewidth',2); % real part
xlabel('n');
ylabel('amplitude');
title('real part of the complex sequence');
subplot(2,1,2);
stem(n,imag(z),'b','linewidth',2); % imaginary part
xlabel('n');
ylabel('amplitude');
title('imaginary part of the complex sequence');
figure;
%complex conjugate of a signal
zc=conj(z);
zc_folded= fliplr(zc);
zc_even=0.5*(z+zc_folded);
zc_odd=0.5*(z-zc_folded);
subplot(2,2,1);
stem(n,real(zc_even),'b','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('real part of the even sequence');
subplot(2,2,2);
stem(n,imag(zc_even),'g','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('imaginary part of the even sequence');
subplot(2,2,3);
stem(n,real(zc_odd),'y','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('real part of the odd sequence');
subplot(2,2,4);
stem(n,imag(zc_odd),'m','linewidth',2);
xlabel('n');
ylabel('amplitude');
title('imaginary part of the odd sequence');
RESULT:
Result :
e1 = 18
Energy signal
e2 =4.0388
p1 =4.5000
Power signal
p2 = 0.3672
1 1
amplitude
amplitude
0 0
-1 -1
-2 -2
0 5 10 15 0 5 10 15
t t2
even part of the signal odd part of the signal
1 1
0.5 0.5
amplitude
amplitude
0 0
-0.5 -0.5
-1 -1
0 5 10 15 0 5 10 15
t t
4
amplitude
-2
-3 -2 -1 0 1 2 3
n
imaginary part of the complex sequence
4
2
amplitude
-2
-4
-3 -2 -1 0 1 2 3
n
amplitude
amplitude
3
0
2
-2
1
0 -4
-5 0 5 -5 0 5
n n
real part of the odd sequence imaginary part of the odd sequence
4 0.5
2
amplitude
amplitude 0
0
-0.5
-2
-4 -1
-5 0 5 -5 0 5
n n
EXPERIMENT NO-5
AIM:
Verify the sampling theorem.
SOFTWARE REQUIRED:
The minimum required sampling rate fs = 2fm is called ' Nyquist rate
Proof:
Let g(t) be a bandlimited signal whose bandwidth is fm (wm = 2πfm).
PROGRAMME:
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,'r','linewidth',2);
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,'g','linewidth',2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs<2fm');
hold on;
subplot(2,2,2);
plot(n1,x1,'b','linewidth',2);
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2,'y','linewidth',2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs=2fm');
hold on;
subplot(2,2,3);
plot(n2,x2,'m','linewidth',2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3,'r','linewidth',2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs>2fm')
hold on;
subplot(2,2,4);
plot(n3,x3)
grid;
RESULT:
Result :
0.5 0.5
x(n)
x(t)
0 0
-0.5 -0.5
-1 -1
-10 0 10 -5 0 5
time time
discrete time signal with fs=2fm discrete time signal with fs>2fm
1 1
0.5 0.5
x(n)
x(n)
0 0
-0.5 -0.5
-1 -1
-5 0 5 -20 0 20
time time
Experiment No-06
AIM: -
SOFTWARE REQURIED :-
• 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:-
clc;
clear all;
close all;
syms t s;
syms w real;
syms A real;
syms o real;
syms b float;
% Fourier Transform
f=dirac(t);
F=fourier(f);
disp('The fourier transform of F =');
disp(F);
f1=A*heaviside(t);
F1=fourier(f1);
disp('The fourier transform of F1 =');
disp(F1);
f2=A*exp(-t)*heaviside(t);
F2=fourier(f2);
F1=A*pi*(dirac(w-o)+dirac(w+o));
f1=ifourier(F1,t);
disp('The inverse fourier transform f1 =');
disp(f1);
F2=A*pi*(dirac(w-o)-dirac(w+o))/i;
f2=ifourier(F2,t);
disp('The inverse fourier transform f2 =');
disp(f2);
F3=A/(1+i*w);
f3=ifourier(F3,t);
disp('The inverse fourier transform f3 =');
disp(f3);
F4=(3*i*w+14)/((i*w)^2+7*i*w+12);
f4=ifourier(F4,t);
disp('The inverse fourier transform f4 =');
disp(f4);
Results:
The fourier transform of F =
1
Experiment No-7
GIBBS PHENOMENON
SOFTWARE REQURIED :-
THEORY:
PROGRAM:-
clc;
clear all;
close all;
N=input('enter different types of harmonics=');
for i=1:N
n_har=input('enter the no. of harmonics in each
signal=');
t=-1:0.001:1;
omega_0=2*pi;
x=0;
for n=1:2:n_har
b_n=2/(n*pi);
x=x+b_n*sin(n*omega_0*t);
end
hold on;
subplot(N,1,i);
plot(t,x,'b','linewidth',2);
xlabel('time--->');
ylabel('amp---->');
axis([-1 1 -0.5 1.5]);
text(0.55,1.0,['no.of har=',num2str(n_har)]);
end
RESULT:-
The operation of Gibbs Phenomenon is successfully completed.
OUTPUT:-
Experiment No -8
CONVOLUTION OF TWO SEQUENCES
SOFTWARE REQURIED :-
• 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:-
clc;
clear all;
close all;
n=0:8;
x1=1;
x2=0;
y1=x1.*(n>=0 & n<=2)+x2.*(n>=2 & n<=8);
subplot(2,2,1);
stem(n,y1);
xlabel('time n ---- >');
ylabel('amplitude --- >');
title('the sequence y1[n]')
y2=x1.*(n>=0 & n<=4)+x2.*(n>=4 & n<=8);
subplot(2,2,2);
stem(n,y2);
xlabel('time n ---- >');
ylabel('amplitude --- >');
title('the sequence y2[n]')
y=conv(y1,y2);
BS LAB ECE DEPARTMENT
TKR COLLEGE OF ENGINEERING AND TECHNOLOGY
L=length(y);
n=0:L-1;
subplot(2,2,[3,4]);
stem(n,y);
xlabel('time n ---- >');
ylabel('amplitude --- >');
title('the convolution sequence of y1[n]&y2[n]');
RESULT:-
OUTPUT:-
Experiment No-9
AUTO-CORRELATION & CROSS-CORRELATION BETWEEN SIGNALS
SOFTWARE REQURIED :-
• 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
PROGRAM: window
clc;
clear all;
close all;
t=0:0.01:1;
f1=3;
x1=sin(2*pi*f1*t);
figure;
subplot(2,1,1);
plot(t,x1);
title('sine wave');
xlabel('time ---- >');
ylabel('amplitude--- >');
grid;
[rxx lag1]=xcorr(x1);
subplot(2,1,2);
plot(lag1,rxx);
grid;
title('auto-correlation function of sine wave');
figure;
subplot(2,2,1);
plot(t,x1);
title('sine wave x1');
xlabel('time ---- >');
ylabel('amplitude --- >');
grid;
f2=2;
x2=sin(2*pi*f2*t);
subplot(2,2,2);
plot(t,x2);
title('sine wave x2');
xlabel('time ---->');,ylabel('amplitude --- >');
grid;
[cxx lag2]=xcorr(x1,x2);
subplot(2,2,[3,4]);
plot(lag2,cxx);
grid;
title('cross-correlation function of sine wave');
RESULT:
Thus the MATLAB Program of computing auto correlation and cross
correlation between signals was completed successfully.
OUTPUT:
Experiment no-10
AIM: -
To write a program to extract the periodic signal masked by Noise
using Auto correlation and Cross Correlation method.
SOFTWARE REQURIED :-
MATLAB R2013a (8.1 Version).
.
PROCEDURE:-
Open MATLAB Software
Open new M-file
Type the program
Save in current directory
Run the program
For the output see command window\ Figure window.
PROGRAM:-
clc;
clear all;
close all;
t=0:0.01:10;
s=cos(2*pi*3*t)+sin(2*pi*5*t); % periodic signal
figure;
subplot(2,1,1);
plot(t,s);
xlabel(' t ---- >') ;
ylabel(' amp --- > ');
title('the periodic signal');
L=length(t);
n=randn(1,L); % noise signal
subplot(2,1,2);
plot(t,n);
xlabel(' t ---- >') ;
ylabel(' amp --- > ');
title('the noise signal');
BS LAB ECE DEPARTMENT
TKR COLLEGE OF ENGINEERING AND TECHNOLOGY
L=length(t);
f=s+n; % received signal
figure;
subplot(2,1,1);
plot(t,f);
xlabel(' t ---- >');
ylabel(' amp --- > ');
title('the received signal');
rxx=xcorr(f,s,200);
subplot(2,1,2);
plot(rxx);
title('the Correlator output');
RESULTS: -
Thus the MATLAB Program to detect the periodic signal masked by
noise using Auto Correlation &Cross Correlation method is performed.
OUTPUT
Experiment No-11(a)
AIM: -
To write a matlab program to verify the given system is linear or non-
linear.
SOFTWARE REQURIED :-
MATLAB R2013a (8.1 Version).
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:-
clc;
clear all;
close all;
x1=input('enter the x1[n] sequence=');
x2=input('enter the x2[n] sequence=');
if length(x1)~=length(x2)
disp(' length of x2 must be equal to the length of x1');
return;
end;
h=input('enter the h[n] sequence=');
a=input('enter the constant a= ');
b=input('enter the constant b= ');
y01=conv(a*x1,h);
y02=conv(b*x2,h);
y1=y01+y02;
x=a*x1+b*x2;
y2=conv(x,h);
L=length(x1)+length(h)-1;
n=0:L-1;
subplot(2,1,1);
stem(n,y1);
label('n --->'); label('amp --- >');
title('sum of the individual response');
subplot(2,1,2);
stem(n,y2);
xlabel('n --->'); ylabel('amp --- >');
title('total response');
if y1==y2
disp('the system is a Linear system');
else
disp('the system is a non-linear system');
end;
RESULT:-
Thus the MATLAB Program of verifying the system is linear or
non linear by using matlab has performed.
INPUT SEQUENCE:
Enter the x1[n] sequence= [0 2 4 6]
Enter the x2[n] sequence= [3 5 -2 -5]
Enter the h[n] sequence= [-1 0 -3 -1 2 1]
Enter the constant a= 2 & enter the constant b= 3
OUTPUT:-
Experiment No-11(b)
AIM: - To write a matlab program to verify the given system is Time –invariant
or Time–variant.
SOFTWARE REQURIED :-
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:-
clc;
clear all;
close all;
x=input('enter the sequence x[n]=');
h=input('enter the sequence h[n]=');
d=input('enter the positive number for delay d=');
xdn=[zeros(1,d),x]; % delayed input
yn=conv(xdn,h); % output for delayed input
y=conv(x,h); % actual output
ydn=[zeros(1,d),y]; % delayed output
figure;
subplot(2,1,1);
stem(0:length(x)-1,x);
xlabel('n ---->'),ylabel('amp --->');
title('the sequence x[n] ');
subplot(2,1,2);
stem(0:length(xdn)-1,xdn);
BS LAB ECE DEPARTMENT
TKR COLLEGE OF ENGINEERING AND TECHNOLOGY
RESULT:-
Thus the MATLAB Program of verifying the system is Time –
invariant or Time–variant System by using matlab has performed.
INPUT SEQUENCE:
Enter the sequence x[n] = [0 2 3 1 -2 7 3]
Enter the sequence h[n] = [4 -5 -11 -3 7 2 6 8 -15]
Enter the positive number for delay d=5
OUTPUT:-
Experiment No-12
SOFTWARE REQURIED :-
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:-
Location of poles and zeros in the S plane
clear all;
close all;
clc;
num = input('Enter the numerator coefficients .... :: ');
den = input('Enter the denominator coefficients .....:: ');
H = tf(num, den)
poles = roots(den)
zeros = roots(num)
sgrid
pzmap(H)
grid on
title('Pole/Zero Plot for Complex Poles and Zeros in S plane');
OUTPUT
Enter the numerator coefficients .... :: [1 2.5]
Enter the denominator coefficients .... :: [1 6 11 6]
Transfer function:
s + 2.5
s^3 + 6 s^2 + 11 s + 6
poles =
-3.0000
-2.0000
-1.0000
zeros =
-2.5000
OUTPUT
Enter the numerator coefficients .... :: [1 2.5]
Enter the denominator coefficients .... :: [1 6 11 6]
p=
-3.0000
-2.0000
-1.0000
z=
-2.5000
PROGRAM 2:
Plotting pole-zero maps in s-plane and z-plane
%Stability of LTI system in s-plane
clc;
num=input('type the numerator vector');
den=input('type the denominator vector');
H=tf(num,den);
[p,z]=pzmap(H);
disp('zeros are at');
disp(z);
disp('poles are at');
disp(p);
figure;
pzmap(H);
[r,p,k]=residue(num,den);
disp('PFE coefficients');%Partial Fraction Expansion coefficients
disp(r);
disp('Gain constant is');
disp(k);
if max(real(p))>=1
disp('All poles do not lie in left half of s-plane');
disp('LTI system is not stable system');
else
disp('All poles lie in left half of s-plane');
disp('LTI system is stable system');
end;
Experiment No-13
AIM:
Finding the Laplace transform & Inverse Laplace transform of some
signals.
SOFTWARE REQURIED :-
• 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
THEORY: window
Laplace transforms:
The Laplace transform of a signal f(t) can be defined as follows:
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);
RESULT:-
Hence Laplace transform verified
Output:
The laplace transform of f = 1/s^2
The laplace transform of f1 = w/(s^2+w^2)
The laplace transform of f2 = cos(w)*w/(s^2+w^2)-sin(w)*s/(s^2+w^2)
ans =-(-cos(w)*w+sin(w)*s)/(s^2+w^2)
Experiment No-14
AIM: -
To write a matlab program to verify the wiener-khintchine relation.
SOFTWARE REQURIED :-
MATLAB R2013a (8.1 Version).
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:-
clc;
clear all,
t=0:0.1:2*pi;
x=sin(2*t);
subplot(3,2,1)
plot(x);
au=xcorr(x,x);
subplot(3,2,2);
plot(au);
title('autocorrelation of x');
v=fft(au);
subplot(3,2,3);
plot(abs(v));
title('psd of x');
y=ifft(v);
subplot(3,2,4);
plot(y);
title('ifft of psd');
RESULT:-
Thus the MATLAB Program of verifying the wiener-khintchine
relation using matlab has performed.
AIM:
Removal of noise by auto correlation/cross correlation in a given signal
corrupted by noise using MATLAB.
SOFTWARE REQUIRED:
PROGRAMME:
clear all;
close all;
clc;
N= input('Enter the number of samples ......:: ');
h=1/N;
x=0:h:1;
y=sin(3*pi*x);
subplot(4,1,1);
plot(x,y);
xlabel('-- > time'); ylabel('-> Amplitude');
title('Original signal');
w=rand(1,N+1);
subplot(4,1,2);
plot(x,w);
xlabel('-- > time'); ylabel('-> Amplitude');
title('Noise');
k=y+w;
subplot(4,1,3);
plot(x,k);
xlabel('-- > time'); ylabel('-> Amplitude');
title('Signal+noise');
m=xcorr(k,100);
subplot(4,1,4)
plot(x,0.01*m(1:N+1));
xlabel('---> time'); ylabel('-> Amplitude');
title('Recovered signal');
OUTPUT
EXPERIMENT NO-16
Generation of Gaussian noise, Computation of its mean, M.S.value and
its skew, kurtosis, PSD and Probability Distribution Function
AIM:
Generate Gaussian noise, Computation of its mean, M.S.value and its skew,
kurtosis, PSD using MATLAB.
SOFTWARE REQUIRED:
PROGRAMME:
clc;
clear all;
close all;
N= input(' Enter the number of samples.....:: ');
R1=randn(1,N);
M=mean(R1)
K=kurtosis(R1)
P=periodogram(R1);
V=var(R1)
x = psd(R1);
subplot(2,2,1);
plot(R1);
title('Normal [Gaussian] Distributed Random
Signal');
xlabel('Sample Number');
ylabel('Amplitude');
subplot(2,2,2);
hist(R1);
title('Histogram [Pdf] of a normal Random
Signal');
xlabel('Sample Number');
ylabel('Total');
BS LAB DEPT OF ECE
TKR COLLEGE OF ENGINEERING AND TECHNOLOGY
subplot(2,2,[3,4]);
plot(x);
title('PSD of a normal Random Signal');
xlabel('Sample Number');
ylabel('Amplitude');
OUTPUT