Basic Siumlation Lab - 12-13, I Semester- SRAWAN
-
Upload
krishna-rama -
Category
Documents
-
view
217 -
download
0
Transcript of Basic Siumlation Lab - 12-13, I Semester- SRAWAN
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
1/60
Basic Simulation lab
AURORAS ENGINEERING COLLEGEBHONGIR, NALGONDA DIST. 508116.
Lab manual of
BASIC SIMULATION LAB
2nd
Year 1st
Semester of ECE
(As per R09 Academic Regulation)
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
2/60
Basic Simulation lab
PREFACE
Research and development over the past 30 years has lead to significant advances in the field of DSP.
Covering the basics of linear continuous time and discrete time systems and their applications along
with MATLAB programs is the need of the day.
This lab is suitable for subjects like S&S, DSP. The various concepts of the subject are arranged logically
and explained in a simple user friendly language like MATLAB.
Working with MAT LAB will enable the students to enhance their concepts in S&S, its applications. This
lab totally consists of basics of signals and systems that is signals and their operations, Fourier
transforms and how to do the operations on matrices. Also contains about the systems, convolution and
correlation and how to remove the noise using correlation.
Sampling theorem and wiener khintchine theorem can be understood by using this lab. MATLAB
software which is 20075B version is user friendly with enhanced feature and improved tools related to
DSP and compatible to interface DSP processors.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
3/60
Basic Simulation lab
LAB CODE
1. Students should report to the concerned labs as per the time table schedule.
2. Students who turn up late to the labs will in no case be permitted to perform the experiment
scheduled for the day.
3. After completion of the experiment, certification of the concerned staff in- charge in the
observation book is necessary.
4. Students should bring a note book of about 100 pages and should enter the readings/
observations into the note book while performing the experiment.
5. The record of observations along with the detailed experimental procedure of the experiment
performed in the immediate last session should be submitted and certified by the staff member
in-charge.
6. Not more than three students in a group are permitted to perform the experiment on a setup.
7. The group-wise division made in the beginning should be adhered to, and no mix up of student
among different groups will be permitted later.
8. The components required pertaining to the experiment should be collected from stores in-
charge after duly filling in the requisition form.
9. When the experiment is completed, students should disconnect the setup made by them, and
should return all the components/instruments taken for the purpose.
10. Any damage of the equipment or burn-out of components will be viewed seriously either
by putting penalty or by dismissing the total group of students from the lab for the
semester/year.
11. Students should be present in the labs for the total scheduled duration.
12. Students are required to prepare thoroughly to perform the experiment before coming to
Laboratory.
13. Procedure sheets/data sheets provided to the students groups should be maintained neatly andto be returned after the experiment.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
4/60
Basic Simulation lab
INDEXSl NO. Name of the Experiment
1 BASIC MATHEMATICAL OPERATIONS ON MATRICES.
2 GENERATION OF VARIOUS SIGNALS
3 OPERATIONS ON SIGNALS
4 SYMMETRY OF A SIGNAL
5 CONVOLUTION OF SIGNALS & SEQUENCES
6 CORRELATION OF SIGNALS
7 LINEARITY AND TIME INVARIENCE PROPERTIES
8 RESPONSE OF LTI SYSTEMS
9 GIBBS PHENOMENON
10 FOURIER TRANSFORM
11 WAVEFORM SYNTHESIS USING LAPLACE TRANFORM
12 POLE-ZERO MAP
13 GENERATION OF GAUSSIONNOISE14 SAMPLING THEOREM VERIFICATION
15 NOISE REMOVAL USING CORRELATION
16 PERIODIC SIGNAL EXTRACTION USING CORRELATION
17 RAISED COSINE FILTER
18 WIENERKHINTCHINE RELATION
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
5/60
Basic Simulation lab
1. BASIC MATHEMATICAL OPERATIONS ON MATRICESAim: Write a MATLAB program to generate matrix and perform basic operations on matrices.
Program:
A=[1 2 3 4;3 4 7 6;5 6 7 8;2 5 4 1] % defining matrix AB=[3 4 5 6;5 6 7 8;1 2 3 4;4 5 6 7] % defining matrix Bdisp('-->size of matrix A is')C=size(A) % displays size of matrixdisp('-->rank of matrix A is')D=rank(A) % displays rank of matrixdisp('-->trace of matrix A is')E=trace(A) % displays trace of matrixdisp('-->addition of matrices A&B is')F=A+B % Addition of two maticesdisp('-->subtraction of matrices A&B is')
G=A-B % subtraction of two maticesdisp('-->multiplication of matrices A&B is')H=A*B % multiplication of matricesdisp('-->element by element multiplication of matrices A&B is')I=A.*B % element by element multiplicationdisp('-->determinant of matrix A is')J=det(A) % determinant of Adisp('-->inverse of matrix A is')K=inv(A) % inverse of AL=K*A % multiplication of A with inv(A) I matrixdisp('-->transpose of matrix A is')
M=transpose(A) % transpose of Adisp('-->scalar addition of matrix A is')N=2+A % scalar additiondisp('-->scalar subtraction of matrix A is')O=2-A % scalar subtractiondisp('-->Identity matrix is')P=eye(3) % Identity matrixdisp('-->Magic matrix is')Q=magic(3) % sum of rows and columns are equaldisp('-->sub matrices of A are')R=A(2:3,2:4) % submatrix of A
S=A(1:4,3:4)A(:,3)=[] % empty matrix
Output:A =
1 2 3 4
3 4 7 65 6 7 8
2 5 4 1
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
6/60
Basic Simulation lab
B =
3 4 5 6
5 6 7 8
1 2 3 44 5 6 7
-->size of matrix A isC =
4 4
-->rank of matrix A isD =
4
-->trace of matrix A is
E =13
-->addition of matrices A&B is
F =4 6 8 10
8 10 14 14
6 8 10 12
6 10 10 8-->subtraction of matrices A&B is
G =
-2 -2 -2 -2-2 -2 0 -2
4 4 4 4
-2 0 -2 -6
-->multiplication of matrices A&B isH =
32 42 52 62
60 80 100 12084 110 136 162
39 51 63 75
-->element by element multiplication of matrices A&B isI =
3 8 15 24
15 24 49 48
5 12 21 328 25 24 7
-->determinant of matrix A is
J = -80.0000
-->inverse of matrix A isK =
-0.9000 0.1000 0.4000 -0.2000
0.4750 -0.4000 0.0250 0.3000-0.2500 0.5000 -0.2500 0.0000
0.4250 -0.2000 0.0750 -0.1000
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
7/60
Basic Simulation lab
L =
1.0000 -0.0000 0 -0.0000
0 1.0000 -0.0000 -0.0000
0.0000 0.0000 1.0000 0.00000.0000 -0.0000 -0.0000 1.0000
-->transpose of matrix A is
M =
1 3 5 22 4 6 5
3 7 7 4
4 6 8 1
-->scalar addition of matrix A is
N =3 4 5 6
5 6 9 8
7 8 9 10
4 7 6 3
-->scalar subtraction of matrix A is
O =1 0 -1 -2
-1 -2 -5 -4
-3 -4 -5 -6
0 -3 -2 1-->Identity matrix is
P =
1 0 00 1 0
0 0 1
-->Magic matrix isQ =
8 1 6
3 5 7
4 9 2-->sub matrices of A are
R =
4 7 6
6 7 8S =
3 4
7 67 8
4 1
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
8/60
Basic Simulation lab
A =
1 2 4
3 4 6
5 6 82 5 1
Result: In this experiment basic operations on matrices using MATLAB have been performed.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
9/60
Basic Simulation lab
2. GENERATION OF VARIOUS SIGNALS AND SEQUENCES
Aim: Write a MATLAB program to generate different types of signals and sequences such as
unit impulse, unit step, sawtooth, triangular, square, sinusoidal, ramp and sinc functions.
A)Unit impulse and unit step signal and sequence
Program:
n=input('enter the value n')t=-n:0.02:n;x=(t==0);subplot(3,1,1)plot(t,x)xlabel('time');ylabel('amplitude')title('impulse signal')y=(t>=0);
subplot(3,1,2)plot(t,y)xlabel('time');ylabel('amplitude')title('unit step signal')subplot(3,1,3)stem(t,y)xlabel('time');ylabel('amplitude')title('unit step sequence')
Output:
enter the value n 4
Impulse, step signal and sequence
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
10/60
Basic Simulation lab
B) Sawtooth and Triangular signalProgram:
n=input('enter the value n');fs=100;t=-n:1/fs:n;x=sawtooth(2*pi*5*t);figuresubplot(2,1,1)plot(t,x)xlabel('time');ylabel('amplitude')title('sawtooth signal')subplot(2,1,2)stem(t,x)xlabel('time');ylabel('amplitude')title('sawtooth sequence')y=sawtooth(2*pi*5*t,0.5);
figuresubplot(2,1,1)plot(t,y)xlabel('time');ylabel('amplitude')title('triangular signal')subplot(2,1,2)stem(t,y)xlabel('time');ylabel('amplitude')title('triangular sequence')
Output:
enter the value n 1 Sawtooth
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
11/60
Basic Simulation lab
Triangular
C) Square and ramp signal and sequence.Program:
n=input('enter the value n');fs=100;t=0:1/fs:n;x=square(2*pi*5*t);
figuresubplot(2,1,1)plot(t,x)xlabel('time');ylabel('amplitude')title('square signal')subplot(2,1,2)stem(t,x)xlabel('time');ylabel('amplitude')title('square wave sequence')y=t;figure
subplot(2,1,1)plot(t,y)xlabel('time');ylabel('amplitude')title('ramp signal')subplot(2,1,2)stem(t,y)xlabel('time');ylabel('amplitude')title('ramp sequence')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
12/60
Basic Simulation lab
Output:enter the value n 2
Square wave
Ramp signal
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
13/60
Basic Simulation lab
D) Sinusoidal and sinc functionsProgram:
fs=100;t=-1:1/fs:1;x=sin(2*pi*5*t);figuresubplot(2,1,1)plot(t,x)gridxlabel('time');ylabel('amplitude')title('sin signal')subplot(2,1,2)stem(t,x)gridxlabel('time');ylabel('amplitude')
title('sin wave sequence')y=sinc(10*t);figuresubplot(2,1,1)plot(t,y)gridxlabel('time');ylabel('amplitude')title('sinc signal')subplot(2,1,2)stem(t,y)grid
xlabel('time');ylabel('amplitude')title('sinc sequence')
Output: Sine signal
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
14/60
Basic Simulation lab
Sinc signal
E) Sine wave with harmonics and noiseProgram:
fs=1000;ts=1/fs;t=0:ts:1;
x=sin(2*pi*10*t)+sin(2*pi*20*t);subplot(2,1,1);plot(t,x);title('sine with two harmonics');xlabel('time');ylabel('amplitude');grid;x1=x+2*randn(size(t));subplot(2,1,2);plot(t,x1);title('sine with noise');xlabel('time');ylabel('amplitude');grid;
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
15/60
Basic Simulation lab
Output:Sine with harmonics and sine wave with noise
Result: In this experiment various signals have been generated using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
16/60
Basic Simulation lab
3. OPERATIONS ON SIGNALS AND SEQUENCES
Aim: Write a MATLAB program to study the operations of the signals and sequences such as
addition, multiplication, scaling, shifting, folding and computation of energy and average power.
Program:
A) Operation on independent variablex(t)= 5 + t -5
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
17/60
Basic Simulation lab
subplot(2,1,2)plot(t,y5)grid;xlabel('time');ylabel('amplitude')title('time scaled signal')
Calling function
function x=y(t)x1=t+5;x2=11+4*t;x3=24-9*t;x4=t-6;x=x1.*(-5*t&t
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
18/60
Basic Simulation lab
Time shifted and time scaled signal
Time shifted and scaled signal
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
19/60
Basic Simulation lab
B) Operation on dependent variableProgram:
clear alltmin=-15;tmax=15;t=tmin:0.1:tmax;y0=3*y(t);y1=3*y(t+4); % time shiftingy2=y0+y1; % additiony3=y0.*y1; % multiplicationy4=2*y0; % scalar multiplicationy5=y0/2; % scalar divisionfiguresubplot(2,1,1)plot(t,y0)grid;xlabel('time');ylabel('amplitude')
title('actual signal')subplot(2,1,2)plot(t,y1)grid;xlabel('time');ylabel('amplitude')title('time shifted signal')figuresubplot(2,1,1)plot(t,y2)grid;xlabel('time');ylabel('amplitude')title('addition of two signals')subplot(2,1,2)
plot(t,y3)grid;xlabel('time');ylabel('amplitude')title('multiplication of two signals')figuresubplot(2,1,1)plot(t,y4)grid;xlabel('time');ylabel('amplitude')title('amplitude scaled signal')subplot(2,1,2)plot(t,y5)grid;xlabel('time');ylabel('amplitude')
title('amplitude scaled signal')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
20/60
Basic Simulation lab
Output:
Actual and time shifted signal
Addition and multiplication of two signals
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
21/60
Basic Simulation lab
Amplitude scaled signals
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
22/60
Basic Simulation lab
C) Computation of energy of the a periodic signalProgram:
t=0:1:50;x=(1/2).^t;plot(t,x)grid;xlabel('time');ylabel('amplitude')title('actual signal')disp('the calculated energy of the signal is')E=sum(abs(x).^2)disp('the theoritical energy of the signal is')E_theory=4/3
Output:
the calculated energy of the signal is
E = 1.3333
the theoritical energy of the signal is
E_theory =
1.3333
Signal
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
23/60
Basic Simulation lab
D) Computation of power of the periodic signalProgram:
N=input('enter the value N');t=-N:0.0001:N;x=cos(2*pi*50*t);y=cos(2*pi*50*t).^2;plot(t,x)axis([-0.2 0.2 -2 2])grid;xlabel('time');ylabel('amplitude')title('actual signal')disp('the calculated power of the signal is')P=sum(abs(y).^2)/length(x)disp('the theoritical power of the signal is')E_theory=3/8Output:
enter the value N 5the calculated power of the signal isP =
0.3750
the theoritical power of the signal is
E_theory =0.3750
Signal
Result:In this experiment the various operations on signals have been performed and computation of
energy and power of various signals have been calculated using MATLAB software.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
24/60
Basic Simulation lab
4. FINDING EVEN AND ODD PARTS OF THE SIGNAL
Aim: Write a MATLAB program to find the even and odd parts of the signal/sequence and real
and imaginary part of the signal.
A)Even and odd parts of the signal
Program:t=0:0.005:4;x=sin(2*pi*5*t)+cos(2*pi*5*t);subplot(221)plot(t,x)gridxlabel('time');ylabel('amplitude')title('original signal')y=sin(-t)+cos(-t);subplot(222)plot(t,y)gridxlabel('time');ylabel('amplitude')title('folded signal')z=(x+y)/2;subplot(223)plot(t,z)gridxlabel('time');ylabel('amplitude')title('even part of the signal')subplot(224)
p=(x-y)/2;plot(t,p)gridxlabel('time');ylabel('amplitude')title('odd part of the signal')q=z+p;figureplot(t,q)gridxlabel('time');ylabel('amplitude')title('original signal')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
25/60
Basic Simulation lab
Output:
Even and odd part of the signal
Reconstructed signal from even and odd parts
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
26/60
Basic Simulation lab
B) Real and imaginary part of the signal.
Program:
x=input('enter complex number')i=imag(x)r=real(x)disp('imaginary part is')disp(i)disp('real part is')disp(r)
Output:enter complex number[1+2i 2+3i 4+5i 5 6+7i]
imaginary part is
2 3 5 0 7
real part is
1 2 4 5 6
Result: In this experiment even and odd parts of the signals and sequence and real and imaginary
part of the signal have been calculated using MATLAB software.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
27/60
Basic Simulation lab
5. CONVOLUTION OF SIGNALS AND SEQUENCES
Aim: Write a MATLAB program to plot the convolution of signals and sequences.
A) For signalsProgram:
t=0:0.01:10;x=cos(2*pi*5*t);h=sin(2*pi*2*t);y=conv(x,h);subplot(3,1,1)plot(x)xlabel('time');ylabel('amplitude');
title('signal1')subplot(3,1,2)plot(h)xlabel('time');ylabel('amplitude');title('signal2')subplot(3,1,3)plot(y)xlabel('time');ylabel('amplitude');title('convolution of two sequences')
Output:
Convolution of two signals
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
28/60
Basic Simulation lab
B) For sequencesProgram:
x=input('enter the first sequence');h=input('enter the second sequence');n1=length(x);n2=length(h);y=conv(x,h);subplot(3,1,1)t1=0:n1-1;stem(t1,x)xlabel('time');ylabel('amplitude');title('first sequence')subplot(3,1,2)t2=0:n2-1;stem(t2,h)
xlabel('time');ylabel('amplitude');title('second sequence')subplot(3,1,3)t3=0:n1+n2-2;stem(t3,y)xlabel('time');ylabel('amplitude');title('convolution of two sequences')
Output:enter the first sequence[1 2 3 5]
enter the second sequence[4 5 7 6]
convolution of two sequences4 13 29 55 58 53 30
Convolution of two sequences
Result: In this experiment convolution of signals and sequences are generated using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
29/60
Basic Simulation lab
6. AUTO CORRELATION AND CROSS CORRELATION BETWEEN SIGNALS AND
SEQUENCES
Aim: Write a MATLAB program to find the auto correlation and cross correlation of signals andsequences.
A) Auto correlationx=input('enter the sequence');D=input('type the delay');xd=[zeros(1,D) x];[r,lag]=xcorr(x,xd);stem(lag,r)title('cross correlation of x and dealayed x');xlabel('lag index')ylabel('autocorrelation')
Output:
enter the sequence[1 2 3 -2 -1]
type the delay3cross correlation of x and dealayed x
Columns 1 through 6
-1.0000 -4.0000 -4.0000 4.0000 19.0000 4.0000
Columns 7 through 12-4.0000 -4.0000 -1.0000 0.0000 0.0000 0.0000
Columns 13 through 15
0 -0.0000 -0.0000Auto correlation of two sequences
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
30/60
Basic Simulation lab
B) Cross correlationProgram:
x=input('enter the first sequence');y=input('enter the second sequence');[r,lag]=xcorr(x,y);disp('cross correlation of x and y')disp(r)stem(lag,r)title('cross correlation of x and y');xlabel('lag index')ylabel('cross correlation')
Output:enter the first sequence[1 2 3 4]
enter the second sequence[4 5 6 7]
cross correlation of x and yColumns 1 through 6
7.0000 20.0000 38.0000 60.0000 47.0000 32.0000
Column 716.0000
Cross correlation of two sequnences
Result: In this experiment correlation of various signals has been performed using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
31/60
Basic Simulation lab
7. VERIFICATION OF LINEARITY AND TIME INVARIANCE PROPERTIES OF A
GIVEN CONTINUOUS/DISCRETE SYSTEMS
Aim: Write a MATLAB program to verify linearity and time invariance properties of a given
continuous/discrete systems.
A)Linear system
Program:
n=0:40; %veriying upto 40 samplesa=2;b=1; %multiplication constantsx1=cos(2*pi*0.1*n); %first inputx2=cos(2*pi*0.4*n); %second inputx=a*x1+b*x2; %single outputy=n.*x; %output upto 40 samplesy1=n.*x1; %first input outputy2=n.*x2; %second input outputyt=a*y1+b*y2; %addition first output,second outputd=y-yt;d=round(d);if d==0
disp('given system is satisfy linearity property')else
disp('given system is not satisfy linearityproperty')endsubplot(3,1,1)
stem(n,y)grid;xlabel('time');ylabel('amplitude')title('output of the system with added inputs')subplot(3,1,2)stem(n,yt)grid;xlabel('time');ylabel('amplitude')title('output of the system with weighted added inputs')subplot(3,1,3)stem(n,d)grid;xlabel('time');ylabel('amplitude')title('differece')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
32/60
Basic Simulation lab
Output:
given system is satisfy linearity property
B)Nonlinear system
Program:
n=0:40; %veriying upto 40 samplesa=2;b=-3; %multiplication constantsx1=cos(2*pi*0.1*n); %first inputx2=cos(2*pi*0.4*n); %second inputx=a*x1+b*x2; %single outputy=n.*x.^2; %output upto 40 samplesy1=n.*x1.^2; %first input outputy2=n.*x2.^2; %second input output
yt=a*y1+b*y2; %addition first output,second outputd=y-yt;d=round(d);if (d==0)
disp('given system is satisy linearity property')else
disp('given system is not satisy linearity property')endsubplot(3,1,1)
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
33/60
Basic Simulation lab
stem(n,y)grid;xlabel('time');ylabel('amplitude')title('output of the system with added inputs')subplot(3,1,2)stem(n,yt)
grid;xlabel('time');ylabel('amplitude')title('output of the system with weighted added inputs')subplot(3,1,3)stem(n,d)grid;xlabel('time');ylabel('amplitude')title('differece')
Output:
Result: In this experiment linearity and time invariance properties of given system has been
verified using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
34/60
Basic Simulation lab
8. COMPUTATION OF UNIT SAMPLE, UNIT STEP, SINUSOIDAL RESPONSES OF
THE GIVEN LTI SYSTEM
Aim: Write a MATLAB program to compute unit sample, unit step, sinusoidal responses of the
given LTI system using MATLAB.
Program:
b=input('enter the numerator coefficients');a=input('enter the numerator coefficients');t=0:0.1:10;x1=sin(2*pi*2*t);h=impulse(b,a);s=step(b,a);si=filter(b,a,x1);subplot(3,1,1)plot(h)grid;xlabel('time');ylabel('amplitude');title('impulse response')subplot(3,1,2)plot(s)grid;xlabel('time');ylabel('amplitude');title('step response')subplot(3,1,3)plot(t,si)grid;xlabel('time');ylabel('amplitude');title('sinusoidal response')
Output:
enter the numerator coefficients[1]
enter the numerator coefficients[1 0.2 0.1]
Transfer function:
1
-----------------
s^2 + 0.2 s + 0.1
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
35/60
Basic Simulation lab
Impulse , step, sinusoidal response of a system
Result: In this experiment unit impulse, unit step, sinusoidal responses of given LTI system havebeen calculated using MATLAB software.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
36/60
Basic Simulation lab
9. GIBBS PHENOMENON
Aim: Write a MATLAB program to verify the Gibbs phenomenon.
Program:
t=-1:0.01:1;y=sin(2*pi*5*t);subplot(5,1,1)plot(t,y)grid;xlabel('time');ylabel('amplitude')title('Gibbs phenomenon')h=2;for k=3:2:9
y=y+sin(k*2*pi*5*t)/k;subplot(5,1,h)plot(t,y)
grid;xlabel('time');ylabel('amplitude');h=h+1;
end
Output:
Gibbs phenomenon
Result: In this experiment Gibbs phenomenon has been verified using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
37/60
Basic Simulation lab
10. FOURIER TRANSFORM OF A GIVEN SIGNAL
Aim: Write a MATLAB program to find the Fourier transform of a signal and plot its magnitude
and phase spectrum.
Program:
Fs=100;t=0:1/Fs:10;x=sin(2*pi*20*t)+cos(2*pi*40*t);N=512;X=fft(x,N);f=Fs*(0:N-1)/N;Xm=abs(X);Xp=angle(X)*180/pi;subplot(3,1,1)plot(t,x)axis([0 1 -1 1])
grid;xlabel('time');ylabel('amplitude');title('signal')subplot(3,1,2)plot(f,Xm)grid;xlabel('frequency');ylabel('magnitude');title('magnitude spectrum')subplot(3,1,3)plot(f,Xp)grid;xlabel('frequency');ylabel('magnitude');title('phase spectrum')
Output: Signal, its magnitude and phase spectrum
Result: The Fourier transform of the given signal is found and its magnitude and phase
spectrums are plotted using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
38/60
Basic Simulation lab
11. WAVEFORM SYNTHESIS USING LAPLACE TRANSORM
Aim: To perform waveform synthesis using Laplace transform of a given signal. A) Laplace transform
Program:syms f t;
f=t;L=laplace(f);disp('laplace transform is')disp(L)
Output:laplace transform is
1/s^2
B) Laplace transformProgram:syms t w sf1=sin(w*t);f2=sin(w*(t+1));L1=laplace(f1);L2=laplace(f2);disp('laplace transorm first signal is')disp(L1)disp('laplace transorm second signal is')disp(L2)
Output:
laplace transorm first signal isw/(s^2 + w^2)
laplace transorm second signal is(w*cos(w) + s*sin(w))/(s^2 + w^2)
C) Inverse Laplace transformProgram:syms F sF=24/(s*(s+8));I=ilaplace(F);disp('inverse laplace transform is')
disp(I)
Output:inverse laplace transform is
3 - 3/exp(8*t)
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
39/60
Basic Simulation lab
D) Signal synthesize using Laplace transformProgram:
Output:
Result: In this experiment the signals are synthesized using Laplace transform using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
40/60
Basic Simulation lab
12. LOCATING POLES AND ZEROS
Aim: To locating the zeros and poles and plotting the pole zero maps in s-plane and z-plane for
the given transfer function using MATLAB.A) S-plane
Prgram:
b=input('enter numerator coeficients');a=input('enter numerator coeficients');H=tf(b,a)[p,z]=pzmap(H);pzmap(H);h=impulse(H);figureplot(h)gridxlabel('time');ylabel('amplitude');title('impulse response')disp('zeros are at')disp(z)disp('poles are at')disp(p)if max(real(p))>0
disp('all poles do not lie in the let half of S-plane')disp('so the system is unstable')
elsedisp('all poles lie in the let half of S-plane')disp('so the system is stable')
end
Output:
enter numerator coeficients[1 2 3 4]enter numerator coeficients[4 5 6 7]
Transfer function:
s^3 + 2 s^2 + 3 s + 4
-----------------------4 s^3 + 5 s^2 + 6 s + 7
zeros are at
-1.6506-0.1747 + 1.5469i
-0.1747 - 1.5469i
poles are at
-1.2078
-0.0211 + 1.2035i-0.0211 - 1.2035i
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
41/60
Basic Simulation lab
all poles lie in the let half of S-plane
so the system is stable
Pole zero map
Impulse response
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
42/60
Basic Simulation lab
B) Z-planeProgram:
b=input('enter numerator coeficients');a=input('enter numerator coeficients');
H=filt(b,a)z=zero(H)[r,p,k]=residuez(b,a)radpole=abs(p);[p,z]=pzmap(H);zplane(b,a);title('pole zero map of given system in Z-plane')figureimpz(b,a)disp('zeros are at')disp(z)disp('poles are at')disp(p)if max(radpole)>=1
disp('all poles do not lie within the unit circle')disp('so the system is unstable')
elsedisp('all poles lie within the unit circle')disp('so the system is stable')
end
Output:enter numerator coeficients[1 2 3 4]
enter numerator coeficients[4 5 7 6]
Transfer function:
1 + 2 z^-1 + 3 z^-2 + 4 z^-3----------------------------
4 + 5 z^-1 + 7 z^-2 + 6 z^-3
Sampling time: unspecifiedz =
-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469i
r =
-0.0972 + 0.0242i-0.0972 - 0.0242i
-0.2222
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
43/60
Basic Simulation lab
p =
-0.1250 + 1.2183i
-0.1250 - 1.2183i
-1.0000k =
0.6667zeros are at-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469ipoles are at
-0.1250 + 1.2183i
-0.1250 - 1.2183i
-1.0000all poles do not lie within the unit circle
so the system is unstable
Pole zero map
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
44/60
Basic Simulation lab
Impulse response
Result: In this experiment the zeros and poles are located and pole zero maps are plotted in s-
plane and z-plane for given transfer function using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
45/60
Basic Simulation lab
13. GAUSSIAN NOISE
Aim: Write a MATLAB program to generate gaussian noise and computes its mean, mean
square value, skew, kurtosis, power spectral distribution, probability distribution function.
Program:
x1=randn(1,5000);x2=randn(1,5000);x3=rand(1,5000);x4=rand(1,5000);xmean=mean(x1);xmsq=sum(x1.^2/length(x1));xstandard=std(x1);xvar=var(x1);xskew=skewness(x1);xkurt=kurtosis(x1);
disp('mean of gaussian noise is');disp(xmean);disp('mean squre value of gaussian noise is');disp(xmsq);disp('standard deviation of gaussian noiseis');disp(xstandard);disp('variance of gaussian noise is');disp(xvar);disp('skew of gaussian noise is');disp(xskew);disp('kurtosis of gaussian noise is');disp(xkurt);figurehist(x1)title('Gaussian(random) distribution')figure
hist(x3)title('uniform distribution')figuresubplot(2,1,1)plot(x1,x2,'.');title('scatter plot of normal(gaussian)distribution randomnumbers')subplot(2,1,2)plot(x3,x4,'.');title('scatter plot of uniform distribution randomnumbers')
Output:
mean of gaussian noise is
-0.0145
mean squre value of gaussian noise is
0.9667
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
46/60
Basic Simulation lab
standard deviation of gaussian noise is
0.9832
variance of gaussian noise is
0.9667
skew of gaussian noise is
-0.0243
kurtosis of gaussian noise is
3.0355
Distribution of Gaussian noise
Uniform distribution
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
47/60
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
48/60
Basic Simulation lab
14. SAMPLING THEOREM VERIFICATION
Aim: Write a MATLAB program to verify the Sampling theorem.
Program:
clc;clear all;t=-5:0.0001:5;f1=5;f2=20;x=cos(2*pi*f1*t)+cos(2*pi*f2*t);figure(1)plot(t,x)axis([-0.4 0.4 -2 2])grid;xlabel('time');ylabel('amplitude')title('continuous time signal');
%%%%% case 1 %%%%%%%%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)axis([-0.4 0.4 -2 2])hold on;plot(t,x,'r');hold off
grid;xlabel('time sample');ylabel('Amplitude');title('Discrete time signal sampling rate fs
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
49/60
Basic Simulation lab
figure(4)stem(n3,xs3)axis([-0.4 0.4 -2 2])hold on;plot(t,x,'r');
hold offgrid;xlabel('time sample');ylabel('Amplitude');title('Discrete time signal sampling rate fs>2*fmax');
Output:
Continuous time signal
Sampling at fs
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
50/60
Basic Simulation lab
Sampling at fs=2*fmax
Sampling at fs>2*fmax
Result: In this experiment sampling theorem has been verified using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
51/60
Basic Simulation lab
15. REMOVAL OF NOISE BY AUTO CORRELATION/CROSS CORRELATION
Aim: Write a MATLAB program to remove noise by auto correlation/cross correlation.
A) Using auto correlationProgram:
t=0:0.01:4;signal=sin(2*pi*10*t);noise=randn(size(t));noisysignal=signal+noise;sc=xcorr(signal,signal);nc=xcorr(noise,noise);snc=xcorr(noisysignal,noisysignal);asnc=sc+nc;figure
subplot(2,1,1)plot(signal)grid;xlabel('time');ylabel('amplitude');title('signal')subplot(2,1,2)plot(noisysignal)grid;xlabel('time');ylabel('amplitude');title('noise added signal')figuresubplot(2,1,1)plot(sc)
grid;xlabel('time');ylabel('amplitude');title('correlation of signal')subplot(2,1,2)plot(nc)grid;xlabel('time');ylabel('amplitude');title('correlation of noise signal')figuresubplot(2,1,1)plot(snc)grid;xlabel('time');ylabel('amplitude');title('correlation of noisy signal')
subplot(2,1,2)plot(asnc)grid;xlabel('time');ylabel('amplitude');title('addition of correlation of signal and noise')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
52/60
Basic Simulation lab
Output:Signal and noise added signal
Correlation of signal and correlation of noise signal
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
53/60
Basic Simulation lab
Correlation o noisy signal and addition of correlation of signal and noise
B) Using cross correlationProgram:t=0:0.01:1;signal=sin(2*pi*10*t);
testsignal=cos(2*pi*10*t); %testing signl with samefrequency of signalnoise=randn(size(t));noisysignal=signal+noise;sc=xcorr(signal,testsignal);nc=xcorr(noise,testsignal);snc=xcorr(noisysignal,testsignal);asnc=sc+nc;figuresubplot(2,1,1)plot(signal)
grid;xlabel('time');ylabel('amplitude');title('signal')subplot(2,1,2)plot(testsignal)grid;xlabel('time');ylabel('amplitude');title('test signal')figuresubplot(2,1,1)plot(noisysignal)
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
54/60
Basic Simulation lab
grid;xlabel('time');ylabel('amplitude');title('noisy signal')subplot(2,1,2)plot(sc)grid;xlabel('time');ylabel('amplitude');
title('correlation of signal&test signal')figuresubplot(3,1,1)plot(nc)grid;xlabel('time');ylabel('amplitude');title('correlation of noise&test signal')subplot(3,1,2)plot(snc)grid;xlabel('time');ylabel('amplitude');title('correlation of noisysignal and testsignal')subplot(3,1,3)plot(asnc)grid;xlabel('time');ylabel('amplitude');title('addtion of correlations sc & nc')
Output:Two periodic signals (with same period)
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
55/60
Basic Simulation lab
Noisy signal and correlation of signal and test signal
Correlation of noise and test signal, Correlation of noisy signal and test signal, addition of sc and nc
Result: In this experiment the detecting of noise by auto correlation/cross correlation has beenverified using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
56/60
Basic Simulation lab
16. Extraction of periodic signal masked by noise using Correlation
Aim: Write a MATLAB program to extract periodic signal masked by noise using correlation.
Program:
t=-2:0.001:2;signal=sin(2*pi*t);impulse=ones(1,20);%testing signal with same frequencyof signalnoise=randn(size(t));noisysignal=signal+noise;si=xcorr(signal,impulse);ni=xcorr(noise,impulse);nsic=xcorr(noisysignal,impulse);figuresubplot(2,1,1)
plot(t,signal)grid;xlabel('time');ylabel('amplitude');title('signal')subplot(2,1,2)stem(impulse)grid;xlabel('time');ylabel('amplitude');title('test signal')figuresubplot(2,1,1)plot(noise)grid;xlabel('time');ylabel('amplitude');
title('noisy signal')subplot(2,1,2)plot(noisysignal)grid;xlabel('time');ylabel('amplitude');title('correlation of signal&test signal')figuresubplot(3,1,1)plot(si)grid;xlabel('time');ylabel('amplitude');title('correlation of noise&test signal')subplot(3,1,2)
plot(ni)grid;xlabel('time');ylabel('amplitude');title('correlation of noisysignal and testsignal')subplot(3,1,3)plot(nsic)grid;xlabel('time');ylabel('amplitude');title('addtion of correlations sc & nc')
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
57/60
Basic Simulation lab
Output:
Actual signal and periodic impulse signal
Noisy signal and Correlation of noise and impulse
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
58/60
Basic Simulation lab
Correlation of noise and impulse, Correlation of noisy signal and impulse, addition of sc and nc
Result: In this experiment the removal of noise by correlation has been verified using
MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
59/60
Basic Simulation lab
17. VERIFICATION OF WIENER-KHINCHINE RELATION
Aim: Verification of Wiener-Khinchine relation using MATLAB.
Program:
Fs=100;t=0:1/Fs:10;x=sin(2*pi*15*t)+sin(2*pi*30*t);N=512;X=fft(x,N);f=Fs*(0:N-1)/N;power=X.*conj(X)/N;rxx=xcorr(x,x);Sxx=fft(rxx,512);subplot(2,1,1)plot(f,power)
title('power spectrum using fourier transform')grid;xlabel('frequency');ylabel('Power')subplot(2,1,2)plot(f,abs(Sxx))title('power spectrum using fourier transform of ACF')grid;xlabel('frequency');ylabel('Power')
Output:
Result: In this experimentthe Wiener-Khinchine relation has been verified using MATLAB.
-
7/29/2019 Basic Siumlation Lab - 12-13, I Semester- SRAWAN
60/60
Basic Simulation lab
18. CHECKING A RANDOM PROCESS FOR STATIONARITY IN WIDE SENSE
Aim: Write a MATLAB program to check a random process for stationarity in wide sense.
Program:
Output:
Result: In this experiment the random process for stationarity in wide sense has been verified
using MATLAB.