Basic Simulation Lab
Basic Simulation Lab
Ex.No.
1. 2. 3. 4. 5. 6. 7. 8.
9. 10. 11.
Reconstruction of Periodic Signal by its Fourier Series Locating Zeros and Poles on S-Plane and Z-Plane Sampling Theorem
ADDITIONAL EXPERIMENTS
1. 2. Removal of noise by Auto correlation / Cross Correlation Impulse response of a raised cosine filter
Dept.of ECE
EXPERIMENT-1 BASIC OPERATIONS ON MATRICES AIM: To perform the different operations on Matrices. Requirements: PC with MATLAB R2008a THEORY: What Is MATLAB? MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building . MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar noninteractive language such as C or Fortran. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis. MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others. Basic Matrix Operations: This is a demonstration of some aspects of the MATLAB language. First, let's create a simple vector with 9 elements called a. a = [1 2 3 4 6 4 3 4 5] a= 1
Now let's add 2 to each element of our vector, a, and store the result in a new vector. Notice how MATLAB requires no special handling of vector or matrix math. b=a+2
Dept.of ECE
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES b= 3 4 5 6 8 6 5 6 7 Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a matrix. A = [1 2 0; 2 5 -1; 4 10 -1] A= 1 2 4
2 0 5 -1 10 -1
We can easily find the transpose of the matrix A. B = A' B= 1 2 4 2 5 10 0 -1 -1 Now let's multiply these two matrices together. Note again that MATLAB doesn't require you to deal with matrices as a collection of numbers. MATLAB knows when you are dealing with matrices and adjusts your calculations accordingly. C=A*B C= 5 12 24 12 30 59 24 59 117 Instead of doing a matrix multiply, we can multiply the corresponding elements of two matrices or vectors using the .* operator. C = A .* B C= 1 4 0 4 25 -10 0 -10 1 Let's find the inverse of a matrix ... X = inv(A) X= 5 2 -2 -2 -1 1 0 -2 1 ... and then illustrate the fact that a matrix times its inverse is the identity matrix. I = inv(A) * A I= 1 0 0 0 1 0 0 0 1
MATLAB has functions for nearly every type of common matrix calculation.
Dept.of ECE
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES There are functions to obtain eigenvalues ... eig(A) ans = 3.7321 0.2679 1.0000 ... as well as the singular value decomposition. svd(A) ans = 12.3171 0.5149 0.1577 The "poly" function generates a vector containing the coefficients of the characteristic polynomial. The characteristic polynomial of a matrix A is p = round(poly(A)) p= 1 -5 5 -1 We can easily find the roots of a polynomial using the roots function. These are actually the eigenvalues of the original matrix. roots(p) ans = 3.7321 1.0000 0.2679 MATLAB has many applications beyond just matrix computation. To convolve two vectors ... q = conv(p,p) q= 1 -10
35 -52
35 -10
15
-1
At any time, we can get a listing of the variables we have stored in memory using the who or whos command. whos Name Size Bytes Class A 3x3 72 double array B 3x3 72 double array C 3x3 72 double array
Dept.of ECE
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES I X a ans b opts p q r 3x3 3x3 1x9 3x1 1x9 1x1 1x4 1x7 1x10 72 double array 72 double array 72 double array 24 double array 72 double array 522 struct array 32 double array 56 double array 80 double array
Grand total is 162 elements using 1218 bytes You can get the value of a particular variable by typing its name. A A= 1 2 4
2 0 5 -1 10 -1
You can have more than one statement on a single line by separating each statement with commas or semicolons. If you don't assign a variable to store the result of an operation, the result is stored in a temporary variable called ans. sqrt(-1) ans = 0 + 1.0000i RESULT: Thus the different basic operations on Matrices and vectors were verified using MATLAB.
QUESTIONS: 1. 2. 3. 4. 5. What is MATLAB ? What are the applications of MATLAB? What are the advantages of MATLAB over other software? What are the different operators in MATLAB? What are the different windows in MATLAB?
Dept.of ECE
Dept.of ECE
%increasing ramp n=-10:2:10; X1=n; X2=0; X=X1.*(n>=0)+X2.*(n<0); subplot(4,3,7); stem(n,X); title('increasing ramp'); xlabel('n')'; ylabel('X(n)'); %decreasing ramp n=-10:2:10; X1=0; X2=-n; X=X1.*(n<=0)+X2.*(n>0); subplot(4,3,8); stem(n,X); title('decreasing ramp'); xlabel('n'); ylabel('X(n)'); %sawtooth wave form t=linspace(0,1,1001); saw2=sawtooth(2*pi*5*t); subplot(4,3,9); plot(t,saw2); title('sawsooth'); xlabel('t'); ylabel('X(t)'); %triangular signal n=-10:2:10; t=linspace(0,1,1001); saw2=sawtooth(2*pi*3*t,1/2); subplot(4,3,10); plot(t,saw2); title('triangular singal'); xlabel('t'); ylabel('x(t)'); %square signal n=-10:2:10; N=20; f=1/20; X=square(2*pi*f*n); subplot(4,3,11); stem(n,X); title('square wave form'); xlabel('n'); ylabel('X(n)'); %rectangular wave form n=-10:3:10; N=20; f=1/20; X=square(2*pi*f*n,75); subplot(4,3,12); stem(n,X); title('rectangular wave form'); xlabel('n'); ylabel('X(n)'); %sinc signal f=(1/20); %compute frequency x=sinc(2*pi*f*n); %generate sinc signal subplot(2,2,3); stem(n,x); %plot the generated sinc signal xlabel('n');ylabel('x(n)');
Dept.of ECE 7
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES title('sinc signal'); Expected Waveforms: Discrete Time Signals
unit impluse step signal time base 0 1 2 t sine function 0 n sawsooth 10
X(n)
1 0.5 0 -10
X(n)
1 0.5 0 -10
0 10 n decreasing exponential 2 1 0 -10 0 10 n decreasing ramp 0 -5 -10 -10 0 10 n square wave form 1 0 -1 -10 0 10 n
1 0.5 0
X(n)
X(n)
X(t)
1 0 -1 -10 1 0 -1
X(n)
X(n)
X(n)
1 0.5 0 -10
X(n)
0 10 n decreasing exponential 2 1 0 -10 0 10 n decreasing ramp 0 -5 -10 -10 0 10 n square wave form 1 0 -1 -10 0 10 n
X(t)
unit impluse
X(n)
x(t)
1 0.5 0 -10
step signal
1 0.5 0
X(n)
X(n)
1 0 -1 -10 1 0 -1
X(n)
X(n)
RESULT:
Thus the various signals in discrete and continuous form were generated by using MATLAB.
Dept.of ECE
X(n)
x(t)
QUESTIONS: 1.Define a signal? A.A signal is defined as a single valued function of one or more independent variables which contains some information. 2.Define unit ramp function? A.The continuous time unit ramp function r(t) is defined as r(t)=t for t>=0; 0 for t<0; r(t)=tu(t) The discrete time unit ramp sequence r(n) is defined as r(n)=n for n>=0; 0 for n<0; r(n)=nu(n) 3.How are signals classified? A.Signals are classified according to their characteristics.some of them are a)Continuous time and discrete signals b)Deterministic and random signals c)Periodic and aperiodic signals d)Energy and power signals e)Even and odd signals f)Causal and non causal signals 4.Define Guassian function? A.The guassian function is defined as by the expression ga(t)=e^(at^2) for infinity<t<infinity 5.Define unit step function? A.The continuous time unit step function u(t) is defined as: U(t)= 1 for t>=0; 0 for t<0 The discrete time unit step sequence u(n) is defined as: U(n)=1 for n>=0; 0 for n<0
Dept.of ECE
EXPERIMENT-3 OPERATIONS ON SIGNALS AND SEQUENCES AIM: To perform the different operations on signals and sequences such as addition, multiplication, scaling, shifting, folding, computation of energy and average power. Requirements: PC with MATLAB R2008a MATLAB Code: a) Operations on signals
%operations on signals N=128; f1=150; f2=450; fs=8000; n=0:N-1; %specify the range of n x1=sin(2*pi*(f1/fs)*n); x2=(1/3)*sin(2*pi*(f2/fs)*n); subplot(2,2,1); plot(n,x1); %plot the generated signal x1(n) grid; xlabel('t');ylabel('x(t)'); title('signal,x1(t)'); subplot(2,2,2); plot(n,x2); %plot the generated signal x2(n) grid; xlabel('t');ylabel('x(t)'); title('signal,x2(t)'); %signal delay x1d=[zeros(1,20),x1(1:N-20)]; subplot(2,2,3); plot(n,x1d); %plot the generated delayed signal grid; xlabel('t');ylabel('x(t)'); title('delayed x1(t),[x1(t-20)]'); %signal addition xadd=x1+x2; %generate signal addition subplot(2,2,4); plot(n,xadd); %plot the generated signal grid; xlabel('t');ylabel('x(t)'); title('x1(t)+x2(t)');
Dept.of ECE
10
x(t)
0 -0.5 -1
x(t)
0 50 100 150
0 -0.2 -0.4
50
100 t x1(t)+x2(t)
150
x(t)
0 -0.5 -1
x(t)
0 50 t 100 150
0 -0.5 -1
50 t
100
150
%signal multiplication N=128; f1=150; f3=1500; fs=8000; n=0:N-1; %specify the range of n x1=sin(2*pi*(f1/fs)*n); x3=sin(2*pi*(f3/fs)*n); subplot(2,2,1); plot(n,x1); %plot the generated signal x1(n) grid; xlabel('t');ylabel('x(t)'); title('signal,x1(t)'); subplot(2,2,2); plot(n,x3); %plot the generated signal x2(n) grid; xlabel('t');ylabel('x(t)'); title('signal,x3(t)'); xmult=x1.*x3; subplot(2,2,3); plot(n,xmult); %plot the generated signal grid; xlabel('t');ylabel('x(t)'); title('x1*x3');
Dept.of ECE
11
x(t)
0 -0.5 -1
x(t)
0 50 t x1*x3 100 150
0 -0.5 -1
50 t
100
150
1 0.5 0 -0.5 -1
50
100
150
%amplitude and frequency scaling N=128; f1=150; f2=450; fs=8000; n=0:N-1; x1=sin(2*pi*(f1/fs)*n); x4=5*sin(2*pi*(f1/fs)*n); %amplitude scaling subplot(2,2,1); plot(n,x1); grid; title('original signal'); subplot(2,2,2); plot(n,x2); grid; title('amplitude scaling of a signal'); %frequency scaling f2=450; x5=sin(2*pi*(f2/fs)*n); subplot(2,2,3); plot(n,x5); grid; xlabel('t');ylabel('x(t)'); title('frequency scaling');
Dept.of ECE
12
50
100
150
50
100
150
x(t)
0 -0.5 -1
50 t
100
150
%time folding t=0:0.1:10; x=0.5*t; lx=length(x); nx=0:lx-1; xf=fliplr(x); nf=-fliplr(x); subplot(1,2,1); stem(nx,x); xlabel('n(x)');ylabel('x'); title('original signal'); subplot(1,2,2); stem(nf,xf); xlabel('nf');ylabel('xf'); title('folding signal'); Expected Waveforms: Signal folding operation
Dept.of ECE
13
xf
OPERATIONS ON SEQUENCE %operations on sequence N=5; n=0:N-1; x1=[1,2,3,-2,7]; x2=[0,-1,4,3,-5]; subplot(2,2,1);stem(n,x1); grid; xlabel('n');ylabel('x(n)'); title('sequence,x1(n)'); subplot(2,2,2);stem(n,x2); grid; xlabel('n');ylabel('x(n)'); title('sequence,x2(n)'); %sequence addition xadd=x1+x2; subplot(2,2,3); stem(n,xadd); grid; xlabel('n');ylabel('x(n)'); title('x1(n)+x2(n)'); %sequence multiplication xmult=x1.*x2; subplot(2,2,4); stem(n,xmult);grid; xlabel('n');ylabel('x(n)'); title('x1(n)*x2(n)'); Expected Waveforms: Addition and Multiplication Oprations
Dept.of ECE
14
x(n)
x(n)
0 -5 0 1 2 3 n x1(n)+x2(n) 4
-5
2 n x1(n)*x2(n)
8 6
20
x(n)
4 2 0
x(n)
-20 0 1 2 n 3 4 -40 0
2 n
%operations on sequence N=5; n=0:N-1; x1=[1,2,3,-2,7]; x2=[0,-1,4,3,-5]; %sequence subtraction xsub=x1-x2; subplot(2,2,1); stem(n,xsub); grid; xlabel('n');ylabel('x(n)'); title('x1(n)-x2(n)'); subplot(2,2,2);stem(n,x1); grid; xlabel('n');ylabel('x(n)'); title('sequence,x1(n)'); %sequence delay x3=[zeros(1,2),x1(1:N-2)]; subplot(2,2,3); stem(n,x3); grid; xlabel('n');ylabel('x(n)'); title('delayed x1(n),[x1(n-3)]'); %amplitude scaling of sequence x4=5*x1; subplot(2,2,4); stem(n,x4); grid; xlabel('n');ylabel('x(n)'); title('amplitude scaling of sequence,x1(n)'); Expected Waveforms: Subtraction , delay and scaling operation
Dept.of ECE
15
x(n)
5 0 -5
x(n)
0 0 2 3 n delayed x1(n),[x1(n-3)] 1 4 2 3 4 n amplitude scaling of sequence,x1(n) 40 -5 0
20
x(n)
x(n)
0 0 0 1 2 n 3 4 -20 0
2 n
%time shifting x=input('type sample'); n1=input('type time origin first sample'); N=length(x); n2=n1+N-1; n=n1:n2; disp('the amount of shift'); disp('enter positive no. for delay,negative no. for advance'); pause; d=input('enter desired amount of shift'); nn=n+d; xs=x; subplot(2,1,1); stem(n,x); xlabel('time index n(sec)');ylabel('x(n)'); title('original signal'); subplot(2,1,2); stem(nn,x); xlabel('time index n(sec)');ylabel('x2(n)'); title('time shifted signal'); Results in command window: type sample [1 2 4 3 0] type time origin first sample 1 the amount of shift enter positive no. for delay, negative no. for advance enter desired amount of shift 2
Dept.of ECE
16
x(n)
2 1 0
1.5
4.5
4 3
x2(n)
2 1 0
3.5
6.5
%energy sequence n=0:1:5; x1=(0.5).^n; disp('calculated energy E is '); E=sum(abs(x).^2); figure subplot(1,2,1); stem(x1);axis([0 5 0 2]); xlabel('n');ylabel('x(n)'); title('x1=(0.5).^n sequence'); subplot(1,2,2); stem(E);axis([0 5 0 3]); xlabel('n');ylabel('x(n)'); title('energy sequence'); %power sequence n=0:1:5; x2=0.8.^n; disp('calculated power P is'); P=(sum(abs(x).^2))/length(x); figure subplot(1,2,1); stem(x2);axis([0 5 0 2]); xlabel('n');ylabel('x(n)'); title('x2=(0.8).^n sequence'); subplot(1,2,2); stem(P);axis([0 5 0 0.5]); xlabel('n');ylabel('x(n)'); title('power sequence');
Dept.of ECE
17
x(n)
x(n)
0 1 2 n 3 4 5
1.5
0.5
2 n
x2=(0.8). n sequence 2 1.8 1.6 1.4 1.2 0.5 0.45 0.4 0.35 0.3
power sequence
x(n)
x(n)
0 1 2 n 3 4 5
2 n
RESULT: Thus the different operations on signals and sequences were performed by using MATLAB. QUESTIONS: 1.What are the basic operations on signals? The basic set of operations on signals are: A)Time shifting b)Time reversal c)Time scaling d)Amplitude scaling e)Signal addition f)Signal multiplication 2.What is an analog signal? A.Continuous time signals are also called as analog signals. 3.What are digital signals? A.The signals that are discrete in time and quantized in amplitude are called digital signals. 4.Distinguish between energy and power signals? A.An energy signal is one whose total energy E=finite value and whose average power P=0. Power signal is the one whose average power P=finite value and total energy E =infinity. 5.Distinguish between deterministic and random signals? A.A deterministic signal is a signal exhibiting no uncertainity of its magnitude and phase at any given instant of time.It can be represented by a mathematical equation. A random signal is a signal characterized by uncertainity about its occurrence.It cannot be represented by a mathematical equation.
Dept.of ECE
18
EXPERIMENT-4 EVEN AND ODD PARTS OF SIGNALS AND SEQUENCES AIM: To find the even and odd parts of signals Requirements: PC with MATLAB R2008a MATLAB Code: %finding the even and odd part of the sequence x(n)=0.8^n n=-5:1:5; %specify the range of n A=0.8; x1=A.^n; %generate the given sequence x2=A.^(-n); %generate the folded sequence if(x2==x1) disp('the given sequence is even sequence'); elseif(x2==(-x1)) disp('the given sequence is odd sequence'); else disp('the given sequence is neither even nor odd signal'); end
Dept.of ECE
19
xe=(x1+x2)/2; %compute even part xo=(x1-x2)/2; %compute odd part subplot(2,2,1);stem(n,x1); %plot the generated sequence xlabel('n');ylabel('x1(n)'); title('sequence,x(n)'); subplot(2,2,2);stem(n,x2); %plot the generated folded sequence xlabel('n');ylabel('x2(n)'); title('sequence,x(-n)'); subplot(2,2,3);stem(n,xe); %plot the generated even part of sequence xlabel('n');ylabel('xe(n)'); title('even part of x(n)'); subplot(2,2,4);stem(n,xo); %plot the generated odd part of sequence xlabel('n');ylabel('xo(n)'); title('odd part of x(n)');
x1(n)
2 1 0 -5
x2(n)
0 n even part of x(n) 5
2 1 0 -5
2 1.5
2 1
xe(n)
1 0.5 0 -5
xo(n)
0 n 5
0 -1 -2 -5
0 n
Dept.of ECE
20
a=real(y); subplot(2,2,1);plot(t,a); xlabel('t');ylabel('x(t)'); title('real part of signal'); b=imag(y); subplot(2,2,2);plot(t,b); xlabel('t');ylabel('x(t)'); title('imaginary part of signal'); c=abs(y); subplot(2,2,3);plot(t,c); axis([-0.5 0.5 0 2]); xlabel('t');ylabel('x(t)'); title('absolute value'); d=angle(y); subplot(2,2,4);plot(t,d); xlabel('t');ylabel('x(t)'); title('phase angle');
Expected Waveforms: Real and Imaginary parts of signal and its magnitude & phase
Dept.of ECE
21
x(t)
0 -0.5 -1 -0.5
x(t)
0 t absolute value 0.5
0 -0.5 -1 -0.5
0 t phase angle
0.5
2 1.5
4 2
x(t)
1 0.5 0 -0.5
x(t)
0 t 0.5
0 -2 -4 -0.5
0 t
0.5
RESULT: Thus the even and odd parts of real signals and complex signals were calculated using MATLAB. QUESTIONS: 1.Distinguish between even and odd signals? A.A continuous time signal x(t) is said to be even (symmetric) signal,if it satisfies the condition X(-t)=x(t) for all t.If it is said to be odd (anti symmetric)signal if it satisfies the condition X(-t)=-x(t) for all t. A discrete time signal x(n) is said to bee even signal if it satisfies the condition X(-n)=x(n) for all n.If it is said to be odd signal if it satisfies the condition X(-n)=-x(n) for all n. 2.Can every signal be decomposed into even and odd parts? A.Yes,every signal can be decomposed into even and odd parts. 3.Write the expression for even and odd parts of signal? A.The even and odd parts of a continuous time signal are given by Xe(t)=1/2[x(t)+x(-t)] Xo(t)=1/2[x(t)-x(-t)] The even and odd parts of a discrete time signal are given by Xe(n)=1/2[x(n)+x(-n)] Xo(n)=1/2[x(n)-x(-n)] 4.Do all the signals correspond to either even or odd type? A.No ,All the signals need not necessarily belong to either even or odd type.There are signals which are neither even nor odd. 5.Distinguish between causal and non causal signals? A.A continuous time signal x(t) is said to be causal,if x(t)=o for t<0,otherwise the signal is non causal. A discrete time signal x(n) is said to be causal, if x(n)=0 for n<0,otherwise the signal is non causal
Dept.of ECE
22
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-5 CONVOLUTION BETWEEN SIGNALS AND SEQUENCES AIM: The convolution between signals and sequences Requirements: PC with MATLAB R2008a MATLAB Code: % convolution between two signals tmin=0; tmax=4; dt=0.01; t=tmin:dt:tmax; x1=1.*(t>=0&t<=2); xa=1; xb=-1; x2=xa.*(t>=0&t<=1)+xb.*(t>=1&t<=2); x3=conv(x1,x2); n3=length(x3); t1=0:1:n3-1; subplot(3,1,1); plot(t,x1); xlabel('t'); ylabel('x1(t)'); title('signal x1(t)'); subplot(3,1,2); plot(t,x2); xlabel('t'); ylabel('x2(t)'); title('signal x2(t)'); subplot(3,1,3); plot(t1,x3); xlabel('t/dt'); ylabel('x3(t)/dt'); title('signal,x3(t)=x1(t)*x2(t)'); Expected Waveforms:
signal x1(t) 1
x1(t)
x2(t)
100
x3(t)/dt
0 -100 0 100 200 300 400 t/dt 500 600 700 800
Dept.of ECE
23
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %CONVOLUTION between two sequences n= 0:1:4; n1=0:1:3; x1=[2 -4 3 -1 5]; x2=[-1 2 -3 6]; N1=length(x1); N2=length(x2); x3=conv(x1,x2) n2=0:1:N1+N2-2; subplot(3,1,1); stem(n,x1); xlabel('n'); ylabel('x1(n)'); title('sequence x1(n)'); subplot(3,1,2); stem(n1,x2); xlabel('n'); ylabel('x2(n)'); title('sequence x2(n)'); subplot(3,1,3); stem(n2,x3); xlabel('n'); ylabel('x3(n)'); title('sequence,x3(n)=x1(n)*x2(n)'); Result in Command Window: x3 = -2 8 -17 31 -40 31 -21 Expected Waveforms:
sequence x1(n) 5
30
x1(n)
10
x2(n)
50
x3(n)
0 -50 0 1 2 3 n 4 5 6 7
%CONVOLUTION of x(t)=1/(1+t^2) itself syms t tau; x=1/(1+t^2); z=int(subs(x,tau)*subs(x,t-tau),tau,-inf,inf); z1=simplify(z); pretty(z1); figure; subplot(211); ezplot(x); subplot(212); ezplot(z1);
Dept.of ECE
24
0.5
0 -5 -4 -3 -2 -1 0 t 1 2 3 4 5
-6
-4
-2
0 t
%CONVOLUTION of x(t)=exp(-t^2);h(t)=3*t^2; syms t tau; x=exp(-t^2); h=3*t^2; z=int(subs(x,tau)*subs(h,t-tau),tau,-inf,inf); z1=simplify(y) figure(); subplot(211);ezplot(x); subplot(212);ezplot(h); figure; ezplot(z); Expected Waveforms: Input Signal x(t) and h(t)
exp(-t 2) 1
0.5
50
0 -6 -4 -2 0 t 2 4 6
Dept.of ECE
25
200
150
100
50
0 -6 -4 -2 0 t 2 4 6
z1 =
3*t^2*pi^(1/2)+3/2*pi^(1/2)
RESULT: Thus the convolution between signals and sequences were verified using MATLAB. QUESTIONS: 1.What is meant by convolution? A.It is a mathematical way (multiplication and addition)if combininig two signals to form a third signal. 2.What is the associative property of convolution? A. x1(t)*[x2(t)*x3(t)] = [x1(t)*x2(t)*]x3(t) where x1(t),x2(t) and x3(t) are three real signals. 3.What is the convolution of a signal with an impulse? A.The convolution of a signal with an impulse is equal to that signal itself. 4.State time convolution theorem? A.The time convolution theorem states that the convolution in time domain is equivalent to multiplication of their spectra in frequency domain.mathematically,if x1(t)<->X1(w) andx2(t)<>X2(w) Then x1(t)*x2(t)<->X1(w) X2(w) 5.State frequency convolution theorem? A.It states that the multiplication of two functions in time domain is equal to convolution of their spectra in frequency domain.Mathematically, if x1(t)<->X1(w) and x2(t)<->X2(w) Then x1(t) x2(t)<->1/2pi[X1(w)*X2(w)]
Dept.of ECE
26
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-6 AUTOCORRELATION AND CROSSCORRELATION BETWEEN SIGNALS AND SEQUENCES AIM: To find autocorrelation and cross correlation between signals and sequences. Requirements: PC with MATLAB R2008a MATLAB Code: %CROSS CORRELATION: N=1024; F=1; Fs=200; n=0:N-1; x=sin(2*pi*F*n/Fs); y=x+10*randn(1,N); subplot(3,1,1); plot(x); title('pure sine wave');grid; subplot(3,1,2); plot(y); grid; title('y(n), pure sine wave + noise'); Rxy=xcorr(x,y); subplot(3,1,3); plot(Rxy); grid; title('cross correlation Rxy'); %AUTOCORRELATION: N=1024; f1=1; Fs=200; n=0:N-1; x=sin(2*pi*f1*n/Fs); t=[1:N]*(1*Fs); subplot(2,1,1); plot(t,x); grid; title('sin wave of frequency 1000 hz[Fs=8000 hz]'); xlabel('time,(s)'); ylabel('amplitude'); Rxy=xcorr(x); subplot(2,1,2); plot(Rxy); grid; title('auto crrelation function of the sine wave'); xlabel('lags'); ylabel('auto correlation');
Dept.of ECE
27
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES Expected Waveforms: %CROSS CORRELATION:
pure sine wave 1
x1
cosine
0 -1 0 200 400 600 800 time cross correlation Rxy 1000 1200
500
Rxy
%AUTO CORRELATION:
sin wave of frequency 1000 hz[Fs=8000 hz] 1
amplitude(x)
0.5 0 -0.5 -1
0.5
1 time,(s)
1.5
2.5 x 10
5
auto correlation(Rxx
500
-500 -1500
-1000
-500
0 time
500
1000
1500
RESULT: Thus the cross correlation and auto correlation of different signals and sequences were verified using MATLAB. QUESTIONS: 1.What is meant by correlation? A: Correlation is measure of the degree of the similarity between two signals. 2. What is auto correlation? A. Auto correlation is the measure of similarity of a signal with its delayed version. 3. What is meant by cross correlation? A. Correlation between the two different signals is called cross correlation. 4. What is the autocorrelation function at the origin? A. Auto correlation at the origin equals to its energy. 5. What is meant by Parsevals theorem? A. Total average power of a periodic signal x(t) is the sum of the squares of its fourier coefficients.
Dept.of ECE 28
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-7 VERIFICATION OF LINEARITY AND TIME INVARIENCE PROPERTIES AIM: To verify the linearity and time-invariance property Reconstruction of a periodic signal by Fourier series. Requirements: PC with MATLAB R2008a MATLAB Code: %LINEARITY: x1=input('type the samples of x1'); x2=input('type the samples of x2'); if(length(x1)~=length(x2)); disp('error:lengths of x1 & x2 are diffrent'); return; end; h=input('type the samples of h'); N=length(x1)+length(x2)-1; disp('length of the output signal will be'); disp(N); a1=input('the scale factor a1 is'); a2=input('the scale factor a2 is'); x=a1*x1+a2*x2 y01=conv(x,h) y1=conv(x1,h) ys1=a1*y1 y2=conv(x2,h) ys2=a2*y2 y02=ys1+ys2 disp('input signal x1 is'); disp(x1); disp('input signal x2 is'); disp(x2); disp('output sequence y01 is'); disp(y01); disp('output sequence y02 is'); disp(y02); if(y01==y02) disp('y01=y02,hence the LTI system is linear'); end;
Dept.of ECE
29
a)Verification of Lineariy: type the samples of x1[1 2 3 4] type the samples of x2[2 3 4 5] type the samples of h[1 2 3 4 5 6 7] length of the output signal will be 7 the scale factor a1 is3 the scale factor a2 is2 x =7 12 17 22 y01 = 7 26 62 120 178 236 294 296 251 154 y1 = 1 4 12 7 14 26 10 30 16 32 20 60 30 60 30 40 50 52 45 28 84 35 70
output sequence y01 is 7 26 62 120 178 236 294 296 251 154 output sequence y02 is 7 26 62 120 178 236 294 296 251 154 y01=y02,hence the LTI system is linear
Dept.of ECE
30
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %TIME INVARIENT: x=input('type the sample of signal x(n)'); h=input('type the samples of signal h(n)'); y=conv(x,h); disp('enter a positive number for delay'); d=input('desired delay of the signals is'); xd=[zeros(1,d),x]; nxd=0:length(xd)-1; yd=conv(xd,h); nyd=0:length(yd)-1; disp('original input signal x(n) is'); disp(x); disp('delayed input signal xd(n) is'); disp(xd); disp('original output signal y(n) is'); disp(y); disp('delayed output signal yd(n) is'); disp(yd); xp=[x,zeros(1,d)]; figure subplot(2,1,1); stem(nxd,xp);grid; xlabel('time index n'); ylabel('x(n)'); title('original input signal x(n)'); subplot(2,1,2); stem(nxd,xd); grid; xlabel('time index n'); ylabel('xd(n)'); title('delayed input signal xd(n)'); yp=[y,zeros(1,d)]; figure subplot(2,1,1); stem(nyd,yp); grid; xlabel('time index n'); ylabel('y(n)'); title('original output signal y(n)'); subplot(2,1,2); stem(nyd,yd); grid; xlabel('time index n'); ylabel('yd(n)'); title('delayed output signal yd(n)');
COMMAND WINDOW:
b)Verification of Time Invarience: type the sample of signal x(n)[1 2 3 4] type the samples of signal h(n)[2 3 4 5 ] enter a positive number for delay desired delay of the signals is 4 original input signal x(n) is 1 2 3 delayed input signal xd(n) is original output signal y(n) is delayed output signal yd(n) is 0 2 0 0 7 0 0 16 0
4 0 30 0 1 34 2 2 31 7 3 20 16 30 34 31 20 4
Dept.of ECE
31
x(n)
2 1 0
4 3
xd(n)
2 1 0
3 4 time index n
y(n)
20 10 0
10
40 30
yd(n)
20 10 0
5 6 time index n
10
RESULT: Thus the linearity and timeinvarient properties of an LTI system were verified using MATLAB. QUESTIONS: 1.What i s meant by linear system? A.A system is said to be linear if it satisfies the superposition principle. 2.What is meant by time-invariant system? A.A system is said to be time-invariant if the i/p-o/p relationship does not vary with time 3.What is meant by causal system? A.A system is said to be causal if the o/p depends only on the values of present i/p. 4.What is meant by stable system? A.A system is said to be stable if bounded i/p results in bounded o/p. 5.What is meant by order of a system? A.The order of a continuous system corresponds to highest derivative of o/p signal which may appear in i/p o/p differential equation.
Dept.of ECE
32
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-8 RESPONSE OF THE LTI SYSTEM AIM: To compute unit sample, unit step response of the LTI systems. Requirements: PC with MATLAB R2008a MATLAB Code: %IMPULSE RESPONSE OF LTI SYSTM: clear all syms z n H=1/(1-0.8*(z^(-1))+0.16*(z^(-2))); disp('impulse response h(n) is'); h=iztrans(H) simplify(h) N=15; b=[1 0 0]; a=[1 -0.8 0.16]; [H,n]=impz(b,a,N); stem(n,H); xlabel('n'); ylabel('h(n)'); title('Impulse response of a LTI system');
Expected Waveforms:
h(n)
6 n
10
12
14
Dept.of ECE
33
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %UNIT STEP RESPONSE OF LTI SYSTM: syms s complex H1=5/(s^2+25); disp('step response of first order system is:'); h1=ilaplace(H1) simplify(h1) H2=1/((s-0.8)^2); disp('step response of second order system'); h2=ilaplace(H2) simplify(h2) s=tf('s'); H1=1/(s+2); H2=1/(s^2+2.5*s+25); t1=0:0.005:5; s1=step(H1,t1); s2=step(H2,t1); subplot(2,1,1); plot(t1,s1); xlabel('time in seconds'); ylabel('s1(t)'); title('step response of first order system'); subplot(2,1,2); plot(t1,s2); xlabel('time in seconds'); ylabel('s2(t)'); title('step response of second order system');
Expected Waveforms:
step response of first order system 0.8 0.6
s1(t)
0.4 0.2 0
0.5
1.5
4.5
0.06
0.04
s2(t)
0.02 0
0.5
1.5
3.5
4.5
RESULT: Thus the step and impulse response of LTI system were verified using MATLAB.
Dept.of ECE
34
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES QUESTIONS: 1.What is meant by system? A:A set of elements or functional blocks which are connected together and produces an output in response to an input signal. 2.What is meant by continuous time system? A:A continuous time system is one in which continuous time i/p signals are transformed continuous time o/p signals. 3. What is meant by discrete time system? A: A discrete time system is one in which discrete time i/p signals are transformed discrete time o/p signals. 4.What is meant by step response of a discrete system? A:The step response of a discrete-time LTI system is the running sum of its impulse response. 5.What is meant by an impulse response ? A:The impulse response specifies the i/p-o/p behavior of an LTI system.
Dept.of ECE
35
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-9 RECONSTRUCTION OF PERIODIC SIGNAL BY FOURIER SERIES OR GIBBS PHENOMENON AIM: To Reconstruct a periodic signal by Fourier series. Requirements: PC with MATLAB R2008a MATLAB Code: %gibbs phenomenon N=input('type the total number of harmonics'); t=0:0.001:1; y=square(2*pi*t); plot(t,y,'r','linewidth',2); axis([0 1.5 -1.5 1.5]); hold; sq=zeros(size(t)); for n=1:2:N; sq=sq+((4/(pi*n))*sin(2*pi*n*t)); end; plot(t,sq); grid; xlabel('t'); ylabel('sq(t)'); title('synthesized square wave using Fourier Series'); legend('N=0','N=3'); COMMAND WINDOW: type the total number of harmonics 3 Expected Waveforms:
synthesized square wave using Fourier Series 1.5 N=0 N=3 1
0.5
sq(t)
-0.5
-1
-1.5
0.5 t
1.5
Dept.of ECE
36
Expected Waveforms:
synthesized square wave using Fourier Series 1.5 N=0 N=5 1
0.5
sq(t)
-0.5
-1
-1.5
0.5 t
1.5
Expected Waveforms:
synthesized square wave using Fourier Series 1.5 N=0 N=111 1
0.5
sq(t)
-0.5
-1
-1.5
0.5 t
1.5
RESULT: Thus the extraction of a periodic signal was performed successfully using MATLAB.
Dept.of ECE 37
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES QUESTIONS: 1.What do you mean by gibbs phenomenon? A.Gibbs discovered that for a periodic signal with discontinuities, if the signal is reconstructed by adding the fourier series ,overshoots appear around the edges.These overshoots decay outwards in a damped oscillatory manner away from the edges.This is called Gibbs Phenomenon. 2.What is fourier spectrum? A.The fourier spectrum of a periodic signal is x(t) is a plot of its Fourier coefficients versus frequency w.It is in two parts:a)The amplitude spectrum b)Phase spectrum 3.What is fourier series? A.The representation of signals over a certain interval of time in terms of the linear combination of orthogonal functions is called fourier series. 4.What are Dirichlets conditions? A.The conditions under which a periodic signal can be represented by a Fourier series are known as Dirichlets conditions.They are: a)The function x(t) must be a single valued function b)The function x(t) has only a finite number of maxima and minima c)The function x(t) has a finite number of discontinuities. d)The function x(t)is absolutely integrable over one period,that is integral(0,t)[l(x(t)ldt]<infinity. 5.What are the types of symmetry that may be present in a waveform? A.The types of symmetry that may be present in a waveform are: a)Even symmetry b)Odd symmetry c)Half wave symmetry d)Quarter wave symmetry
Dept.of ECE
38
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-10 FINDING FOURIER TRANSFORM AIM: To find the Fourier Transform of a various signals such as cosine, sine, impulse, step, square and rectangular signals Requirements: PC with MATLAB R2008a MATLAB Code: %cosine signal clc;clear all; f=100; fs=1000; Fs=1/fs; N=1024; n=[0:N-1]*Fs; x=0.8*cos(2*pi*f*n); figure; plot(n,x); grid; axis([0 0.05 -1 1]); title('cosine signal of frequency f'); xlabel('time t(sec)');ylabel('x(t)'); xk=fft(x,N); k=0:N-1; figure; xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2);plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase'); Expected Waveforms:
Dept.of ECE
39
x(t)
0.005
0.01
0.015
0.035
0.04
0.045
0.05
magnitude
200
400
1000
1200
2 1
phase
0 -1 -2
200
400
800
1000
1200
%sine signal clc;clear all; f=100; fs=1000; Fs=1/fs; N=1024; n=[0:N-1]*Fs; x=0.8*sin(2*pi*f*n); figure; plot(n,x); grid; axis([0 0.05 -1 1]); title('sine signal of frequency f'); xlabel('time t(sec)');ylabel('x(t)'); xk=fft(x,N); k=0:N-1; figure;
Dept.of ECE
40
xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2); plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase'); Expected Waveforms:
sine signal of frequency f 1 0.8 0.6 0.4 0.2
x(t)
0.005
0.01
0.015
0.035
0.04
0.045
0.05
magnitude
200
400
1000
1200
4 2
phase
0 -2 -4
200
400
800
1000
1200
Dept.of ECE
41
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %square signal clc;clear all; f=100; fs=900; Fs=1/fs; N=1024; n=[0:N-1]*Fs; x=0.5*square(2*pi*f*n); figure; plot(n,x); grid; axis([0 0.05 -1 1]); title('square signal of frequency f'); xlabel('time t(sec)');ylabel('x(t)'); xk=fft(x,N); k=0:N-1; figure; xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2); plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase');
square signal of frequency f 1 0.8 0.6 0.4 0.2
x(t)
0.005
0.01
0.015
0.035
0.04
0.045
0.05
magnitude
200
400
1000
1200
4 2
phase
0 -2 -4
200
400
800
1000
1200
Dept.of ECE
42
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %impulse signal n=-20:2:20; N=1024; x1=1; x2=0; x=x1.*(n==0)+x2.*(n~=0); figure; stem(n,x);grid; axis([-20 20 -1 1]); title('impulse signal'); xlabel('time n(sec)');ylabel('x(n)'); xk=fft(x,N); k=0:N-1; figure; xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2); plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase');
x(n)
-15
-10
-5
0 time n(sec)
10
15
20
magnitude
1 0
200
400
1000
1200
4 2
phase
0 -2 -4
200
400
800
1000
1200
Dept.of ECE
43
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %rectangular pulse n=-20:2:20; t=-10:1:10; f=1/20; x=square(2*pi*f*t,75); figure; stem(n,x);grid; axis([0 40 -1 1]); title('rectangular pulse'); xlabel('time n(sec)');ylabel('x(n)'); xk=fft(x,N); k=0:N-1; figure; xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2); plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase');
rectangular pulse 1 0.8 0.6 0.4 0.2
x(n)
10
15
20 time n(sec)
25
30
35
40
magnitude
10
200
400
1000
1200
4 2
phase
0 -2 -4
200
400
800
1000
1200
Dept.of ECE
44
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %step signal n=-20:2:20; N=1024; x1=1; x2=0; x=x1.*(n>=0)+x2.*(n<0); figure; stem(n,x);grid; axis([-10 10 0 1]); title('step signal'); xlabel('time n(sec)');ylabel('x(n)'); xk=fft(x,N); k=0:N-1; figure; xmag=abs(xk); subplot(2,1,1); plot(k,xmag); grid; title('magnitude of Fourier Transform'); xlabel('frequency index,k');ylabel('magnitude'); subplot(2,1,2); plot(k,angle(xk)); grid; title('phase of fourier transform'); xlabel('frequency index,k');ylabel('phase');
step signal 1 0.9 0.8 0.7 0.6
x(n)
-8
-6
-4
-2
0 2 time n(sec)
10
magnitude
10
200
400
1000
1200
4 2
phase
0 -2 -4
200
400
800
1000
1200
Dept.of ECE
45
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES % Fourier Transform Rectangular Pulse z = int(x*expw, omega,-2,2); z=simplify(z); figure(); subplot(211);ezplot('2',[-2,2]); subplot(212);ezplot(z); Expected Waveforms:
2 3 2.5 2 1.5 1 -2
-1.5
-1
-0.5
0 x 4/t sin(2 t)
0.5
1.5
8 6 4 2 0 -2 -6 -4 -2 0 t 2 4 6
RESULT: Thus the computation of Fourier transform of a given signal was done using MATLAB. QUESTIONS: 1.What is Fourier transform? A.Fourier transform is a transformation technique which transforms signals from the continuous time domain into frequency domain and vice versa. 2.Write the formulae for Fourier transform and inverse fourier transform? A.The formula for Fourier transform,also called the equation for direct transform or analysis equation is: X(w)=integral(-infinity,infinity)[x(t)e^(-jwt)dt] The formulae for I.F.T also called the equation for inverse transform or the synthesis equation is: x(t)=1/2pi[integral(-infinity,infinity)[X(W)e^(jwt)dw]] 3.What is frequency spectrum? A.The plot of lX(w)l versus w is known as magnitude spectrum or amplitude spectrum,and the plot of LX(w) versus w is known as phase spectrum.The amplitude spectrum and phase spectrum together is called the frequency spectrum. 4.What are the limitations of F.T? A.a)It is less powerful than Laplace transformation. b)There are many functions for which the laplace transform exists,but the fourier transform does not exist. 5.What is CTFT? A.CTFT(continuous time fourier transform) is the F.T applied to continuous time signals.In general CTFT is called as Fourier Transform.
Dept.of ECE
46
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-11 FINDING THE LAPLACE TRANSFORM OF GIVEN FUNCTIONS AIM: To write a MATLAB program to find the Laplace transform of a given
signal. F(t)=1.5-2.5te^-2t+1.25e^-3t
Requirements: PC with MATLAB R2008a MATLAB Code:
Expected Results:
Dept.of ECE
47
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES QUESTIONS: 1.How is laplace transform useful in the analysis of LTI system? A.The laplace transform is a powerful mathematical technique used to convert the differential equations in time domain into algebraic equations in s-domain. 2.What is the region of convergence(ROC)? A.The set of points in the s plane for which the laplace transform of x(t) ,i.e. the function X(s) converges is called the ROC. 3.What is the usual condition for x(t) to be laplace transformable? A.The usual condition for x(t) to be laplace transformable is that it should be piece-wise continuous and must be of exponential order. 4.What is the relation between F.T and L.T? a.Laplace transform is a complex fourier transform.The Fourier transform of a function can be obtained from its laplace transform by replacing s by jw,i.e. F.T is the L.T evaluated along the imaginary axis of the s plane. 5.What is transient response? A.The transient response is the response due to the poles of the system function H(s).It vanishes after some time and hence is called the transient response of the system.
Dept.of ECE
48
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-12 LOCATING POLES AND ZEROS IN S-PLANE AND Z-PLANE AIM: To write a MATLAB program to find the location of poles and zeros, and plotting the pole-zero maps in S-plane and Z-plane for given transfer function. Requirements: PC with MATLAB R2008a MATLAB Code:
%LOCATING POLES
syms s num_coeff=[1 5 6]; disp('roots of numerator polynomial are'); zeros=roots(num_coeff) den_coeff=[1 9 20]; disp('roots of denominator polynomial are'); poles=roots(den_coeff) H=tf('s'); a=tf([num_coeff],[den_coeff]); grid on; pzmap(a); if (max(real(poles)))>=1 disp('all poles DO NOT LIE in the left Half of S-plane'); disp('The given LTI system is NOT a stable system'); else disp('ALL the POLES lie in the Left half of S-plane'); disp('The given LTI system is a STABLE system'); end;
Dept.of ECE
49
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES Command Window: case(1):num_coeff = [1 5 6] den_coeff = [1 9 20] roots of numerator polynomial are zeros = -3.0000 -2.0000 roots of denominator polynomial are poles = -5.0000 -4.0000 ALL the POLES lie in the Left half of S-plane The given LTI system is a STABLE system
Imaginary Axis
0.2 5 0 -0.2 -0.4 0.997 -0.6 0.99 -0.8 0.974 -1 -5 -4.5 -4 -3.5 0.945 -3 -2.5 Real Axis 0.9 -2 0.82 -1.5 0.66 -1 0.4 -0.5 0 4 3 2 1
Dept.of ECE
50
Case(2): num_coeff = [1 5 6] den_coeff = [1 -9 20] roots of numerator polynomial are zeros = -3.0000 -2.0000 roots of denominator polynomial are poles = 5.0000 4.0000 all poles DO NOT LIE in the left Half of S-plane The given LTI system is NOT a stable system
Expected Waveforms:
0.93
0.86
0.6
0.982
0.2
0.966 -1 -4 -3
0.93 -2
0.86 -1
0.6 0 1 2 3 4 5
Real Axis
Dept.of ECE
51
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES %Z-PLANE: syms z num_coeff=[1 3 5]; disp('roots of numerator polynomial are'); zeros=roots(num_coeff) den_coeff=[1 1 0.16]; disp('roots of denominator polynomial are'); poles=roots(den_coeff) H=tf('z'); a=tf([num_coeff],[den_coeff]); radpoles=abs(poles); grid on; pzmap(a); if max(radpoles)<=1 disp('all the poles lie with in the unit circle'); disp('the given LTI system is a stable system'); else disp('all the poles donot lie with in the unit circle'); disp('the given LTI system is not a stable system'); end;
COMMAND WINDOW:
Case(1):num_coeff = [1 3 5] den_coeff = [1 -1 0.16] roots of numerator polynomial are zeros = -1.5000 + 1.6583i -1.5000 - 1.6583i roots of denominator polynomial are poles = 0.8000 0.2000 all the poles lie with in the unit circle the given LTI system is realizable and stable system Pole Zero map in Z-Plane:
Pole-Zero Map 2
1.5
0.5
Imaginary Axis
-0.5
-1
-1.5
-2 -2
-1.5
-1
0.5
Dept.of ECE
52
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES Case(2):num_coeff=[1 3 5]; den_coeff=[1 0.5 -1.25]; roots of numerator polynomial are zeros = -1.5000 + 1.6583i -1.5000 - 1.6583i roots of denominator polynomial are poles = -1.3956 0.8956 all the poles donot lie with in the unit circle the given LTI system is not a stable system >>
Pole-Zero Map 2
1.5
0.5
Imaginary Axis
-0.5
-1
-1.5
-2 -2
-1.5
-1
0.5
RESULT: Thus the poles and zeros in S-Plane and Z-Plane were located and plotted using MATLAB.
Dept.of ECE
53
QUESTIONS: 1.What are the advantages and limitations of Z-Transforms? A.Advantages of Z-Transform: 1.They convert the difference equations of a discrete time system into linear algebraic equations so that the analysis become easy and simple. 2.Convolution in time domain is converted into multiplication in Z-domain. 3.Z-transform exists for most of the signals for which DTFT does not exist. Limitation:Frequency domain response cannot be achieved and cannot be plotted 2.What is ROC of Z-Transform? A.The range of values of lzl for which X(z) converges is called ROC of X(z). 3.What is the ROC of an infinite duration causal sequences? A.The ROC of an infinite duration causal sequences is lzl>alpha,i.e. it is the exterior of a circle of radius alpha where z=alpha is the largest pole in X(z). 4.What is the ROC of an infinite duration non causal sequences? A.The ROC of an infinite duration non causal sequences is lzl<alpha i.e. it is the interior of a circle of radius alpha where z=alpha is the smallest pole in X(z). 5.State the linearity property of Z-Transform? A.The linearity property of Z-Transform states that the Z-transform opf a weighted sum of two signals is equal to the weighted sum of individual Z-transform I.e. If and then x1(n)<------->X1(z) x2(n)---->X2(z) ax1(n)+bx2(n)---->aX1(Z)+bX2(z)
Dept.of ECE
54
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-13 RANDOM NOISE SIGNAL GENERATION
AIM: To write a MATLAB program to generate the random noise signal. Requirements: PC with MATLAB R2008a MATLAB Code: clear all; x1=randn(1,5000); x2=randn(1,5000); figure;plot(x1,x2,'.') title('scatter plot of gaussian distributed random numbers'); x1=rand(1,5000); x2=rand(1,5000); figure;plot(x1,x2,'.') title('scatter plot of uniform distributed random numbers'); x3=rand(1,100000); figure;subplot(2,1,1);hist(x3) title('uniform distribution') y=randn(1,100000); subplot(2,1,2);hist(y) title('gaussian distribution') ymu=mean(y); ymsq=sum(y.^2)/length(y); ysigma=std(y); yvar=var(y); yskew=skewness(y); ykurt=kurtosis(y);
EXPECTED GRAPH :
4 3 2 1 0 -1 -2 -3 -4 -4 -3
-2
-1
Dept.of ECE
55
1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
uniform distribution
0.4
0.5
0.6
0.7
0.8
0.9
gaussian distribution
-1
RESULT: Thus the different characteristics of a random noise signal were verified using MATLAB. QUESTIONS: 1. What is meant by Mean of a signal? Ans: Mean is the average value of a signal and is a natural measure of center of distribution. It is obtained by adding all the values xi of a signal and div iding by N, the total number of values, as sum(xi)/N from i=0 to N-1 2. What is meant by Mean squqre of a signal? Ans:The summation of a squared sample values of the signal and its average. 3. What is meant by standard deviation of a signal? Ans:the standard deviation is a measure of how far the signal fluctuates from the mean. 4.What is meant by varience? Ans:The square of the standard deviation is called the varience of the signal.
Dept.of ECE
56
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-14 VERIFICATION OF SAMPLING THEOREM AIM: To write a MATLAB code for verification of Sampling theorem. Requirements: PC with MATLAB R2008a MATLAB Code: % MATLAB Code for Verification of Sampling Theorem t = -5 : 0.0001 : 5; F1 = 3; F2 = 23; x = cos(2*pi*F1*t) + cos (2*pi*F2*t); figure(1); plot(t,x); axis([-0.4 0.4 -2 2]) xlabel('Time t(sec)'); ylabel('x(t)'); title('Continuous Time Signal : x(t) = cos(2*pi*F1*t) + cos (2*pi*F2*t)'); %CASE 1 Fs1 = 1.4*F2; ts1 = 1/Fs1; %set the sampling freq to be 1.4 times Fmax=F2 n1 = -0.4 : ts1 : 0.4; xs1 = cos(2*pi*F1*n1) + cos (2*pi*F2*n1); figure(2); stem(n1,xs1); hold on; plot(t, x, 'r:'); axis([-0.4 0.4 -2 2]); hold off; xlabel('Time samples (n)'); ylabel('Amplitude'); title('Discrete Time Signal'); legend('Fs < 2Fmax'); %CASE 2 Fs2 = 2*F2; ts2 = 1/Fs2; %set the sampling freq to be 1.4 times Fmax=F2 n2 = -0.4 : ts2 : 0.4; xs2 = cos(2*pi*F1*n2) + cos (2*pi*F2*n2); figure(3); stem(n2,xs2); hold on; plot(t, x, 'r:'); axis([-0.4 0.4 -2 2]); hold off; xlabel('Time samples (n)'); ylabel('Amplitude'); title('Discrete Time Signal'); legend('Fs = 2Fmax'); %CASE 3 Fs3 = 7*F2; ts3 = 1/Fs3; %set the sampling freq to be 1.4 times Fmax=F2 n3 = -0.4 : ts3 : 0.4; xs3 = cos(2*pi*F1*n3) + cos (2*pi*F2*n3); figure(4); stem(n3,xs3); hold on; plot(t, x, 'r:'); axis([-0.4 0.4 -2 2]); hold off; xlabel('Time samples (n)'); ylabel('Amplitude'); title('Discrete Time Signal'); legend('Fs > 2Fmax');
Dept.of ECE
57
-0.3
-0.2
-0.1
0 Time t(sec)
0.1
0.2
0.3
0.4
-0.3
-0.2
0.2
0.3
0.4
Dept.of ECE
58
-0.3
-0.2
0.2
0.3
0.4
-0.3
-0.2
0.2
0.3
0.4
RESULT: Thus the Sampling theorem was verified successfully using MATLAB.
Dept.of ECE 59
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES QUESTIONS: 1.What is sampling? A.Sampling is the process of converting a continuous time signal into a discrete time signal. 2.What is sampling period? A.Sampling period or a sampling interval is the time interval between successive samples. 3.What is Nyquist rate? A.Nyquist rate is the theoretical minimum sampling rate at which a signal can be sampled and still be rteconstructed from its samples without any distortion. 4.What is aliasing? A.Aliasing is defined as the phenomenon in which a high frequency component in the frequency spectrum of signal takes identity of a lower frequency component in the spectrum of the sample signal. 5.State sampling theorem? A.The sampling theorem also called uniform sampling theorem or low pass sampling theorem states thatA band limited x(t) with X(w)=0 for lwl>=wm can be represented into and uniquely determined from its samples x(nT), if the sampling frequency fs>=2fm,where fm is the highest frequency component present in it.
Dept.of ECE
60
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-15 NOISE REMOVAL USING CORRELATION AIM: To Write a MATLAB Code for Noise Removal using cross correlation or auto correlation. Requirements: PC with MATLAB R2008a MATLAB Code: clear all; N=100; n=0:N-1; dsnr=input('type desired SNR in dB'); x=sqrt(2)*sin((pi/5)*n); figure(1);stem(n,x);grid %axis([0 50 -1.5 1.5]) xlabel('n');ylabel('x(n)');title('sinusoidal signal x(n)') px=var(x) ; an=sqrt(px*(10^(-1*dsnr/10))); w=sqrt(12)*(rand(1,N)-0.5); w=w*an; pn=var(w); disp('The calculated SNR'); SNRdB=10*log10(px/pn); figure(3);stem(n,w);grid axis([0 50 min(w) max(w)]) xlabel('n');ylabel('w(n)'); title('Random Noise Signal w(n)'); y=x+w; figure(6); subplot(2,1,1); Stem(n,y);grid axis([0 50 min(y) max(y)]) xlabel('n');ylabel('y(n)=x(n)+w(n)'); title('Sinusoidal Signal Corrupted With Random NOise') [ryy,lag]=xcorr(y,y,'unbiased'); subplot(2,1,2);stem(lag,ryy);grid axis([0 50 -1.5 1.5]) xlabel('lag index 1');ylabel('R_y_y(1)'); title('Auto Correlation R_y_y(1)') [rxx,lag]=xcorr(x,x); figure(2);stem(lag,rxx);grid axis([-20 20 min(rxx) max(rxx)]) xlabel('lag index 1');ylabel(R_x_x(1)'); title('Auto Correlation R_x_x(1)') [rxw,lag]=xcorr(x,w); figure(5);stem(lag,rxw);grid axis([-20 20 min(rxw) max(rxw)]) xlabel('lag index 1');ylabel(R_x_w(1)'); title('Cross Correlation Between x(n) and w(n)') [rww,lag]=xcorr(w,w); figure(4);stem(lag,rww);grid axis([-20 20 min(rww) max(rww)]) xlabel('lag index 1');ylabel(R_w_w(1)'); title('Auto Correlation R_w_w(1)')
Dept.of ECE 61
100 80 60 40 20 0 -20 -40 -60 -80 -20 -15 -10 -5 0 lag index 1 5 10 15 20
w(n)
Dept.of ECE
62
10
15
20
40
45
50
1
R (1)
yy
0 -1 0 5 10 15 20 25 30 lag index 1 35 40 45 50
RESULT: Thus the removal of noise by correlation was erformed using MATLAB. QUESTIONS: 1. What are the applications in which the removal of noise is required( correlation)? Ans: Detection of RADAR and SONAR signals , ocean wave analysis and Geo Physics. 2. What is the procedure to remove noise signal? Ans: A signal is masked by noise can be detected either by correlation technique or by filtering. 3.What is the signal to noise ratio? A.Signal to noise ratio is measure of signal power to noise power. SNR=10 log10(Ps/Pn) 4.What is the auto correlation of a periodic signal? N-1 A:Rxx(l)=1/N x(n)x(n-l) n=0 5. What is the cross correlation of a periodic signal? N-1 A:Rxy(l)=1/N x(n)y(n-l) n=0
Dept.of ECE
63
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-16 IMPULSE RESPONSE OF RAISED COSINE FILTER
AIM: To write a MATLAB program to plot the impulse response of raised cosine filter. Requirements: PC with MATLAB R2008a MATLAB Code: clc; clear all; t=linspace(-30,30,1000); b=0.2; T=1; h1=(sin(pi*t/T))./(pi*t/T); h2=(cos(pi*b*t/T))./(1-(2*b*t/T).^2); h=h1.*h2; figure(1); plot(t,h);
RESULT: Thus the periodic signal extraction BY correlation was performed successfully using MATLAB.
Dept.of ECE
64
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES QUESTIONS: 1. What is meant by raised cosine filter? Ans: A raised cosine filter is a low pass filter which is commonly used in digital communication systems, such as digital data modems, especially for pulse shaping and to avoid inter symbol interference(ISI). 2. What is meant by ISI? Ans: The ISI is a form of distortion of a signal in which one digital symbol interferes which subsequent symbols. 3. What are the three different frequency bands of a filter? Ans: Pass band, Transition band, Stop band. 4. What is meant by transition band? Ans: The region between fp(pass band edge frequency) and fs(stop band edge frequency). 5. What is the Ideal value of transition band? Ans: Zero
Dept.of ECE
65
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-17 WINER KHINTCHINE RELATIONS AIM: To verify Winer Khintchine Relations Requirements: PC with MATLAB R2008a MATLAB Code: clc; clear all; close all; fs=100; t=0:1/fs:10; x=sin(2*pi*15*t); N=512; X=fft(x,N); f=fs*(0:N-1)/N; power=X.*conj(X)/N; figure(1) plot(f,power); title('power spectrum through fourier transform'); xlabel('frequency'); ylabel('power'); figure(2) rxx=xcorr(x,x); sxx=fft(rxx,512); plot(f,abs(sxx)); title('fourier transform of autocorrelation function'); xlabel('frequency'); ylabel('abs(sxx)'); Expected Waveforms:
power spectrum through fourier transform 120
100
80
power
60
40
20
10
20
30
40
50 60 frequency
70
80
90
100
Dept.of ECE
66
3.5
x 10
2.5
abs(sxx)
1.5
0.5
10
20
30
40
50 60 frequency
70
80
90
100
RESULTS: Thus power spectrum, auto correlation of a signal using fourier transform were plotted. QUESTIONS: 1. What is the use of winer-khintchine theorem?
Ans: The important properties of a signal like correlation and spectral density can be analysied using wiener-khitchine theorem. 2. What is meant by wiener-khitchine theorem? Ans:It states that the Energy spectral density of an energy signal is the fourier transform of its auto correlation. 3. Which of the two parameters contains the same information about a signal? Ans: Auto correlations and Energy spectral density.
Dept.of ECE
67
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-1 GENERATION OF COEFFICIENTS FOR ANALOG LOWPASS FILTER %%generation of coefficients for analog lowpass filter%% r=1000; c=0.000001; w1=1/(r*c); h1=[]; w2=[]; theta1=[]; for w=10:10:10000 h=(1/sqrt(1+(w/w1)^2)); theta= -atan(w/w1); theta1=[theta1,theta]; deg=rad2deg(theta1); h1=[h1,h]; w2=[w2,w]; end subplot(2,1,1); semilogx(w2,h1,'k-'); grid on; xlabel('angular frequency'); ylabel('gain'); title('Magnitude plot for lowpass filter') subplot(2,1,2); plot(w2,theta1,'k-'); grid on; xlabel('frequency'); ylabel('phase angle'); title('Phase plot for lowpass filter')
gain
0.5
0 1 10
10
10
10
phase angle
-0.5 -1
-1.5
1000
2000
3000
4000
7000
8000
9000 10000
RESULTS: Thus the spectrum were plotted for low pass filter.
Dept.of ECE
68
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES EXPERIMENT-2 GENERATION OF COEFFICIENTS FOR ANALOG HIGHPASS FILTER AIM: To Write a MATLAB Code for generation of analog lowpass filter. Requirements: PC with MATLAB R2008a MATLAB Code: %%generation of coefficients for analog highpass filter%% r=10000; c=0.000001; w1=1/(r*c); h1=[]; w2=[]; theta1=[]; for w=10:10:10000 h=(1/sqrt(1+(w1/w)^2)); theta= atan(w1/w); theta1=[theta1,theta]; deg=rad2deg(theta1); h1=[h1,h]; w2=[w2,w]; end subplot(2,1,1); semilogx(w2,h1,'k-'); grid on; xlabel('angular frequency'); ylabel('gain'); title('Magnitude for highpass filter') subplot(2,1,2); plot(w2,theta1,'k-'); grid on; xlabel('frequency'); ylabel('phase angle'); title('Phase plot for highpass filter')
gain
0.5
0 1 10
10
10
10
phase angle
1 0.5
1000
2000
3000
4000
7000
8000
9000 10000
RESULTS: Thus the spectrum was plotted for high pass filter.
Dept.of ECE
69