P. 1
Matlab Manual

Matlab Manual

|Views: 3,720|Likes:
Published by Sri Harsha

More info:

Published by: Sri Harsha on May 27, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/28/2013

pdf

text

original

EC 45

IV Semester

Rajesh N

Dept of Electronics and Communication Engg Nitte Meenakshi Institute of Technology
Yelahanka, Bangalore – 560 064

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

Syllabus Part - A ( 8 Lab Sessions of 3Hrs Each)
(Perform the experiments using MatLab) 1. Vector and matrix operations, solving non linear equations. 2. a) Representation of basic signals, Basic operations on continuous/discrete time signals: Add/sub of two signals, scaling, shifting, time reversal , signal energy / power calculation b) Verification of Shannon sampling theorem. 3. Convolution and Correlation of continuous/ discrete time signals. 4. Fourier analysis of signals: Computing CTFS/CTFT and DTFS/DTFT, properties of DTFT 5. The z and Inverse z-Transform: Properties of z-Ttransform. Determination of system function and the unit sample response of a linear time invariant systems described by difference equation. 6. Laplace Transform analysis of linear systems. 7. PID design. 8. Frequency response analysis: Bode Plots , Nyquist Plot. Root Locus 9. Simulink model of first /second order systems.

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

2

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

EXPERIMENT No.1

Vector and matrix operations, solving non linear equations.
Aim: Study Vector and matrix operations and solving non linear equations. Refer Appendix for vector and matrix operations. Example:1. Solve the given quadratic equation x2 + 5x +6 = 0 roots = -3 and -2 program: Result: ans = -3.0000 -2.0000 Example:2. Solving given difference equation Theory: • A difference equation with constant coefficients describes a LTI system. For example the difference equation y[n] + 0.8y[n-2] + 0.6y[n-3] = x[n] + 0.7x[n-1] + 0.5x[n-2] describes a LTI system of order 3. The coefficients 0.8, 0.7, etc are all constant i.e., they are not functions of time (n). The difference equation y[n]+0.3ny[n-1]=x[n] describes a time varying system as the coefficient 0.3n is not constant. • • The difference equation can be solved to obtain y[n], the output for a given input x[n] by rearranging as y[n] = x[n] + 0.7x[n-1]+0.5x[n-2]- 0.8y[n-2]- 0.6y[n-3] and solving. The output depends on the input x[n] o With x[n]= δ[n], an impulse, the computed output y[n] is the impulse response. o If x[n]=u[n], a step response is obtained. o If x[n] = cos(wn) is a sinusoidal sequence, a steady state response is obtained (wherein y[n] is of the same frequency as x[n], with only an amplitude gain and phase shift-refer Fig.7.3). o Similarly for any arbitrary sequence of x[n], the corresponding output response y[n] is computed. b=[1 5 6]; roots(b)

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

3

Input the two sequences as a and b representing the coefficients of y and x. y is the output sequence which is of same length as x. the response y[n] can be calculated. The MATLAB function filter is used to compute the impulse response/ step response/ response to any given x[n].. 2.} the number of ones = the length of the IIR response ↑ required-1 (say 100 implemented by function ones(1.} the number of zeros = the length of the IIR response ↑ required (say 100 implemented by function zeros(1. whereas the output sequence from conv function is of a longer length (xlength + hlength-1)... which is not possible with conv function (remember conv requires both the sequences to be finite).a. Note the zero in b (x[n-1] term is missing). y=filter(b. Algorithm: 1.99)). then input the length of the response required (say 100.a).e. y[n-1].0. which can be made constant). represents a system whose impulse response is of finite duration (FIR). 3. If IIR response. Also remember a0. Given a difference equation a0y[n]+a1y[n-1]+a2y[n-2]=b0x[n]+b2x[n-2]. etc leads to a recursive system.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG • The difference equation containing past samples of output.x) where x is the input sequence... Note: The filter function evaluates the convolution of an infinite sequence (IIR) and x[n].. The filter function results in a response whose length is equal to that of the input x[n]. • The difference equation having only y[n] and present and past samples of input (x[n]. 4 . For impulse response x[n] = {1. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. The response of FIR systems can be obtained by both the ‘conv’ and ‘filter’ functions.1.0. x[n-k]). given the input and difference equation coefficients (b.1. i. y[n-2]. For such systems the impulse response is computed for a large value of n. Plot the input sequence & impulse response (and also step response. MATLAB Implementation: MATLAB has an inbuilt function ‘filter’ to solve difference equations numerically.1. the coefficients are written in a vector as b=[b0 0 b2] and a=[a0 a1 a2].1. For step response x[ n] = {1.. Compute the output response using the ‘filter’ command.. etc if required). whose impulse response is of infinite duration (IIR).. Similarly for any given x[n] sequence.100). the coefficient of y[n] should always be 1.0. 4. say n=100 (to approximate n=∞). BANGALORE.

1. 1. 1.50)]. inp=1. stem(n.1111. 1.a. 1.^n. %y(n)-0. %x(n) is an impulse function IMP=[1. 1. 1. 1.1111 . X=2.1111 1.1111. 1.1111.1111. grid on. stem(n.1111.1y(n-1)=x(n) %x(n)=u(n) %initial condition y(-1)=2 b=input('Enter the numerator co-effiecients') a=input('Enter the denominator co-effiecients') N=input('Enter the length of the input sequence') n=0:1:N-1.1111.1111.zeros(1.1111.1111.a.1000 Enter the denominator co-effiecients[1 -0.1111.0000 -0.1112.1111.1111. xlabel('n').1111. 1. 1. 1.1111. figure(1). 1. 1. 1.a. 1. 1. 1. 1. 1. 1. 1.2000.1111.1111. 1. 1. title('impulse response output of difference equation').1111.RES1).1111.1111. RESULTS: Enter the numerator co-effiecients[1] b= a= 1 1. 1.1111. title('step response output of difference equation').1111. close all . 1. 1. 1.1111.1111.1111.1111. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 1.1111.1111. 1. XIC=filtic(b.RES2).1111. xlabel('n'). figure(2). 1.1111.1111. RES2=filter(b.XIC). n=0:1:length(RES2)-1.inp.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG MATLAB Program: clear all.1200.1111. RES1=filter(b.1111.1111. ylabel('amplitude'). 1. 1. 5 . 1.IMP. BANGALORE.1111. 1. 1.1111. ylabel('amplitude'). 1.1111.1] Enter the length of the input sequence50 N = 50 RES1= 1. 1.1111. 1. 1. 1.X).1111.1111. 1. 1. 1.1120. 1.1111. grid on.1111. 1.1111.XIC). 1.1111. 1.1111.

0001. 0.0000. 0.0000. 0.0000. 0. BANGALORE. 0.0000 0.0000.0012.0000. 0.0000. 0.2000. 0. 0.1200.0000.0000.0000. 0. 0.0120.0000.9y(n-2) = x(n). 0. 0.0000.0000 0. 0. 0. 0.0000.0000. 0.0000 Questions: 1)Difference equation y(n) .0000.0000.0000.0000. 0.0000.0000. 0.0000.…..0000. 0. 0.0000.8y[n-1]=x[n] NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 0. 0. Calculate impulse response h(n) and also step response at n=0. 0. given y[n]-0. 0. 0. 0. 0.0000.0000. 0.0000.0000.0000. 0.. 0.0000. 0. 0.0000. 0.0000.0000.100 2)Plot the steady state response y[n] to x[n]=cos(0. 0.0000. 0. 0.05πn)u(n).0000.0000 0.0000.0000. 0. 0. 0.0000 0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG RES2= 1.0000 0. 0.0000. 0.0000.0000. 0.y(n-1) + 0. 0. 6 . 0.0000.0000.

