You are on page 1of 60

Basic Simulation lab

AURORAS ENGINEERING COLLEGE


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

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.

Basic Simulation lab

LAB CODE
1. 2. Students should report to the concerned labs as per the time table schedule. Students who turn up late to the labs will in no case be permitted to perform the experiment scheduled for the day. After completion of the experiment, certification of the concerned staff inobservation book is necessary. charge in the

3.

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. 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. Not more than three students in a group are permitted to perform the experiment on a setup. 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. The components required pertaining to the experiment should be collected charge after duly filling in the requisition form. from stores in-

5.

6. 7.

8.

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. 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. Students should be present in the labs for the total scheduled duration. Students are required to prepare thoroughly to perform the experiment before coming to Laboratory. Procedure sheets/data sheets provided to the students groups should be maintained neatly and to be returned after the experiment.

10.

11. 12.

13.

Basic Simulation lab

INDEX
Sl NO. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Name of the Experiment BASIC MATHEMATICAL OPERATIONS ON MATRICES. GENERATION OF VARIOUS SIGNALS OPERATIONS ON SIGNALS SYMMETRY OF A SIGNAL CONVOLUTION OF SIGNALS & SEQUENCES CORRELATION OF SIGNALS LINEARITY AND TIME INVARIENCE PROPERTIES RESPONSE OF LTI SYSTEMS GIBBS PHENOMENON FOURIER TRANSFORM WAVEFORM SYNTHESIS USING LAPLACE TRANFORM POLE-ZERO MAP GENERATION OF GAUSSION NOISE SAMPLING THEOREM VERIFICATION NOISE REMOVAL USING CORRELATION PERIODIC SIGNAL EXTRACTION USING CORRELATION RAISED COSINE FILTER WIENER KHINTCHINE RELATION

Basic Simulation lab

1. BASIC MATHEMATICAL OPERATIONS ON MATRICES Aim: 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 A B=[3 4 5 6;5 6 7 8;1 2 3 4;4 5 6 7] % defining matrix B disp('-->size of matrix A is') C=size(A) % displays size of matrix disp('-->rank of matrix A is') D=rank(A) % displays rank of matrix disp('-->trace of matrix A is') E=trace(A) % displays trace of matrix disp('-->addition of matrices A&B is') F=A+B % Addition of two matices disp('-->subtraction of matrices A&B is') G=A-B % subtraction of two matices disp('-->multiplication of matrices A&B is') H=A*B % multiplication of matrices disp('-->element by element multiplication of matrices A&B is') I=A.*B % element by element multiplication disp('-->determinant of matrix A is') J=det(A) % determinant of A disp('-->inverse of matrix A is') K=inv(A) % inverse of A L=K*A % multiplication of A with inv(A) I matrix disp('-->transpose of matrix A is') M=transpose(A) % transpose of A disp('-->scalar addition of matrix A is') N=2+A % scalar addition disp('-->scalar subtraction of matrix A is') O=2-A % scalar subtraction disp('-->Identity matrix is') P=eye(3) % Identity matrix disp('-->Magic matrix is') Q=magic(3) % sum of rows and columns are equal disp('-->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 5 6 2 5

3 7 7 4

4 6 8 1

Basic Simulation lab

B= 3 5 1 4

4 6 2 5

5 7 3 6

6 8 4 7

-->size of matrix A is C= 4 4 -->rank of matrix A is D= 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 is H= 32 42 52 62 60 80 100 120 84 110 136 162 39 51 63 75 -->element by element multiplication of matrices A&B is I= 3 8 15 24 15 24 49 48 5 12 21 32 8 25 24 7 -->determinant of matrix A is J = -80.0000 -->inverse of matrix A is K= -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

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.0000 0.0000 -0.0000 -0.0000 1.0000 -->transpose of matrix A is M= 1 2 3 4

3 4 7 6

5 6 7 8

2 5 4 1

-->scalar addition of matrix A is N= 3 5 7 4

4 6 8 7

5 6 9 8 9 10 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 0 0 1 0 0 0 1 -->Magic matrix is Q= 8 1 6 3 5 7 4 9 2 -->sub matrices of A are R= 4 7 6 6 7 8 S= 3 4 7 6 7 8 4 1

Basic Simulation lab

A= 1 3 5 2

2 4 6 5

4 6 8 1

Result: In this experiment basic operations on matrices using MATLAB have been performed.

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

Basic Simulation lab

B) Sawtooth and Triangular signal Program: n=input('enter the value n'); fs=100; t=-n:1/fs:n; x=sawtooth(2*pi*5*t); figure subplot(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); figure subplot(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

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

Basic Simulation lab

Output: enter the value n 2 Square wave

Ramp signal

Basic Simulation lab

D) Sinusoidal and sinc functions Program: fs=100; t=-1:1/fs:1; x=sin(2*pi*5*t); figure subplot(2,1,1) plot(t,x) grid xlabel('time');ylabel('amplitude') title('sin signal') subplot(2,1,2) stem(t,x) grid xlabel('time');ylabel('amplitude') title('sin wave sequence') y=sinc(10*t); figure subplot(2,1,1) plot(t,y) grid xlabel('time');ylabel('amplitude') title('sinc signal') subplot(2,1,2) stem(t,y) grid xlabel('time');ylabel('amplitude') title('sinc sequence') Output: Sine signal

