Professional Documents
Culture Documents
SCHOOL OF ENGINEERING
UDAIPUR
LABORATORY MANUAL
DEPARTMENT
DEPARTMENT OF ELECTRONICS & COMMUNICATION
ENGINEERING
1
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
2
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
LIST OF EXPERIMENTS
NAME OF THE STUDENT………………………………………. ENROLL. NO…………………………
INDEX
Page Date of Date of Sign /grade
S. N. Name of the experiment
no. allotment conduction
To study MATLAB and
1
communication tool box
To generate AM wave without
2
using matlab inbuilt function
To generate AM wave and plot it’s
3
frequency spectrum using matlab
To generate AM wave for different
4 value of modulation index(m<1,
m=1 & m>1) using matlab
To generate FM wave and plot it’s
5
frequency spectrum using matlab
To generate Amplitude Modulation
6 (AM) wave and determine it’s
Modulation Index ‘ma ’
To demodulate amplitude
7
modulated wave
To generate frequency modulation
8
wave
To demodulate frequency
9
modulated wave
3
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:01
1. AIM:
2. APPARATUS/COMPONENTS REQUIRED:
Theory:
MATLAB
1. INTRODUCTION
( a )What is MATLAB?
4
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
( 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,
5
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
84
( 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
You can exit MATLAB with the command exit or quit. A computation can be stopped with
[ctrl-c]
6
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
7
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
( 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
8
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
( iv) To recall previous commands, MATLAB uses the cursor keys ←, ↑, →, ↓ on your
keyboard.
>> e= 1/3
e=
0.3333
>> e
e=
0.33333333333333
9
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
( vi ) To suppress the display of output of a command on screen put semicolon ‘;’ after the
command.
>> 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
10
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
>> abs ( c )
ans =
2.2361
>> real ( c )
ans =
1
>> imag ( c )
ans =
-2
>> angle ( c )
ans =
-1.1071
>> help
11
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Scalers - 1 by 1 matrix
Row vector - matrix with one row
Column vector - matrix with one column.
>> 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 ];
>> b = a’
b=
1 4 7
2 5 8
3 6 9
12
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Function Task
+ Addition
- Subtraction
* Multiplication
^ Power
‘ Transpose
\ Left Division
/ Right Division
Examples:
2 6 10
6 10 14
10 14 18
0 -2 -4
2 0 -2
4 2 0
c=
14 32 50
32 77 122
50 122 194
13
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
16.1168
-1.1168
0.0000
d=
16.1168 0 0
0 -1.1168 0
0 0 0.0000
14
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
3 3
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
15
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
>> a = hilb(5)
a=
ans =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
ans =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
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
16
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
1 2 3 4
5 6 7 1
2 3 4 5
>> b= a(1:2,3) (Vector consisting of the first 2 entries of the 3rd column of a)
b=
3
7
c=
3
7
4
1 2 3 4
5 6 7 1
e=
2 3 4 5
f=
2 4
6 1
3 5
17
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
aa =
3 4
7 1
b=
1 2 3 0 0
4 5 6 0 0
7 8 9 0 0
1 1 1 1 0
1 1 1 0 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
5 4 3 2 1 0
18
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
25
>> mean(t) (mean of elements of t)
ans =
1 3 5 7 9
ans =
945
ans =
>> any(t)
ans =
19
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
>> all(t)
ans =
1
>> std(t) (standard deviation)
ans =
3.1623
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
>> x = 0:0.5:10; (generates points in the given interval)
>> y = sin(x); (calculate function values at the x points)
>> plot(x,y) (Plots x verses y)
This will display the following graph:
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7 8 9 10
20
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
We can also give the title, x-label, y-label to the graph, to do this you type as follows on
MATLAB command prompt:
>> title(‘Graph Of Sine Function’);
>>xlabel(‘X Values’);
>>ylabel(‘Y=Sin(x)’);
It will display the graph as follows:
0.8
0.6
0.4
0.2
Y = Sin(x)
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7 8 9 10
X Values
More on plots
plot(x,y) plots vector y versus vector x.
If x or y is a matrix, then the vector is plotted versus the rows or columns of the matrix,
whichever line up.
plot(y) plots the columns of y versus their index.
If y is complex, plot(y) is equivalent to plot(real(y),imag(y)).
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 colunms:
y yellow . point - solid m magenta
o circle : dotted c cyan x x-mark
-. dashdot r red + plus -- dashed
g green * star b blue s square
w white d diamond k black v triangle (down)
^ triangle (up) < triangle (left) > triangle (right) p pentagram
h hexagram
21
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.More
than one plot in the same graph
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 2Π)
>> 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)
x=sin(t)
0.8 y=cos(t)
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
22
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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)
>> grid
>> subplot(2,2,4),plot(x,z1)
>>grid
It displays the graph as follows:
23
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
40 1
35
30 0.5
25
20 0
15
10 -0.5
0 -1
-10 -5 0 5 10 -10 -5 0 5 10
1 600
500
0.5
400
0 300
200
-0.5
100
-1 0
-10 -5 0 5 10 -10 -5 0 5 10
24
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
MATLAB Programming
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.
Example: In a file rkg.m enter the following:
% This is a sample m-file
a = [1,2,3;0,1,1;1,2,3]
b =a’;
c = a+b
d = inv(c)
save this file. Then to execute this file, type
a=
1 2 3
0 1 1
1 2 3
b=
1 0 1
2 1 2
3 1 3
25
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
c=
2 2 4
2 2 3
4 3 6
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 comments. MATLAB will ignore the rest of
the line. However, the first comment lines which document the m-file are available to the on-
line 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
Save this file with filename prod.m then type on the MATLAB prompt
>> prod (3,4)
ans =
12
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:
a=input (‘ Enter a number ‘);
26
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Control Flow
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
27
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
28
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
while expression
statements
end
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:
(assuming a already defined)
e = 0*a; f = e + eye(size(e)); n = 1;
while norm(e+f-e,1) > 0,
e = e + f;
f = a*f/n;
n = n + 1;
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
29
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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:
(assuming method exists as a string variable):
switch lower(method)
case {'linear','bilinear'}, disp('method is linear')
case 'cubic', disp('method is cubic')
case 'nearest', disp('method is nearest')
otherwise, disp('unknown method.')
end
9) case switch statement case:
case is part of the switch statement syntax, whose general form is:
switch switch_expr
case case_expr,
statement, ..., statement
case {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
otherwise,
statement, ..., statement
end
otherwise is part of the switch statement syntax, whose general form is:
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 preceeding case expressions match the
switch expression.
30
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
Example:
function d = det(a)
if isempty(a)
d = 1;
return
else
...
end
Suppose we have created a m-file & saved. Now to run this program, on command prompt
type the file name and just press the ENTER KEY that will run the file.
Data File:
31
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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;
}
To compile & link this example at the MATLAB prompt, type
>>mex add.c
and press the “ENTER”key, it will give the output.
>> pause --- causes to stop execution of until any key is pressed.
Some Examples:
1) Example for if, else
for i = 1:n
for j = 1:n
if i==j
a(i, j) = 2
32
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
eps = 1
while (1+eps)>1
eps = eps/2;
end
eps = eps*2
3) Gauss Elimination Method
33
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
RELATIONAL OPERATORS
Relational Description
Operator
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or
equal to
==
Equal to
~=
Not equal to
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.
>> 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
34
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
>> 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
Example:
>> a = 1:15;
>> 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
35
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Columns 1 through 12
0 0 1 1 1 1 1 0 0 0 0 0
Columns 13 through 15
0 0 0
Columns 1 through 12
1 1 1 1 1 1 1 1 1 1 1 1
Columns 13 through 15
1 1 1
36
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Function M-files must satisfy a number of criteria. Some of them are as follows:
1. The function M-file name and the function name ( e.g., rkg) that appears in the first line
of the file should be identical. In reality, MATLAB ignores the function name in the first
line and executes functions based on the file name stored on disk.
2. Function M-file names can have up to 31 characters. This maximum may be limited by
the operating system, in which case the lower limit applies. MATLAB ignores
characters beyond the thirty-first or the operating system limit, so longer names can be
used, provided the legal characters point to a unique file name.
3. Function names must begin with a letter. Any combination of letters, numbers, and
underscores can appear after the first character. This naming rule is identical to that for
variables.
4. The first line of a function M-file is called the function declaration line and must
contain the word function followed by the calling syntax for the function in its most
general form. The input and output variables identified in the first line are variables local
to the function. The input variables contain data passed to the function and the output
variables contain data passed back from the function. It is not possible to pass data back
though the input variables.
5. The first sets of contiguous comment lines after the function declaration line are the help
text for the function. The first comment line is called the H1 line and is the line searched
by the lookfor command. The H1 line typically contains the function name in uppercase
characters and a concise description of the function’s purpose. Comment lines after the
first describe possible calling syntaxes, algorithms used, and simple examples, if
appropriate.
6. All statements after the first set of contiguous comment lines compose the body of the
function. The body of a function contains MATLAB statements that operate on the input
arguments and produce results in the output arguments.
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 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.
37
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
MATLAB functions can have any number of input and output arguments. The features and
criteria of these arguments are as follows:
1. Function M-files can have zero input and zero output arguments.
2. Functions can be called with fewer input and output arguments than the function
definition line in the M-file specifies. Functions cannot be called with more input or
output arguments than the M-file specifies.
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
38
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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,
function y = myfunction (x, y, z)
causes the variable y to be copied immediately into the workspace of myfunction.
5. If a function declares one or more output arguments, but no output is desired, simply do
not assign values to the output variable or variables.
6. Functions can accept a variable and unlimited number of input arguments by specifying
varargin as the last input argument in the function declaration line. Varargin is a
predefined cell array whose ith cell is the ith argument starting from where varargin
appears. For example, consider a function having the function declaration line
Function a = myfunction(varargin)
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)
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).
39
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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. Since 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))
issuing inputname(1) inside of myfunction returns the character string ‘xdot’,
inputname(2) returns ‘time’, and inputname (3) returns an empty array because
sqrt(2) is not a variable, but rather an expression that produces an unnamed temporary
result.
40
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5. The name of the M-file being executed is available within a function in the variable
myfilename. For example, when the M-file myfunction.m is being executed, the
workspace of the function contains the variable myfilename, which contains the
character string ‘myfunction’. This variable also exists within script files, in which case
it contains the name of the script file being executed.
Function M-files are one of the fundamental strengths of MATLAB. They allow one to
encapsulate sequences of useful commands and apply them over and over. Since M-files
exist as text files on disk, it is important that MATLAB maximize the speed at which the
files are found, opened, and executed. The techniques that MATLAB uses to maximize
speed are as follows:
1. The first time MATLAB executes a function M-file, it opens the corresponding text file
and compiles the commands into an internal pseudocode representation in memory that
speeds execution for all later calls to the function. If the function contains references to
other M-file functions and script M-files, they too are compiled into memory.
2. The function inmem returns a cell array of strings containing a list of functions and
script files currently compiled into memory.
3. It is possible to store the compiled or P-Code version of a function M-file to disk using
the pcode command. When this is done, MATLAB loads the compiled function into
memory rather than the M-file. For most functions this step does not significantly
shorten the amount of time required to execute a function the first time. However, it can
speed up large M-files associated with complex graphical user interface functions. P-
Code files are created by issuing
where myfunction.m is the M-file name to be compiled. P-Code files are platform-
independent binary files that have the same name as the original M-file, but end in .p
rather than .m. P-Code files also provide a level of security, since they are visually
undecipherable and can be run without the corresponding M-file.
4. When MATLAB encounters a name that it does not recognize, it follows a set of rules to
determine what to do. Given the information presented here, the set of rules can be
updated as follows:
When you enter cow at the MATLAB prompt or if MATLAB encounters a reference to
cow in a script or function M-file,
41
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5. it checks to see if cow.p and then cow.m exists in the current directory;
if not,
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.
MATLAB uses the first match it finds.
5. When MATLAB is started, it caches the name and location of all M-files stored within
the toolbox subdirectory and in all subdirectories of the toolbox directory. This allows
MATLAB to find and execute function M-files much faster. It also makes the command
lookfor work faster.
In the development of M-file functions, it is best to store them outside the toolbox
directory, perhaps in the MATLAB directory, until they are considered complete. When
they are complete, move them to a subdirectory inside the read only toolbox directory.
Finally, make sure the MATLAB search path is changed to recognize their existence.
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.
NOTE: You can also create your own toolboxes.
>> [x , t]=ode45(‘filename’,tspan,x0)
42
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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)
will solve this system of differential equations.
>> 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)
will solve this system of differential equations.
43
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
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.
• Modulation Features of the Toolbox--Overview of the modulation types and
modulation operations that the Communications Toolbox supports
• Modulation Terminology--Definitions of terms, as well as inequalities that certain
modulation quantities must satisfy
• Analog Modulation--Representing analog signals and performing analog modulation
• 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.
44
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
45
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Syntax
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.
Syntax
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.
Syntax:
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.
46
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Syntax :
z = ssbdemod(y,Fc,Fs)
z = ssbdemod(y,Fc,Fs,ini_phase)
z = ssbdemod(y,Fc,Fs,ini_phase,num,den)
Description:
For All Syntaxesz = 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.
Syntax
y = ssbmod(x,Fc,Fs)
y = ssbmod(x,Fc,Fs,ini_phase)
y = ssbmod(x,fc,fs,ini_phase,'upper')
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 sisedband.
REFERENCES:
47
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
QUESTIONS:
48
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO: 02
.
1. AIM:
2. APPARATUS REQUIRED:
3. PROGRAM:
clear all
T = 1/100;
fm = 0.25;
fc = 10;
mt = sin(2*pi*fm*[0:T:10]);
subplot (3,1,1);
plot(mt)
ct = sin(2*pi*fc*[0:T:10]);
subplot(3,1,2);
plot(ct)
4. CONCLUSION:
49
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5. REFERENCES:
1. Getting started with MATLAB7 by Rudra Pratap (Oxford press)
2. Contemporary communication systems using MATLAB by Proakis, Salehi and
Bauch (Cenage learning)
6. QUESTIONS:
50
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:03
1. AIM:
To generate AM wave and plot it’s frequency spectrum using MATLAB
2. APPARATUS REQUIRED
S.N. Item required Specification Quantity
1. Computer
2. MATLAB
3. PROGRAM
51
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
52
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
4. CONCLUSION:
5. REFERENCES:
1. Getting started with MATLAB7 by Rudra Pratap (Oxford press)
2. Contemporary communication systems using MATLAB by Proakis, Salehi
and Bauch (Cenage learning)
6. QUESTIONS:
53
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
4. EXPERIMENT NO:04
1. AIM:
2. APPARATUS REQUIRED:
3. PROGRAM:
%Amplitude modulation ----Single Tone Modulation
%Carrier Amplitude
Ac=1;
%Carrier frequency
Fc=0.4;
%baseband frequency
Fm=0.05;
%sampling
Fs=10;
%%undermodulation
mu=0.5;
t=0:1/Fs:200;
mt=cos(2*pi*Fm*t);
st=Ac*(1+mu*mt).*cos(2*pi*Fc*t);
subplot(2,1,1);
plot(t,st,t,Ac*(mu*mt+ones(1,length(mt))),'r');
title('\mu=0.5 undermodulation£ºAc(1+\mucos(2\pi0.05t))cos(2\pi0.4t)');
xlabel('time (s)');ylabel('amplitude');
st_fft=fft(st);
st_fft=fftshift(st_fft);
st_fft_fre=Fs/2*linspace(-1,1,length(st_fft));
% st_fft=abs(st_fft(1:length(st_fft)/2+1));
% st_fft_fre=[0:length(st_fft)-1]*Fs/length(st_fft)/2;
subplot(2,1,2);
plot(st_fft_fre,abs(st_fft));
title('spectrum£ºside frequency amplitude=carrier frequency amplitude*\mu/2');
xlabel('Frequency (Hz)');axis([-1 1 0 1000*Ac+100]);
54
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
%total modulation
Fs=10;
Fm=2;
figure;
mu=1;
t=0:1/Fs:200;
mt=cos(2*pi*Fm*t);
st=Ac*(1+mu*mt).*cos(2*pi*Fc*t);
subplot(2,1,1);
plot(t,st,t,Ac*(mu*mt+ones(1,length(mt))),'r');
title('\mu=1 total modulation£ºAc(1+\mucos(2\pi0.05t))cos(2\pi0.4t)');
xlabel('time (s)');ylabel('amplitude');
st_fft=fft(st);
st_fft=fftshift(st_fft);
st_fft_fre=Fs/2*linspace(-1,1,length(st_fft));
subplot(2,1,2);
plot(st_fft_fre,abs(st_fft));
title('spectrum£ºside frequency amplitude=carrier frequency amplitude*\mu/2');
xlabel('Frequency (Hz)');axis([-1 1 0 1000*Ac+100]);
%%overmodulation
figure;
mu=2;
t=0:1/Fs:200;
mt=cos(2*pi*Fm*t);
st=Ac*(1+mu*mt).*cos(2*pi*Fc*t);
subplot(2,1,1);
plot(t,st,t,Ac*(mu*mt+ones(1,length(mt))),'r');
title('\mu=2 overmodulation£ºAc(1+\mucos(2\pi0.05t))cos(2\pi0.4t)');
xlabel('time (s)');ylabel('amplitude');
st_fft=fft(st);
st_fft=fftshift(st_fft);
st_fft_fre=Fs/2*linspace(-1,1,length(st_fft));
subplot(2,1,2);
plot(st_fft_fre,abs(st_fft));
title('spectrum£ºside frequency amplitude=carrier frequency amplitude*\mu/2');
xlabel('Frequency (Hz)');axis([-1 1 0 1000*Ac+100]);
55
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
4. RESULT:
.
5. REFERENCES:
5. Getting started with MATLAB7 by Rudra Pratap (Oxford press)
2. Contemporary communication systems using MATLAB by Proakis, Salehi
and Bauch (Cenage learning
6. QUESTIONS:
2. Draw AM envelope.
56
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:05
1. AIM:
3. PROGRAM:
%The frequency modulation(FM)waveform in time and frequency domain.
%fm=250HZ,fc=5KHZ,Vm=1V,Vc=1V,m=10,t=0:0.00001:0.09999
% setting
vc=1;
vm=1;
fm=250;
fc=5000;
m=10;
% x-axis:Time(second)
t=0:0.00001:0.09999;
f=0:10:99990;
% y-axis:Voltage(volt)
wc=2*pi*fc;
wm=2*pi*fm;
sc_t=vc*cos(wc*t);
sm_t=vm*cos(wm*t);
%kf=1000;
s_fm=vc*cos((wc*t)+10*sin(wm*t));
vf=abs(fft(s_fm,10^4))/5000;
% Plot figure in time domain
figure;
plot(t,s_fm);
hold on;
plot(t,sm_t,'r');
axis([0 0.01 -1.5 1.5]);
xlabel('time(second)'),ylabel('amplitude');
title('FM time-domain');
grid on;
57
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
4. RESULT:
58
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5. QUESTIONS:
.
4. What is the commercial Broadcast band FM?
59
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:06
1. AIM:
To generate Amplitude Modulation (AM) wave and determine it’s modulation
index ‘ma ’
2. APPARATUS REQUIRED:
3. BLOCK DIAGRAM
Message
signal m(t)
e (t)
fvbfggfs d ff
AM modulator CRO
Carrier
dfd
signal c(t)
4. THEORY:
A message signal (audio or video or pulses) cannot be transmitted over long distances
directly due to attenuation, distortion, interference and noise in any medium. A suitable high
frequency signal needs to be modulated by the low frequency band so that the message can be
transmitted efficiently over long distances.
Modulation:. Modulation is a scheme which alters some characteristics of the high frequency
signal, called the carrier signal of frequency fc, in accordance with the instantaneous value of
the low frequency message signal called the modulating signal of frequency fm . The resultant
60
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
signal is called modulated signal. The resultant modulation is accordingly termed as Analog
Modulation or Digital Modulation depending on whether the carrier is an Analog signal or a
Digital signal. The Analog modulation can be either Amplitude modulation or Angle
modulation (Phase modulation or Frequency modulation) for periodic continuous carrier waves
(continuous in time domain) or Pulse modulation for pulsed carrier (not continuous in time
domain).
Amplitude Modulation (AM): It is a process in which the maximum amplitude of the carrier
wave is varied linearly in accordance with instantaneous amplitude of modulating signal or base
band signal. The waves can be voltage or current signals. The waveforms of the carrier wave,
modulating wave and the resultant modulated wave are shown below. If the base band signal
consists of single frequency it is called as single tone modulation. If the base band signal
consists of more than one frequency it is called as multi tone modulation.
π fct+Φc)
ec(t) = Ecmax sin (2π
In amplitude modulation a voltage proportional to the modulating signal is added to the carrier
amplitude. Then modulated carrier wave is given by,
πfct+Φc)
e(t) = Ecmax +em(t) cos (2π
The term [Ecmax +em(t)] describes the envelop of the modulated wave.
Modulation index: The ratio of maximum amplitude of the modulating signal to the maximum
amplitude of carrier wave is defined as the amplitude modulation index and denoted by ‘ma ’.
The modulation index is also known as depth of modulation or degree of modulation or
modulation factor. Normally the value of ‘ma’ lies between 0 and 1. The modulation index is
given by expression
ma = Vm / Vc
61
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Clearly, the Envelope of the modulated signals has the same shape as m(t) when m < 1. If the
value of ‘ma’ exceeds 1, then the percentage modulation is greater than 100 and the base band
signal is not preserved in the envelope. In this case the base band signal recovered from the
envelope by the demodulator of a receiver will be distorted. This type of distortion is called
envelope distortion and AM signal is called over modulated.
Frequency spectrum: It is evident from the equation (7) that the frequency spectrum of the
resultant modulated signal in case of single tone modulation consists of the original carrier
frequency fc as well as additional frequencies (fc + fm) called as upper side frequency and
(fc- fm) called as lower side frequency. In case of multi tone modulation the base band
contains a range of frequencies from (fm + fm). In this case the frequency spectrum of the
resultant modulated signal consists of the original carrier frequency fc, an upper side band of
frequencies (fc + fm) to (fc + fm + fm) and a lower side band of frequencies (fc- fm) to (fc -
fm- fm).
62
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Benefits of modulation:
(i) Efficient radiation (ii) Practicality of antenna (iii) Frequency translation
(iv) Multipl;exing (v) Remove interference (vi) Reduction of noise
5. EXPERIMENTAL PROCEDURE :
63
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
6. OBSERVATION TABLE:
7. CONCLUSION:
8. REFERENCES:
64
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
9 QUESTIONS:
Q. 1. What is modulation?
65
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:07
1. AIM:
2. APPARATUS REQUIRED:
3. Block Diagram
Message
signal m(t)
e (t)
AM modulator
AM
fvbfggfs d ff
m’(t)
THEORY: 4
AM Demodulation is a process by which the message is recovered from the modulated
signal at the receiver. The devices used for demodulation or detection are called demodulator or
detector. Following two types of demodulators used for detection of amplitude modulated
waves.
(i) Square law detector
(ii) Envelop detectors
While Square law detectors are used for detection of low level amplitude modulated signal,
Envelope detectors are used for detection of high level amplitude modulated signal.
Square Law detectors: It is similar to diode modulator except the inclusion of a band pass
filter of low band width centered around modulating frequency fm. It uses the non
linear characteristic of diode. The detected waveform contains frequencies fm, fc, fc +
fm. While the modulating signal of low frequency fm is allowed to pass through the
66
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
filter, the high frequency carrier signal fc as well as upper side band fc +fm and lower
side band of frequency fc- fm are rejected.
Envelope detectors: Modulated signal output of receiver IF amplifier tuned circuit is passed
through the Envelope diode detector which has a parallel combination of R & C as the load
resistance across which rectified output voltage is developed .At its positive peak of the RF
cycle, C charges up to a potential almost to a peak signal voltage. The difference is due to the
diode drop since the forward resistance is small. Between peaks a little of the charge in C
decays through R, to be replenished at the next positive peak. The result is output envelope
which resembles the original modulating message signal. AGC circuit is used at the output of
the De-Modulator. In this demodulator the time constant RC is a critical parameter. If the value
of RC is very high, the capacitor C discharges slowly and in the process, the envelope does not
follow the modulating signal , if the amplitude of the later is decreasing and of negative slope.
This results in clipping of the amplitude of envelope. On the other hand if the value of RC is
very low, the capacitor C discharges very fast to a value lesser than the peak amplitude of next
positive cycle even before the arrival of peak value of next positive cycle. This results in saw
tooth type envelope. The resultant demodulated wave form is a highly distorted form of original
modulating signal under both condition of very high RC or very low RC. The distortion is least
only when the value of RC is chosen properly.
WAVEFORMS:
An example of Amplitude Demodulation. The top diagram shows the detected modulating
signal of low frequency as well as the high frequency carrier wave. The bottom diagram shows
the amplitude modulated signal. Notice how the peaks of the modulated output follow the
cantour of the original modulating signal.
67
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5 EXPERIMENTAL PROCEDURE :
6 OBSERVATION TABLE:
Sr. Demodulated
Mesaage Signal RF Signal.
No. AM Wave output
Frequency Amplitude Frequency Amplitude Vmax . Vmin.
Amplitude=
1
Frequency=
Amplitude=
2
Frequency=
7 CONCLUSION:
68
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
8. REFERENCES:
8. QUESTIONS:
Q.1. What is the most commonly used demodulator?
69
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:08
1. AIM:
To generate frequency modulation wave
2. APPARATUS REQUIRED:
3. BLOCK DIAGRAM:
Message
signal m(t)
e (t)
fvbfggfs d ff
FM modulator CRO
Carrier
dfd
signal c(t)
4. THEORY:
Frequency modulation is a form of angle modulation in which the amplitude of the modulated
carrier is kept constant while its frequency and its rate of change are varied by the modulating
signal. A sinusoidal carrier signal is said to be frequency modulated when its instantaneous
frequency varies in accordance with the instantaneous amplitude of modulating signal. A
frequency modulated signal x (t) can be represented as
x(t)+A cos[Wct+k ∫ m(t )dt]
Where
A= amplitude of signal
Wc=frequency of carrier signal
K=constant of proportionality
m(t)= Modulating signal
The instantaneous frequency deviation Wi(t)of this FM signal is given by
wi(t) = d/ dt(Wct+k ∫ m(t )dt)
= wc+k.m (t)
70
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
mf = w/wm
B=2(mf+1) fm
% Modulation= δ*100/δmax
Frequency Deviation: It is the amount by which carrier frequency is varied from
its unmodulated value and it is same as frequency variation.
Max Frequency deviation W =KX(t)。max
Very often we write W = h ;
Maxium allowed deviation =75 khz
Frequency Modulation Index (mf )- It is the ratio of frequency deviation W in rad/sec to the
angular frequency of modulating signal Wm or frequency deviation in Hertz/sec to to the
71
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
WAVE FORMS :-
An example of frequency modulation. The top diagram shows the modulating signal
superimposed on the carrier wave. The bottom diagram shows the resulting frequency-
modulated signal
5. EXPERIMENTAL PROCEDURE :
1. Make the connection according to the block diagram
2. Switch on the power supply .Connect 1 KHz, 2V AF Generator to CRO and note the
frequency and amplitude of AF output. .
3. Similarly note the output amplitude and frequency of RF Carrier wave.
4. Set the amplitude of AF generator and amplitude of carrier wave so that modulated
output can be observed conveniently by easy manipulation of CRO
5. Connect 1 KHz, 2v audio frequency to the modulator.
6. Connect the modulator output to CRO & Observe output on CRO.
7. Connect the FM Modulator output to CRO.
8. Vary the amplitude of modulating signal and observe FM wave on CRO.
8. Tabulate the results
72
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
6. OBSERVATION TABLE:
Vm= Vc=
7. CONCLUSION:
8. REFERENCES:
73
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
9. QUESTIONS:
74
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:09
1. AIM:
To demodulate frequency modulated wave
2. APPARATUS REQUIRED:
3. BLOCK DIAGRAM:
Message
signal m(t)
e (t)
FM modulator
FM
fvbfggfs d ff
m’(t)
4. THEORY:
The function of FM De-Modulator is to perform demodulation process. Frequency
de-Modulation is a process of recovering a modulating signal from a frequency modulated
signal. FM De-Modulator changes the frequency deviation of the incoming carrier into an AF
variation. This conversion should be done efficiently & linearly. Detector circuit is used in
frequency De-Modulation which converts frequency modulated IF voltage of constant
amplitude into a voltage The FM demodulator or detector performs its function in two steps as
follow:
(i) It converts the FM signal into a corresponding AM signal with the help of frequency
dependent circuits means the circuits whose output voltage depends upon the input
frequency. These circuits are generally called frequency discriminators.
(ii) The original modulating signal is recovered from this AM signal with the help of
the linear diode detector
75
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
Types of FM Demodulator
1. Slope Detector
The principle of operation of Slope detector depends upon the slope of the frequency
response characteristics of a frequency selective network .The two main FM detectors ,
which use detuned resonant circuits come under this category, are:
(i) Single-tuned detector circuit or simple slope detector.
(ii) Staggered tuned detector circuit or balanced slope detector
The circuit consists of a tuned circuit which is slightly detuned from the carrier
frequency fc. In other words, the circuits uses two tuned circuits which are tuned to two
different frequencies. First one is tuned to the incoming FM carrier frequency fc whereas the
second one is tuned to a frequency slightly different from the carrier frequency fc.
Therefore, this portion of the circuit which contains two tuned circuits tuned to different
frequencies, is called discriminator. This circuit converts the FM signal into an AM signal as
shown in the slope detector characteristics curve. The another portion of the circuit is
envelope detector. The AM signal from the output of the discriminator is applied at the
input of envelope detector. At the output of envelope detector, the original modulating or
base band signal is obtained.
(i) The circuits non-linear characteristics produces a harmonic distortion .The non-
linearity is obvious from the fact that the slope is not the same at each point of the
characteristics.
(ii) The circuit does not eliminate the amplitude variations and the output is sensitive to
any amplitude variations in the input FM signal which is obviously not a desirable
feature. A good discriminator circuit must respond variations and not to amplitude
variations.
76
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
WAVEFORMS:
The top diagram shows the modulating signal superimposed on the carrier wave. The bottom
diagram shows the resulting frequency-modulated signal
5. EXPERIMENTAL PROCEDURE:
77
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
6. OBSERVATION TABLE:
Message Demodulated FM
S.NO. Carrier signal
signal FM wave wave
7. CONCUSION:
8. REFERENCES:
78
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
9.QUESTIONS:
Q.1. what is modulation index in FM?
79
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
EXPERIMENT NO:10
1. AIM:
To study super heterodyne AM receiver
2. APPARATUS REQUIRED:
3. BLOCK DIAGRAM :
4. THEORY:
The super heterodyne receiver consists of three principle parts, the local oscillator that
produces a high-frequency signal close to the signal being detected, a mixer that mixes the local
oscillator's signal with the received signal, and a tuned amplifier. Reception starts with an
antenna signal, optionally amplified, including the frequency the user wishes to tune, fd. The
local oscillator is tuned to produce a frequency close to fd, fLO. The received signal is mixed
with the local oscillator's, producing four frequencies in the output; the original signal, the
original fLO, and the two new frequencies fd - fLO and fd + fLO. The output signal also generally
contains a number of undesirable mixtures as well. The amplifier portion of the system is tuned
to be highly selective at a single frequency, fIF. By changing fLO, the resulting fd - fLO (or fd + fLO)
signal can be tuned to the amplifier's fIF. In typical amplitude modulation that frequency is
usually 455 kHz; for FM receivers, it is usually 10.7 MHz; Although the other signals from the
80
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
mixed output of the heterodyne are still present when they reach the amplifier, they are either
filtered out or simply left un-amplified.
The diagram above shows the basic elements of a single conversion super heterodyne
receiver. In practice not every design will have all these elements, nor does this convey the
complexity of other designs, but the essential elements of a local oscillator and a mixer followed
by a filter and IF amplifier are common to all heterodyne circuits. Cost-optimized designs may
use one active device for both local oscillator and mixer—this is sometimes called a "converter"
stage. The advantage to this method is that most of the radio's signal path has to be sensitive to
only a narrow range of frequencies. Only the front end (the part before the frequency converter
stage) needs to be sensitive to a wide frequency range. For example, the front end might need to
be sensitive to 1–30 MHz, while the rest of the radio might need to be sensitive only to 455
kHz, a typical IF. Only one or two tuned stages need to be adjusted to track over the tuning
range of the receiver; all the intermediate-frequency stages operate at a fixed frequency which
need not be adjusted. Sometimes, to overcome obstacles such as image response, more than one
IF is used. In such a case, the front end might be sensitive to 1–30 MHz, the first half of the
radio to 5 MHz, and the last half to 50 kHz.
The IF Amplifier in this receiver consists of two stages of amplification and provides the
main signal amplification and selectivity. Operating at a fixed IF frequency means that the
design of the amplifier can be simplified. If it were not the fixed frequency, all the amplifier
may need to be tunable across the whole range of incoming RF frequencies and it would be
difficult to arrange for the amplifier to keep in step as they are re-tuned. In addition, the radio
must select the wanted transmission and reject all the others. To do this the band pass of all
stages must carefully controlled. Each IF stage does not necessary has the same band pass
characteristics. The overall response is important. Again, this is something which is much more
easily achieved without the added complication of making them tunable. At the final output
from the IF amplifiers, we have a 455 KHz wave which is amplitude modulated by the wanted
audio information. The selectivity of the IF amplifiers has removed the unwanted components
generated by the mixing process. Occasionally special-purpose receivers will use an
intermediate frequency much higher than the signal, in order to obtain very high image
rejection. Super heterodyne receivers have superior characteristics to simpler receiver types in
frequency stability and selectivity. They offer much better stability than Tuned radio frequency
receivers (TRF) because a tunable oscillator is more easily stabilized than a tunable filter,
especially with modern frequency synthesizer technology. IF filters can give much narrower
pass bands at the same Q factor than an equivalent RF filter. A fixed IF also allows the use of a
crystal filter in very critical designs such as radiotelephone receivers, in which exceptionally
high selectivity is necessary.
The amount that a signal is down-shifted by the local oscillator depends on whether its
frequency f is higher or lower than fLO. That is because its new frequency is |f − fLO| in either
case. Therefore, there are potentially two signals that could both shift to the same fIF one at f =
fLO + fIF and another at f = fLO − fIF. One or the other of those signals has to be filtered out prior
to the mixer to avoid aliasing. When the upper one is filtered out, it is called high-side injection,
because fLO is above the frequency of the received signal. The other case is called low-side
injection.
One major disadvantage to the super heterodyne receiver is the problem of image
frequency. In heterodyne receivers, an image frequency is an undesired input frequency equal to
the station frequency plus twice the intermediate frequency. The image frequency results in two
81
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
stations being received at the same time, thus producing interference. Image frequencies can be
eliminated by sufficient attenuation on the incoming signal by the RF amplifier filter of the
super heterodyne receiver.
An ‘imaginary frequency’ is an unwanted frequency that can also combine with the
Local Oscillator output to create the IF frequency. Notice how the difference in frequency
between the wanted and unwanted stations is twice the IF frequency. It means that the image
frequency is always 910 KHz above the wanted station. This is a large frequency difference and
even the poor selectivity of the RF amplifier is able to remove the image frequency unless it is
very strong. In this case, it will pass through the receiver and will be heard at the same time as
the wanted station. Frequency interactions between the two stations tend to cause irritating
whistles from the loudspeaker.
The function of the diode detection is to extract the audio signal from the signal at the
output of the IF amplifiers. It performs this task in a very similar way to a half wave rectifies
converting an AC input to a DC output. The diode conducts every time the input signal applied
to its anode is more positive than the voltage on the top plate of the capacitor. When the voltage
falls below the capacitor voltage, the diode ceases to conduct and the voltage across the
capacitor leaks away until the next time the input signal is able to switch it on again.
The result is an output which contains three components:
1. The wanted audio information signal.
2. Some ripple at the IF frequency.
3. A positive DC voltage level.
At the input to the audio amplifier, a low pass filter is used to remove the IF ripple and a
capacitor blocks the DC voltage level.
The AGC circuit is used to prevent very strong signals from overloading the receiver. It
can also reduce the effect of fluctuations in the received signal strength. The AGC circuit makes
use of the mean DC voltage level present at the output of the diode detector. If the signal
increases, the mean DC voltage level also increases. If the mean DC voltage level exceeds a
predetermined threshold value, a voltage is applied to the RF and IF amplifiers in such a way as
to decrease their gain to prevent overload.
As soon as the incoming signal strength decreases, such that the mean DC voltage level is
reduced below threshold, the RF and IF amplifiers return to their normal operation.
Drawbacks to the super heterodyne receiver include interference from signal frequencies
close to the Intermediate Frequency. To prevent this, IF frequencies are generally controlled by
regulatory authorities, and this is the reason most receivers use common IFs. Examples are 455
kHz for AM radio, 10.7 MHz for FM and 45 MHz for television. Additionally, in urban
environments with many strong signals, the signals from multiple transmitters may combine in
the mixer stage to interfere with the desired signal.
82
SPSU, UDAIPUR Lab Manual
Department of E & C Engineering
5. CONCUSION:
6. REFERENCES:
7 QUESTIONS:
83