Implement all the exercises given in chapter-2: “S&S”.a. BANGALORE. %difference equation coefficient arrays Y=[-2 -3].3596 5.Y.J.7176 -3.xic). where xic are the initial conditions computed as xic=filtic(b.0281 Exercises: 1.95 0. %For 8 output samples using filter function.a.9025]. we need not specify the impulse input x[n]. Using impz. where 3 ⎛ πn ⎞ x[n] = cos⎜ ⎟u[ n] and the initial conditions are y[-1]=-2. n=0:7.Roberts. y[-2]=-3. x[-2]=1.xic).Y.a.a.4014 1.X). n≥0. 7 .x.8398 -1. M. %output response Answer: y = 1. Example: Find the first 8 samples of the complete response y[n] for the difference equation 1 [x[n] + x[n − 1] + x[n − 2]] + 0. just the coefficients and length N that we desire (refer experiment 2). the input should also be of size 8 x=cos(pi*n/3).x. then X need not be specified. X=[1 1]. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.5664 -4.9025 y[n − 2]. If x[n]=0 for n<0.t]=impz(b.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG *note. where Y=[y(-1) y(-2)…y(N-1)] & X=[x(-1) x(-2)…x(-M)] are the initial condition arrays.3555 2. The sample program for the above problem is: b=[1/3 1/3 1/3].Use [h.X).95 y[n − 1] − 0. %initial condition arrays xic=filtic(b.a.N) to find the impulse response and find the difference between y~=h’ (=0). %input sequence y=filter(b. a=[1 -0.8075 4. x[-1]=1. ⎝ 3 ⎠ y[n] = Solution: Use MATLAB function filter(b.

½ for input argument values equal to zero.NaN for noninteger arguments . y=num.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG EXPERIMENT No. % rectangle function . function y=ramp(t) y=t. BANGALORE./den .5) . 8 . function y=tri(t) y=ramp(t+1) -2*ramp(t) + ramp(t-1) . % Works for vectors and scalars equally well.uses the definition % of the triangle functionin terms of the ramp function. function y=sinc(t) zero=(t==0) . % Function to generate the discrete-time impulse function defined as one % for input integer arguments equal to zero and zero otherwise .pos =(t>0) .this function % may be intrinsic in some versions of MATLAB. % function to compute the triangle function. function y=u(t) zero=(t==0) . % works for vectors or scalars equally well. uses the definition of the rectangle % function in terms of the unit step function. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.*(pi*t) +zero . % Returns.y=zero/2 + pos .u(t-0.works on % vectors or scalars equally well. % Function to compute the ramp function defined as zero for % Values of the argument less than zero and the value of % The argument for arguments greater than or equal to zero.Works for vectors and % Scalars equally well .*(t >=0) . %And one for input argument values greater than zero. % indicate the locations of zeros in t. function y=rect(t) y=u(t+0.*sin(pi*t) + zero . % function to compute sinc(t) defined as sin(pi*t)/(pi*t) . num=(~zero).2 Representation of basic signals Program to represent some basic signals: %Unit step function defined as 0 for input argument values %Less than zero.works % for vectors and scalars equally well.5) . den = (~zero).

/ ((~(t==0)). t=-10:0.(t>=0)). title('Ramp') subplot(324).*(pi*t) +(t==0))). BANGALORE. title('Exponential') subplot(323). grid on case{6} % Sinc plot(t. % program to demonstrate some basic CT signals %-------------------------------------------------------------------------------clc. plot(t. grid on otherwise subplot(321). grid on. grid on case{5} % Rectangle plot(t./ ((~(t==0)).*sin(pi*t) + (t==0)).*(t >=0))). ss=find(round(n)~=n) y(ss)==NaN .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG function y=impDT(n) y=(n==0) .sin(t)).*(pi*t) +(t==0))).exp(t)).N) x=diric(2*pi*t. grid on . grid on. % function to compute values of the dirichlet function. plot(t. % x= sin(N*pi*t)/(N*sin(pi*t)) function x =drcl(t.(t.(t.*(t >=0))). grid on case{3} % Ramp plot(t.end of program ---------------------------------------- NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.((~(t==0)). plot(t. title('Rectangle') subplot(326).*sin(pi*t) + (t==0)). switch(Choice) case{1} % Sine plot(t. title('Sine Wave') subplot(322).N) . grid on .1:10. plot(t. 9 . plot(t. grid on .exp(t)). title('Step') subplot(325). % Works for vectors or scalars equally well. plot(t. disp('Select the finction') %----Next part of the program accepts choice of function -------------------disp('1-Sine 2-Exponential 3-Ramp 4-Step 5-Rectangle 6-Sinc '). grid on case{2} % Exponential plot(t. Find noninteger values of n. grid on case{4} % Step plot(t. grid on.(t>=0)). Choice = input('Enter choice of function = ').(t>=-1&t<=1)).. % % % % impulse is one where argument is zero and zero otherwise.(t>=-1&t<=1)). Set corresponding outputs to NaN.((~(t==0)).sin(t)).title('Sinc') end %-----------------------.

x1 =exp(-t).pi. x2 =sinc(t). xlabel('\itt').2) . xlabel('\itt'). t=-4:1/60:4. set(p. 10 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Continuous time Signals Discrete time Signals --------------------------------------------------------------------------------------------------------------% program to plot some demonstrations of CT function combination. % x1(t) = exp(-t).2) .x1.1.x2.'k'). p=plot(t.2).pi. ylabel('x_2({\itt})') . BANGALORE.pi. ylabel('x_1({\itt})') .t)+exp(-t/2)sin(19.t).'LineWidth'. set(p.'LineWidth'.1.sin(20. p=plot(t.*sin(19*pi*t) .t) % x2(t) = sinc(t)cos(20.*sin(20*pi*t) + exp(-t/2). subplot(2.'k'). subplot(2. t=0:1/120:6.1). NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.*cos(20*pi*t).

% compute the first transformation .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG g.*(-2<t & t<=0) +y2.title('Third Transformation').g0.'LineWidth'.gmin.gmin.g(3*t)/2 .'k').y3=16 -2*t .gmax] ) .'linewidth'.max(g3)]) . gmax=max([max(g0) . g0=g(t) .gmax] ).grid .max(g2) . % Find the maximum and minimum g values in all the transformed % Functions and use them to scale all plots the same .ylabel('g(3t)/2').'k') .*(4<t & t<=8) .tmax. % set the time between points % set the vector of times for the plot.2. p=plot(t. g2=g(3*t) /2 .2). subplot(2.title('Second Transformation'). ylabel('-2g((t-1)/2)').2). tmin =-4 .*(0<t & t<=4) +y3 .3). subplot(2. g3=-2*g((t-1)/2) .g1. % plot grid lines. using the grid command . axis([tmin.grid.2) . axis([tmin. % compute the original g(t).gmax] ).min(g3)]) . set (p. xlabel('t'). g(t)'). gmin=min([min(g0) .2). t=tmin:dt:tmax. set(p.gmin. %splice together the different functional variations in their respective ranges of validity.'k').2.gmin.ylabel('g(t)'). subplot(2.tmax. ylabel('3g(t+1)'). set(p. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.grid. % set the time range for the plot . Script file: % program to plot the function .min(g2) . % plot them all on the same scale using the axis command .'k').'LineWidth'. % plot all four functions in a 2 by 2 arrangement .2. xlabel('t'). dt=0. tmax =20. % Write a function for g(t) and store.p=plot(t.tmax. axis([tmin. y1=-4 -2*t . xlabel('t'). 11 .g3. p=plot(t.grid.g2.gmax]).to aid in reading values.4).max(g1) .min(g1) . % compute the second transformation .tmax.g(t) and then to % plot 3*g(t+1) .2. BANGALORE.and -2*g(t-1)/2 . p=plot(t.1).2). title ('First Transformation'). % compute the third transformation .1 . axis([tmin. title('Original Function. xlabel('t'). Subplot (2.y2= -4 +3*t .m function y=g(t) %calculate the functional variation for each range of t. set(p. g1=3*g(t+1) .'LineWidth'. y=y1.

p=plot(t. BANGALORE.1. xlabel( '\ itt') .1/20. axis([-20.x24.x7. p=plot(t.Even*odd') .1. -1.5) . title ( 'diric -The MATLAB "Dirichlet" function') . t= -20:1/20:20 . NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.ylabel( 'x_7({\itt})' ).2. 'k') .1) . 1.subplot(4.-1. axis([ -20 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG --------------------------------------------------------------------------------------------------------------------------% program to illustrate some of MATLAB s built-in functions % close all .5 . subplot(2.2.5] ) .5] ) . subplot(4.2) .6) .5 .title( 'square . xlabel ( '\itt') . x5=rectpuls(t/10) .1. subplot(4.x6.20.8) . p=plot(t. axis([ -20 .20 . figure.x1. 'k') .x4. subplot(4. subplot (4. p =plot(t. x3=sawtooth(t) . 'k') . axis([ -20 .1. -1.x8.x2. x4=square(t) .1. ylabel( 'x_8({\itt })') . xlabel( '\itt') .20.5 . xlabel( ' \ itt') .-1. title( 'sinc(t)') . subplot(4.2.4) .The Signum Function') . title( 'tripuls -A Triangular Pulse Wave') . axis([-20. 12 .2. 'k') .2. p=plot(t. 'k') .7) .2. 'k') .20 . subplot(4. ylabel( 'x_1({\itt })') .3) .x3.5.5]) .A Square Wave') . title( 'sign . 'k' ) . ylabel( 'x_2({\itt})') .20 .20 .5. axis([ -20 . axis([-20.5 .1) .1. subplot (4. xlabel ( '\itt') .20 -1. ylabel( 'x_4({\itt })') .20.A Rectangular Pulse Wave') . x8=sign(t/2) . xlabel( '\itt') . title( 'chirp . xlabel( '\itt') .2.-1.*x4 . ylabel( 'x_3({\itt})') .ylabel( 'x_6({\itt})') . -1.5] ) . title( 'rectpuls . plot(t.20. xlabel ( '\itt') . axis([-20.A "chirped" cosine') . 'k') . 'k') . x2=diric(t. title( 'sawtooth -A Periodic Sawtooth') .-1. title( 'x_2*x_4 .2.p=plot(t. axis([ -20 .5] ) . 1.x5.5] ) . x7=sinc(t/2) .5] ) . x24=x2.5] ) .5) . ylabel( 'x_2_4({ \itt})') .2.5 . ylabel ( 'x_5 ({\itt})' ).5. x6=tripuls(t/10) .1.5 . x1=chirp(t. p=plot(t. p=plot(t. xlabel( '\itt') .20 -1.5] ) .1/3) .

'k') .2. xlabel( '\itt') .1. subplot(2. subplot(2.2) .ylabel( 'x_2_6({\itt})') .-1. ylabel( 'x3_7({\itt})') . 13 .5] ) .Even*Even') . title( 'Even Part of x_1') .1. x26=x2 .xle.1) . axis([ -20 . -1.5] ) .-1. xle= (x1 + x1(end: -1 :1)) /2 . x37=x3 .x34 .5] ) . plot(t. plot(t .1.1.5 . % % % % % pole zero plot from coefficients of a difference equation. xlabel( '\itt') . subplot(2.20 .20 .1.*x7 . x37 .3) .5] ) . ylabel( 'x_1_e({\itt})') . This Matlab program accepts the coefficients of the difference equation and generates pole zero plot against the unit circle. xlo= (x1 ..*x6 .20 .x1(end : -1 :1))/2 . 'k') .5 . axis([ -20 .odd*Even') .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG x34=x3 .20 . xlabel( '\itt') . ylabel( 'x_3_4({\itt})') .20 . subplot(2. title( 'x_2*x_6 . plot(t. -1. BANGALORE.*x4 . The format of the difference equation is as follows.5 . axis([ -20 . axis( [ -20 . plot(t.5 . title( 'x_3*x_4 -odd*odd') . xlabel( '\itt') .1. axis([ -20 .xlo . 'k') . 'k') . 'k') .-1. title( 'odd Part of x_1') . plot(t. subplot(2. ylabel ( 'x_1_o({\itt})') .5]) . NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.4) .1.2.2. title( 'x_3*x_7 .5 . xlabel( '\itt') .x26 .2) .

title('Pole zero plot').] % +b0*x(n) + b1*x(n-1) + b2*x(n-2) + .] % a = [a0 a1 a2 a3 .. disp(' '). . which is represented as a sequence of numbers. %-----------------------.] = ').] %----.. Theory: • Sampling is a process of converting a continuous time signal (analog signal) x(t) into a discrete time signal x[n].. .... (D/A converter) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. disp(' Pole zero plot'). . (A/D converter) • ) Converting back x[n] into analog (resulting in x (t ) ) is the process of reconstruction. BANGALORE..Next part accepts coefficients of the difference equation ---------------clc.. % plot the pole zero plot = b0*x(n) + b1*x(n-1) + b2*x(n-2) + .Next part plots the pole zero plot -------------------------------------zplane(b. 14 .. % enter the coefficients of y(n) %-----... % b = [b0 b1 b2 b3 .a). % % here a0 = 1 and the coefficients are to be entered as...end of program ---------------------------------------- Verification of Sampling theorem. % a0*y(n) + [a1*y(n-1) + a2*y(n-2) + a3*y(n-3) + .] = '). b = input('enter [b0 b1 b2.. % enter the coefficients of x(n) a = input('enter [a0 a1 a2. % the above equation can also be written as follows..MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG % y(n) = -[a1*y(n-1) + a2*y(n-2) + a3*y(n-3) + . Aim: To verify Sampling theorem for a signal of given frequency.. .

results due to under sampling. 15 .x). if 1/T≥2 fN (fS≥2fN). ) For x (t ) to be exactly the same as x(t). sampling theorem in the generation of x(n) from x(t) is used. The Sampling Theorem: If a signal xa(t) has a bandlimited Fourier transform Xa(jΩ) such that Xa(jΩ)=0 for Ω≥2πfN. it finds practical applications in stroboscope and sampling oscilloscopes. -∞<n<∞.(iii) spline interpolation. BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG • Techniques for reconstruction-(i) ZOH (zero order hold) interpolation results in a staircase waveform. Though it is undesirable in ADCs. (ii) FOH (first order hold) where the adjacent samples are joined by straight lines is implemented by MATLAB plotting function plot(n. Time domain sequence and corresponding spectrum. then xa(t) can be uniquely reconstructed from equally spaced samples xa(nT). • • Aliasing-A high frequency signal is converted to a lower frequency.x). etc. is implemented by MATLAB plotting function stairs(n. The sampling frequency fs determines the spacing between samples. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.

BANGALORE. 16 . aliasing occurs x fs >= 2 * highest freq in x t fs < highest freq in x t NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG To avoid aliasing need : 2π / T − Ω N > Ω N or 2π / T > 2 Ω N or 1 / T > 2 FN case where 1 / T < 2 FN .

MATLAB Program: close all. subplot(4. figure(1). b=fft(a. n4=-50:1:50.1.4).MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Plots of a sampled cosine wave of 200Hz Algorithm: 1.grid on. s=s(1:100). a=(1+cos(2*pi*f*n)).abs(b)).101).. 4. clear all. f=5. plot(s). Nyquist & under sampled discrete time signals. subplot(4.101).stem(a).stem(a1).1).2). BANGALORE. a1=(1+cos(2*pi*f*n2)). 17 . fs=2*f.grid on. Generate an analog signal xt of frequency fd for comparison. s=abs(ifft(b)). stem(n4.1.plot(a). subplot(4. b=fft(a1. grid on. % for fs >> fm n=0.01:1. figure(2).1. subplot(4. b=fftshift(b). 2.01:0.grid on.plot(a).2). Input the desired frequency fd (for which sampling theorem is to be verified). Generate oversampled.1). 3. %a1=1+sin(2*pi*f*n2)+(1+sin(2*pi*2*f*n2))/2+(1+sin(2*pi*3*f*n2))/3. subplot(4.1. % for fs = fm n2=0:1/(fs/2):1. %a=1+sin(2*pi*f*n)+(1+sin(2*pi*2*f*n))/2+(1+sin(2*pi*3*f*n))/3. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.1.1. subplot(4.grid on.3).grid on. Plot the waveforms and hence prove sampling theorem.

1). stem(n4. d) Reconstructed signal.grid on. a2=(1+cos(2*pi*f*n1)).101). stem(n4.1. plot(n3*100. figure(3).'r').1.3). a2=(1+cos(2*pi*f*n3)). g=abs(ifft(b.1. g=abs(ifft(b. g1=abs(ifft(b.101)).1.'r').101). b=fftshift(b).MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG b=fftshift(b).'r').2). subplot(4. subplot(4. BANGALORE. subplot(4. stem(n4.3).plot(n*100. grid on.101)).abs(b)).grid on.grid on.a). NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.4).stem(n3*100.3).4).abs(b)).1. %a2=1+sin(2*pi*f*n3)+(1+sin(2*pi*2*f*n3))/2+(1+sin(2*pi*3*f*n3))/3. grid on.a).4). plot(g1(1:length(n2)).grid on. c) Spectrum. b=fft(a2. subplot(4.1. b=fft(a2.1.1). subplot(4.grid on. g(1:length(n3)). subplot(4.plot(n*100.grid on.stem([a2]). subplot(4. % for fs =2*(2* fm) n3=0:1/(2*fs):1. grid on.grid on. b=fftshift(b).abs(b)). 18 . Result: fs>>fm Fig: a) 5Hz sinusoidal time domain signal b) Sampled sequence at high sampling rate. %a2=1+sin(2*pi*f*n1)+(1+sin(2*pi*2*f*n1))/2+(1+sin(2*pi*3*f*n1))/3. % for fs =2* fm n1=0:1/(fs):1.2).1.1. figure(4).101)).1. plot(g(1:length(n1)). subplot(4. subplot(4. subplot(4.a2).

fs=2*fm Fig: a) 5Hz sinusoidal time domain signal b) Sampled sequence at Nyquist rate. d) Reconstructed signal. d) Reconstructed signal. d) Reconstructed signal. 19 . c) Spectrum. c) Spectrum. BANGALORE. fs=2*(2*fm) Fig: a) 5Hz sinusoidal time domain signal b) Sampled sequence at double the Nyquist rate. c) Spectrum.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG fs=fm Fig: a) 5Hz sinusoidal time domain signal b) Sampled sequence at half the Nyquist rate. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.

e. o A system function H(z) (obtained by applying Z transform to the difference Y ( z ) b0 + b1 z −1 + b2 z −2 equation). Half the Nyquist rate. H ( z ) = = X ( z ) 1 + a1 z −1 + a 2 z − 2 o A frequency response function obtained by applying DTFT on the impulse response h[n] (or by replacing z with ejΩ in H(z)) to get Y (e jΩ ) b0 + b1e − jΩ + b2 e −2 jΩ jΩ H (e ) = = X (e jΩ ) 1 + a1e − jΩ + a 2 e − 2 jΩ Given the difference equation or H(z). for example. This is elaborated in experiment no. Impulse response of a given system Aim: To find the impulse response h(n) of the given LTI system whose response y(n) to an input x(n) is given. At Nyquist rate plot shows a reconstructed signal almost similar to that of the analog signal.1: A LTI system • • A discrete time LTI system (also called digital filters) as shown in Fig. Nyquist Rate b. 20 . y[n-2]. Twice the Nyquist Rate c. Generate sine/cosine waveforms of multiple frequencies.1 is represented by o A linear constant coefficient difference equation. then its impulse response is of infinite NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.7 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Note: Mark the labeling for above graphs. y[n-1]. The reconstructed (from under sampled plot) signal is of a lower frequency. Using low pass filtering the wave form can be further smoothened. i. Questions: 1. y[n] + a1 y[n − 1] − a 2 y[n − 2] = b0 x[n] + b1 x[n − 1] + b2 x[n − 2]. The analog signal is of 5Hz. etc . The over sampled plot shows a reconstructed signal similar to that of the analog signal. BANGALORE. If the difference equation contains past samples of output.2. fd2 are 2 different frequencies. Theory: Fig.2. the impulse response of the LTI system is computed using filter or impz MATLAB functions. Sample a band limited continuous time signal band limited to fm = 3400 Hz under the following conditions a. say x1=sin(2*pi*fd1*n1)+ sin(2*pi*fd2*n2). where fd1.Solving a given difference equation. Inference:From the under sampling plot observe the aliasing effect. 2..