Basic Simulation lab

Sinc signal

E) Sine wave with harmonics and noise Program: 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;

Basic Simulation lab

Output: Sine with harmonics and sine wave with noise

Result: In this experiment various signals have been generated using MATLAB.

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 variable x(t)= 5+t -5<t<-2

11+4*t -2<t<1 24-9*t t-6 1<t<3 3<t<6

clear all tmin=-15;tmax=20; t=tmin:0.1:tmax; y0=y(t); y1=y(-t); % time folding y2=y(t+4); % time shifting y3=y(2*t); % time scaling y4=y(2*t-3); % time shiting and scaling y5=y(t/2); % time shiting figure subplot(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 folded signal') figure subplot(2,1,1) plot(t,y2) grid;xlabel('time');ylabel('amplitude') title('time shifted signal') subplot(2,1,2) plot(t,y3) grid;xlabel('time');ylabel('amplitude') title('time scaled signal') figure subplot(2,1,1) plot(t,y4) grid;xlabel('time');ylabel('amplitude') title('time shited and scaled signal')

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<=-2)+x2.*(2<t&t<=1)+x3.*(1<t&t<=3)+x4.*(3<t&t<=6); Output: Actual and time folded signal

Basic Simulation lab

Time shifted and time scaled signal

Time shifted and scaled signal

Basic Simulation lab

B) Operation on dependent variable Program: clear all tmin=-15;tmax=15; t=tmin:0.1:tmax; y0=3*y(t); y1=3*y(t+4); % time shifting y2=y0+y1; % addition y3=y0.*y1; % multiplication y4=2*y0; % scalar multiplication y5=y0/2; % scalar division figure subplot(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') figure subplot(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') figure subplot(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')

Basic Simulation lab

Output: Actual and time shifted signal

Addition and multiplication of two signals

Basic Simulation lab

Amplitude scaled signals

Basic Simulation lab

C) Computation of energy of the a periodic signal Program: 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

Basic Simulation lab

D) Computation of power of the periodic signal Program: 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/8 Output: enter the value N 5 the calculated power of the signal is P = 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.

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) grid xlabel('time');ylabel('amplitude') title('original signal') y=sin(-t)+cos(-t); subplot(222) plot(t,y) grid xlabel('time');ylabel('amplitude') title('folded signal') z=(x+y)/2; subplot(223) plot(t,z) grid xlabel('time');ylabel('amplitude') title('even part of the signal') subplot(224) p=(x-y)/2; plot(t,p) grid xlabel('time');ylabel('amplitude') title('odd part of the signal') q=z+p; figure plot(t,q) grid xlabel('time');ylabel('amplitude') title('original signal')

Basic Simulation lab

Output: Even and odd part of the signal

Reconstructed signal from even and odd parts

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.

Basic Simulation lab

5. CONVOLUTION OF SIGNALS AND SEQUENCES Aim: Write a MATLAB program to plot the convolution of signals and sequences. A) For signals Program: 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

Basic Simulation lab

B) For sequences Program: 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 sequences 4 13 29 55 58 53 30 Convolution of two sequences

Result: In this experiment convolution of signals and sequences are generated using MATLAB.

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 and sequences. A) Auto correlation x=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 delay3 cross 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.0000 Auto correlation of two sequences

Basic Simulation lab

B) Cross correlation Program: 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 y Columns 1 through 6 7.0000 20.0000 38.0000 60.0000 47.0000 32.0000 Column 7 16.0000 Cross correlation of two sequnences

Result: In this experiment correlation of various signals has been performed using MATLAB.

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 samples a=2;b=1; %multiplication constants x1=cos(2*pi*0.1*n); %first input x2=cos(2*pi*0.4*n); %second input x=a*x1+b*x2; %single output y=n.*x; %output upto 40 samples y1=n.*x1; %first input output y2=n.*x2; %second input output yt=a*y1+b*y2; %addition first output,second output d=y-yt; d=round(d); if d==0 disp('given system is satisfy linearity property') else disp('given system is not satisfy linearity property') end subplot(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')

Basic Simulation lab

Output: given system is satisfy linearity property

B) Nonlinear system Program: n=0:40; %veriying upto 40 samples a=2;b=-3; %multiplication constants x1=cos(2*pi*0.1*n); %first input x2=cos(2*pi*0.4*n); %second input x=a*x1+b*x2; %single output y=n.*x.^2; %output upto 40 samples y1=n.*x1.^2; %first input output y2=n.*x2.^2; %second input output yt=a*y1+b*y2; %addition first output,second output d=y-yt; d=round(d); if (d==0) disp('given system is satisy linearity property') else disp('given system is not satisy linearity property') end subplot(3,1,1)

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.

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

