You are on page 1of 59

Advanced Communication Lab (MATLAB)-Programs

INDEX
No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Program Title Introduction to MATLAB Function Plotting. Signal Generation : Sine , Square, Triangular and Unit Step Amplitude Modulation Sampling Discrete Fourier Transform(DFT) using FFT IIR Low pass Butterworth filter Using Bilinear Transformation. IIR High pass Butterworth filter Using Bilinear Transformation. IIR Band pass Butterworth filter Using Bilinear Transformation. IIR Band Stop Butterworth filter Using Bilinear Transformation. IIR Low pass Chebyshev-1 filter Using Bilinear Transformation. IIR High pass Chebyshev-1 filter Using Bilinear Transformation. IIR Band pass Chebyshev-1 filter Using Bilinear Transformation. IIR Band Stop Chebyshev-1 filter Using Bilinear Transformation. FIR Low pass filter Using Kaiser Window. Page No. 03 21 27 33 37 41 43 45 47 49 51 53 55 57 59

MEA Engineering College

ECE Department

Page

1

Advanced Communication Lab (MATLAB)-Programs

Try these commands in command window >>x=[0 .1*pi .2*pi .3*pi .4*pi .5*pi .6*pi .7*pi .8*pi .9*pi pi] x= Columns 1 through 9 0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133

Columns 10 through 11 2.8274 >>y=sin(x) y= Columns 1 through 9 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 3.1416

Columns 10 through 11 0.3090 >> x(3) ans = 0.6283 >> y(5) ans = 0.9511 >> x(1:5) ans = 0 0.3142 0.6283 0.9425 1.2566 0.0000

MEA Engineering College

ECE Department

Page

2

Advanced Communication Lab (MATLAB)-Programs 1. Introduction to MATLAB MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software package, which is used extensively in both academia and industry. It is an interactive program for numerical computation and data visualization, which along with its programming capabilities provides a very useful tool for almost all areas of science and engineering. Unlike other mathematical packages, such as MAPLE or MATHEMATICA, MATLAB cannot perform symbolic manipulations without the use of additional Toolboxes. It remains however, one of the leading software packages for numerical computation.

As you might guess from its name, MATLAB deals mainly with matrices. A scalar is a 1by-1 matrix and a row vector of length say 5, is a 1-by-5 matrix. We will elaborate more on these and other features of MATLAB in the sections that follow. One of the many advantages of MATLAB is the natural notation used. It looks a lot like the notation that you encounter in a linear algebra course. This makes the use of the program especially easy and it is what makes MATLAB a natural choice for numerical computations.

1.1 The basic features Let us start with something simple, like defining a row vector with components the numbers 1, 2,3, 4, 5 and assigning it a variable name, say x. » x = [1 2 3 4 5] x = 1 2 3 4 5

Note that we used the equal sign for assigning the variable name x to the vector, brackets to enclose its entries and spaces to separate them. (Just like you would using the linear algebra notation). We could have used commas ( , ) instead of spaces to separate the entries, or even a combination of the two. The use of either spaces or commas is essential! To create a column vector (MATLAB distinguishes between row and column vectors, as it should) we can either use semicolons ( ; ) to separate the entries, or first define a row vector and take its transpose to obtain a column vector. Let us demonstrate this by defining a column vector Page ECE Department y with entries 6, 7, 8, 9, 10 using both techniques.

MEA Engineering College

3

Advanced Communication Lab (MATLAB)-Programs >> x(7:end) ans = 1.8850 2.1991 2.5133 2.8274 3.1416

>> y(3:-1:1) ans = 0.5878 >> x(2:2:7) ans = 0.3142 0.9425 1.5708 0.3090 0

>> linspace(0,2,11) ans = Columns 1 through 9 0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.4000 1.6000

Columns 10 through 11 1.8000 >> b=x' b= 0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.1416 2.0000

MEA Engineering College

ECE Department

Page

4

Advanced Communication Lab (MATLAB)-Programs » y = [6;7;8;9;10] y = 6 7 8 9 10 » y = [6,7,8,9,10] y = 6 7 8 9 10 » y' ans = 6 7 8 9 10 Let us make a few comments. First, note that to take the transpose of a vector (or a matrix for that matter) we use the single quote ( ' ). Also note that MATLAB repeats (after it processes) what we typed in. Sometimes, however, we might not wish to “see” the output of a specific command. We can suppress the output by using a semicolon ( ; ) at the end of the command line. Finally, keep in mind that MATLAB automatically assigns the variable name ans to anything that has not been assigned a name. In the example above, this means that a new variable has been created with the column vector entries as its value. The variable ans, however, gets recycled and every time we type in a command without assigning a variable, ans gets that value.

1.2 Vectors and matrices We have already seen how to define a vector and assign a variable name to it. Often it is useful to define vectors (and matrices) that contain equally spaced entries. This can be done by specifying the first entry, an increment, and the last entry. MATLAB will automatically figure out how 3, …, 7, 8, you can type

MEA Engineering College

ECE Department

Page

5

many entries you need and their values. For example, to create a vector whose entries are 0, 1, 2,