If both y[n] and x[n] are finite then the impulse response is finite (FIR). MATLAB Implementation: h=deconv(y. (IIR) 21 . 4.A) deconvolves vector A out of vector B. Use deconv to get impulse response h.9y(n-2) = x(n). The result of dividing B by A is quotient Q and remainder R. The result is returned in vector Q and the remainder in vector R such that B = conv(A. Algorithm for Problem2: 1. Algorithm for Problem1: 1. • Given only the input sequence x[n] and the output sequence y[n]. If A and B are vectors of polynomial coefficients. (Remember conv is polynomial multiplication). Given Problem 1) Find the impulse response h(n) of the given LTI system whose response y(n)=[1 2 3 2 1 2 ] to an input x(n)=[1 2 3] is given.h) to get y back..MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG duration (IIR).Q) + R. Input the two sequences as x and y. BANGALORE. [Q.y(n-1) + 0.….x): ‘y’ the output sequence should be of longer length than x.R] = DECONV(B. else the conv verification will result in a slightly different y (because of the remainder generated by deconv). Verify using conv(x. deconvolution is equivalent to polynomial division. DECONV Deconvolution and polynomial division. (The conv operation convolves 2 sequences x[n] and h[n] to obtain the output y[n]. say n=100 (to approximate n=∞). Use impz unction to get impulse response h. Plot the impulse response. Input the two coefficient arrays as b and a. 3. 3. Find its impulse response h(n) at n=0.. (FIR) 2) A LTI system is described by the difference equation y(n) . Note: Valid y and x should be given. 2. Also verify the result using conv operation. For such systems the impulse response is computed for a large value of n. 2. 4. we can find the impulse function h[n] by using the inverse operation deconv. for convolution operation refer experiment no 3: Linear convolution of two given sequences). Plot the sequences.50. • The deconvolution operation is valid only if the LTI system is ‘invertible’. Input the length of the impulse response required as N. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.

stem(n. h=deconv(y. %graphical display part N=length(h). The verified convolution output sequence is the same as the given y[n].N). MATLAB Programs: Program 1: y= input('The output sequence y(n) of the system='). where b and a are coefficient arrays obtained from difference equation. N = length of the response required.T] = IMPZ(B.A) computes the impulse response of the filter B/A choosing the number of samples for you.a. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. BANGALORE..7).A. (refer expt. title('impulse response of a system') %Verification yv=conv(x. IMPZ Impulse response of digital filter. returns the impulse response h[n]. xlabel('Time index n').MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG h=impz(b. and returns the response in column vector H and a vector of times (or sample intervals) in T (T = [0 1 2 . disp(yv) Result: The output sequence y(n) of the system = [1 the input sequence of the system = [1 1 1 1] the impulse response of the system is = 1 the verified output sequence is 1 2 1 2 1 1 0 -1] 1 -1 1 0 -1 Inference: The impulse response h[n] is of finite duration.T] = IMPZ(B.h).9]. [H. [H. For the given difference equation b=[1].]'). disp('the verified output sequence is').x). disp(h). ylabel('Amplitude'). a=[1 -1 0. disp('the impulse response of the system is='). 22 .. n=0:1:N-1.N) computes N samples of the impulse response. x=input('the input sequence of the system=').h).

3618. 1. 0. -0.2563... b=input('Enter the numerator coefficients').1316. Result: Enter the sequences as follows Numerator coefficients: b=[b0 b1 b2 . 0.0391.5912.. -0.2405. 23 . title('IMPULSE RESPONSE USING DIFFERENTIAL EQUATION').4300. 0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Program 2 disp('Enter the sequences follows'). grid on.0465.an] Enter the numerator coefficients[1] Enter the denominator coefficients>> [1 -1 0.0988. -0.1700. -0. 0. -0. disp(h). -0.h).N). 0.0431. -0. 0.0000.0169. disp('Impulse response is:')... 0. n=0:1:N-1. disp('Denominator coefficients: a=[a0 a1 a2 .2434. disp('Numerator coefficients: b=[b0 b1 b2 . -0.2033.bn] Denominator coefficients: a=[a0 a1 a2 . 0. 0.1881.0051.2249 -0.4895.0210. 0.1028. -0. 0.a. -0.1642.1498.8900.2583 0.bn]').5065. -0. BANGALORE. 0.0600.6310..1145 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.0320.2758.1688 0. 0.2071.3722.7840.0852. 0.8000.2489. -0. h = impz(b. ylabel('h(n)').0441 0.1976. xlabel('n'). -0. 0.0794. -0. -0. -0. -0. a=input('Enter the denominator coefficients').6840.0448. N=50.3016.0000. 0. 0.2522. -0. -0. 0.2161 -0.9] Impulse response is: 1. 0.1348. -0.. -0.1309.an]'). 0.1000. stem(n.. -0. 0.

Theory: • The output y[n] of a LTI (linear time invariant) system can be obtained by convolving the input x[n] with the system’s impulse response h[n]. x2 2. Input the two sequences as x1. The conv function assumes that the two sequences begin at n=0 and is invoked by y=conv(x. creates a vector with values from -3 to 5 with an increment of 1. Even if one (or both) of the sequences is infinite (say.h). Algorithm: 1.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Inference: The impulse response h[n] is of infinite duration. then we need to provide a beginning and end point to y[n] which are ybegin=xbegin+hbegin and yend=xend+hend respectively. 3. • • • The convolution sum is y[n] = x[n] ∗ h[n] = k = −∞ ∑ x[k ]h[n − k ] = +∞ k = −∞ ∑ x[n − k ]h[k ] n +∞ x[n] and h[n] can be both finite or infinite duration sequences. • • • The length of y[n] = xlength + hlength -1. we can analytically evaluate the convolution formula to get a functional form (closed form solution) of y[n]. decaying exponential). Convolve both to get output y. h[n] = (0. say n=-3:5.9 ) u[n] ). The timing information for a sequence is provided by another vector. Index 0 is also not recognized.or n=2. then we can use the MATLAB function ‘conv’ to evaluate the convolution sum to obtain the output y[n]. +∞ Aim: To obtain convolution of two finite duration sequences. • If both the sequences are of finite duration. 24 . Convolution is implemented as polynomial multiplication (refer MATLAB help). BANGALORE. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. EXPERIMENT NO 3: Linear convolution of two given sequences. Even if one of the sequences begin at other values of n. MATLAB Implementation: MATLAB recognizes index 1 to positive maximum. h[n] is stable (as h[n] is absolutely summable n = −∞ ∑ h[n] < ∞ . say n=-3. Plot the sequences.

for k=1:lx if((n-k)>=0&(n-k)<lh) y(n)=y(n)+x(k).1. t=0:1:len-1. MATLAB Program: % linear convolution clear all. % Plot subplot(3. for n=1:len y(n)=0. subplot(3.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG During plotting.y). t1=0:1:lx-1. stem(t1. title('Linear Convolution of two sequences'). lh=length(h). disp('Convolution from inbuilt function') disp(yc). disp('System response Output') disp(y) % Compare the result with inbuilt function. ylabel('----> h(n)'). grid on. yc=conv(x. ylabel('----> y(n)').1). the time vector size and the sequence size should be the same.1.2). 25 . end end end % to dispaly the result. Similarly for x2 and y.e. xlabel('-----------> n'). len=lx+lh-1. stem(t. subplot(3. xlabel('-----------> n'). the number of elements in the sequence x1 and in its time vector n1 should be the same. BANGALORE.h).x).1.h). grid on. t2=0:1:lh-1.3). grid on. stem(t2. ylabel('----> x(n)').*h(n-k+1). xlabel('-----------> n'). close all. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. x=input('Enter the signal x(n)=') h=input('Enter the impulse response sequence h(n)=') lx=length(x).. i.

. Theory: • Correlation is mathematical technique which indicates whether 2 signals are related and in a precise quantitative way how much they are related.±2... Write a program to compute the convolution using FT Autocorrelation of a given sequence and verification of its properties.. l = 0. Write a program to compute the convolution of two sided sequences.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Result: Enter the signal x(n)=[1 2 3 4] x= 1 2 3 4 Enter the impulse response sequence h(n)=[1 1 1 1] h= 1 1 1 1 System response Output: 1 Convolution from inbuilt function: 3 6 10 9 7 4 1 3 6 10 9 7 4 Inferences: …………. Questions: 1. BANGALORE.±1..±1..±2. ∞ Some of the properties of autocorrelation are enumerated below NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.. 2. The parameter ‘l’ called ‘lag’ indicates the time shift between the pair. 26 . Autocorrelation sequence of x[n] is given by rxx [l ] = n = −∞ ∑ x[n]x[n − l ]. Aim: To obtain autocorrelation of the given sequence and verify its properties.. l = 0. A measure of similarity between a pair of energy signals x[n] and y[n] is given by the cross correlation sequence rxy[l] defined by rxy [l ] = • • • ∞ n = −∞ ∑ x[n] y[n − l ].

. 5.±1... BANGALORE. at l=0. Input the sequence as x. 3.±2. Use the ‘xcorr’ function to get auto correlated output r...±1. 27 . the autocorrelation of x[n] and y[n] are the same regardless of the value of the time shift k. and this rxx[l] is also n =0 N −1 periodic with N... All other samples are of lower value.1.) returns a vector of lag indices (LAGS).e. 5. o For power signals the autocorrelation sequence is given by k 1 ∑ x[n]x[n − l ]. The zeroth lag of the output correlation is in the middle of the sequence at element M. XCORR(. rxx [l ] ≤ rxx [0] = ε x = • n = −∞ ∑x ∞ 2 [n] . MATLAB Implementation: MATLAB has the inbuilt function XCORR(A).e.e.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG o The autocorrelation sequence is an even function i.. is the auto- correlation sequence. For example. when A is a vector.5] Algorithm: 1. This is verified in Fig.e. i.MAXLAG) computes the (auto/cross) correlation over the range of lags: -MAXLAG to MAXLAG.. l = 0. i.].e.. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 2*MAXLAG+1 lags.. Also the maximum value = 11 = energy of the pulse [12+12+12. If missing. rxx [l ] = rxx [−l ] o At zero lag. then the xcorr function returns the length 2*M-1 auto-correlation sequence. [C.25*pi*n)) corrupted by an additive uniformly distributed random noise of amplitude in the range [-0. 2..LAGS] = XCORR(. This can be verified with a sine and cosine sequences of same amplitude and frequency will have identical autocorrelation functions.3 where we use the periodicity property of the autocorrelation sequence to determine the period of the periodic signal y[n] which is x[n] (=cos(0... default is MAXLAG = M-1.. the sample value of the autocorrelation sequence has its maximum value (equal to the total energy of the signal εx) i. then ryy[l] = rxx[l] i. where the autocorrelation of the rectangular pulse (square) has a maximum value at l=0. l = 0. Plot the sequences. and for periodic signals with k →∞ 2k + 1 n=− k rxx [l ] = lim period N it is rxx [l ] = 1 N ∑ x[n]x[n − l ].5 0. This is verified in Fig. let y[n]=x[n-k].. If A is of length M vector (M>1). o A time shift of a signal does not change its autocorrelation sequence.±2..

MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG MATLAB Programs %Energy signals %simple sequence x2=[3.0000 7. fliplr(x)). r).1) stem(n. title('autocorrelation output').0000 10. stem(k. 5 3 %plot the sequences subplot(2.0000 5. % Compute the correlation sequence Result: The output plot is in Fig.0000 7.0000 4.0000 3.0000 10.11).0000 4.3 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.0000 1.2.1. subplot(2. xlabel('Lag index'). 28 .0000 5. disp(r). >> xcorr(x2) ans = 3 5 -3 15 -3 %r = conv(x.0000 6. 5.0000 3. ylabel('Amplitude'). BANGALORE.-1. %Computation of Autocorrelation of a % rectangular Sequence n = -5:5. disp('autocorrelation sequence r='). r=xcorr(x).2 Fig. % Generate the square sequence x = ones(1. title('square sequence').0000 11.x).1 autocorrelation sequence r = 1.0000 8.1.1].0000 Inference: Following Autocorr properties are verified 1) Max peak of 11 (=energy of the pulse) at zero lag (l=0) 2)the autocorr seq is an even function Fig.0000 2.0000 2.2) k = -N:N. N=10.0000 9.0000 8.0000 9.5.0000 6.5.

BANGALORE. Program: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 5.3) does not show any noticeable periodicity. whereas the sequence y[n] is shifted w. Comparing the equations for the linear convolution and cross correlation we find that rxy [l ] = n = −∞ ∑ x[n] y[n − l ] = ∞ n = −∞ ∑ x[n] y[−(l − n)] = x[l ] ∗ y[−l ] . 29 . Hence cross correlation is employed to compute the exact value of the delay k between the 2 signals.2. • The properties of cross correlation are 1) the cross correlation sequence sample values are upper bounded by the inequality rxx [l ] ≤ rxx [0]ryy [0] = ε x ε y 2) The cross correlation of two sequences x[n] and y[n]=x[n-k] shows a peak at the value of k.e. Cross correlation of a given sequence and verification of its properties. Theory: • Cross Correlation has been introduced in the last experiment.indicating thaty[n] is a periodic with N=8 (cos(0. (Use ‘fliplr’ function for folding the sequence for correlation). but its autocorrelation sequence has distinct peaks at lags that are multiples of 8. the autocorrelation of the noise component has a very strong peak only at zero lag. Used in radar and sonar applications. 3) The ordering of the subscripts xy specifies that x[n] is the reference sequence that remains fixed in time.25*pi*n)=cos(wn) implies w=2*pi*f.r. where the received signal reflected from the target is the delayed version of the transmitted signal (measure delay to determine the distance of the target). i. N= 1/f = 2/0.25 =8). The amplitudes are considerably smaller at other values of the lag as the sample values (of noise generated by rand function) are uncorrelated with each other. Aim: To obtain cross correlation of the given sequence and verify its properties.t x[n]. If y[n] is the reference sequence then ryx [l ] = rxy [−l ] .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Inference 2: The plot of noise corrupted signal y[n] (Fig. Also notice the strong peak at zero lag. Hence ryx[l] is obtained by time reversing the sequence rxy[l]. convolving the ∞ reference signal with a folded version of sequence to be shifted (y[n]) results in cross correlation output..5. From Fig.

0.−3} ↑ xcorr(x2.B). 2.r). ylabel('Amplitude').0. k=2 >> xcorr(xi.0} ↑ Inference: Strong peak of 15 at lag = -2 implies the delay between xi and x2 is 2.y). r = xcorr(x. Input the sequence as x and y.3. ryx [l ] = rxy [−l ] is verified.-1]. %time vector for plotting stem(k. 3. BANGALORE.fliplr(y)).1. y = input('Type in the second sequence = ').7. disp('Cross correlation output is =').2. the shortest one is zero-padded.0. ylabel('Amplitude').MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG %Verification of the properties %Small MATLAB code xi=[1. xcorr(xr.2.xr) ans = {−3. where A and B are length M vectors (M>1). 1.i. MATLAB Implementation: MATLAB has the inbuilt function XCORR: Say C = XCORR(A. MATLAB Program: % Computation of Cross-correlation Sequence using folded sequence and convolution x = input('Type in the reference sequence = '). disp(r). Using convolution to implement correlation. 30 . If A and B are of different length.2} ↑ Inference: Strong peak of 10 at lag = 2 implies the delay between xr and x2 is 2. y = input('Type in the second sequence = '). Also peak =15=energy of xi (1+22+32+(-1)2) implies that both xi and x2 are strongly correlated.y).3. disp(r).2. % Compute the correlation sequence n1 = length(y)-1. stem(k.3. Plot the sequences.5.−1.-1. n2 = length(x)-1.r). returns the length 2*M-1 cross-correlation sequence C.lag]=xcorr(x. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. % Computation of Cross-correlation Sequence %using xcorr function x = input('Type in the reference sequence = '). n2 = length(x)-1.-1].10. xlabel('Lag index'). % Compute the correlation sequence n1 = length(y)-1.0. 2.2. x2=[0.r).1.2. %stem(lag. Algorithm: 1. r = conv(x. %[r.2].1. xlabel('Lag index').0. 2.15. x2=[3..5.7. Use the ‘xcorr’ function to get cross correlated output r.0]. k = (-N):N. it implies that xr and x2 are uncorrelated slightly (may be due to noise.x2) ans = {−1. k = (-n1):n2.5. but since 10<15. FLIPLR(X) returns X with row preserved and columns flipped in the left/right direction.10. the instruction is FLIPLR Flip matrix in left/right direction. %consider the below sequences xr=[1. N=max(n1.x2) ans = {2. X = 1 2 3 becomes 3 2 1. disp(‘Cross correlation output is =’).etc).e. %=xr[n-2].n2) .-1.5.

X(ejω) can alternately be expressed in the form NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 31 . respectively. This information is called the system's frequency response. the output is {-0. -0. BANGALORE.0000 .0000.0000.0000 .0000.Since both the impulse response and the frequency response contain complete information about the system. Fig. 21. 28.0000 .0000.y).n2)-1 = 2* 9-1=17 whereas using conv program. -15.0000.0000.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Result: Type in the reference sequence = [1 3 -2 1 2 -1 4 4 2] Type in the second sequence = [2 -1 4 1 -2 3] Cross correlation output is = 3 7 -11 14 13 -15 28 6 -2 21 12 12 6 4 Verification: with xcorr(x.0000.0000. 7.0000. The output of a linear system to a sinusoidal input is a sinusoid of the same frequency but with a different magnitude and phase. 6. 6. the length of output is n1+n2-1.0000.6. H [ ] is used for the frequency response.0000. the real and imaginary parts of X(ejω). 4. 12.1 Cross correlation output using Convolution Fig.The relationship between the impulse response and the frequency response is one of the foundations of signal processing:A system's frequency response is the Fourier Transform of its impulse response Since h [ ] is the common symbol for the impulse response. the length of the output using xcorr is 2*max(n1. there must be a one-to-one correspondence between the two. 3. -2.0000} Note: For sequences with different lengths. 13. you can calculate the other. 12. Discrete Time Fourier Transform: The discrete-time Fourier transform (DTFT) X(ejω) of a sequence x[n] is defined In general X(ejω) is a complex function of the real variable ω and can be written as where Xre(ejω) and Xim(ejω) are. -11. Any linear system can be completely described by how it changes the amplitude and phase of cosine waves passing through it. and are real functions of ω.6.0000.0000. Given one. 0.2 Cross correlation output using xcorr FREQUENCY RESPONSE: The frequency response is a representation of the system's response to sinusoidal inputs at varying frequencies. 14.

subplot(2. the Fourier transform is called the Fourier spectrum and. n) 01: Compute the discrete Fourier transform of the following function analytically and Then plot the magnitude and phase: Its DTFT is given as: MATLAB Code: w = [0:500]*pi/500. The DTFT X(ejω) is a periodic continuous function in ω with a period 2π. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. b = angle(x)*180/pi. Y = fft(X.a).1). plot(w/pi. computed with a fast Fourier transform (FFT) algorithm.1. The DTFT satisfies a number of useful properties that are often uitilized in a number of applications.n) returns the n-point FFT. 32 . plot(w/pi. Y = fft(X) Y = fft(X. a = abs(x). BANGALORE.9*z). the magnitude R and phase angle theta are given by: R = abs (Z) Theta = angle (Z) Y = fft(X) returns the discrete Fourier transform of vector X.^(-1).1. subplot(2. x = 3*(1-0. MATLAB COMMANDS: For complex Z. |X(ejω)| and θ(ω) are referred to as the magnitude spectrum and phase spectrum. respectively.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The quantity |X(ejω)| is called the magnitude function and the quantity θ(ω) is called the phase function In many applications.b).2). z = exp(-j*w). likewise.

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

OUTPUT:

#2: Evaluate the DTFT of the given coefficients. num=[2 1] den=[1 –0.6]

• •

Plot real and imaginary parts of Fourier spectrum. Also plot the magnitude and phase spectrum. title('Imaginary part of H(e^{j\omega})') xlabel('\omega /\pi'); ylabel('Amplitude'); subplot(2,2,3) plot(w/pi,abs(h)); grid on; title('Magnitude Spectrum |H(e^{j\omega})|') xlabel('\omega /\pi'); ylabel('Amplitude'); subplot(2,2,4) plot(w/pi,angle(h)); grid on; title('Phase Spectrum arg[H(e^{j\omega})]') xlabel('\omega /\pi'); ylabel('Phase, radians');

MATLAB CODE: % Evaluation of the DTFT

clc; % Compute the frequency samples of the DTFT w = -4*pi:8*pi/511:4*pi; num = [2 1]; den = [1 -0.6]; h = freqz(num, den, w); % Plot the DTFT subplot(2,2,1) plot(w/pi,real(h)); grid on; title('Real part of H(e^{j\omega})') xlabel('\omega /\pi'); ylabel('Amplitude'); subplot(2,2,2) plot(w/pi,imag(h)); grid on;
NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

33

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

OUTPUT

Fast Fourier Transform: The Fast Fourier Transform (FFT) is just a computationally fast way to calculate the DFT.

03:
Determine the Fourier transform of the following sequence. Use the FFT (Fast Fourier Transform) function. x (n) = {4 6 2 1 7 4 8} MATLAB Code: n = 0:6; x = [4 6 2 1 7 4 8]; a = fft(x); mag = abs(a); pha = angle(a); subplot(2,1,1); plot(mag); grid on title('Magnitude Response'); subplot(2,1,2); plot(pha); grid on title('phase Response');

OUTPUT:

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

34

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

Time-shifting property of DTFT:

If ‘x[n]’ be the sequence ,and X(ejw) be its fourier transform then,
x[n] ----F----- X(ejw)

then, for the time-shifted sequences, a simple transformation of the index of summation in the discrete-time Fourier transform yields
x[n-nd] ----F----- e-jwndX(ejw)

#04: Observe the time-shifting property of DTFT.
• • Plot and compare the magnitude spectrum of the original input with time delayed input. Plot and compare the phase spectrum of the original input with delayed input.

MATLAB CODE:

% Time-Shifting Properties of DTFT clc; w = -pi:2*pi/255:pi; D = 10; num = [1 2 3 4 5 6 7 8 9]; h1 = freqz(num, 1, w); h2 = freqz([zeros(1,D) num], 1, w); subplot(2,2,1) plot(w/pi,abs(h1)); grid on; title('Magnitude Spectrum of Original Sequence') subplot(2,2,2) plot(w/pi,abs(h2)); grid on; title('Magnitude Spectrum of Time-Shifted Sequence') subplot(2,2,3) plot(w/pi,angle(h1)); grid on; title('Phase Spectrum of Original Sequence') subplot(2,2,4) plot(w/pi,angle(h2)); grid on; title('Phase Spectrum of Time-Shifted Sequence')

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

35

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

Frequency-shifting property of the DTFT:

#05: Observe the frequency shifting property of DTFT.
• • Plot and compare the magnitude spectrum of the original input with frequency shifted input. Plot and compare the phase spectrum of the original input with frequency shifted input..

MATLAB CODE:

% Frequency-Shifting Properties of DTFT clc; w = -pi:2*pi/255:pi; wo = 0.4*pi; num1 = [1 3 5 7 9 11 13 15 17]; L = length(num1); h1 = freqz(num1, 1, w); n = 0:L-1; num2 = exp(wo*i*n).*num1; h2 = freqz(num2, 1, w); subplot(2,2,1); plot(w/pi,abs(h1)); grid on; title('Magnitude Spectrum of Original Sequence') subplot(2,2,2) plot(w/pi,abs(h2)); grid on; title('Magnitude Spectrum of Frequency-Shifted Sequence') subplot(2,2,3) plot(w/pi,angle(h1)); grid on; title('Phase Spectrum of Original Sequence') subplot(2,2,4) plot(w/pi,angle(h2)); grid on; title('Phase Spectrum of Frequency-Shifted Sequence')

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

36

MAT LAB

MANUAL

DEPT OF ELECTRONICS AND COMMUNICATION ENGG

OUTPUT

Questions:
1. Determine the Fourier transform of the following sequence. Use the FFT (Fast Fourier Transform) function,

x(n) = {4 3 2 1 1 2 3 4}
2. Compute the discrete Fourier transform of the following function analytically and then Plot the magnitude and phase

x(n) = 2(0.8)n+2 u(n-2)
3. Determine H(w) and plot its magnitude and phase for the following system. Y(n) = 2x(n) + x(n-1) – 0.25y(n-1) + 0.25y(n-2)

4. Given below is the frequency response of the system, H(ejw) = 1+e-jw 1-e-jw+0.9e-j2w

a) Write a MATLAB code that manually implements the above system. b) Compare with the spectrum obtained from freqz command • Plot the magnitude and frequency spectrum. • Also plot real and imaginary plots

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY, BANGALORE.

37

Rational Z-transform to factored Z-transform: Example: Let the given transfer function be in the rational form. which is a sequence of real or complex numbers. and the s-plane. or elliptic. Matlab command required for converting rational form to factored form be NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. this definition is used when the signal is causal. the z-domain. The Laplace transforms deals with differential equations. the single-sided or unilateral Z-transform is defined as In signal processing. the two techniques are not a mirror image of each other. recursive digital filters are developed with a parallel technique called the z-transform. 38 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Z-transform and Inverse Z-transform Analysis Objective: To study the Z-transform and Inverse Z-transform practically using MATLAB. Bilateral Z-transform: The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z) defined as . The Z transform of a discrete time system X[n] is defined as Power Series. can be defined as either a one-sided or twosided transform. As analog filters are designed using the Laplace transform. such as the Butterworth. Unilateral Z-transform : Alternatively. Correspondingly. so that we can find the poles and zeros mathematically by applying quadratic equation. the z-transform deals with difference equations. like many other integral transforms. The Z-transform. the Z-transform converts a discrete timedomain signal. into a complex frequency-domain representation. However. the s-domain. BANGALORE. Recursive digital filters are often designed by starting with one of the classic analog filters. 2z4+16z3+44z2+56z+32 G(z)= -------------------------------3z4+3z3-15z2+18z-12 It is required to convert it into factored form. Chebyshev. The overall strategy of these two transforms is the same: probe the impulse response with sinusoids and exponentials to find the system's poles and zeros. while the z-plane uses a polar format. in cases where x[n] is defined only for n ≥ 0. the s-plane is arranged in a rectangular coordinate system. and the z-plane. A series of mathematical conversions are then used to obtain the desired digital filter. Description: In mathematics and signal processing.

