Lab Work File: 5 Semester ECE (2017 Batch)
Lab Work File: 5 Semester ECE (2017 Batch)
Submitted to
By
Deepak
1702074
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:
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.
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.
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:
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
A=
1
2
3
Entering a row vector:
A= [1 2 3] or [1,2,3]
A=
1 2 3
A= [1 2 3; 4 5 6]
A=
1 2 3
4 5 6
If A= [1,2,3]; B=[4,5,6];
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:
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
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
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
1 2 3 4 5 7 8 9 10
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.
det(A)-determinant of A.
eig(A)- eigenvalues and eigenvectors.
inv(A)-inverse of A .
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.
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:
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.
δ(n)=1, at n=0,
δ(n)=0, at n≠0.
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.
function[x,n]=impseq(n0,n1,n2)
n=[n1:n2];
x=[(n-n0)==0];
stem(n,x,'linewidth',2);
xlabel('n');
ylabel('amplitude');
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
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.
function[x,n]=stepseq(n0,n1,n2)
n=(n1:n2);
x=[(n-n0)>=0];
stem(n,x,'linewidth',2);
xlabel('n');
ylabel('x');
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.
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.
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');
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.
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.
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.
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.
function[y,n]=foldseq(n,x)
n=-fliplr(n);
y=fliplr(x);
stem(n,y,'linewidth',2);
xlabel('n');
ylabel('amp');
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)
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.
function[y,n]=shiftseq(n0,n,x)
n=n-n0;
y=x;
stem(n,y,'linewidth',2);
xlabel('time axis');
ylabel('amplitude');
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