8274i 3.1416i >> e=d' e= 0 0.1.0.2566i 1.5133i 2.9425 .5133i 2.2.3142i 0.6283i 0.8850i 2.2566 + 1.Advanced Communication Lab (MATLAB)-Programs >> d=complex(x.0.3142i 0.9425i 1.6283 + 0.5708 .' f= 0 0.9425i 1.8274 + 2.6283i 0.6283 .8850 + 1.3.1416i MEA Engineering College ECE Department Page 6 .1991i 2.1.5133 + 2.2.9425 + 0.5133i 2.9425i 1.3142 + 0.3142 .8850 .9425 + 0.1416 + 3.1991 + 2.1.2.0.6283i 0.1991i 2.8850 + 1.8274i 3.8274 .x) d= Columns 1 through 5 0 0.1991 .5708i 1.8274i Column 11 3.1416i >> f=d.1416 .5133 .1991 + 2.5708 + 1.1416 + 3.2566i Columns 6 through 10 1.8274 + 2.6283 + 0.3142i 0.2566 .8850i 2.3142 + 0.8850i 2.5708i 1.5708i 1.1991i 2.2566i 1.5133 + 2.2566 + 1.5708 + 1.

Page MEA Engineering College ECE Department 7 . To obtain a vector whose entries are 0. and 8. Since we omitted the increment value. The following command lists the first 4 entries of the vector v. instead of brackets. 2. The two colons ( : ) “tell” MATLAB to fill in the (omitted) entries using the specified increment value. to refer to the entries of the vector.Advanced Communication Lab (MATLAB)-Programs » u = [0:8] u = 0 1 2 3 4 5 6 7 8 Here we specified the first entry 0 and the last entry 8. the increment value 2. To define a matrix A. you enter each row of the matrix as a row vector (remember to separate the entries either by commas or spaces) and you separate the rows by semicolons ( . MATLAB automatically filled-in the (omitted) entries using the (default) increment 1. 4. That is. you can treat it like a column of row vectors. you can use the same notation you used to create the vector: » v(1:3) ans = 0 2 4 Note that we used parentheses. and the last entry 8. You could also specify an increment as is done in the next example. separated by a colon ( : ). using the increment value 2 : » v(1:2:4) ans = 0 4 Defining a matrix is similar to defining a vector. MATLAB will allow you to look at specific parts of the vector. to only look at the first 3 entries in the vector v. for example. If you want. MATLAB automatically assumes that the increment is 1. 6. ). you can type in the following line: » v = [0:2:8] v = 0 2 4 6 8 Here we specified the first entry 0.

