Sie sind auf Seite 1von 24

BEANT COLLEGE OF ENGINEERING & TECHNOLOGY

GURDASPUR – 143 521

Lab Work File


BTEC-505 Lab Digital Communication System
5th Semester ECE (2017 Batch)

Submitted to

Dr. Praveen Kumar

(Associate Professor, ECE)

By
Deepak
1702074

Department of Electronics and Communication Engineering

July- Dec, 2019


BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

INDEX
S.NO EXPERIMENT PAGE DATED REMARK
. NO.
1 Introduction to Matlab
2 TO DEVELOP A PROGRAM TO GENERATE
UNIT IMPULSE RESPONSE.
3 TO DEVELOP A PROGRAM TO GENERATE
UNIT STEP FUNCTION.
4 TO DEVELOP A PROGRAM TO GENERATE
A RAMP SEQUENCE.
5 TO DEVELOP A PROGRAM TO GENERATE
AN EXPONENTIAL SEQUENCE.
6 TO DEVELOP A PROGRAM TO GENERATE
SIGNAL FOLDING.
7 TO DEVELOP A PROGRAM TO GENERATE
SIGNAL TIME SHIFTING.

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO.1

 INTRODUCTION TO MATLAB

Matlab (MATRIX LABORATORY) is an interactive software system for numerical computation and
graphics, developed by CLEVE MOLER in order to make the FORTRAN libraries LINPACK and
EISPACK accessible from the command line. As the name suggested, Matlab is especially designed for
matrix computations: solving systems of linear equations, computing Eigen values and eigenvectors,
functioning matrices, and so forth.
.
In addition, it has a variety of graphical capabilities, and can be extended through programs written in its
own programming language. Many such programs come with the system. A number of these extend
Matlab’s capabilities to nonlinear problems, such as the solution of initial value problems for ordinary
differential equations.

MATLAB is designed to solve problems numerically, that is, in finite-precision arithmetic. Therefore it
produces approx. rather than exact solutions, and should not be confused with a symbolic computation
system (SCS) such as mathematics or Maple.

Features include:

 High-level language for technical computing.


 Development environment for managing code, files, and data.
 Interactive tools for iterative exploration, design, and problem solving.
 Mathematical functions for linear algebra, statistics, fourier analysis, filtering and numerical
integration.
 2-D and 3-D graphics functions for visualizing data.
 Tools for building custom graphical user interfaces.
 Functions for integrating MATLAB based algorithms with external applications and languages,
such as C, C++, Fortran, javaTM, COM, and Microsoft Excel.

Matlab screen mainly include four parts-command window, workspace, command history, current
directory.

 Command window:

The window where we type commands and non-graphic output is displayed. A ‘>>’ prompt shows we
the system is ready for input. The lower left hand corner of the main window also displays ‘Ready’ or
‘Busy’ when the system is waiting for calculating. Previous commands can be accessed using the up
arrow to save typing and reduce errors.

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 Workspace window:

It shows all variable that we have currently defined and some basic information about reach one,
including its dimensions, minimum, and maximum values. The icons at the top of the window allow us
to perform various basic tasks on variables, creating, saving, deleting, plotting, etc. Double-clicking on
a variable opens it in the Variable or Array Editor. A;; the variables that we’ve defined can be saved
from one session to another using File > Save Workspace As (Ctrl-S). The extension for a work space
file is .mat.

 Command history window:


This is where past commands are remembered. If we want to re-run a previous command or to edit it
will can drag it from this window to the command window or double click to re-run it.

 Current directory window:


This is the directory (Folder) that MATLAB is currently working in. This is the place where anything
we save will go by default, and it will also influence what files MATLAB can see. We won’t be able
to run a script that we saved in a different directory (unless we give the full directory path), but we run
one that’s in a sub-directory.

 MATLAB Screen:

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 Editor:
It is the window where we edit m-files. The files that hold scripts and functions that we’ve defined or
are editing are includes most standard word-processing options and keyboard shortcuts. It can be
opened by typing edit in the command window. Multiple files are generally opened as tabs in the same
editor window, but they can also be titles for some by side comparison. Orange warnings and red errors
appear as underlining and as bars in the margin. Hovering over them provides more information;
clicking on the bar takes us to the relevant bit of text. Also remember that MATLAB runs the last saved
version of a life, so we to save before any changes take effect.

 MATLAB Help:
