0% found this document useful (0 votes)
53 views7 pages

Exp 1

The document describes an experiment using MATLAB for communication system design. It discusses MATLAB basics like scalars, vectors, matrices and plotting. It also covers m-files, functions, and creating script and function files in MATLAB. Key points covered include using the colon operator, plotting sin and cos waves, and defining a sample function to calculate the factorial of a number.

Uploaded by

Mohammad Hasnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views7 pages

Exp 1

The document describes an experiment using MATLAB for communication system design. It discusses MATLAB basics like scalars, vectors, matrices and plotting. It also covers m-files, functions, and creating script and function files in MATLAB. Key points covered include using the colon operator, plotting sin and cos waves, and defining a sample function to calculate the factorial of a number.

Uploaded by

Mohammad Hasnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EXPERIMENT # 1

MATLAB Basics for Communication System Design


Objective
• To understand the use of MATLAB for solving communication engineering
problems.
• Learn the basics of MATLAB as used in Communication.
• To develop understanding of MATLAB environment, commands and syntax.

MATLAB
MATLAB is a powerful tool that is utilized by the engineers and others professionals in
development and testing of various projects. It is versatile software, with the help of which
you can solve and develop any sort of engineering problem. The name MATLAB stands for
MATRIX LABORAORY. All the work done in MATLAB is basically in the form of
matrices. Scalars are referred as 1-to-1 matrix and vectors are matrices having more than 1
row and column. MATLAB is programmable and have the same logical, relational,
conditional and loop structures as in other programming languages, such as C, Java etc. It’s
very easy to use MATLAB, all we need is to practice it and become a friend of it.
Summary:

• Scalars
• Vectors
• Matrices
• Plotting
• m-files
• functions

Getting Started:

a) Go to the start button, then programs, MATLAB and then start MATLAB. It is
preferred that you have MATLAB2015a. You can then start MATLAB by double
clicking on its icon on Desktop, if there is any.

b) The Prompt:

>>

The operator shows above is the prompt in MATLAB. MATLAB is interactive


language like C, Java etc. We can write the commands over here.
c) In MATLAB we can see our previous commands and instructions by pressing the
up key. Press the key once to see the previous entry, twice to see the entry before
that and so on. We can also edit the text by using forward and back-word keys.

Help in MATLAB
In order to use the built-in help of the MATLAB we use the help keyword. Write it on the
prompt and see the output.

>> help sin

Also try

>> lookfor sin

Scalars

A scalar is a single number. A scalar is stored in the MATLAB as a 1 x 1 matrix. Try these
on the prompt.
>> A = 2;

>> B = 3;

>> C = A^B

>> C = A*B

Try these instructions as well

>> C = A+B

>> C = A-B

>> C = A/B

>> C = A\B

Note the difference between last two instructions.

Try to implement these two relations and show the result in the provided space

a) 25 ( 31/3 ) + 2 (2+92) =

b) 5x3 + 3x2 + 5x + 14 for x = 3 is

Vectors
Vectors are also called arrays in MATLAB. Vectors are declared in the following format.
>> X = [1 2 3 4]

>> Y = [2 5 8 9]
Try these two instructions in MATLAB and see the result
>> length (X) =

>> size (X) =

Try these instructions and see the results.

>> X.*Y =

>> X.^Y =

>> X+Y =

>> X-Y =

>> X./Y =

>> X’ =

Also try some new instructions for this and notice the outputs in each case.
>> ones (1,4)

>> ones (2,4)

>> ones (4,1)

>> zeros (1,4)

>> zeros (2,4)

There is an important operator, the colon operator (:), it is very important operator and
frequently used during these labs. Try this one.

>> X = [0:0.1:1]

Notice the result. And now type this

>> length (X)

>> size (X)

Now try this one.


Lab Manual of Analog & Digital Communication

>>A= [ones(1,3), [2:2:10], zeros(1,3)] What is the length and size of this?

>> Length =

Size =

Try ‘help ones’ and ‘help zeros’ as well, and note down its important features.

MATRICES

Try this and see the output.


>> A = [1 2 3;4 5 6;7 8 9]

>> B = [1,2,3;4,5,6;7,8,9]

Is there any difference between the two? Try to implement 2-to-3 matrix and 3-to-2 matrix.

Also take help on mod, rem, det, inv and eye and try to implement them. Try to use
length and size commands with these matrices as well and see the results.

Try to solve these.


1. 6x + 12y + 4z = 70

7x – 2y + 3z= 5

2x + 8y -9z = 64

2. A = [2 3 4 5; 1 8 9 0; 2 3 1 3; 5 8 9 3]
Solve 6A – 2I + A2 =

PLOTTING
Plotting is very important as we have to deal with various type of waves and we have to view
them as well.
Try these and have a look on the results.
>> x = [0:0.1:10];
>> y = sin (x);
>> z = cos (x);
>> subplot (3,1,1);
>> plot (x,y);
>> grid on;
>> subplot (3,1,2);
>> plot (x,z);
>> grid on; hold on;
>> subplot (3,1,3);
Lab Manual of Analog & Digital Communication

>> stem (x,z);


>> grid on;
>> hold on;
>> subplot (3,1,3);
>> stem (x,y, ,'r');
Take help on the functions and commands that you don’t know. See the difference
between the stem and plot.

See help on plot, figure, grid, hold, subplot, stem and other features of it.

Figure 1.1
Lab Manual of Analog & Digital Communication

M-FILES

MATLAB can execute a sequence of statements stored in disk files. Such files are called M-
files because they must have the file type ‘.m’. Lot of our work will be done with creation of
m-files.

There are two types of m-files: Script and function files.

Script Files

We can use script files in order to write long programs such as one on the previous page.
A script file may contain any command that can be entered on the prompt. Script files can
have any name but they should be saved with “.m” extension. In order to excurse an m-file
from the prompt, just type its name on the prompt. You can make an m-file by typing edit
on the prompt or by clicking on the file then new and m-file. See an example of m-file.
Write it and see the results.

% This is comment
% A comment begins with a percent symbol
% The text written in the comments is ignored by the MATLAB
%comments in your m-files.

clear;
clc;
x = [0:0.1:10];
y = sin (x);
subplot (2,2,1);
plot (x,y, ,'r');
grid on;
z = cos (x);
subplot (2,2,2);
plot (x,z);
grid on;
w = 90;
yy = 2*pi*sin
(x+w)
subplot (2,2,3);
plot (x,yy);
grid on;
zz = sin (x+2*w);
subplot (2,2,4);
stem (x,zz, ,'g');
hold on;
stem (x,y, ,'r');
grid on;
Lab Manual of Analog & Digital Communication

Figure 1.2
Function Files

MATLAB have many built-in functions including trigonometry, logarithm, calculus and
hyperbolic functions etc. In addition we can define our own functions and we can use built-
in functions in our functions files as well. The function files should be started with the
function definition and should be saved with the name of function. The general format of
the function file is

Function [output_variables] = function name (input_variables)

See the following example and implement it.

% this is a function file

% this function computes the factorial of a number function [y] = my_func (x)

y = factorial (x);

POST LAB

Try to develop a function that will compute the maximum and minimum of two numbers.

You might also like