9 10 11 12] g= 1 5 9 2 6 10 3 4 7 8 11 12 >> h=[1 1 1 1.2 2 2 2.5 6 7 8. >> g./h MEA Engineering College ECE Department Page 8 ans = .*h ans = 1 10 27 2 3 4 12 14 16 30 33 36 >> g*h ??? Error using ==> mtimes Inner matrix dimensions must agree.Advanced Communication Lab (MATLAB)-Programs >> g=[1 2 3 4.3 3 3 3] h= 1 2 3 >> g+h ans = 2 7 12 3 4 5 8 9 10 13 14 15 1 2 3 1 2 3 1 2 3 >> 2*g-h ans = 1 3 5 7 8 10 12 14 15 17 19 21 >> g.

6 7 8] A = 1 2 3 3 4 5 6 7 8 We can avoid separating each row with a semicolon if we use a carriage return instead. thus » A(2. the number 5 lies in the 2nd row. This means that A(2. we get an error message. there is no 4th row and MATLAB realizes that. You can refer to a particular entry in a matrix by using parentheses. 1st column. we could have defined A as follows » A = [1 2 3 3 4 5 6 7 8] A = 1 2 3 3 4 5 6 7 8 which is perhaps closer to the way we would have defined A by hand using the linear algebra notation. 3 4 5.Advanced Communication Lab (MATLAB)-Programs » A = [1 2 3. MEA Engineering College 9 . Since A is a 3-by-3 matrix. For example. 2nd column.3) refers to the number 5 in the above example and A(3.3) ans = 5 The order of rows and columns follows the convention adopted in the linear algebra notation. In this case MATLAB told us exactly what the Page ECE Department problem was. which is in the 3rd row. Note MATLAB’s response when we ask for the entry in the 4th row. In other words. » A(4.1) ??? Index exceeds matrix dimensions.2) refers to the number 7. 3rd column of A. As expected. The error messages that we get from MATLAB can be quite informative when trying to find out what went wrong.

0000 2.5000 3.5000 3.0000 0.0000 4.1250 0.0000 >> 1.0000 4.5000 4.\g ans = 1.1667 0.0909 0.3333 3.2500 0.^2 ans = 1 4 9 16 25 36 49 64 81 100 121 144 >> 2.0000 3.0000 3.3333 3.6667 4.0000 4.0000 3.Advanced Communication Lab (MATLAB)-Programs 1.0000 >> h.3333 0.6667 4./g ans = 1.0000 2.0000 3.5000 0.^g ans = 2 32 512 >> ones(3) ans = 1 1 1 1 1 1 1 1 1 4 64 1024 8 16 128 256 2048 4096 0.0000 2.1111 >> g.1429 0.0000 3.5000 3.2000 0.1000 0.0833 2.0000 MEA Engineering College ECE Department Page 10 .0000 3.0000 3.

For example to obtain the submatrix that consists of the first two rows and last two columns of A we type » A(1:2. » B = [ -1 3 10 -9 5 25 0 14 2] B = -1 3 10 -9 5 25 0 14 2 » s = [-1 8 5] s = -1 8 5 MEA Engineering College ECE Department Page 11 .2) A(3. We type » A(:.2) A(2. say the 3rd one.2) ans = 2 4 7 where the colon was used to tell MATLAB that all the rows are to be used. using the colon ( : ) as follows.Advanced Communication Lab (MATLAB)-Programs We can “extract” submatrices using a similar notation as above. Suppose we want to get the 2nd column of A. The same can be done when we want to extract an entire row.2:3) ans = 2 3 4 5 We could even extract an entire row or column of a matrix.:) ans = 6 7 8 Define now another matrix B. and two vectors s and t that will be used in what follows. » A(3. We basically want the elements [A(1.2)].

7621 0.4860 0.0185 0.8913 0.4565 0.8214 0 0 0 0 0 1 1 1 1 0 0 0 0 MEA Engineering College ECE Department Page 12 .Advanced Communication Lab (MATLAB)-Programs >> zeros(2.9501 0.6068 0.2311 0.4) ans = 1 0 0 0 1 0 >> rand(3) ans = 0.5) ans = 0 0 0 0 0 0 >> size(g) ans = 3 4 >> ones(size(g)) ans = 1 1 1 1 1 1 1 1 1 >> eye(4) ans = 1 0 0 0 1 0 0 0 1 0 0 0 >> eye(2.

since s has size 1-by-3 and t has size 3-by-1. » s-t ??? Error using ==> Matrix dimensions must agree. We must be equally careful when using multiplication. » B*s ??? Error using ==> * Inner matrix dimensions must agree.0. This error was expected. to subtract 1 from every entry in the matrix A we type » A-1 ans = 0 1 2 2 3 4 5 6 7 It is just as easy to add (or subtract) two compatible matrices (i. » A+B ans = 0 5 13 -6 9 30 6 21 10 The same is true for vectors.11] t = 7 0 11 The real power of MATLAB is the ease in which you can manipulate your vectors and matrices.e. For example.Advanced Communication Lab (MATLAB)-Programs » t = [7. » B*t MEA Engineering College ECE Department Page 13 . matrices of the same size). We will not get an error if we type » s-t' ans = -8 8 -6 since by taking the transpose of t we make the two vectors compatible.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 14 .

0000 0.6801 0.7390 x is the solution of B x = t as can be seen in the multiplication below. » B*x ans = 7. » format long » x x = 2. . If M is an invertible† square matrix and b is a compatible vector then x = M\b is the solution of M x = b and x = b/M is the solution of x M = b.Advanced Communication Lab (MATLAB)-Programs ans = 103 212 22 Another important operation that MATLAB can perform with ease is “matrix division”.73903002309469 On a PC the command format long can also be used through the Window Menus. MATLAB will allow us to do this with “element-wise” operations. MEA Engineering College ECE Department Page 15 There are many times when we want to perform an operation to every entry in a vector or matrix.0000 Since x does not consist of integers.68013856812933 0.4307 0.0000 11.43071593533487 0. which tells MATLAB to display more digits. MATLAB only displays four digits beyond the decimal point of a real number unless we use the command format long. » x=B\t x = 2. it is worth while mentioning here the command format long. Let us illustrate the first of the two operations above with M = B and b = t.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 16 .

s(3)*s(3)].^ " can also be used since we are after all raising s to a power. » s*s ??? Error using ==> * Inner matrix dimensions must agree. In other words. In fact.subtraction * multiplication ^ power ' transpose \ left division / right division Remember that the multiplication. power and division operators can be used in conjunction with a period to specify an element-wise operation. suppose you want to obtain the vector s2 = [s(1)*s(1).^2 ans = 1 64 25 The table below summarizes the operators that are available in MATLAB. (The period is needed here as well. MEA Engineering College ECE Department Page 17 .*".*s ans = 1 64 25 The symbol " . This is done with the symbols ". The command s*s will not work due to incompatibility.Advanced Communication Lab (MATLAB)-Programs For example. s(2)*s(2). What is needed here is to tell MATLAB to perform the multiplication element-wise. » s. suppose you want to multiply each entry in the vector s with itself. + addition .) » s. you can put a period in front of most operators to tell MATLAB that you want the operation to take place on each entry of the vector (or matrix).

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 18 .