Basic Simulation lab

Impulse , step, sinusoidal response of a system

Result: In this experiment unit impulse, unit step, sinusoidal responses of given LTI system have been calculated using MATLAB software.

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.

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.

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 transform Program: syms t w s f1=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 is w/(s^2 + w^2) laplace transorm second signal is (w*cos(w) + s*sin(w))/(s^2 + w^2) C) Inverse Laplace transform Program: syms F s F=24/(s*(s+8)); I=ilaplace(F); disp('inverse laplace transform is') disp(I) Output: inverse laplace transform is 3 - 3/exp(8*t)

Basic Simulation lab

D) Signal synthesize using Laplace transform Program: Output: Result: In this experiment the signals are synthesized using Laplace transform using MATLAB.

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); figure plot(h) grid xlabel('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') else disp('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

Basic Simulation lab

all poles lie in the let half of S-plane so the system is stable Pole zero map

Impulse response

Basic Simulation lab

B) Z-plane Program: 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') figure impz(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') else disp('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: unspecified z= -1.6506 -0.1747 + 1.5469i -0.1747 - 1.5469i r= -0.0972 + 0.0242i -0.0972 - 0.0242i -0.2222

Basic Simulation lab

p= -0.1250 + 1.2183i -0.1250 - 1.2183i -1.0000 k= 0.6667 zeros are at -1.6506 -0.1747 + 1.5469i -0.1747 - 1.5469i poles are at -0.1250 + 1.2183i -0.1250 - 1.2183i -1.0000 all poles do not lie within the unit circle so the system is unstable

Pole zero map

Basic Simulation lab

Impulse response

Result: In this experiment the zeros and poles are located and pole zero maps are plotted in splane and z-plane for given transfer function using MATLAB.

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 noise is');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); figure hist(x1) title('Gaussian(random) distribution') figure hist(x3) title('uniform distribution') figure subplot(2,1,1) plot(x1,x2,'.'); title('scatter plot of normal(gaussian)distribution random numbers') subplot(2,1,2) plot(x3,x4,'.'); title('scatter plot of uniform distribution random numbers') Output: mean of gaussian noise is -0.0145 mean squre value of gaussian noise is 0.9667

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

Basic Simulation lab

Scatter plot of gaussian and uniform noises

Result: In this experiment the Gaussian noise has been generated and mean, mean square value, skew, kurtosis, power spectral distribution, probability distribution function are also computed.

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<2*fmax'); %%%%%%%% case 2 %%%%%% fs2=2*f2; ts2=1/fs2; n2=-0.4:ts2:0.4; xs2=cos(2*pi*f1*n2)+cos(2*pi*f2*n2); figure(3) stem(n2,xs2) 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=2*fmax'); %%%%%%% case 3 %%%%%%%%% fs3=8*f2; ts3=1/fs3; n3=-0.4:ts3:0.4; xs3=cos(2*pi*f1*n3)+cos(2*pi*f2*n3);

Basic Simulation lab

figure(4) stem(n3,xs3) 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>2*fmax'); Output: Continuous time signal

Sampling at fs<2*fmax

Basic Simulation lab

Sampling at fs=2*fmax

Sampling at fs>2*fmax

Result: In this experiment sampling theorem has been verified using MATLAB.

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 correlation Program: 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') figure subplot(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') figure subplot(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')

Basic Simulation lab

Output: Signal and noise added signal

Correlation of signal and correlation of noise signal

Basic Simulation lab

Correlation o noisy signal and addition of correlation of signal and noise

B) Using cross correlation Program: t=0:0.01:1; signal=sin(2*pi*10*t); testsignal=cos(2*pi*10*t); %testing signl with same frequency of signal noise=randn(size(t)); noisysignal=signal+noise; sc=xcorr(signal,testsignal); nc=xcorr(noise,testsignal); snc=xcorr(noisysignal,testsignal); asnc=sc+nc; figure subplot(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') figure subplot(2,1,1) plot(noisysignal)

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') figure subplot(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)

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 been verified using MATLAB.

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 frequency of signal noise=randn(size(t)); noisysignal=signal+noise; si=xcorr(signal,impulse); ni=xcorr(noise,impulse); nsic=xcorr(noisysignal,impulse); figure subplot(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') figure subplot(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') figure subplot(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')

Basic Simulation lab

Output: Actual signal and periodic impulse signal

Noisy signal and Correlation of noise and impulse

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.

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 experiment the Wiener-Khinchine relation has been verified using MATLAB.

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.

You might also like