MATLAB’s help documentation is very good, and can tell us pretty much any-thing we need to know.
Help>Product help opens the help window, which largely like a web browser, including forward and
back buttons. It can also suggest better ways of doing things. Typing help command name in the
Command Window will also bring up the help file for that command.

COMMANDS FOR MANAGING WORK SESSION

COMMAND DESCRIPTION
Clc Clear Command Window
Clear Clear all variable from workspace or memory
Clear variable name Removes particular variable from memory
Quit, exit Stops Matlab.
Who List currently variable in memory, suppress output
or screen printing; start new row in an array
; All output, separates elements of an array
, Generates an array having regularly
: Colon

 The Beginning:
When we start MATLAB, the command prompt “>>” appears. We will tell MATLAB what to do by
typing commands at the prompt.

 Entering Matrix:
The best way for us to get started with MATLAB is to learn hoe to handle natrics. Start MATLAB and
follow along with each example. We can enter matrics into MATLAB is several ways:

 Enter an explicit list of elements.


 Load matrices from external data files.
 Generate matrix in built in functions.

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 Create matrices with our own functions in M-files.


 Start by entering Darers matrix as a list of its elements. We only have to follow a few basic
conventions:
 Separate the elements of a row with blanks or commas.
 Use a semicolon to indicate the end of each row.
 Surround the entire list of elements with square brackets,[].

Entering a column vector: A=[1; 2; 3]

A=
1
2
3
Entering a row vector:

A= [1 2 3] or [1,2,3]
A=
1 2 3

Entering a general matrix:

A= [1 2 3; 4 5 6]
A=
1 2 3
4 5 6

If A= [1,2,3]; B=[4,5,6];

Horizontal concatenation: Vertical concatenation:


C=hortzcat(A,B) or [AB] C=vertcat(A,B) or [A;B]
C= C=
123456 1 2 3
4 5 6

A Few Useful Math Functions:

Function MATLAB Syntax


x
e exp(x)
½
x sqrt(x)
ln x log(x)
Log10x, where 10 is at base log10(x)
Cos x Cos(x)
sin -1x Sin(x)

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 Indexing:

To enter Durer’s matrix, simply type in the Command Window


