Lab 1
Lab 1
Lab 1
EXPERIMENT 1
INTRODUCTION TO COMMUNICATION SYSTEMS
USING MATLAB
1.0 OBJECTIVE
3.0 THEORY
MATLAB
1. INTRODUCTION
( a ) What is MATLAB?
MATLAB is an interactive, matrix-based system for scientific and engineering numeric
computation and visualization. The word MATLAB stands for MATrix LABoratory. Each
entry is taken as a matrix in it, in particular scalar is considered as a 1 by 1 matrix.
MATLAB is available for a number of operating systems like Windows, Linux etc.
MATLAB was originally written in FORTRAN and is licensed by The Math Works, Inc,
(http:// www.mathworks.com). The version of MATLAB we use is ver 6.1. There is a
relatively inexpensive student edition available from Prentice Hall Publishers.
2
ECE 112 Communication Systems (LAB) Laboratory 1
( i ) If you want to add two numbers say 7 & 12, type as follows
>> 7+12
and press the ENTER or return key, you see the following output:
ans =
19
Here, ans stands for the answer of computation. Similarly, the following gives product and
difference of these numbers,
( ii ) If you want to store the values 7 and 12 in MATLAB variables a & b and store
the values of their product and division in c and d, do as follows:
>> a =7 <ENTER>
a =
7
3
ECE 112 Communication Systems (LAB) Laboratory 1
You can exit MATLAB with the command exit or quit. A computation can be stopped
with[ctrl-c]
Expressions are composed of operators, function and variable names. After evaluation
the value is assigned to the variable and displayed. If the variable name and = sign are
omitted, a variable ans (for answer) is automatically created and the result is assigned
to it.
A statement is normally terminated with the carriage returns. However, a statement can
be continued on the next line with three or more periods followed by a carriage return.
Several statements can be placed on a single line if separated by commas or semicolons.
If the last character of a statement is a semicolon, then values of the variable printing to
the screen will be suppressed, but the assignment is still carried out.
Rules of Precedence:
Expressions are evaluated from left to right with exponential operation having the
highest precedence, followed by multiplication and division having equal
precedence, followed by addition and subtracting having equal precedence.
Parentheses can be used to alter this ordering in which case these rules of precedence
are applied within each set of parentheses starting with the innermost set and proceeding
outward.
4
ECE 112 Communication Systems (LAB) Laboratory 1
( iii ) The most recent values assigned to the variables you used in the current
session are available. For example, if you type a at the prompt you get the output
as:
>> a
a =
7
If you cannot remember the names of the variables, you have used in the current session,
you can use the who command for a list of variables it has in the current session.
>> who
Your variables are
ans a b c d
The command whos will list the variables in the workspace and their size.
The command
>> clear
will remove all current variables from the memory of the system.
>> clear a
will clear only the variable a.
( v ) The display of numerical values can have different format as we see below:
>> e= 1/3
e =
0.3333
>> format long (long decimal format)
>> e
e =
0.33333333333333
>> e
e =
3.3333 e-01
5
ECE 112 Communication Systems (LAB) Laboratory 1
>>e
e =
0.3333
>> a=3;
>>
>> exit
When we log out or exit, MATLAB will lose all the current variables from the memory.
To save the current session, type
>> save
This saves the all current variables to a binary diskfile matlab.mat. When you later re-
enter MATLAB, the command
>> load
>> c = 1-2i
c =
1.000–2.0000 i
>> real( c )
ans =
1
>> imag( c )
ans =
-2
6
ECE 112 Communication Systems (LAB) Laboratory 1
>> angle( c )
ans =
-1.1071
>> help
Scalers - 1 by 1 matrix
Row vector - matrix with one row
Column vector - matrix with one column.
1 2 3
If you want to store a matrix |4 5 6| in a variable a in the MATLAB’s current
7 8 9
>> a = [1 2 3; 4 5 6; 7 8 9]
a=
1 2 3
4 5 6
7 8 9
The rows are separated by semicolons and elements are separated by space or by
comma. That is, the above matrix can also be stored by the following command.
>> a = [1,2,3;4,5,6;7,8,9];
or by the statement
>> a = [
1 2 3
4 5 6
7 8 9 ];
7
ECE 112 Communication Systems (LAB) Laboratory 1
>> b = a’
b=
1 4 7
2 5 8
3 6 9
Function Task
+ Addition
- Subtraction
* Multiplication
^ Power
‘ Transpose
\ Left Division
/ Right Division
Examples:
>> a1 = a+b (matrices a and b are added and stores in a1)
a1 =
2 6 10
6 10 14
10 14 18
8
ECE 112 Communication Systems (LAB) Laboratory 1
The following are some special matrices generated by built-in statements and functions
9
ECE 112 Communication Systems (LAB) Laboratory 1
>> a = hilb(5)
a =
1.0000 0.5000 0.3333 0.2500 0.2000
0.5000 0.3333 0.2500 0.2000 0.1667
0.3333 0.2500 0.2000 0.1667 0.1429
0.2500 0.2000 0.1667 0.1429 0.1250
0.2000 0.1667 0.1429 0.1250 0.1111
We can also load a matrix from an external ASCII file, say data.ext (where .ext is any
extension). If this ascii file contain a rectangular array of just the numeric matrix entries,
then to load the matrix type the command
10
ECE 112 Communication Systems (LAB) Laboratory 1
>> b= a(1:2,3) (Vector consisting of the first 2 entries of the 3rd column of a)
b =
3
7
11
ECE 112 Communication Systems (LAB) Laboratory 1
Functions of vectors
>> t = [1:2:10] (Makes a row vector t having element starting from 1 up to 10 with step size 2)
t =
1 3 5 7 9
12
ECE 112 Communication Systems (LAB) Laboratory 1
>> any(t)
ans =
1
>> all(t)
ans =
1
4. PLOTTING GRAPHS
2-D plots:
Suppose we want to plot the graph of y = sin(x), in a interval [0,10]. Type as follows
13
ECE 112 Communication Systems (LAB) Laboratory 1
More on plots
If x or y is a matrix, then the vector is plotted versus the rows or columns of the matrix,
whichever line up.
In all other uses of plot, the imaginary part is ignored. various line types, plot symbols
and colors may be obtained with plot(x,y,s) where s is a character string made
from one element from any or all the following columns:
Example:
plot(x,y,'c+:') plots a cyan dotted line with a plus at each data point.
plot(x,y,'bd') plots blue diamond at each data point but does not draw any line.
puts two plots, plot(x, y, ‘b’) and plot(x, z, ‘g’) in one graph. The
first one with blue color and
the second with green color.
Example:
>> t = linspace(0,2*pi); (line space generates 100 t points between 0 and 2P)
>> x = sin(t);
>> y = cos(t);
>> plot(t, x,’*’, t, y,’-’) (plots sine and cos graphs in the same plot)
>> legend(‘x = sin(t)’, ’y = cos(t)’) (provides legends for graphs)
>> grid (provides grid lines)
14
ECE 112 Communication Systems (LAB) Laboratory 1
Subplots
You can hold more than one set of axes on one figure window. The command
subplot(m,n,p) subdivides the current figure window into an m-by-n matrix of
plotting areas and chooses the pth area to be active.
Example:
>> x = -2*pi:pi/10:2*pi;
>> y = x.^2;
>> z = sin(x);
>> y1 = cos(x);
>> z1 = exp(x);
>> subplot(2,2,1),plot(x,y)
>> grid
>> subplot(2,2,2),plot(x,z)
>> grid
>> subplot(2,2,3),plot(x,y1)
15
ECE 112 Communication Systems (LAB) Laboratory 1
>> grid
>> subplot(2,2,4),plot(x,z1)
>>grid
Function Task
plot - Linear plot
hold - Hold current graph
loglog - Log-log scale plot
semilogx - Semi-log scale plot
semilogy - Semi-log scale plot
axes - Create axes in arbitrary positions
subplot - Create axes in tiled positions
legend - Graph legend
title - Graph title
polar - Polar coordinate plot
xlabel - X-axis label
ylabel - Y-axis label
text - Text annotation
16
ECE 112 Communication Systems (LAB) Laboratory 1
Function Task
plotyy - Graphs with y tick labels on the left and right
grid - Grid lines
gtext - Place text with mouse
box - Axis box
MATLAB Programming
We can also do programming in MATLAB as we are doing in FORTRAN, C & C++. To
make a file in MATLAB we have to click on “New” in the file menu in menu bar. It will open a
new file as we are doing in “word”; and if we save this file (called m-file), will be saved in
“bin” folder of MATLAB.
Such files are called “M-files” because they have an extension of “.m” in its filename. Much
of your work with MATLAB will be creating and refining M-files.
There are two types of M-files: Script Files and Function Files
Script Files
A script file consists of a sequence of normal MATLAB statements. If the file has the
filename, say, rkg.m, then the MATLAB command >> rkg will cause the statements in the
file to be executed. Variables in a script file are global and will change the value of variables
of the same name in the environment of the current MATLAB session.
Script files are often used to enter data into a large matrix; in such a file, entry errors can
be easily edited out.
17
ECE 112 Communication Systems (LAB) Laboratory 1
d =
-1.5000 0 1.0000
0 2.0000 -1.0000
1.0000 -1.0000 0
The % symbol indicates that the rest of the line is a comment. MATLAB will ignore the rest
of the line. However, the first comment lines which document the m-file are available to the
online help facility and will be displayed
A M-file can also reference other M-files, including referencing itself recursively.
Function Files
Function files provide extensibility to MATLAB. You can create new functions specific to
your problem which will then have the same status as other MATLAB functions. Variables in
a function file are by default local. However, you can declare a variable to be global if you
wish.
Example
function y = prod (a,b)
y = a*b;
Save this file with filename prod.m then type on the MATLAB prompt
As we know that if we don’t write “;” after a statement in MATLAB, it will print the
output also. That means if in a programme we write:
Control Flow
MATLAB offers the following decision making or control flow structures:
1. If- Else –End Construction
2. For loops
18
ECE 112 Communication Systems (LAB) Laboratory 1
3. While loops
4. Switch-Case constructions etc.
if expression
statements
elseif expression
statements
else
statements
end
The statements are executed if the real part of the expression has all non-zero elements.
The else and elseif parts are optional. zero or more elseif parts can be used as well as
nested if's. The expression is usually of the form
expr rop expr
where rop is ==, <, >, <=, >=, or ~=.
Example:
if i == j
a(i,j) = 2;
elseif abs(i-j) == 1
a(i,j) = -1;
else
if expression
statements
elseif expression
statements
else
statements
end
19
ECE 112 Communication Systems (LAB) Laboratory 1
if expression
statements
elseif expression
statements
else
statements
end
4) end terminate scope of for, while, switch, try, and if statements. Without end's, for,
while, switch, try, and if wait for further input. each end is paired with the closest previous
unpaired for, while, switch, try or if and serves to terminate its scope. end can also serve as
the last index in an indexing expression. in that context,
end = size(x,k) when used as part of the k-th index. examples of this use are,
x(3:end) and x(1,1:2:end-1). when using end to grow an array, as in x(end+1) = 5,
make sure x exists first.
The columns of the expression are stored one at a time in the variable and then the
following statements, up to the end, are executed. The expression is often of the form x:y, in
which case its columns are simply scalars. some examples
Long loops are more memory efficient when the colon expression appears in the for
statement since the index vector is never created.
6) The break statement can be used to terminate the loop prematurely. break terminate
execution of while or for loop. In nested loops, break exits from the innermost loop only.
20
ECE 112 Communication Systems (LAB) Laboratory 1
The statements are executed while the real part of the expression has all non-zero
elements. The expression is usually the result of expr rop expr where rop is ==, <,
>, <=, >=, or ~=.
Example:
switch switch_expr
case case_expr,
statement, ..., statement
case {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
otherwise,
statement, ..., statement
end
The first case where the switch_expr matches the case_expr is executed. when the case
expression is a cell array (as in the second case above), the case_expr matches if any of
the elements of the cell array match the switch expression. If none of the case expressions
match the switch expression then the otherwise case is executed (if it exists). Only one
case is executed and execution resumes with the statement after the end. the switch_expr
can be a scalar or a string. A scalar switch_expr matches a case_expr if
switch_expr==case_expr. A string switch_expr matches a case_expr if
strcmp(switch_expr,case_expr) returns 1 (true).
Example:
21
ECE 112 Communication Systems (LAB) Laboratory 1
switch switch_expr
case case_expr,
statement, ..., statement
case {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
otherwise,
statement, ..., statement
end
The otherwise part is executed only if none of the preceding case expressions match the
switch expression.
Normally, only the statements between the try and catch are executed. however, if an error
occurs while executing any of the statements, the error is captured into lasterr and the
statements between the catch and end are executed. if an error occurs within the catch
statements, execution will stop unless caught by another try...catch block. The error string
produced by a failed try block can be obtained with lasterr.
22
ECE 112 Communication Systems (LAB) Laboratory 1
Example:
function d = det(a)
if isempty(a)
d = 1;
return
else
...
End
Data File:
Now to make a data file in MATLAB, we just make a file in which all the data are stored.
Now we make another file in which the operation on that data is to be done. Then in this file,
where we have to call that data we have to just type the file name of the file in which data is
stored and write the rest of the programming statements. So when run this file the file in
which data is stored will be called and then rest of the programming statements are
executed & finally we get the output.
MEX-Files:
We can call our C programs from MATLAB as if they were built in functions. Those
programs in C which are callable in MATLAB are referred as MEX-Files. MEX-files are
dynamically linked subroutines that the MATLAB interpreter can automatically load &
execute.
For example the following program in C to add two integers having file name “add”.
#include<stdio.h>
main( )
{ int a=2,b=3;
d=a+b;
printf(‘sum is:’,d);
return 0;
}
>>mex add.c
23
ECE 112 Communication Systems (LAB) Laboratory 1
Some Examples:
1) Example for if, else
for i = 1:n
for j = 1:n
if i==j
a(i, j) = 2
elseif abs(i – j) ==1
a(i, j) = -1;
else
a(i, j) = 0;
end
end
end
eps = 1
while (1+eps)>1
eps = eps/2;
end
eps = eps*2
24
ECE 112 Communication Systems (LAB) Laboratory 1
RELATIONAL OPERATORS
MATLAB relational operators includes the following:
MATLAB relational operators can be used to compare two arrays of the same size, or to
compare an array to a scalar. When we compare an array to a scalar, scalar expansion is
used to compare the scalar to each array element and the result has the same size as the
array.
NOTE: = and == mean two different things:
== compares two variables and returns ones where they are equal and zeros where
they are not; while, = is used to assign the output of an operation to a variables.
Example:
>> a = 1:0.5:10;
>> b = 5:0.5:14;
>> c = a > 5
c =
Columns 1 through 12
0 0 0 0 0 0 0 0 0 1 1 1
Columns 13 through 19
1 1 1 1 1 1 1
>> d = (a ==b)
d =
Columns 1 through 12
0 0 0 0 0 0 0 0 0 0 0 0
Columns 13 through 19
0 0 0 0 0 0 0
LOGICAL OPERATORS
MATLAB logical operators include the following:
Example:
>> a = 1:15;
25
ECE 112 Communication Systems (LAB) Laboratory 1
>> b = ~ ( a < 5 )
b =
Columns 1 through 12
0 0 0 0 1 1 1 1 1 1 1 1
Columns 13 through 15
1 1 1
26
ECE 112 Communication Systems (LAB) Laboratory 1
7. A function M-file terminates after the last line in the file is executed or whenever a
return statement is encountered.
8. A function can abort operation and return control to the command window by calling
the function error. This function is useful for flagging improper function usage, as
shown in the following file fragment:
if length ( mat ) > 1
error ( ‘MAT must be a scalar.’)
end
if the function error is executed as shown, the string ‘VAL must be a scalar.’ Is
displayed in the command window after a line identifying the file the error message
originated from. If the function error is given a zero-length character string, it takes no
action.
9. A function can report a warning and then continue operation by calling the function
warning. This function is useful for reporting exceptions and other anomalous
behavior. warning (‘some message’) displays a character string in the command
window. The difference between the function warning and the function disp is that
warning messages can be turned on or off globally by issuing the commands warning
on and warning off, respectively.
10. Function M-files can contain calls to script files. When a script file is encountered, it is
evaluated in the function’s workspace, not the MATLAB workspace.
11. Multiple functions can appear in a single function M-file. Additional functions, called
subfunctions or local functions, are simply appended to the end of the primary function.
Subfunctions begin with a standard function statement line and follow function
construction rules.
12. Subfunctions can be called by the primary function in the M-file as well as by other
subfunctions in the same M-file. As with all functions, subfunctions have their own
individual workspaces.
13. Subfunctions can appear in any order after the primary function in a M-file. Help text
for subfunctions is not returned by the help command.
14. It is suggested that subfunction names begin with the word local (e.g., local_bsr).
Doing so improves the readability of the primary function because calls to local
functions are clearly identifiable. All local function names can have up to 31 characters.
15. In addition to subfunctions, M-files can call private M-files, which are standard function
M-files that reside in a subdirectory of the calling function that is entitled private. Only
functions in the immediate parent directory of private M-files have access to private
M-file.
16. It is suggested that private M-file names begin with the word private (e.g.,
private_bsr). Doing so improve the readability of the primary function because calls
to private functions are clearly identifiable. As with other function names, all private M-
file names can have up to 31 characters.
27
ECE 112 Communication Systems (LAB) Laboratory 1
3. The number of input and output arguments used in a function call can be determined
by calls to the functions nargin and nargout, respectively. Since nargin and
nargout are functions, not variables, one cannot reassign them with statements
such as
Nargin = nargin – 1
4. When a function is called, the input variables are not copied into the function’s
workspace, but their values are made readable within the function. However, if any
values in the input variables are changed, the array is then copied into the function’s
workspace. Thus, to conserve memory and increase speed, it is best to extract
elements from large arrays and then modify them, rather than forcing the entire array
to be copied into the function’s workspace. Note that using the same variable name
for both an input and output argument causes an immediate copying of the contents
of the variable into the function’s workspace. For example,
If this function is called as a = myfunction(x, y, z), then inside the function varargin(1)
contains the array x, varargin(2) contains the array y, and varargin(3) contains the
array z. Likewise, if the function is called as a = myfunction(x), varargin has length
1 and varargin{1} = x. Every time myfunction is called, it can be called with a
different number of arguments. In any case, the function nargin returns the actual
number of input arguments used.
In those cases where one or more input arguments are fixed, varargin must appear
as the last argument, such as
If this function is called as a = myfunction(x, y, z), then inside the function x and y
are available and varargin(1) contains z.
7. Functions can accept a variable and unlimited number of output arguments by
specifying varargout as the last output argument in the function declaration line.
Varargout is a predefined cell array whose ith cell is the ith argument starting from
where varargout appears. For example, consider a function having the function
declaration line
function varargout = myfunction (x)
28
ECE 112 Communication Systems (LAB) Laboratory 1
If this function is called as [a, b] = function (x), then inside the function the contents of
varargout(1) must be assigned to the data that become the variable a, and
varargout(2) must be assigned to the data that become the variable b. As with
varargin, the length of varargout is equal to the number of output arguments used
and nargout returns this length. In those cases where one or more output arguments
are fixed, varargout must appear as the last argument in the function declaration line
–for example, function [a, b, varargout] = myfunction (x).
FUNCTION WORKSPACES
Functions accept inputs, act on those inputs, and create outputs. Any and all variables
created within the function are hidden from the MATLAB or base workspace. Each function
has its own temporary workspace that is created with each function call and then deleted
when the function completes execution. MATLAB functions can be called recursively and
each call has a separate workspace. In addition to input and output arguments, MATLAB
provides several techniques for communicating among function workspaces and the
MATLAB or base workspace.
1. Function can share variables with other function, the MATLAB workspace, and
recursive calls to themselves if the variables are declared global. To gain access to a
global variable within a function or the MATLAB workspace, the variable must be
declared global within each desired workspace. The MATLAB functions tic and toc
illustrate the use of global variables. The functions tic and toc form a simple stopwatch
for timing MATLAB operations. When tic is called, it declares the variable TICTOC
global, assigns the current time to it, and then terminates. Later when toc is called,
TICTOC is declared global in the toc workspace, there by providing access to its
contents, and the elapsed time is computed. It is important to note that the variable
TICTOC exists only in the workspaces of the functions tic and toc; it does not exist in
the MATLAB workspace unless global TICTOC is issued there.
2. In addition to sharing data through global variables, MATLAB provides the function
evalin, which allows one to reach into another workspace, evaluate an expression,
and return the result to the current workspace. The function evalin is similar to eval,
except that the string is evaluated in either the caller or base workspace. The caller
workspace is the workspace from which the current function was called. The base
workspace is the MATLAB workspace in the command window. For example,
A = evalin(‘caller’,’expression’) evaluates ‘expression’ in the caller workspace and
returns the results to the variable A in the current workspace. evalin also provides
error trapping with the syntax evalin(‘workspace’,’try’,’catch’), where ‘workspace’
is either ‘caller’ or ‘base’, ‘try’ is the first expression evaluated, and ‘catch’ is an
expression that is evaluated in the current workspace if the evaluation of ‘try’
produces an error.
3. one can evaluate an expression in another workspace, it makes sense that one can
also assign the results of some expression in the current workspace to a variable in
another workspace. The function assignin provides this capability.
assignin(‘workspace’,’vname’,X), where ‘workspace’ is either ‘caller’ or ‘base’,
assigns the contents of the variable X in the current workspace to a variable in the
‘caller’ or ‘base’ workspace named ‘vname’.
4. The function inputname provides a way to determine the variable names used when
a function is called. For example, suppose a function is called as
>> y = myfunction(xdot,time,sqrt(2))
29
ECE 112 Communication Systems (LAB) Laboratory 1
30
ECE 112 Communication Systems (LAB) Laboratory 1
(6) it checks to see cow.p and then cow.m exists in each directory
specified on the MATLAB search path, by searching in the order in
which the search path is specified.
NOTE: M-file functions that are cached are considered read-only. If they are executed and
then later altered, MATLAB will simply execute the function that was previously compiled into
memory, ignoring the changed M-files. Moreover, if new M-files are added within are added
within the toolbox directory after MATLAB is running, their presence will not be noted in the
cache, and thus they will be unavailable for use.
6. When new M-files are added to a cached location, MATLAB will find them only if the
cache is refreshed by issuing the command path(path). On the other hand, when
cached M-files are modified, MATLAB will recognize the changes only if a previously
compiled version is dumped from memory by issuing the clear command.
7. MATLAB keeps track of the modification date of M-files outside the toolbox directory.
As a result, when an M-file function is encountered that was previously compiled into
memory, MATLAB compares the modification dates of the compiled M-file with that of
the M-file on disk. If the dates are the same, MATLAB executes the compiled M-file.
On the other hand, if the M-file and compiles the newer, revised M-file for execution.
>> [x , t]=ode45(‘filename’,tspan,x0)
Here we have to create a new file suppose the file name is orddiff.m. In that file we have to
write the above system of differential equation, and for that we write a function:
function y = filename (t, x)
y = [system of differential equations]
31
ECE 112 Communication Systems (LAB) Laboratory 1
i.e. we write :
function y = orddiff(t,x)
y = [-x(1)-t .^2*x(2); -t .^2*x(1)-x(2)]
After doing this go to command prompt. Here initial conditions are [1 1]’ so our x0=[1 1]’ and
we have to solve this ode on [0 1] so our tspan=[0 1], then
>> [x t] = ode45(‘orddiff’,tspan,x0)
>> X= fmin(‘filename’,x1,x2)
Here we have to create a new file suppose the file name is rkgmin.m. In that file we have to
write the above function, and for that we write a function:
function y = filename (x)
y = function
i.e. we write :
function y = rkgmin(x)
y = x .^2;
After doing this go to command prompt. Here the interval on which we have to find the
minimum is [2, 4] so our x1 = 2 and x2 = 4. On command prompt now you type:
>>X = fmin(‘rkgmin’,x1,x2)
32
ECE 112 Communication Systems (LAB) Laboratory 1
In most media for communication, only a fixed range of frequencies is available for
transmission. One way to communicate a message signal whose frequency spectrum does
not fall within that fixed frequency range, or one that is otherwise unsuitable for the channel,
is to alter a transmittable signal according to the information in your message signal. This
alteration is called modulation, and it is the modulated signal that you transmit. The receiver
then recovers the original signal through a process called demodulation. The contents of this
tool box are as follows.
a) Modulation Features of the Toolbox--Overview of the modulation types and
modulation operations that the Communications Toolbox supports
b) Modulation Terminology--Definitions of terms, as well as inequalities that certain
modulation quantities must satisfy
c) Analog Modulation--Representing analog signals and performing analog modulation
d) Digital Modulation—Representing digital signals, representing signal constellations for
digital modulation, and performing digital modulation
This section describes how to represent analog signals using vectors or matrices. It provides
examples of using the analog modulation and demodulation functions. Representing Analog
Signals To modulate an analog signal using this toolbox, start with a real message signal and
a sampling rate Fs in hertz. Represent the signal using a vector x, the entries of which give
the signal's values in time increments of 1/Fs. Alternatively, you can use a matrix to represent
a multichannel signal, where each column of the matrix represents one channel..
Syntax
z = amdemod(y,Fc,Fs)
z = amdemod(y,Fc,Fs,ini_phase)
z= amdemod(y,Fc,Fs,ini_phase,carramp)
z = amdemod(y,Fc,Fs,ini_phase,carramp,num,den)
33
ECE 112 Communication Systems (LAB) Laboratory 1
Description:
z = amdemod(y,Fc,Fs)
demodulates the amplitude modulated signal y from a carrier signal with frequency Fc (Hz).
The carrier signal and y have sample frequency Fs (Hz). The modulated signal y has zero
initial phase and zero carrier amplitude, so it represents suppressed carrier modulation.
The demodulation process uses the lowpass filter specified by [num,den] =
butter(5,Fc*2/Fs).
Note: The Fc and Fs arguments must satisfy Fs > 2(Fc + BW) where BW is the bandwidth
of the original signal that was modulated.
z = amdemod(y,Fc,Fs,ini_phase)
specifies the initial phase of the modulated signal in radians.
z = amdemod(y,Fc,Fs,ini_phase,carramp)
demodulates a signal that was created via transmitted carrier modulation instead of
suppressed carrier modulation. carramp is the carrier amplitude of the modulated signal.
z = amdemod(y,Fc,Fs,ini_phase,carramp,num,den)
specifies the numerator and denominator of the lowpass filter used in the demodulation.
y = ammod(x,Fc,Fs)
y = ammod(x,Fc,Fs,ini_phase)
y = ammod(x,Fc,Fs,ini_phase,carramp)
Description:
y = ammod(x,Fc,Fs)
uses the message signal x to modulate a carrier signal with frequency Fc (Hz) using
amplitude modulation. The carrier signal and x have sample frequency Fs (Hz). The
modulated signal has zero initial phase and zero carrier amplitude, so the result is
suppressed-carrier modulation.
Note The x, Fc, and Fs input arguments must satisfy Fs > 2(Fc + BW), where BW is the
bandwidth of the modulating signal x.
y = ammod(x,Fc,Fs,ini_phase)
specifies the initial phase in the modulated signal y in radians.
y = ammod(x,Fc,Fs,ini_phase,carramp)
performs transmitted-carrier modulation instead of suppressed-carrier modulation. The
carrier amplitude is carramp.
34
ECE 112 Communication Systems (LAB) Laboratory 1
y = fmmod(x,Fc,Fs,freqdev)
y = fmmod(x,Fc,Fs,freqdev,ini_phase)
Description:
y = fmmod(x,Fc,Fs,freqdev)
modulates the message signal x using frequency modulation. The carrier signal has
frequency Fc (Hz) and sampling rate Fs (Hz), where Fs must be at least 2*Fc. The freqdev
argument is the frequency deviation (Hz) of the modulated signal.
y = fmmod(x,Fc,Fs,freqdev,ini_phase)
specifies the initial phase of the modulated signal, in radians.
z = fmdemod(y,Fc,Fs,freqdev)
z = fmdemod(y,Fc,Fs,freqdev,ini_phase)
Description:
z = fmdemod(y,Fc,Fs,freqdev)
demodulates the modulating signal z from the carrier signal using frequency demodulation.
The carrier signal has frequency Fc (Hz) and sampling rate Fs (Hz), where Fs must be at
least 2*Fc. The freqdev argument is the frequency deviation (Hz) of the modulated signal
y.
z = fmdemod(y,Fc,Fs,freqdev,ini_phase)
specifies the initial phase of the modulated signal, in radians.
y = pmmod(x,Fc,Fs,phasedev)
y = pmmod(x,Fc,Fs,phasedev,ini_phase)
Description
y = pmmod(x,Fc,Fs,phasedev)
modulates the message signal x using phase modulation. The carrier signal has frequency
Fc (Hz) and sampling rate Fs (Hz), where Fs must be at least 2*Fc. The phasedev argument
is the phase deviation of the modulated signal in radians.
y = pmmod(x,Fc,Fs,phasedev,ini_phase)
specifies the initial phase of the modulated signal in radians.
35
ECE 112 Communication Systems (LAB) Laboratory 1
z = pmmod(y,Fc,Fs,phasedev)
z = pmmod(y,Fc,Fs,phasedev,ini_phase)
Description:
z = pmmod(y,Fc,Fs,phasedev)
demodulates the phase-modulated signal y at the carrier frequency Fc (Hz). z and the
carrier signal have sampling rate Fs (Hz), where Fs must be at least 2*Fc. The phasedev
argument is the phase deviation of the modulated signal, in radians.
z = pmmod(y,Fc,Fs,phasedev,ini_phase)
specifies the initial phase of the modulated signal, in radians.
z = ssbdemod(y,Fc,Fs)
z = ssbdemod(y,Fc,Fs,ini_phase)
z = ssbdemod(y,Fc,Fs,ini_phase,num,den)
Description:
For All Syntaxes
z = ssbdemod(y,Fc,Fs)
demodulates the single sideband amplitude modulated signal y from the carrier signal
having frequency Fc (Hz). The carrier signal and y have sampling rate Fs (Hz). The
modulated signal has zero initial phase, and can be an upper- or lower-sideband signal.
The demodulation process uses the lowpass filter specified by [num,den] =
butter(5,Fc*2/Fs).
Note The Fc and Fs arguments must satisfy Fs > 2(Fc + BW), where BW is the bandwidth
of the original signal that was modulated.
z = ssbdemod(y,Fc,Fs,ini_phase)
specifies the initial phase of the modulated signal in radians.
z = ssbdemod(y,Fc,Fs,ini_phase,num,den) specifies the numerator and
denominator of the
lowpass filter used in the demodulation.
y = ssbmod(x,Fc,Fs)
y = ssbmod(x,Fc,Fs,ini_phase)
y = ssbmod(x,fc,fs,ini_phase,'upper')
36
ECE 112 Communication Systems (LAB) Laboratory 1
Description:
y = ssbmod(x,Fc,Fs)
uses the message signal x to modulate a carrier signal with frequency Fc (Hz) using single
sideband amplitude modulation in which the lower sideband is the desired sideband. The
carrier signal and x have sample frequency Fs (Hz). The modulated signal has zero initial
phase.
y = ssbmod(x,Fc,Fs,ini_phase)
specifies the initial phase of the modulated signal in radians.
y = ssbmod(x,fc,fs,ini_phase,'upper')
uses the upper sideband as the desired sideband.
REFERENCES:
1. Getting started with MATLAB7 by Rudra Pratap (Oxford press)
2. Contemporary communication systems using MATLAB by Proakis, Salehi and
Bauch (Cenage learning)
4.0 QUESTIONS:
1. What are the application areas of MATLAB?
2. List out types of file in MATLAB.
3. How to generate x and y coordinates of 100 equidistant points on a unit circle?
4. How to do array operations?
37