commands) in MATLAB.Advanced Communication Lab (MATLAB)-Programs 1.3 Built-in functions There are numerous built-in functions (i. They are summarized in the table below. but operate element-wise when applied to a matrix (or vector). We will mention a few of them in this section by separating them into categories. sin trigonometric sine cos trigonometric cosine tan trigonometric tangent asin trigonometric inverse sine (arcsine) acos trigonometric inverse cosine (arccosine) atan trigonometric inverse tangent (arctangent) exp exponential log natural logarithm abs absolute value sqrt square root rem remainder round round towards nearest integer floor round towards negative infinity ceil round towards positive infinity MEA Engineering College ECE Department Page 19 . Scalar Functions Certain MATLAB functions are essentially used on scalars.e.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 20 .

\pi to \pi') as long as we remember to enclose the text in parentheses within single quotes. We placed a semicolon at the end of the input line to avoid seeing the (long) output. respectively.e. we can first define the vector x with components equally spaced numbers between – π and π. say 0. If x and y are two vectors of the same length then plot(x. (using a semicolon again) and we ask for the plot » plot(x. some of which will be illustrated below.y) At this point a new window will open on our desktop in which the graph (as seen below) will appear. to obtain the graph of y = cos(x) from – π to π. It is good practice to label the axis on a graph and if applicable indicate what each axis represents. and enclosed within single quotes. For example.y) plots x versus y.01:pi. plotting). By typing help plot you can see the various capabilities of this main command for two-dimensional plotting.01. We could even put a title on top using » title('Graph of cosine from . ignore the present commend and simply type » title('Graph of cosine from -pi to pi') Page ECE Department MEA Engineering College 21 . » xlabel('x') » ylabel('y=cos(x)') Inside parentheses. we define the vector y » y=cos(x). Note that the smallest the increment. Function Plotting We end our discussion on the basic features of MATLAB by introducing the commands for data visualization (i. This can be done with the xlabel and ylabel commands. the “smoother” the curve will be. Next. with increment. The back-slash ( \ ) in front of pi allows the user to take advantage of LaTeX commands.Advanced Communication Lab (MATLAB)-Programs 2. we type the text that we wish to be displayed along the x and y axis. If you are not familiar with the mathematical typesetting software LaTeX (and its commands). » x=-pi:0.

>>plot(x.2*pi.y. >>title('Sine Wave').y.x.y. >.z). >> y=sin(x). >>grid on.2*pi. >> plot(x.'cos(x)'). >> title('Sine Wave').30).y). Example:5 >> set(0. >>plot(x.x.'r--'.z). Example:4 >>subplot(1.y.30). MEA Engineering College ECE Department Page 22 .1). >> subplot(1.y). >> plot(x.2. >>legend('sine(x)').3).legend('sine(x)'.z. >> z=cos(x). >> plot(x.'b:'). >> title('sine and cosine'). >>grid on.2). >>x=linspace(0.x.2. Example:3 >> subplot(1. >> plot(x. Example:2 >> z=cos(x).1). >> title('Sine Wave'). >>subplot(1. >> x=linspace(0. >> z=cos(x).30).y.2).'r--').'r--').2*pi. >> plot(x.Advanced Communication Lab (MATLAB)-Programs Example:1 >> x=linspace(0. >> title('Sine Wave'). >> grid on. >> title('sine and cosine').'DefaultLineLineWidth'. >> y=sin(x).2.2.

we can get both graphs on the same axis. We could get a dashed line instead of a solid one by typing » plot(x.z. plot symbols and colors can be used. When multiple curves appear on the same axis. say a blue dotted line by typing » plot(x. we must do the same here. If for example we define another vector » z = sin(x).solid * star : dotted -.y. We must be consistent with the ordering of the two curves. y m c r g b w k yellow magenta cyan red green blue white black .y. The command legend does exactly this.Advanced Communication Lab (MATLAB)-Programs Various line types.x. it is a good idea to create a legend to label and distinguish them.’b:’) Multiple curves can appear on the same graph. » legend('cos(x)'. appears within single quotes. If these are not specified (as in the case above) MATLAB will assign (and cycle through) the default ones as given in the table below. point o circle x x-mark + plus .dashed So.'b:') The resulting graph will show. to obtain the same graph but in green. dashdot -. distinguished by their line type. so since in the plot command we asked for cosine to be plotted before sine. Page MEA Engineering College ECE Department 23 . using » plot(x.y. represents the legend labels.'r--'.’g’) where the third argument indicating the color.’--’) or even a combination of line type and color. with the red dashed line representing y = cos(x) and the blue dotted line representing z = sin(x).y. we type » plot(x.'sin(x)') The text that appears within single quotes as input to this command.

>>h=exp(c)-c.2*pi. >>plot(a. >> y=sin(x).2. >>c=0:0.h).g). >>y=exp(x). >> hold on.'DefaultLineLineWidth'.'r--').4). >> b=0:0. >> grid on. >> set(0.'DefaultLineLineWidth'. >>subplot(2.30). MEA Engineering College ECE Department Page 24 .4:10. >> subplot(2. >>grid on.'b--').z).2). >> g=exp(b)-b.^2.1). >>a=0:0.'DefaultLineLineWidth'.y).2:10.2). >> plot(x. Example 7: >> set(0. >> plot(x.3:10.z.2. >>grid on. >>subplot(2. >> x=linspace(0.y. >> z=exp(a)-a.^3.4).2. >> x=0:0.1:10. >>subplot(2.3). >> z=cos(x). >>plot(x.Advanced Communication Lab (MATLAB)-Programs Example 6: >>set(0. >>plot(c. >>grid on.2). >>plot(b. >>grid on.2.

Type help grid for more information.Advanced Communication Lab (MATLAB)-Programs Another nice feature that can be used in conjunction with plot is the command grid. which places grid lines to the current axis (just like you have on graphing paper). Other commands for data visualization that exist in MATLAB include subplot create an array of (tiled) plots in the same window loglog plot using log-log scales semilogx plot using log scale on the x-axis semilogy plot using log scale on the y-axis surf 3-D shaded surface graph surfl 3-D shaded surface graph with lighting mesh 3-D mesh surface -4 MEA Engineering College ECE Department Page 25 .

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 26 .

10000). t2=1. clear all. t=linspace(0. MEA Engineering College ECE Department Page 27 .Advanced Communication Lab (MATLAB)-Programs 3. t=t1:tstep:t2.5. w0=T*d/100. y=(tmp<w0).'DefaultLineLineWidth'.5.x) axis([t1 t2 -2 2]) title('Sine Wave') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (ii) Square Wave : ADC_Square. T=10.m %%%%%MATLAB PROGRAM FOR GENERATING SQUARE WAVE%%%% clear all close all clc set(0. tstep=0. t1=-0. fs=.5. tmp=mod(t.T). clc. phi=pi/2.m %%%%%MATLAB PROGRAM FOR GENERATING SINE WAVE%%%%% close all. x=Xs*sin(((2*pi*fs*t)+phi)).3) Xs=1. set(0.a. Signal Generation (i) Sine Wave : ADC_Sine. plot(t. d=25.'DefaultLineLineWidth'.1.3) a=30.

y) xlabel('time(t)') 28 .Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page plot(t.

'DefaultLineLineWidth'. plot(t. y=(tmp<w0).3) N=20.5).%sampling interval k=-N:N.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc set(0.Advanced Communication Lab (MATLAB)-Programs ylabel('Amplitude(x)') axis([0 (a+2) -2 2]) title('\bf SQUARE WAVE') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (iii) Triangular Wave : ADC_Triangular. T=5.1. w0=T*d/100.y) xlabel('time(t)') ylabel('Amplitude(x)') axis([0 (d+2) -2 2]) title('\bf TRIANGULAR WAVE') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (iv) Unit Step : ADC_Unitstep. d=25 tmp=mod(t. T=0.T).30.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all close all clc set(0.'DefaultLineLineWidth'. MEA Engineering College ECE Department Page 29 .3) t=linspace(0.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 30 .

t for i=1:(((2*(N*T))/T)+1) if(t(i)<0) x(i)=0. end end % x(t>=0)=1. xlabel('time(t)') ylabel('Amplitude(x)') axis([-2 2 -2 2]) title('\bf UNIT STEP FUNCTION') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MEA Engineering College ECE Department Page 31 .Advanced Communication Lab (MATLAB)-Programs t=-N*T:T:N*T.x plot(t. else x(i)=1.x).

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 32 .

t=t1:tstep:t2. clear all. phi=pi/2.001.001. : ADC_AM. plot(t.m %%%MATLAB PROGRAM FOR AMPLITUDE MODULATION%%%%%%% close all.2.5.5. tstep=0.5. t2=1.3) %%% GENERATION OF MESSAGE SIGNAL xm=Xm*sin(Wt+(pi/2))%%%% subplot(2. t2=1. xm=Xm*sin((2*pi*fm*t)+phi).5.5.2) Xc=1. xc=Xc*sin(2*pi*fc*t). t1=-0.xm) xlabel('time(t)') ylabel('Amplitude(x)') axis([t1 t2 -(Xm+2) (Xm+2)]) title('\bf MESSAGE SIGNAL') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% GENERATION OF CARRIER SIGNAL xc=Xc*sin(Wct) %%%%%%%% subplot(2. clc.5.xc) xlabel('time(t)') ylabel('Amplitude(x)') axis([t1 t2 -(Xc+2) (Xc+2)]) MEA Engineering College ECE Department Page 33 . fc=10.1) Xm=1. tstep=0.2. t=t1:tstep:t2. t1=-0. fm=. plot(t.Advanced Communication Lab (MATLAB)-Programs 4. set(0. Program to Perform Amplitude Modulation.'DefaultLineLineWidth'.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 34 .

2.Advanced Communication Lab (MATLAB)-Programs title('\bf CARRIER') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%ADDITION OF TWO%%%%%%%%%%%%%%%%%%%%%%% subplot(2.%%%Amplitude Modulation plot(t. t2=1. AM=((Xc+xm). tstep=0.2.001. t=t1:tstep:t2.*sin(2*pi*fc*t)).5.z) xlabel('time(t)') ylabel('Amplitude(x)') axis([t1 t2 -(Xc+2) (Xc+2)]) title('\bf SIMPLE ADDITION OF TWO') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%AMPLITUDE MODULATED SIGNAL%%%%%%%%%%%%%%%% subplot(2.5.4) t1=-0. plot(t.AM) xlabel('time(t)') ylabel('Amplitude(x)') axis([t1 t2 -(Xc+2) (Xc+2)]) title('\bf AMPLITUDE MODULATED OUTPUT') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MEA Engineering College ECE Department Page 35 .3) z=xm+xc.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 36 .

1. 37 . t1=-0.1. y = (k>=k1).1. clear all.5. plot(t. x=Xs*sin((2*pi*fs*t)+phi).x) xlabel('time(t)') ylabel('Amplitude(x)') axis([t1 t2 -(Xs+2) (Xs+2)]) title('\bf SINE WAVE') grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%UNIT IMPULSE SEQUENCE%%%%%%%%%%%%%%%%%%%%% subplot(3.5.m MEA Engineering College ECE Department Page close all.*x. t=t1:tstep:t2. t2=1. k = k1:kstep:k2.5. clc.'DefaultLineLineWidth'.2) k1 = -0.y) hold on xlabel('k') ylabel('\delta_k') title('\bf UNIT IMPULSE SEQUENCE') axis([k1 k2 -2 2]) grid on %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%SAMPLED SIGNAL%%%%%%%%%%%%%%%%%%%%%%%%% subplot(3.1.3) z=y. tstep=0.5. kstep=0.1) Xs=1. k2 = 1.2) %%%%%%%%%%%%%%%%%%%%Message signal%%%%%%%%%%%% subplot(3. phi=pi/2. Program to Perform Sampling : ADC_SAMPLING.Advanced Communication Lab (MATLAB)-Programs 5. stem(k.1. fs=. set(0.5.

Advanced Communication Lab (MATLAB)-Programs MEA Engineering College ECE Department Page 38 .

xlabel('k') ylabel('\delta_k') title('\bf AFTER SAMPLING') axis([k1 k2 -2 2]) grid on MEA Engineering College ECE Department Page 39 .Advanced Communication Lab (MATLAB)-Programs stem(k.z).

0000 + 6.2426 + 1.0000 .0000 Columns 6 through 8 -1.1.1.0000i MEA Engineering College ECE Department Page 40 .0000i 6.2426 + 1.0000i 7.0000i -1.6.2426 .0000i 6.0000 7.0000i 8.Advanced Communication Lab (MATLAB)-Programs Result: Enter the input sequence x(n): [5 3 1 -3 2] Enter the number of points needed: 8 The DFT of the given sequence is: X= Columns 1 through 5 8.2426 .

disp('The DFT of the given sequnce is: ').2). stem(n.Advanced Communication Lab (MATLAB)-Programs 6.m MEA Engineering College ECE Department Page 41 .N). ylabel('MAGNITUDE -------------------->').: clc clear all x=input('Enter the input sequence x(n): ').2. xlabel('TIME INDEX n------------------>'). stem(n. ylabel('PHASE -------------------->'). ADC_DFT. subplot(1. if(N<length(x)) error('N should be >= to length of x'). end. title('MAGNITUDE RESPONSE').X n=0:1:N-1. X=fft(x.abs(X)). title('PHASE RESPONSE'). Program to Compute DFT of the Sequence. subplot(1.2.1).(angle(X)*180/pi)). xlabel('TIME INDEX n------------------>'). N=input('Enter the number of points needed: ').

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 0.3 Enter the stopband attenuation 50 Enter the passband edge frequency 1000 Enter the stopband edge frequency 3000 Order of the filter is N= 5 MEA Engineering College ECE Department Page 42 .

.>')......Advanced Communication Lab (MATLAB)-Programs 7..wc......... ylabel('PHASE.. [N. title('PHASE RESPONSE OF FILTER')...a]=butter(N.. wp2=2*Fs*tan(wp1/2)...... title('MAGNITUDE RESPONSE OF FILTER').... : iir_lpf.... m=20*log(abs(h)).>')..1. xlabel('FREQUENCY...... xlabel('FREQUENCY........den....1. ylabel('MAGNITUDE......f]=freqz(num.... Program to Realize IIR Low pass Butterworth filter Using Bilinear Transformation. fs=input('Enter the stopband edge frequency '). ws2=2*Fs*tan(ws1/2). ang=angle(h)*180/pi.N [b. [h.ws2.m)... fp=input('Enter the passband edge frequency ').>')...m clc clear all Fs=input('Enter the Sampling Frequency : ').. [num. MEA Engineering College ECE Department Page 43 .a...512.as.Fs).... as=input('Enter the stopband attenuation ').wc]=buttord(wp2............... wp1=(2*pi*fp)/Fs.. disp('Order of the filter is '). plot(f.. plot(f. subplot(2...1)....ap...... subplot(2... ap=input('Enter the passband attenuation ')..2).'s').....Fs)..den]=bilinear(b. ws1=(2*pi*fs)/Fs....'s')..ang)...>').

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 0.3 Enter the stopband attenuation 90 Enter the passband edge frequency 3500 Enter the stopband edge frequency 2000 Order of the filter is N= 8 MEA Engineering College ECE Department Page 44 .

..>')..ap........ subplot(2....>').ws2..1....m clc clear all Fs=input('Enter the Sampling Frequency : ')...f]=freqz(num......: iir_hpf.2).>')... ap=input('Enter the passband attenuation ').den]=bilinear(b.... fp=input('Enter the passband edge frequency ')......... wp2=2*Fs*tan(wp1/2). [N. ang=angle(h)*180/pi.........a.Advanced Communication Lab (MATLAB)-Programs 8.. ylabel('MAGNITUDE. MEA Engineering College ECE Department Page 45 .. title('MAGNITUDE RESPONSE OF FILTER').wc]=buttord(wp2.wc.... xlabel('FREQUENCY......m)..... xlabel('FREQUENCY... m=20*log(abs(h)).Fs)..... disp('Order of the filter is ')....'high'..512..>').......N [b.... [h. title('PHASE RESPONSE OF FILTER').1)..'s').as. wp1=(2*pi*fp)/Fs.. as=input('Enter the stopband attenuation ').. subplot(2..... ws1=(2*pi*fs)/Fs...den... ylabel('PHASE... fs=input('Enter the stopband edge frequency ')...1..a]=butter(N..'s').. plot(f.Fs).. Program to Realize IIR High pass Butterworth filter Using Bilinear Transformation. plot(f.... [num.. ws2=2*Fs*tan(ws1/2).ang)...

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 0.3 Enter the stopband attenuation 50 Enter the passband edge frequency [1000 2000] Enter the stopband edge frequency [500 3000] Order of the filter is N= 7 MEA Engineering College ECE Department Page 46 .

>').'s')... ylabel('PHASE........as..>')..a. title('PHASE RESPONSE OF FILTER').. : iir_bpf. Program to Realize IIR Band pass Butterworth filter Using Bilinear Transformation..ap. disp('Order of the filter is ').wc....ang)... xlabel('FREQUENCY. plot(f.. wp1=(2*pi*fp)/Fs.... [h..... fp=input('Enter the passband edge frequency '). xlabel('FREQUENCY... fs=input('Enter the stopband edge frequency ')....'s')..1).1. as=input('Enter the stopband attenuation ').. ws2=2*Fs*tan(ws1/2).... ws1=(2*pi*fs)/Fs...... m=20*log(abs(h)).1...ws2. plot(f..den... [num........ ap=input('Enter the passband attenuation ')..... [N.2).. ylabel('MAGNITUDE.. subplot(2.. title('MAGNITUDE RESPONSE OF FILTER')...... wp2=2*Fs*tan(wp1/2).....f]=freqz(num..Advanced Communication Lab (MATLAB)-Programs 9. subplot(2...m clc clear all Fs=input('Enter the Sampling Frequency : ').... MEA Engineering College ECE Department Page 47 .....den]=bilinear(b..m).Fs).. ang=angle(h)*180/pi...>').Fs)....'bandpass'....512....>').N [b...........a]=butter(N..wc]=buttord(wp2..

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 0.3 Enter the stopband attenuation 50 Enter the passband edge frequency [500 3500] Enter the stopband edge frequency [1000 2000] Order of the filter is N= 7 MEA Engineering College ECE Department Page 48 .

: iir_bsf.. title('PHASE RESPONSE OF FILTER').......Fs).. MEA Engineering College ECE Department Page 49 ...m)..ap.. ylabel('PHASE. fs=input('Enter the stopband edge frequency ')..... ang=angle(h)*180/pi.'s'). xlabel('FREQUENCY. m=20*log(abs(h)).... plot(f.2).as...512.. xlabel('FREQUENCY.... ap=input('Enter the passband attenuation '). title('MAGNITUDE RESPONSE OF FILTER'). [num..ws2...1....'stop'.....a................ plot(f.>')....Program to Realize IIR Band stop Butterworth filter Using Bilinear Transformation..>')...a]=butter(N... subplot(2..f]=freqz(num..........'s').>').......1). [h....ang). disp('Order of the filter is ').. ylabel('MAGNITUDE.. ws1=(2*pi*fs)/Fs..wc]=buttord(wp2......1. [N. wp2=2*Fs*tan(wp1/2). ws2=2*Fs*tan(ws1/2).Fs).den... wp1=(2*pi*fp)/Fs...m clc clear all Fs=input('Enter the Sampling Frequency : '). subplot(2.... fp=input('Enter the passband edge frequency ').>')....den]=bilinear(b..Advanced Communication Lab (MATLAB)-Programs 10.. as=input('Enter the stopband attenuation ')....N [b....wc..

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 5 Enter the stopband attenuation 60 Enter the passband edge frequency 900 Enter the stopband edge frequency 3500 Order of the filter is N= 3 MEA Engineering College ECE Department Page 50 .

.....>')... ylabel('PHASE.. [h. disp('Order of the filter is '). subplot(2.... fp=input('Enter the passband edge frequency ').....a]=cheby1(N.f]=freqz(num.a.... xlabel('FREQUENCY...den]=bilinear(b.....'s')... ylabel('MAGNITUDE. ws1=(2*pi*fs)/Fs.2).. title('MAGNITUDE RESPONSE OF FILTER')... subplot(2. m=20*log(abs(h)). xlabel('FREQUENCY....>').>').wc...Advanced Communication Lab (MATLAB)-Programs 11.. wp1=(2*pi*fp)/Fs...m)...as... MEA Engineering College ECE Department Page 51 . title('PHASE RESPONSE OF FILTER').....N [b..ap.... ws2=2*Fs*tan(ws1/2).'s').. ap=input('Enter the passband attenuation ').....wc]=cheb1ord(wp2.. as=input('Enter the stopband attenuation ').. plot(f.....Fs)......1...m clc clear all Fs=input('Enter the Sampling Frequency : ').......1. plot(f..ws2......Fs). ang=angle(h)*180/pi.....Program to Realize IIR Chebyshev-1 Butterworth Low pass filter Using Bilinear Transformation.>')..512.. fs=input('Enter the stopband edge frequency ').ap...1). : iir_cheby_lpf.........den.ang)... wp2=2*Fs*tan(wp1/2)... [N...... [num.

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 3 Enter the stopband attenuation 90 Enter the passband edge frequency 500 Enter the stopband edge frequency 3500 Order of the filter is N= 3 MEA Engineering College ECE Department Page 52 .

Fs).. subplot(2. title('PHASE RESPONSE OF FILTER')...m clc clear all Fs=input('Enter the Sampling Frequency : ')...'s')...... subplot(2.........den]=bilinear(b........ plot(f...>').. title('MAGNITUDE RESPONSE OF FILTER')..a..: iir_cheby_hpf.Advanced Communication Lab (MATLAB)-Programs 12.Fs).. [N. ylabel('PHASE......... wp1=(2*pi*fp)/Fs..m).>').'s').wc...ap.... ws2=2*Fs*tan(ws1/2)....2)...... ang=angle(h)*180/pi... xlabel('FREQUENCY....1. [num.den..>').'high'.f]=freqz(num... wp2=2*Fs*tan(wp1/2)......... MEA Engineering College ECE Department Page 53 .Program to Realize IIR Chebyshev-1 Butterworth High pass filter Using Bilinear Transformation.wc]=cheb1ord(wp2...N [b.. disp('Order of the filter is ').....>').as. ylabel('MAGNITUDE. ws1=(2*pi*fs)/Fs..........512.... [h.. plot(f.ws2..ap.. fs=input('Enter the stopband edge frequency '). ap=input('Enter the passband attenuation ')... xlabel('FREQUENCY... as=input('Enter the stopband attenuation ').1)..ang).. fp=input('Enter the passband edge frequency ').... m=20*log(abs(h)).1.a]=cheby1(N.....

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 3 Enter the stopband attenuation 60 Enter the passband edge frequency [1000 2500] Enter the stopband edge frequency [500 3500] Order of the filter is N= 5 MEA Engineering College ECE Department Page 54 .

ylabel('PHASE. xlabel('FREQUENCY..... ws2=2*Fs*tan(ws1/2). as=input('Enter the stopband attenuation '). xlabel('FREQUENCY.512.den..2).'s'). subplot(2.. fp=input('Enter the passband edge frequency ').N [b.........Program to Realize IIR Chebyshev-1 Butterworth Band pass filter Using Bilinear Transformation : iir_cheby_bpf............. wp2=2*Fs*tan(wp1/2)...>'). subplot(2. MEA Engineering College ECE Department Page 55 . wp1=(2*pi*fp)/Fs. [N... plot(f..'bandpass'... title('PHASE RESPONSE OF FILTER').ws2.. ap=input('Enter the passband attenuation ')......ap..... m=20*log(abs(h))..as.ap.. fs=input('Enter the stopband edge frequency ')..ang)............. ylabel('MAGNITUDE.1...>'). plot(f....wc...m clc clear all Fs=input('Enter the Sampling Frequency : ')......Advanced Communication Lab (MATLAB)-Programs 13...m). title('MAGNITUDE RESPONSE OF FILTER')..wc]=cheb1ord(wp2..a]=cheby1(N...a..1)...1...>')....Fs).. [num.den]=bilinear(b... ws1=(2*pi*fs)/Fs....'s').... disp('Order of the filter is '). ang=angle(h)*180/pi..f]=freqz(num.Fs)..>').... [h.......

Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband attenuation 3 Enter the stopband attenuation 70 Enter the passband edge frequency [800 3500] Enter the stopband edge frequency [1400 2000] Order of the filter is N= 5 MEA Engineering College ECE Department Page 56 .

ap=input('Enter the passband attenuation ').'stop'........ ylabel('PHASE.....2)..den]=bilinear(b. ws1=(2*pi*fs)/Fs...m clc clear all Fs=input('Enter the Sampling Frequency : ')...512... xlabel('FREQUENCY.. fs=input('Enter the stopband edge frequency ').. title('PHASE RESPONSE OF FILTER'). xlabel('FREQUENCY. ylabel('MAGNITUDE... [N..... plot(f.'s').. plot(f..>').. subplot(2. : iir_cheby_bsf... [h..... fp=input('Enter the passband edge frequency ')....'s')... [num... MEA Engineering College ECE Department Page 57 ....Advanced Communication Lab (MATLAB)-Programs 14. ang=angle(h)*180/pi... ws2=2*Fs*tan(ws1/2).>').wc....... subplot(2..Program to Realize IIR Chebyshev-1 Butterworth Band Stop filter Using Bilinear Transformation...>').. as=input('Enter the stopband attenuation ').>')..... title('MAGNITUDE RESPONSE OF FILTER').Fs)......... m=20*log(abs(h)).. wp2=2*Fs*tan(wp1/2). wp1=(2*pi*fp)/Fs.....ap..ap..N [b......as.....wc]=cheb1ord(wp2.....m).a. disp('Order of the filter is ')..a]=cheby1(N..........1..den.1.ws2..f]=freqz(num.1)..ang).Fs)...

15 Enter the stopband ripple in dB 90 Enter the passband edge frequency 1900 Enter the stopband edge frequency 3500 MEA Engineering College ECE Department Page 58 .Advanced Communication Lab (MATLAB)-Programs Result: Enter the Sampling Frequency : 8000 Enter the passband ripple in dB 0.

.. title('FREQUNCY RESPONSE PLOT OF FIR FILTER USING KAISER WINDOW').1... ylabel('FREQUENCY RESPONSE....1.... title('IMPULSE RESPONSE PLOT OF THE FIR FILTER USING KAISER WINDOW')..>'). subplot(2.. n=0:1:N-1...........>')... fp=input('Enter the passband edge frequency ')...512. MEA Engineering College ECE Department Page 59 ..1). wp=2*fp/Fs.. plot(f...Fs)..>'). as=input('Enter the stopband ripple in dB '). ap=input('Enter the passband ripple in dB ')..... w=kaiser(N.... [h.......m).... m=20*log(abs(h)).......... xlabel('TIME. ws=2*fs/Fs.b)...... : fir_kaiser_lpf...FIR Low pass filter Using Kaiser Window......beta]=kaiserord([wp... xlabel('TIME..... dp=1-10^-(ap/20).ds]).m clc clear all Fs=input('Enter the Sampling Frequency : ')...f]=freqz(b.... b=fir1(N-1.>').[1 0]. ylabel('IMPLSE RESPONSE....ws].w)... [N.... stem(n.....2).beta)....wc........ ds=10^-(as/20).[dp.Advanced Communication Lab (MATLAB)-Programs 15.. fs=input('Enter the stopband edge frequency ').wc. subplot(2.1...