A=[16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

MATLAB displays the matrix we just entered:

A= 16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

The element in row i and column j of A is denoted by A(i,j) For example, A(4,2) is the number in the
fourth row and second column. For our magic square, A(4,2) is 15. So to compute the sum of the
elements in the fourth column of A, type

A(14)+ A(2,4) +A(3.4) +A(4.4)


This produces
Ans=34

but is not the most elegant way of summing a single column.


It is also possible to refer to the elements of a matrix with a single subscript, A(k). This is the usual
way of referencing row and column vectors. But it can also apply to a fully two- dimensional matrix,
in which case the army is regarded one long column vector formed from the columns of the original
matrix. So, for our magic square, A(8) is another way of referring to the value 15 stored in A(4,2). If
we try to use the value of an element outside of the matrix, it is an error:

T= A(4,5)
Index exceeds matrix dimensions.

On the other hand, if we store a value in an element outside of the man the size increases to
accommodate the newcomer:
X=A
X(4,5)=17

X=
16 3 2 13 0
5 10 11 8 0
9 6 7 12 0
4 15 14 1 17

 The colon operator:


The colon : is one of the most important MATLAB operators. If occurs in several different forms. The
expression

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

1:10

is a row vector containing the integers from 1 to 10:

1 2 3 4 5 7 8 9 10

To obtain non-unit spacing, specify an increment. For example,


100:-7:50
Is
100 93 86 79 72 65 58 51
and
0:pi:4:pi
Is
0 0.7854 1.5708 2.3562 3.1416

Subscript expressions involving colons refer to portions of a matrix:

A(1:k,j)
is the first k elements of the jth column of A.So

sum(A( 1:4.4))
computes the sum of the fourth column. But there is a better way. The colon by itself refers to all the
elements in a row or column of matrix and the keyword end refers to the last row or column. So

sum(A(:,end))
computes the sum of the elements in the last column of A :

ans =
34
5:1 will not work, and Gives empty matrix.

Arithmetic operators

 Arithmetic operators
>>C= A+B or C=A-B
Adds/ subtracts matrices A, B. A and B must be same size unless one of them is a scalar.

>>C= A.*B
is the element-wise product- A and B must be same size unless one of them is a scaler.

>> C= A./B
is the element-wise division C(i,j)= A(i, j)/ B(i, j),

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

C= A.^p;
is the element-wise p-th power of A.

C=A*B
is the matrix multiplication of A and B (columns of A must equal row B) or one must rows them can
be a scalar.

A few other useful matrices are:

 Zeros- create a matrix of zeros.


 ones-create a matrix of ones.
 rand-create a matrix of random numbers.
 eye-create an identity matrix.

Useful matrix functions:

 det(A)-determinant of A.
 eig(A)- eigenvalues and eigenvectors.
 inv(A)-inverse of A .

 M-files and functions:

An m-file, or script file, is a simple text file where we can place MATLAB commands. When the file
is run, MATLAB reads the commands and them exactly as it would executes if we had typed each
command sequentially at the MATLAB prompt. All m-file names must end with the extension'.m' (e.g.
test.m). If we create a m-file with the same new name as an existing m-file, MATLAB will choose the
one which appears first in the path order (type help path in the command window for more information).
To make life easier, choose a name for our m-file which doesn't already exist. To if filename.m already
exists, type help

>>Function[C]= name[A,B]
>> A=2; B=3;
>>C=A+B;
>> end

When we pass matrix and value C to this function the value C=A+B is returned. We can now call this
function from the command line or in another m-file.

Use of m-files:

For simple problems, entering our requests at the MATLAB prompt is fast and efficient. However, as
the number of commands increases or trial and error is done by changing certain variables or values,
typing the commands over and over at the MATLAB prompt.

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 Plotting:
Now that we can load data into MATLAB and easily manipulate it, we’ll want to be able to display the
results in a meaningful l(and hopefully aesthetically pleasing) way. Let's create some sample data for
an example plotting a function of sine wave:

>>x=pi:0.01:pi;
>>y=sin(x);
>>plot(x,y);
labeling of plot
>>x label(‘time’) // label the horizontal axis.
>>y label(‘amplitude’) // label the vertical axis.
>>title(‘plot if (sinx)’) // attach the title to plot.

To plot two or more waves on a same graph

>>hold on // keep plotting in the same window


>>y(2)=cos(x)
>>plot(x,y2)
>>hold off //turn off the keep plotting in the same command window
>>y2=cos(x)
>>plot(x,y2)

plotting arrays with plot(X,Y)

 ‘Linespec’,-, --, .-, :


 ‘Linewidth’
 ‘Marker’,+,o,.,*,x,>,<,^,v,p,h,s
 ‘Markersize’
 ‘MarkerEdgeColor’

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

 ‘MarkerFaceColor’

Labeling of plot:

>>xlabel('Time')
>>ylabel( Amplitude)
>>title('Plot of sin(x)’)

Legend:
>>Iplot= legend('cos(x)','sin(x)’)
>>set(iplot, 'Location',’North West’)

 Color Coding:

RGB Value Short Name Long Name


[110] Y Yellow
[101] M Magenta
[011] C Cyan
[100] R Red
[010] G Green
[001] B Blue
[111] W White
[000] K Black

Once we're all done with our plots, we can save them to look at later – use "save as" to done our save
as a figure file. We can also make images of our figures to use posters, publications, etc. Use the"print"
command to export figures image format(e.g., ps, eps, tif, jpg).

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-2
AIM- TO DEVELOP A PROGRAM TO GENERATE UNIT IMPULSE RESPONSE.

THEORY- Unit impulse function can be defined as,

δ(n)=1, at n=0,
δ(n)=0, at n≠0.

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor
window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODING TO GENERATE UNIT IMPULSE FUNCTION:

function[x,n]=impseq(n0,n1,n2)

n=[n1:n2];

x=[(n-n0)==0];

stem(n,x,'linewidth',2);

xlabel('n');

ylabel('amplitude');

title('impulse function ');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Output:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)
Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-3

AIM- TO DEVELOP A PROGRAM TO GENERATE UNIT STEP FUNCTION.

THEORY- Continuous timeUnit step function can be defined as,

U(n)=1, for n≥0


U(n)=0, for n<0

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor
window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODING TO GENERATE UNIT STEP SEQUENCE:

function[x,n]=stepseq(n0,n1,n2)

n=(n1:n2);

x=[(n-n0)>=0];

stem(n,x,'linewidth',2);

xlabel('n');

ylabel('x');

title('step function ');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Output:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-4
AIM- TO DEVELOP A PROGRAM TO GENERATE A RAMP SEQUENCE.

THEORY- The ramp function can be defined as,

R(n)=an for n≥0


R(n)=0 for n=0

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODING TO GENERATE RAMP SEQUENCE:

function[x,n]=rampseq(n0,n1,n2)

n=(n1:n2);

x1=[(n-n0)>=0];

x=(n-n0).*x1;

stem(n,x,'linewidth',2);

xlabel('n');

ylabel('x');

title('ramp function ');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

OUTPUT:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)
Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-5
AIM- TO DEVELOP A PROGRAM TO GENERATE AN EXPONENTIAL SEQUENCE.

THEORY- The exponential function can be defined as,

Where * represents the convolution sign.

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODES TOGENERATE AN EXPONENTIAL FUNCTION:

function[x,n]=inexpseq(n0,n1,n2)

n=(n1:n2);

x1=[(n-n0)>=0];

x=(exp(n-n0)).*x1;

stem(n,x,'linewidth',2);

xlabel('n');

ylabel('x');

title('exponential function');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

OUTPUT:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)
Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-6
AIM- TO DEVELOP A PROGRAM TO GENERATE SIGNAL FOLDING.