24__ + _0.000 z-1 +2.33 z-1) 1 – 0. G(z)= 0.33 z-1 Matlab command that converts rational z-transform in to partial fraction form is ‘residuez’.transfer function in factored for.36__ + __0.4z-1 + 0.000z-1 -4.000 + 2. Or simply we have poles and zeros of the given system we can find the transfer function in factored form.5333 z-2) (1. Example: Consider the transfer function in the rational form i-e.000z-2 )(1. The partial fraction form be.36__ + __0.000 + 2.000z-2 )(1. Partial fraction form to Z-transform: This technique is used when it is required to convert partial fraction expression in to rational Ztransform.a) This function displays the poles and zeros of discrete-time systems.6667 + 0. BANGALORE. Example: Lets use the above result i-e.1.33 z-1 Matlab command that converts partial fraction form into rational z-transform is ‘residuez’ Zplane: Zero-pole plot zplane(b.4____ (1+0.5333 z-2) (1.000 + 2.000 z-2) (1.000z-1 -4.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG ‘Zp2sos’ The factored form of G(z) as evaluated by ‘zp2sos’ be.5z-1 1+0. while taking the inverse Z-transform and when the order ‘H(z)’ is high so that it is quite difficult to solve it mathematically.000 z-2) For building up transfer function in rational form we find the poles and zeros of above system simply by using matlab ‘root’ command or by hand.000 . Rational Z-transform to partial fraction form: This technique is usually used . Example: Take the partial fraction form of above . G(z)= 0. G(z)= ( 0.poles to rational Z-transform: It is the inverse of the above case. 39 .33 z-1) 1 – 0.5z-1 1+0.000 z-1 +2.1.000 z-1 + 1. Matlab command that converts poles and zeros of the system in to transfer function is ‘zp2tf’ . NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.24__ + _0. 18z3 G(z)= -----------------18z3+3z2-4z-1 We can evaluate the partial fraction form of the above system using matlab command.000 z-1 + 1.4____ (1+0.000 .6667 + 0. G(z)=( 0.4z-1 + 0.000 z-2) (1.000 z-2) Factored Z-transform / zeros. when the transfer function is given in factored form and it is required to convert in rational form then a single ‘matlab’ command can serve the purpose.000 + 2.

1. Of Denominator. Fs= Sampling Frequency Matlab Code: b=[2 5 9 5 3] a= [5 45 2 1 1] freqz(b.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Pole Zero Diagrams For A Function In Z Domain: Z plane command computes and display the pole-zero diagram of Z function.Transform of the function freqz(b.0000 + 1. Of Numerator.a). The Command is Zplane(b. 40 . NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. a= Coeff.Fs) b= Coeff. BANGALORE.a.0000 . use root(a) To display the zero value. use root(b) Matlab Code: b=[0 1 1 ] a= [1 -2 +3] roots(a) roots(b) zplane(b.4142i ans= -1 Frequency Response: The Freqz function computes and display the frequency response of given Z.a) To display the pole value.4142i 1. ans = 1.a).

phaH = angle(H)*180/pi.1.5) (z − 0.a. xlabel('frequency in pi units'). H=freqz(b.75)(z + 0. ylabel('│H│').1).25 z − 0. plot(w/pi. = + = + (z − 0.2).68(y(n-2) Matlab Code: b = [0. subplot(2.52.5) (z − 0. subplot(2.375 z z − 0. a= [1.8 z z . title('Phase Response'). ylabel('Degrees').52y(n-1) – 0.1. xlabel('frequency in pi units').2]. = 2 −1 −2 1 − 0.2x(n) + 0. Example: Assume we have a transfer function in the z-domain given by X (z ) = z −1 z .75) (z + 0.25 z − 0.5) The inverse z-transform of this is thus NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.w).68]. title('Magnitude Response').magH). 0. plot(w/pi. it’s partial fraction expansion can be found to be X (z ) = c1 z c2 z 0.8 z − 0. magH = abs(H).75) (z + 0. w = [0:1:500]*pi/500.375 Factoring this. 41 . -0.phaH). BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Example: Plot the magnitude and phase of the frequency response of the given digital filter Using freqz function: y(n) = 0.

10) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.8 0.375].0000 -0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG x (n ) = [(0 .5 1 We can find the impulse response (or inverse z-transform) of the polynomial based on the power series expansion method using the “impz” function h = impz(num. 8 )(0 .den. 42 . 8 )(− 0 .4 Imaginary Part 0.den.6 -0. 5 ) u (n ) n ] There are several MATLAB functions that could assist with calculating and analyzing these results.7500 -0.5 0 Real Part 0. BANGALORE.5000 >> zplane(z. We can find the roots of the denominator polynomial using >> den = [1 -0.375] den = 1.p) numerator and denominator coefficients in row vectors >> num = [0 1 0] num = 0 1 0 >> den = [1 -0. >> roots(den) ans = 0.2 0 -0.25 -0.7500 -0.6 0.25 -0. 75 ) n + (− 0 .75. -0.4 -0.N) where N is the number of terms or coefficients to compute >> h = impz(num.5000 We can then plot the zeros and poles either with (1) zeros and poles in column vectors >> z = [0] z= 0 >> p = [0.2500 -0.3750 >> zplane(num.5] p= 0.2 -0.8 -1 -1 -0.den) 1 0.

2148 0.25 -0.2031 0. 43 .P.375 1 − 0.0770 0.5000 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. >> den = [1 -0.den) R= 0. poles.8000 -0.4375 0.25 z −1 − 0. >> [R.7500 -0. BANGALORE.0000 0.0616 MATLAB can also be used to find the partial fraction expansion Assume you have a polynomial of the form −2 −M + −1 + + + (z ) = B(z ) = b0 b1 z −1 b2 z −2 L bM z − N H A( z ) a 0 + a1 z + a 2 z + L + a N z This can be turned into a partial fraction expansion of the form R3 Rn R1 R2 B(z ) = + + +L+ +K −1 −1 −1 A( z ) 1 − p1 z 1 − p2 z 1 − p3 z 1 − p n z −1 Rz R z Rz R z B(z ) = 1 + 2 + 3 +L+ n + K A( z ) z − p1 z − p 2 z − p3 z − pn where we can get the residues (coefficients).K]=residuez(num.1130 0.2500 0.375 z − 2 so in MATLAB we would enter >> num = [0 1]. Thus for our example we have z z −1 X (z ) = 2 = z − 0.375].MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG h= 0 1.1299 0.8000 P= 0.25 z − 0. and direct terms.

den.75 z + 0.6 0.4 0.25 -0.7 0.9 1 Here we have used the form freqz(num.N) where ‘num’ are the numerator coefficients.den.8 z + +0 z − 0. abs(H)) ‘num’ and ‘den’ are the same.2 0. 44 . >> den = [1 -0.5 Normalized Frequency 0.Fs) plot(f.8 (×π rad/sample) 0.2 0.3 0.5) u (n ) X (z ) = [ ] We can also plot the frequency response of a particular polynomial with freqz For X (z ) = z we would enter z − 0.7 0. ‘den’ are the denominator coefficients.N.8)(0.8)(− 0.den. >> freqz(num. ‘Fs’ is the sampling frequency.8 z − 0. The response data versus frequency are stored in H. ‘N’ values between 0 and Fs are calculated. and ‘N’ is the number of points to use in the plot which goes from 0 to π.9 1 0 P a e( e r e ) h s d ge s -50 -100 -150 -200 0 0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG K= [] which corresponds to a partial fraction expansion of 0.375 2 >> num = [0 1 0]. >> den = [1 -0.1 0.25 -0.3 0.75) + (− 0.4 0.375].5 Normalized Frequency 0. 512) 10 Mg itu e( B an d d ) 5 0 -5 0 0.25 z − 0.f] = freqz(num.375]. An alternative form is to use [H. BANGALORE.1 0.8 (×π rad/sample) 0.5 n n x(n ) = (0. >> num = [0 1 0].6 0. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.

8000). >> plot(f. BANGALORE.den.5 2 1. Solution: >> syms t >> f=5*exp(-2*t). you need to first define the variable t as a "symbol". 45 .512. 2z4+16z3+44z2+56z+32 G(z)= -------------------------------3z4+3z3-15z2+18z-12 Task#2: Determine the partial fraction expansion of the z-transform G(z) given by 18z3 G(z)= -----------------18z3+3z2-4z-1 LAPLACE TRANSFORMS You can compute Laplace transform using the symbolic toolbox of MATLAB. MATLAB forms Laplace transform symbolically. you must use the syms operator to alert MATLAB that you are using a symbolic variable. SYMS Command Whenever you want to use symbolic mathematics. Thus. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.and then determine its ROCs.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG >> [H.5 1 0.abs(H)) 3 2.f] = freqz(num. plot its poles and zeros.5 0 500 1000 1500 2000 2500 3000 3500 4000 Question: Task#1: Express the following z-transform in factored form . and that it does not have a specific value Example 1.

t the time variable. >> ilaplace(F) ans = 3-3*exp(-8*t) 3. BANGALORE. 46 . and MATLAB can help you with that.d) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. >> [r.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG >> L=laplace(f) L= 5/(s+2) >> ilaplace(1/s-2/(s+4)+1/(s+5)) Matlab result: Ans : 1-2*exp(-4*t)+exp(-5*t) Examples: 1. If you want to compute the inverse Laplace transform of = You can use the following command lines. f the function. You can compute Laplace transform using the symbolic toolbox of MATLAB. >> f=t. >> syms F S >> F=24/(s*(s+8)). >> d=[1 3 2 0 0]. >> n=[0 0 4 4 4]. You write the coefficients of the numerator and the denominator in separate vectors and MATLAB gives you the coefficients with the corresponding poles in the expansion. We can also do inverse Laplace transform using partial fraction expansion. >> laplace(f) ans =1/s^2 where f and t are the symbolic variables.k]=residue(n. If you want to compute the Laplace ace transform of x(t) = t . >> syms f t >> f=t. you can use the following MATLAB program. If you want to find the partial-fraction expansion of the following MATLAB program gives you the coefficients in the expansion. 2.p. The inverse transform can also be computed using MATLAB.

Alternatively. >> F=laplace(f. First you need to specify that the variable t and s are symbolic ones.25*exp(-2*t).s) To make the expression more readable one can use the commands.5*t*exp(-2*t)+1.t. This is done with the command >> syms t s Next you define the function f(t). simplify and pretty. >> syms t s >> f=-1.r= -3 4 -1 2 p= -2 -1 0 0 Therefore. Lets calculate the inverse of the previous function F(s).25+3. One also needs to define the symbols t and s.t.5 ---------s (s + 2)2 which corresponds to F(s). The actual command to calculate the transform is >> F=laplace(f. one can write the function f(t) directly as part of the laplace command: >>F2=laplace(-1. here is an example for the function f(t).5*t*exp(-2*t)+1. >> syms t s . the partial fraction expansion is: Calculating the Laplace F(s) transform of a function f(t) is quite simple in Matlab.25*exp(-2*t)) Inverse Laplace Transform The command one uses now is ilaplace.25+3.s) F = -5/4/s+7/2/(s+2)^2+5/4/(s+2) >> simplify(F) ans = (s-5)/s/(s+2)^2 >> pretty(ans) s .

5/4 + 7/2 t exp(-2 t) + 5/4 exp(-2 t) Which corresponds to f(t) Alternatively one can write >> ilaplace((s-5)/(s*(s+2)^2)) Here is another example. >> ilaplace(F) ans = -5/4+(7/2*t+5/4)*exp(-2*t) >> simplify(ans) ans = -5/4+7/2*t*exp(-2*t)+5/4*exp(-2*t) >> pretty(ans) . Matlab often gives the inverse Laplace Transform in terms of sinhx and coshx. Using the following definition one can rewrite the hyperbolic expression as a function of exponentials: Also. making use of the trigonometric relationship. 48 . you may find the “Heaviside(t) function which corresponds to the unit step function u(t): thus the function H(t) = heaviside(t) =0 for t<0 and H(t) = heaviside(t)=1 for t>0. suppose that Matlab gives you the following result for the inverse Laplace transform: 2 heaviside(t-10) exp(-5/2t+25) sinh(1/2t-5) This can be re-written. using the definition of the sinh(x) function: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. >> F=10*(s+2)/(s*(s^2+4*s+5)).MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG >> F=(s-5)/(s*(s+2)^2). >> ilaplace(F) ans = -4*exp(-2*t)*cos(t)+2*exp(-2*t)*sin(t)+4 Which gives f(t). BANGALORE. As an example.

BANGALORE. E. 49 . SIMULINK: • To begin your SIMULINK session open first MATLAB ICON by clicking mouse twice and then type »simulink You will now see the Simulink block library.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG This last expression is closer to what your hand calculations will give you for the inverse Laplace Transform. • Browse through block libraries.. you will see the following: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. if you click Continuous.g.

and its inverse . we are now ready to start generating a simple Simulink diagram. Roughly. s 1 d corresponds to derivative operator. 50 . to integration. where s is Laplace variable. This s operator notation comes from linear systems domain. . BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG 1 Observe the description of the integrator beside the block that will be used for integrator. . then New and Model. . s dt z • Math Operations library is shown below After browsing through other block libraries. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. This file will be called untitled. • Choose in menu selection File.

keep pressing the mouse while you move the block to the untitled file and then release the mouse. Move the cursor on top of Gain. The result is shown below. Move that block in the same way as the others to the untitled file. It is fed into an amplifier with gain 2. 51 . In the beginning.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Untitled file. you need to install a sink from Sinks library. If you fail. Solution: Pick first the amplifier. The result is shown below. where the SIMULINK configuration is constructed using different blocks in the library. The numerical value inside the block will now change to 2. BANGALORE. In order to see the result. The gain has only one parameter. Next find the input signal block. This is under Sources and is called Sine Wave. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. This you can find under Math and it is called Gain. keep it down and move the Gain block to untitled file and release it. With a mouse you can configure your model into the empty space. EXAMPLE 1: Input signal is sin t . You can change it by moving the cursor close to 1 and clicking once and then operating as you would with any word processing system. Again move the cursor on top of it. which has value of 1. click OK. try again. Simulate the output of the amplifier. Once finished. the easiest sink to use is scope.

You’ll see a hairline cursor. BANGALORE. while you drag your mouse. You’ll see a line forming. Before simulation you should check that the parameter values in the Sine Wave block are correct. This is done with the mouse. Open it by placing the cursor on top and click twice. Once you reach the input another hairline cursor can be seen and you can release the mouse. when you are close enough. Take the cursor to the output of Sine Wave block. Now press the mouse down. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 52 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The only thing missing of the system is to connect the peaces together. Your simulation system is now complete. Keep it down and move it close to the input of gain.

you can use differential operator D. Note: The input is 1 after t> 0. There is no phase shift and sampling is not issue here. that the stepping time is not t=0 but t=1. d . Note however. Then the differential equation becomes Let D = dt Dx = −2 x +1 (1) or Dx + 2 x = ( D + 2) x = 1 . dt x (0 ) = 0 . Simulation menu Start button EXERCISE 2: Solve the differential equation dx = − 2 x + 1.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG For this example Amplitude is 1 and frequency (rad/s) is also 1. so default values are OK. 53 . This further leads to NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. Solution: If you are inexperienced with differential equations. You can begin simulation by choosing Start simulation from Simulation menu or by clicking the start button. This can be taken as a step function from the Sources block library. BANGALORE. t > 0 .

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. Correct it as shown below. except for the initial conditions.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG x= 1 D+2 (2) You can use either (1) or (2) for SIMULINK configuration. The sign in summation is wrong. 54 . Input to the integrator is Dx = 1 s dx and output x. The result is shown above. We will use the first one: Dx = −2 x + 1 . The solution is found by choosing under Simulation menu Start simulation or by clicking Start button. it is clear (why?) that we have made a mistake in configuration. Now the result corresponds to our expectations (if any). Thus in dt configuration you set up the right hand side and connect the everything to the input of the integrator. Laplace transform operator s is almost the same as D. In SIMULINK means integration (see the block below). BANGALORE. If you study the equation and the result.

NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. If you wish to simulate longer you have to change it. use Mux (multiplexer) block. To do that open Simulation menu and choose Simulation parameters. Double-click Initial condition As seen above you can change the initial value to e. 55 . –3.g. Set up the system as shown below. BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG If you want to see both the input and output at the same time. which you can find under Signals and Systems block library. The default time for simulation is 10.

Complete the exercise. SOLUTION: Solve equation first with respect to the highest order derivative to obtain d2x dx = −5 − 9 x 2 dt dt To set up the right-hand side two integrators are needed: The input to the first integraror is the second derivative d 2x dx . PURPOSE: To illustrate how to configure a SIMULINK diagram for a higher order differential equation and how to introduce initial conditions into it. Run the simulation from SIMULINK and also from Command window. DAMPED OSCILLATOR : Solve the damped oscillator problem d 2x dx + 5 + 9 x = u (t ) 2 dt dt dx & = x(0) = −2 dt x(0) = 2 Assume that u(t) = 0. that is. there is no input. In this way we have constructed the left-hand side of the equation. 56 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG You can change the Stop time according to your needs. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. The latter is the innput to the 2 and its output is dt dt second integrator producing x(t) at its output. BANGALORE.

x(t) from the output of the second integrator and u(t). so a gain is required. Here x(t) must also be multiplied by 9. The initial values are added to the integrators.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG d 2x Since the second derivative is equal to the right hand side. we collect it term by term. BANGALORE. The first figure is SIMULINK scope and the dt second is the result from Command window simulation. . below. The final configuration is given below. the step input need dt must be generated. The solution x(t) and dx are shown in Fig. All these items are to be summed up so a sum block is also needed. 57 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. The resulting configuration is given below. In order to do that we dt 2 dx from the output of the first integrator. set up the initial conditions by clicking the integrators one at a time and making appropriate changes. Next.

Change the coefficient 5 to 1. dx . i. 58 . It is due to display graphics. the result is a sinusoidal. not enough points have been saved to have a smooth presentation.4 s is not real. BANGALORE. This is not the case. Increasing the damping will result in damping oscillations. The result is shown below. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.e. To see the effect better. If the coefficient The damping factor can be changed by changing the coefficient 5 in front of dt is zero (no damping). it should be smooth. First you might suspect numerical difficulties (there are none) due to too large a step size. Complete the study to obtain the following responses. start with less damping.. Note that here time has been eliminated.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The sharpness of the lower curve around t = 0. Let us also plot a phase plane plot (x vs dx/dt).

59 . Physical interpretation: In origin both position and velocity are zero. click the XY Graph open and adjust the scales. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. Adjusting also the Sample time results in smooth picture. It converges towards the origin. In order to see the whole picture. BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG XY Graph does not adjust the scales automatically. CONCLUSION: A stable system.

Evaluating Polynomials using ‘polyval’ »a=[1 2 1]. if m>=n z=x+[zeros(1. »c=conv(a. Plotting Complex Frequency Response of H(s) using ‘freqs’ » b=[1 0 1].m-n).alpha.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG REVIEW: 1.0000 3. Inverse Laplace Transform using ‘ilaplace’ (this was not introduced in EE 311) » syms F s » F=(s^2+1)/(s^3+6*s^2+11*s+6).0000 -2. Adding Polynomials.n-m). 6. % A(s) »[gamma. % B(s) »a=[1 6 11 6].0000 -2. Finding the roots of a polynomial using ‘roots’ »a=[1 10 35 50 24]. end 4. Multiplying Polynomials using ‘conv’ »a=[1 2 1].b=[1 4 3]. For typical systems the transfer function can be expressed as a rational function.a) gamma = 5. Only polynomials with the same length can be added together. »polyval(a.0000 -5.0000 -1.n=length(y).b) c= 1 6 12 10 3 -1.0000 2.k]=residue(b.[1:3]) ans = 4 9 16 5.0000 1.0000 k = [] 7.0000 alpha = -3. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.x].y]. such as B( s) s2 +1 s2 +1 H ( s) = = = 3 A( s ) ( s + 1)( s + 2)( s + 3) s + 6 s 2 + 11s + 6 Partial Fraction Expansion using ‘residue’ »b=[1 0 1]. BANGALORE. 60 . »r=roots(a) r= -4. m=length(x). »ilaplace(F) ans = 5*exp(-3*t)-5*exp(-2*t)+exp(-t) 8.0000 -3. else z=y+[zeros(1.

BANGALORE. 61 . » freqs(b.a) % The output of this is seen in Figure One below. SIMULINK is a powerful simulation tool provided by MATLAB. It allows for analysis/simulation of interconnections of dynamic systems (both continuous-time and discrete-time).MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG » a=[1 6 11 6].[1 6 11 6]). s2 +1 s3 +6s2 +11s+6 Step T ransfer Fcn S co p e si m out T o Workspace Figure Three SIMULINK diagram for the step response of the system used in Figures One and Two NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. B o d e D i a g ra m 0 -5 0 Magnitude (dB) -1 0 0 -1 5 0 -2 0 0 9 0 4 5 Phase (deg) 0 -4 5 -9 0 1 0 -1 1 0 0 1 0 F re q u e n c y (ra d / se c ) 1 1 0 2 Figure Two Bode plot of the same system from Figure One SIMULINK model : Now we wish to use SIMULINK to simulate the system. e.. see the output when the input is a step function (see the Figure Three below). » bode(sys) % This is shown in Figure Two below.g. Figure One Output of ‘freqs’ Create Bode Diagrams using ‘bode’ (frequency response with dB magnitude plot) » sys=tf([1 0 1]. 10 0 Magnitude 10 -2 10 -4 10 F re q u e n c y (ra d / s ) 100 Phase (degrees) 50 0 -5 0 -1 0 0 0 10 1 10 F re q u e n c y (ra d / s ) 0 10 1 9.

The root locus must have n branches.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Root Locus Closed-Loop Poles The root locus of an (open-loop) transfer function H(s) is a plot of the locations (locus) of all possible closed loop poles with proportional gain k and unity feedback: Y ( s) KH ( s ) = R( s ) 1 + KH ( s ) and thus the poles of the closed loop system are values of s such that 1 + K H(s) = 0. the poles of the closed-loop system are b(s) = 0 or the zeros of H(s). If H(s) has more poles than zeros (as is often the case). In the limit as k -> infinity. the poles of the closed-loop system are a(s) = 0 or the poles of H(s). The number of zeros at infinity is n-m. the closed-loop system will be unstable. In the limit as k -> 0. so even though the system has three or four poles. m < n and we say that H(s) has zeros at infinity. In this case. where n is the number of poles of H(s). it may still act like a second or even first order system depending on the location(s) of the dominant pole(s). Plotting the root locus of a transfer function Consider an open loop system which has a transfer function of NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. the limit of H(s) as s -> infinity is zero. The closed-loop transfer function is: If we write H(s) = b(s)/a(s). BANGALORE. 62 . Since the root locus is actually the locations of all possible closed loop poles. The poles that are closest to the imaginary axis have the greatest influence on the closed-loop response. and is the number of branches of the root locus that go to infinity (asymptotes). We will consider all positive values of k. If any of the selected poles are on the right half plane. the number of poles minus the number of zeros. No matter what we pick k to be. each branch starts at a pole of H(s) and goes to a zero of H(s). then this equation has the form: Let n = order of a(s) and m = order of b(s) [the order of a polynomial is the highest power of s that appears in it]. from the root locus we can select a gain such that our closed-loop system will perform the way we want. the closed-loop system must always have n poles.

we need an overshoot less than 5% (which means a damping ratio Zeta of greater than 0.8).7) and a rise time of 1 second (which means a natural frequency Wn greater than 1.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG How do we design a feed-back controller for the system by using the root locus method? Say our design criteria are 5% overshoot and 1 second rise time. To determine what part of the locus is acceptable. in between these lines.7.8 and outside the circle Wn > 1.8. Wn) On the plot above.Wn) to plot lines of constant damping ratio and natural frequency. Its two arguments are the damping ratio (Zeta) and natural frequency (Wn) [these may be vectors if you want to look at a range of acceptable values].7 and outside of the lines Zeta < 0.[1 5]). Wn=1.8. Make a MATLAB file called rl.m. sys=tf(num.7. 63 .8. we can use the command sgrid(Zeta. the poles will have Zeta > 0. In our problem. rlocus(sys) axis([-22 3 -15 15]) Choosing a value of K from the root locus The plot above shows all possible closed-loop pole locations for a pure proportional controller. Enter the transfer function. inside the circle. Obviously not all of those closed-loop poles will satisfy our design criteria. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.7. BANGALORE. den=conv(conv([1 0]. Wn < 1. the two dotted lines at about a 45 degree angle indicate pole locations with Zeta = 0. and the command to plot the root locus: num=[1 7].den). sgrid(zeta.[1 20])).conv([1 15]. Enter in the MATLAB command window: zeta=0. The semicircle indicates pole locations with a natural frequency Wn = 1.

So in this case we need only a proportional controller to move the poles to the desired region. So now we know only the part of the locus outside of the semicircle and in between the two lines are acceptable. Remember they will affect the response too. You need to include the proportional gain that you have chosen. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. look at the help file for the MATLAB function feedback. which can find the closed-loop transfer function with a gain in the feedback loop. 64 . or let MATLAB do it for you sys_cl= feedback(k*sys. You can use rlocfind command in MATLAB to choose the desired poles on the locus: [k. and to make the rise time shorter than 1 second. you need to know the closedloop transfer function. You could compute this using the rules of block diagrams. Note that since the root locus may has more than one branch. Closed-loop response : In order to find the step response. when you select a pole. You may want to select the points indicated in the plot below to satisfy the design criteria.poles] = rlocfind(sys) Click on the plot the point where you want the closed-loop pole to be. BANGALORE. Check out the step response of your closed-loop system: step(sys_cl) As we expected. this response has an overshoot less than 5% and a rise time less than 1 second. so the closed-loop system will be stable. All the poles in this location are in the lefthalf plane. the poles have to be outside of the white dotted semicircle. We can go ahead and use the chosen k as our proportional controller.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Going back to our problem. From the plot above we see that all the poles selected (all the "+" signs) are at reasonable positions. Unity feedback is assumed. From the plot above we see that there is part of the root locus inside the desired region. the poles have to be in between the two white dotted lines. to make the overshoot less than 5%. you may want to find out where the other pole (poles) are. If you have a non-unity feedback situation.1) The two arguments to the function feedback are the numerator and denominator of the open-loop system.

The signal (u) just past the controller is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error. let's take a look at how the PID controller works in a closed-loop system using the schematic shown above. and the new output (Y) will be obtained. The variable (e) represents the tracking error. 65 . In this tutorial. we will consider the following unity feedback system: Plant: A system to be controlled Controller: Provides the excitation for the plant. the difference between the desired input value (R) and the actual output (Y).MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG PID Controller Introduction This tutorial will show you the characteristics of the each of proportional (P). This signal (u) will be sent to the plant. BANGALORE. and the derivative (D) controls. and how to use them to obtain a desired response. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. This new output (Y) will be sent back to the sensor again to find the new error signal (e). the integral (I). and the controller computes both the derivative and the integral of this error signal. This process goes on and on. This error signal (e) will be sent to the PID controller. The controller takes this new error signal and computes its derivative and its integral again. Designed to control the overall system behavior The three-term controller The transfer function of the PID controller looks like the following: • • • Kp = Proportional gain KI = Integral gain Kd = Derivative gain First.

A derivative control (Kd) will have the effect of increasing the stability of the system. the table should only be used as a reference when you are determining the values for Ki. and improving the transient response. CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR Kp Ki Kd Decrease Decrease Small Change Increase Increase Decrease Small Change Increase Decrease Decrease Eliminate Small Change Note that these correlations may not be exactly accurate. reducing the overshoot. Ki. Kd. In fact. Kp and Kd. An integral control (Ki) will have the effect of eliminating the steady-state error. and Ki on a closed-loop system are summarized in the table shown below. changing one of these variab can change the effect of the other two. because Kp. spring. and damper problem.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The characteristics of P. I. For this reason. Example Problem Suppose we have a simple mass. we get The transfer function between the displacement X(s) and the input F(s) then becomes NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. but it may make the transient response worse. and Kd are dependent on each other. The modeling equation of this system is (1) Taking the Laplace transform of the modeling equation (1). and D controllers A proportional controller (Kp) will have the effect of reducing the rise time and will reduce but never eliminate the steady-state error. BANGALORE. Effects of each of controllers Kp. 66 .

we see that the proportional controller (Kp) reduces the rise time. plant=tf(num. Proportional control From the table shown above. The closed-loop transfer function of the above system with a proportional controller is: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.5 seconds.den). so 0. and the settling time is about 1. Let's design a controller that will reduce the rise time. den=[1 10 20]. and eliminates the steady-state error. This corresponds to the steady-state error of 0. quite large indeed.95. 67 .s/m k = 20 N/m F(s) = 1 Plug these values into the above transfer function The goal of this problem is to show you how each of Kp. Ki and Kd contributes to obtain • • • Fast rise time Minimum overshoot No steady-state error Open-loop step response Let's first view the open-loop step response. Furthermore. the rise time is about one second.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Let • • • • M = 1kg b = 10 N.05 is the final value of the output to an unit step input. Create a new m-file and add in the following code: num=1. reduce the settling time. step(plant) Running this m-file in the MATLAB command window should give you the plot shown below. BANGALORE. increases the overshoot. The DC gain of the plant transfer function is 1/20. and reduces the steady-state error.

we see that the derivative controller (Kd) reduces both the overshoot and the settling time.1). contr=tf([Kd Kp].t) Running this m-file in the MATLAB command window should give you the following plot. t=0:0. increased the overshoot. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. sys_cl=feedback(contr*plant. contr=Kp. 68 . let's take a look at a PD control.01:2. Kd=10. step(sys_cl. Note: The MATLAB function called feedback was used to obtain a closed-loop transfer function directly from the open-loop transfer function (instead of computing closed-loop transfer function by hand). The above plot shows that the proportional controller reduced both the rise time and the steadystate error. The closed-loop transfer function of the given system with a PD controller is: Let Kp equal 300 as before and let Kd equal 10. Enter the following commands into an m-file and run it in the MATLAB command window. and decreased the settling time by small amount. From the table shown above. BANGALORE.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Let the proportional gain (Kp) equal 300 and change the m-file to the following: Kp=300. Proportional-Derivative control Now. Kp=300.1).

sys_cl=feedback(contr*plant. Create an new m-file and enter the following commands. t=0:0. and had a small effect on the rise time and the steady-state error.01:2. let's take a look at a PI control. Proportional-Integral control Before going into a PID control.t) This plot shows that the derivative controller reduced both the overshoot and the settling time. Ki=70. For the given system. step(sys_cl. t=0:0. the closed-loop transfer function with a PI control is: Let's reduce the Kp to 30.t) Run this m-file in the MATLAB command window. step(sys_cl. BANGALORE.01:2.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG sys_cl=feedback(contr*plant. 69 . we see that an integral controller (Ki) decreases the rise time. Kp=30.1).[1 0]).1). and eliminates the steady-state error. and let Ki equal 70. contr=tf([Kp Ki]. and you should get the following plot. increases both the overshoot and the settling time. From the table. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.

the gains Kp=350. let's take a look at a PID controller. t=0:0.01:2. enter the following commands to an m-file and run it in the command window. To confirm. contr=tf([Kd Kp Ki]. The closed-loop transfer function of the given system with a PID controller is: After several trial and error runs. BANGALORE. Ki=300. sys_cl=feedback(contr*plant. Ki=300. Kd=50.1). Kp=350. The above response shows that the integral controller eliminated the steady-state error. You should get the following step response. Proportional-Integral-Derivative control Now. step(sys_cl. 70 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG We have reduced the proportional gain (Kp) because the integral controller also reduces the rise time and increases the overshoot as the proportional controller does (double effect). and Kd=50 provided the desired response.t) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.[1 0]).

else ys_prime = [ys ys_prime]. ys = y(length(y).dtspan. yp = []. er1 = er . follow the steps shown below to obtain a desired response. for i=1:dt:Tf dtspan = [i i+dt].2*eold. % Simulation time yold = 0. For example.er2). (yold-yold1)]. please keep in mind that you do not need to implement all three controllers (proportional.eold. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 3. You can always refer to the table shown in this "PID Tutorial" page to find out which controller controls what characteristics. % Reference to follow Tf = 1000.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Now. % Second derivative of error eold = refe.er1. er = refe. eold2 = eold . init_con = [yold . % Initial conditions for the diffirential equations options = []. if a PI controller gives a good enough response (like the above example). BANGALORE. derivative. Keep the controller as simple as possible. we have obtained a closed-loop system with no overshoot. 71 . if not necessary. 2. and no steady-state error. T=360.options. eold = er. 5. and integral) into a single system. % System Parameters refe = 10.er. if i <= theta ys_prime = [0 ys_prime]. General tips for designing a PID controller When you are designing a PID controller for a given system. [t. er = refe . Ki. end yold = ys_prime(1).y] = ode45(@pid_ctrl. theta= 80.yold1=0. yold1 = yold. Code: % This Matlab code simulates a PID controller for a fisrt order time delay system % G(s) = (K*e(-theta*s))/(T*s+1) clear all.init_con. er2 = er + eold2 . dt = 1.9. eold2 = 0. 4.yold. Obtain an open-loop response and determine what needs to be improved Add a proportional control to improve the rise time Add a derivative control to improve the overshoot Add an integral control to eliminate the steady-state error Adjust each of Kp. then you don't need to implement a derivative controller on the system. clc. % First derivative of error er2 = 0. % Error (Initial error = Reference) er1 = 0. Lastly. and Kd until you obtain a desired overall response.1). fast rise time. K=14. ys_prime = []. 1.

er1.m function yprime = pid_ctrl(t.5. For example. the phase is given in degrees. num = 50.den).9. pid_ctrl. you can use the MATLAB bode command. title('Output of the system with PID Controller'). % PID Controller parametrs yprime = [y(2). and the magnitude is given as the gain in decibels.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG yp = [yp yold]. a Bode plot is the representation of the magnitude and phase of G(j*w) (where the frequency vector w contains only positive frequencies). xlabel('Time'). K=14. Ki = 0. Bode Plots As noted above. grid on.y. To see the Bode plot of a transfer function.05. den = [1 9 30 40]. bode(sys) displays the Bode plots for the transfer function: 50 ----------------------s^3 + 9 s^2 + 30 s + 40 Please note the axes of the figure. sys = tf(num.er. ylabel('Output'). Kd = 3. % System parametrs Kp = 0. The frequency is on a logarithmic scale. ((1/T)*(-y(2)+ K*Kd*er2 + K*Kp*er1 + K*Ki*er))]. 72 .er2) T=360. Note: a decibel is defined as 20*log10 ( |G(j*w| ) Gain and Phase Margin Let's say that we have the following system: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. BANGALORE. end plot(yp).

The gain margin is defined as the change in open loop gain required to make the system unstable. One nice thing about the phase margin is that you don't need to replot the Bode in order to find the new phase margin when changing the gains. a time delay can be represented as a block with magnitude of 1 and phase w*time_delay (in radians/second). adding gain only shifts the magnitude plot up. suppose you entered the command bode(sys). For now. Finding the phase margin is simply the matter of finding the new cross-over frequency and reading off the phase margin. Wgc). The phase margin also measures the system's tolerance to time delay. If there is a time delay greater than 180/Wpc in the loop (where Wpc is the frequency where the phase shift is 180 deg). If you recall. the gain margin is the difference between the magnitude curve and 0dB at the point corresponding to the frequency that gives us a phase of -180 deg (the phase cross over frequency. the system will become unstable in closed loop.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG where K is a variable (constant) gain and G(s) is the plant under consideration. For example. Wpc). The phase margin is the difference in phase between the phase curve and -180 deg at the point corresponding to the frequency that gives us a gain of 0dB (the gain cross over frequency. That is. BANGALORE. 73 . This is the equivalent of changing the y-axis on the magnitude plot. Likewise. Systems with greater gain margins can withstand greater changes in system parameters before becoming unstable in closed loop. we won't worry about where all this comes from and will concentrate on identifying the gain and phase margins on a Bode plot. The phase margin is defined as the change in open loop phase shift required to make a closed loop system unstable. The time delay can be thought of as an extra block in the forward path of the block diagram that adds phase to the system but has no effect the gain. You will get the following bode plot: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. Keep in mind that unity gain in magnitude is equal to a gain of zero in dB.

Let's check it out: margin(sys) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. your bode plot may not be exactly the same shape. by entering the command bode(100*sys). and a graphical representation of these on the Bode plot. BANGALORE. the same as the second Bode plot. the gain and phase cross over frequencies. depending on the scale used): As you can see the phase plot is exactly the same as before. by using MATLAB. It should be about -60 degrees. You should get the following plot (note we changed the axis so the scale would be the same as the plot above. We can find the gain and phase margins for a system directly. and the magnitude plot is shifted up by 40dB (gain of 100). This command returns the gain and phase margins. The phase margin is now about -60 degrees. find where the curve crosses the -40dB line. Now suppose you added a gain of 100. and read off the phase margin. look at the first Bode plot. Just use the margin command.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG You should see that the phase margin is about 100 degrees. Try this. This same result could be achieved if the y-axis of the magnitude plot was shifted down 40dB. 74 .

our bandwidth frequency will be the frequency corresponding to a gain of -3 dB.4 rad/s. We can also read off the plot that for an input frequency of 0. den = [1 0. bode (sys) Since this is the closed-loop transfer function. Sinusoidal inputs with frequency greater than Wbw are attenuated (in magnitude) by a factor of 0. sys = tf(num. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. We will find that sinusoidal inputs with frequency less than Wbw (the bandwidth frequency) are tracked "reasonably well" by the system.5 s + 1 First of all. For a complete derivation of this approximation.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Bandwidth Frequency The bandwidth frequency is defined as the frequency at which the closed-loop magnitude response is equal to -3 dB. We must also keep in mind that we want to view the steady state response.3.707 or greater (and are also shifted in phase). 75 . For an input frequency of 3 rad/sec. Therefore. num = 1. In order to illustrate the importance of the bandwidth frequency. consult your textbook. consider a sinusoidal input with a frequency lower than Wbw. We can use the lsim command to simulate the response of the system to sinusoidal inputs.5 1]. Therefore. First.den). we will use a second-order system approximation and say that the bandwidth frequency equals the frequency at which the open-loop magnitude response is between -6 and . let's find the bandwidth frequency by looking at the Bode plot: num = 1. w = 0.3 radians. we find that it is approximately 1. looking at the plot. we will modify the axes in order to see the steady state response clearly (ignoring the transient response). we will show how the output changes with different input frequencies.5dB. the output magnitude should be about -20dB (or 1/10 as large as the input) and the phase should be nearly -180 (almost exactly out-of-phase). Let's say that we have the following closed-loop transfer function representing a system: 1 --------------s^2 + 0. when we design via frequency response. the output sinusoid should have a magnitude about one and the phase should be shifted by perhaps a few degrees (behind the input).7. we are interested in predicting the closed-loop behavior from the open-loop response. assuming the open loop phase response is between -135 deg and -225 deg. However. BANGALORE.

t.1:100. then the closed-loop system will be stable. if we set the frequency of the input higher than the bandwidth frequency for the system.den).t] = lsim(sys.y. sys = tf(num. 76 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.-2. sys = tf(num. we get a very distorted response (with respect to the input): w = 3. Feel free to experiment and view the response for several different frequencies w. note that the magnitude is about 1/10 that of the input.den).100.u.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG den = [1 0. plot(t.u.u) axis([50. den = [1 0.t] = lsim(sys. [y. 1]) Again.t.y. and see if they match the Bode plot. If the gain cross over frequency is less than the phase cross over frequency (i.5 1].t). . u = sin(w*t). t = 0:0. Closed-loop performance In order to predict closed-loop performance from open-loop frequency response. t = 0:0. we need to have several concepts clear: • • The system must be stable in open loop if we are going to design via Bode plots. [y. and that it is almost exactly out of phase (180 degrees behind) the input. 100.2]) Note that the output (blue) tracks the input (purple) fairly well. However.e.u) axis([90. -1. it is perhaps a few degrees behind the input as expected. BANGALORE.t). as predicted. Wgc < Wpc). num = 1.5 1]. u = sin(w*t).1:100. plot(t.

the rise time is 1. sys = tf(num. We can use this concept with caution if the phase margin is greater than 60 deg. Since the bandwidth frequency is roughly the same as the natural frequency (for a first order system of this type). There are two ways of solving this problem: one is graphical and the other is numerical. 77 .8/BW=1. the graphical approach is best. we can see that the bandwidth frequency is around 10 rad/sec. there should be no overshoot. Let's use these concepts to design a controller for the following system: Where Gc(s) is the controller and G(s) is: 10 ---------1. bode(sys) There are several several characteristics of the system that can be read directly from this Bode plot. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. let's look at the Bode plot. Create an m-file with the following code: num = 10. Maximum overshoot must be less than 40%. A very rough estimate that you can use is that the bandwidth is approximately equal to the natural frequency.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG • • For second-order systems. BANGALORE. The relation damping ratio = pm/100 only holds for PM < 60/ Since the system is first-order. First.1]. First of all. den = [1.8/10=1.25. Within MATLAB. so we will say the rise time is about 2 seconds. Settling time must be less than 2 secs. so that is the approach we will use.8 seconds. This is a rough estimate.25s + 1 The design must meet the following specifications: • • • Zero steady state error. the closed-loop damping ratio is approximately equal to the phase margin divided by 100 if the phase margin is between 0 and 60 deg. The phase margin for this system is approximately 95 degrees.den).

We choose a PI controller because it will yield zero steady state error for a step input. The gain is 20dB (magnitude 10). and has a steady-state error of about 9%. Therefore. If our system was type one instead of type zero. Now we need to choose a controller that will allow us to meet the design criteria.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The last major point of interest is steady-state error. sys_cl = feedback(sys. has no overshoot. the PI controller has a zero. or Ka) is found from the intersection of the low frequency asymptote with the w=1 line. which we can place. This gives us additional design flexibility to help us meet our criteria. The steady-state error can be read directly off the Bode plot as well. Recall that a PI controller is given by: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.091. 78 . The steady-state error is 1/(1+Kp)=1/(1+10)=0. This can be done by adding the following two lines of code into the MATLAB command window. the intersection is easy to find. Kv. Also. The system has a rise time of about 2 seconds. The constant (Kp. The magnitude at this point is the constant. step(sys_cl) As you can see. we know this system is of type zero. our predictions were very good. the constant for the steady-state error would be found in a manner similar to the following Let's check our predictions by looking at a step response plot. What this means is that the constant for the error function it 10.1). Since the Bode plot of this system is a horizontal line at low frequencies (slope = 0). Just extend the low frequency line to the w=1 line. BANGALORE.

Let's see how the integrator portion of the PI or affects our response.2)) Our phase margin and bandwidth frequency are too small. Let's place the zero at 1 for now and see what happens. Therefore. we can start our design.denPI). we find that the damping ratio corresponding to this overshoot is approximately 0. Therefore.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG K*(s+a) Gc(s) = ------s The first thing we need to find is the damping ratio corresponding to a percent overshoot of 40%. Plugging in this value into the equation relating overshoot and damping ratio (or consulting a plot of this relation).2)) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. plant = tf(num. We will add gain and phase with a zero. logspace(0. plant = tf(num. contr = tf(numPI.28.25 1].den). Now that we know our desired phase margin and bandwidth frequency. Change your m-file to look like the following (this adds an integral term but no proportional term): num = 10. contr = tf(numPI. bode(contr * plant. logspace(0. denPI = [1 0]. 79 . our bandwidth frequency will be the frequency corresponding to a gain of approximately -7 dB. We must have a bandwidth frequency greater than or equal to 12 if we want our settling time to be less than 1. den = [1.den). denPI = [1 0].denPI). numPI = 1. den = [1. numPI = [1 1].75 seconds which meets the design specs. Remember that we are looking at the open-loop Bode plots. Change your m-file to look like the following: num = 10. BANGALORE.25 1]. bode(contr * plant. our phase margin should be at least 30 degrees.

den). Although satisfactory. step(sys_cl) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.2)) That looks really good. numPI = 5*[1 1]. Our phase margin is greater than 60 degrees (even less overshoot than expected) and our bandwidth frequency is approximately 11 rad/s. 80 .denPI). BANGALORE. contr = tf(numPI. denPI = [1 0]. den = [1. bode(contr * plant.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG It turns out that the zero at 1 with a unit gain gives us a satisfactory answer. let's try to get a higher bandwidth frequency without changing the phase margin too much. Let's look at our step response and verify our results. Add the following two lines to your m-file: sys_cl = feedback(contr * plant.25 1]. logspace(0. This will make the gain shift and the phase will remain the same. plant = tf(num. num = 10. the response is not quite as good as we would like.1). Therefore. Let's try to increase the gain to 5 and see what happens. which will give us a satisfactory response.

we can use them to our advantage when we are designing a controller: bode(1. [1 0]) 1 --s bode(1. [1 1]) 1 -----s + 1 bode([1 0]. if we know the frequency response of simple functions. Therefore.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Sample Bode Plots Let's say that we have the following system: We can view the open loop Bode plot of this system by looking at the Bode plot of Gc(s)G(s). we can also view the Bode plots of G(s) and of Gc(s) and add them graphically. 1) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. However. BANGALORE. 81 .

BANGALORE. Let's see a couple of examples: bode(1. If we have a pole or zero farther from the origin.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG s bode([1 1]. 1) s+1 Note that the location of the pole or zero(a) will greatly affect the frequency response. 0. 10]) 1 -----s + 10 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.[ 1.1 bode(1. the response at lower frequencies will undergo the most drastic changes. 82 . If we have a pole close to the origin. the response at higher frequencies will undergo the most drastic changes.[ 1.1]) 1 -----s + 0. Also remember that a change in gain will shift the entire gain response up or down and will not affect the phase.

83 . NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.1) s + 10 Modifying the location of these poles or zeros.1) s + 0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG bode([1. The Nyquist Diagram The Nyquist plot allows us to predict the stability and performance of a closed-loop system by observing its open-loop behavior. 0. The Nyquist criterion can be used for design purposes regardless of open-loop stability (remember that the Bode design methods assume that the system is stable in open loop). Therefore.1]. BANGALORE.1 bode([1. we use this criterion to determine closed-loop stability when the Bode plots display confusing information. we can manipulate the frequency response of the combined system to something that will suit our purposes. 10].

and we must loop around them when we are plotting the contour. When studying feedback controls.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The Nyquist diagram is basically a plot of G(j* w) where G(s) is the open-loop transfer function and w is a vector of frequencies which encloses the entire right-half plane. 84 . the MATLAB nyquist command does not take poles or zeros on the jw axis into account and therefore produces an incorrect plot. we can use either the nyquist command or nyquist1. If we have a pole on the jw axis. Encirclements of the origin are counted as positive if they are in the same direction as the original closed contour or negative if they are in the opposite direction. As we mentioned before. Such a contour would look as follows: Please note that the contour loops around the pole on the jw axis. please download and use nyquist1. we are not as interested in G(s) as in the closed-loop transfer function: G(s) --------1 + G(s) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. We will represent positive frequencies in red and negative frequencies in green. BANGALORE. The frequency vector used in plotting the Nyquist diagram usually looks like this (if you can imagine the plot stretching out to infinity): However.m. both positive and negative frequencies (from zero to infinity) are taken into account. In drawing the Nyquist diagram. or if we have pole-zero cancellation. If there are no poles or zeros on the jw-axis. G(s) will not be defined at those points. the number of times that the plot of G(s) encircles the origin is equal to the number of zeros of G(s) enclosed by the frequency contour minus the number of poles of G(s) enclosed by the frequency contour. if we have open-loop poles or zeros on the jw axis. we have to use nyquist1.m. The Cauchy criterion The Cauchy criterion (from complex analysis) states that when taking a closed contour in the complex plane. To correct this. and mapping it through a complex function G(s).

5]). sys = tf(num.5 ------s . and lnyquist commands with this particular function. To correct this. We will see the difference between using the nyquist.m function to your files.5.0. Therefore. however. den = [1 0 0]. Since we are interested in the closed-loop stability. More details on how to determine this will come later. you can add the lnyquist. we want to know if there are any closed-loop poles (zeros of 1 + G(s)) in the right-half plane.m command plots the Nyquist diagram using a logarithmic scale and preserves the characteristics of the -1 point. nyquist(sys) nyquist1(sys) lnyquist(sys) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. then G(s) will enclose the point -1.den). the behavior of the Nyquist diagram around the -1 point in the real axis is very important. BANGALORE. the axis on the standard nyquist diagram might make it hard to see what's happening around this point. we will define the following transfer function and view the Nyquist plot: 0. The lnyquist.[1 -0. nyquist1.5 sys=tf(0. nyquist(sys) Now we will look at the Nyquist diagram for the following transfer function: s + 2 ----s^2 Note that this function has a pole at the origin. num = [1 2]. To view a simple Nyquist plot using MATLAB. 85 .MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG If 1+ G(s) encircles the origin.

Keeping careful track of open. N is positive.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Note that the nyquist plot is not the correct one. In this case the equation becomes Z = P . Now ask yourself: How many times did I turn my head a full 360 degrees? Again. and if the motion is anti-clockwise. The P and Z variab remain the same. if the motion was clockwise. but it's hard to see what happens close to the -1 point. BANGALORE.and closed-loop transfer functions. the nyquist1 plot is correct. N is negative.N. It is very important (and somewhat tricky) to learn how to count the number of times that the diagram encircles -1.P). Throughout these tutorials. The Nyquist criterion then states that: • • • • • P = the number of open-loop (unstable) poles of G(s)H(s) N = the number of times the Nyquist diagram encircles -1 clockwise encirclements of -1 count as positive encirclements counter-clockwise (or anti-clockwise) encirclements of -1 count as negative encirclements Z = the number of right half-plane (positive. Closed Loop Stability Consider the negative feedback system: Remember from the Cauchy criterion that the number N of times that the plot of G(s)H(s) encircles -1 is equal to the number Z of zeros of 1 + G(s)H(s) enclosed by the frequency contour minus the number P of poles of 1 + G(s)H(s) enclosed by the frequency contour (N = Z . and the lnyquist plot is correct and has an appropriate scale. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. Another way of looking at it is to imagine you are standing on top of the -1 point and are following the diagram from beginning to end. 86 . real) poles of the closed-loop system Z = P + N The important equation which relates these three quantities is: Note: This is only one convention for the Nyquist criterion. we will use a positive sign for clockwise encirclements. you should convince yourself that: • • the zeros of 1 + G(s)H(s) are the poles of the closed-loop transfer function the poles of 1 + G(s)H(s) are the poles of the open-loop transfer function. Another convention states that a positive N counts the counter-clockwise or anti-clockwise encirclements of -1. as well as numerators and denominators.

Therefore. If the number of encirclements is less than two or the encirclements are not anti-clockwise. we need two anticlockwise (N = -2) encirclements of the Nyquist diagram in order to have a stable closed-loop system (Z = P + N). The system we will test looks like this: where G(s) is : s^2 + 10 s + 24 --------------s^2 . The first thing we need to do is find the number of positive real poles in our open-loop transfer function: roots([1 -8 15]) ans = 5 3 The poles of the open-loop transfer function are both positive. Now we will see how the system behaves if we increase the gain to 20: nyquist(20*sys) NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. since we have to make sure that our closed-loop system will be stable. the closed-loop system is unstable. nonzero number. We can also use the Nyquist diagram to find the range of gains for a closed-loop unity feedback system to be stable. Therefore.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG Knowing the number of right-half plane (unstable) poles in open loop (P). we can determine the closed-loop stability of the system. If Z = P + N is a positive. we will see that we can only vary this gain within certain limits. However. BANGALORE. 87 . [ 1 -8 15]). nyquist(sys) There are two anti-clockwise encirclements of -1. the system is stable for a gain of 1. our system will be unstable. Let's look at our Nyquist diagram for a gain of 1: sys = tf([ 1 10 24]. This is what we will be looking for: the range of gains that will make this system stable in the closed loop.8 s + 15 This system has a gain K which can be varied in order to modify the response of the closed-loop system. and the number of encirclements of -1 made by the Nyquist diagram (N).

80.5*sys) The system is now unstable. Gain Margin We already defined the gain margin as the change in open-loop gain expressed in decibels (dB). if we decrease the gain. the diagram will contract and the system might become unstable. we know that the system will be stable no matter how much we increase the gain.79. such as : 50 ----------------------s^3 + 9 s^2 + 30 s + 40 Looking at the roots. and 0. Let's see what happens for a gain of 0. required at 180 degrees of phase shift to make the system unstable. Therefore. how much can we vary the gain before this system becomes unstable in closed loop? Let's look at the following figure: NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY.81.5: nyquist(0. We can verify our answers by zooming in on the Nyquist plots as well as by looking at the closed-loop steps responses for gains of 0.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The diagram expanded. 88 . First of all. Now. 0. Now we are going to find out where this comes from. However. let's say that we have a system that is stable if there are no Nyquist encirclements of -1. By trial and error we find that this system will become unstable for gains less than 0.80. we find that we have no open loop poles in the right half plane and therefore no closed-loop poles in the right half plane if there are no Nyquist encirclements of -1. BANGALORE.

j*w)/polyval([1 9 30 40]. Recall that the function is: 50 ----------------------s^3 + 9 s^2 + 30 s + 40 and that the Nyquist diagram can be viewed by typing: sys = tf(50. we realize that if the gain is equal to a. where the diagram crosses the real axis) and -1 represents the amount of increase in gain that can be tolerated before closed-loop instability. Therefore. Now we can proceed to find the gain margin. the gain margin is : GM = 20*log10(a) [dB] We will now find the gain margin of the stable.2174 The answer is: -0. We can then find the value of G(j*w) at this point using polyval: w=sqrt(30). all that we need to do to find the gain margin is find 'a'. The real part also makes sense. The negative real axis area between -1/a (defined as the point where the 180 degree phase shift occurs. we need to find the point where there is exactly 180 degrees of phase shift. so we just need to look at the denominator. BANGALORE. we say that the gain margin is 'a' units.. The imaginary part is zero. for G(j*w) to be real. To do this. When s = j*w. as defined in the preceding figure. If we think about it. The numerator is already real.j*w) You should get the following output from MATLAB ans = -0.that is.2174 + 0i. -1/a = -0. Hence. we mentioned before that the gain margin is usually measured in decibels. This means that the transfer function at this point is real (has no imaginary part).2174 + 0i. nyquist(sys) As we discussed before. However. However. We found that the 180 degrees phase shift occurs at -0. the diagram will touch the -1 point: Therefore.2174 NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 89 . [1 9 30 40 ]). so we know that our answer is correct. We can also verify by looking at the Nyquist plot again. we must have: -j w^3 + 30 j w = 0 which means w=0 (this is the rightmost point in the Nyquist diagram) or w=sqrt(30). This point was previously defined as -1/a. the only terms in the denominator that will have imaginary parts are those which are odd powers of s. polyval(50. we now have 'a'. which is the gain margin. Therefore. open-loop transfer function we viewed before.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG The open-loop system represented by this plot will become unstable in closed loop if the gain is increased past a certain boundary. we need to express the gain margin in decibels..

and measure the phase shift needed for this point to be at an angle of 180 deg.MAT LAB MANUAL DEPT OF ELECTRONICS AND COMMUNICATION ENGG => a = 4. we will only talk about where this concept comes from.6 and zooming in on the Nyquist plot: a = 4. we must also realize that if the diagram is shifted by theta degrees. However. 4. NITTE M EENAKSHI INSTITUTE OF TECHNOLOGY. 90 . and 4. BANGALORE. Therefore. In order to find the point we measure this angle from. find the point in the Nyquist diagram with a magnitude of 1 (gain of zero dB).26 dB We now have our gain margin. We will now verify the accuracy of our results by viewing the zoomed Nyquist diagrams and step responses for gains of 4. Therefore. it will then touch the -1 point at the negative real axis. Let's look at the following graphical definition of this concept to get a better idea of what we are talking about.6.6 => GM = 20*log10( 4. Let's analyze the previous plot and think about what is happening. we draw a circle with radius of 1.6 nyquist(a*sys) The plot appears to go right through the -1 point. the angle required to make this system marginally stable in closed loop is called the phase margin (measured in degrees). making the system marginally stable in closed loop.6) = 13. From our previous example we know that this particular system will be unstable in closed loop if the Nyquist diagram encircles the -1 point. Let's see how accurate it is by using a gain of a = 4. Phase Margin We have already discussed the importance of the phase margin.5.7. We have defined the phase margin as the change in open-loop phase shift required at unity gain to make a closed-loop system unstable.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->