THEORY- The convolution function can be defined as,

If X=[a b] and Y=[c d] , then


Z=X*Y

Where* represents the convolution sign,

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODING TO GENERATE SIGNAL FOLDING SEQUENCE:

function[y,n]=foldseq(n,x)

n=-fliplr(n);

y=fliplr(x);

stem(n,y,'linewidth',2);

xlabel('n');

ylabel('amp');

title('signal folding ');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

OUTPUT:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)
Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EXPERIMENT NO-7
AIM- TO DEVELOP A PROGRAM TO GENERATE SIGNAL TIME SHIFTING.

THEORY-

Time shifting: This operation is very important in consideration of any as well as in discrete signals.
There are two types of time shifting :
1. Time delay i.e. u(n-k)
2. Time advance i.e. u(n+k)

SOFTWARE- MATLAB R-2011-B

PROCEDURE-
1. The program is entered in the MATLAB editor and is saves with the *.m extension.
2. The program is executed in the command window/editor window.
3. If any error is reported then debug it and again execute it from command window/editor
window.
4. Input if required is entered from the command window.
5. The result is displayed as plot.

CODES TO GENERATE SIGNAL TIME SHIFTING:

function[y,n]=shiftseq(n0,n,x)

n=n-n0;

y=x;

stem(n,y,'linewidth',2);

xlabel('time axis');

ylabel('amplitude');

title('signal shifting ');

end

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

OUTPUT:

TEACHER’S SIGNATURE
(MR.PARVEEN KUMAR)
Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019
BEANT COLLEGE OF ENGINEERING AND TECHNOLOGY, GURDASPUR
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Deepak BTEC-506
5008/17 (1702074) Digital Signal Processing
5th Sem (Batch 2017) July-Dec 2019

Das könnte Ihnen auch gefallen