0% found this document useful (0 votes)
2 views12 pages

DSP_UE205015

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

EXPERIMENT NO.

AIM: Introduction to MATLAB.

APPARATUS: MATLAB 7.1 software

THEORY:

MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming in an easy-to-use environment where problems and
solutions are expressed in familiar mathematical notation. The name MATLAB stands for
matrix laboratory. MATLAB was originally written to provide easy access to matrix.

Some of MATLAB applications are:


• Computation and mathematics

• Development of algorithms.
• Modeling and simulation of systems.

• Exploration, visualization and data analysis.

• Creation of scientific plots.


Features of MATLAB

 MATLAB is a high-level language: MATLAB Supports Object oriented programming.


It also supports different types of programming constructs like Control flow
statements (IF-ELSE, FOR, WHILE).

 Interactive graphics: MATLAB has inbuilt graphics to enhance user experience. We


can actually visualize whatever data is there in forms of plots and figures. It also
supports processing of image and displaying them in 2D or 3D formats.

 A large library of Mathematical functions: MATLAB has a huge inbuilt library of


functions required for mathematical analysis of any data.
MATLAB ENVIRONMENT:
Parts of MATLAB window are

 Command Window

 Workspace

 Current Directory

 Figure Window

Command Window: Whenever MATLAB is invoked, the main window called command
window is activated. The command window displays the command prompt’>>’ and a cursor
where commands are entered and are executed instantaneously.

Workspace: A workspace is a collection of all the variables that have been generated so far
in the current MATLAB session and shows their data type and size. All the commands
executed from Command Window and all the script files executed from the Command
Window share common workspace, so they can share all the variables.

Current Directory: The Current Directory window contains all the files and folders present in
the Current Directory. To run any file, it must either be in the Current Directory or on the
search path.
Edit Window: An Edit Window is used to create a new program file, or to modify existing
files. In this window, programs can be written, edited and saved. The programs written
using the MATLAB editor are automatically assigned an extension (.m) by the editor and are
known as M- files.

Figure Window: A Figure Window is a separate window with default white background and
is used to display MATLAB graphics. The results of all the graphic commands executed are
displayed in the figure window.

BASIC COMMANDS:

 clear: Removes all variables from workspace


 clc: Clears the Command window and homes the cursor.
 help: searches for ahelp topic
 quit : stops MATLAB
 Who: lists current variable
 Whos: lists current variable[long display]
 Input: displays prompts and waits for inputs
 ; : suppress screen printing
 Plot: generates xy plot
 Title: puts text at top of plot
 Xlabel: adds text label to x-axis
 Ylabel: adds text labels to y-axis
 Stem: creates stem plot
EXPERIMENT NO. 2
AIM: To generate elementary discrete time signals using MATLAB i.e.

a)Unit step signal b)unit ramp signal c)Unit impulse signal d)Exponential signal

APPARATUS: MATLAB 7.1 software


THEORY:

MATLAB provides a wide range of graph plotting application. The uses can plot 2D as well as
3D graphs. It also provides us the different color codes to highlight different segments of the
graph.

Stem(Y) plots the data sequence, Y, as stems that extend from a baseline along the x-axis.
The data values are indicated by circles terminating each stem:

 If y is a vector, then the x-axis scale ranges from 1 to length(y).


 If y is a matrix, then stem plots all elements ranges in a row 1 to against the same x
value, and the x-axis scale ranges from 1 to the number of rows in y.
Discrete Time Unit Step Signal : The unit step signal which is defined only at discrete
instants of time is known as discrete-time unit step signal. It is denoted by u(n).
Mathematically, the discrete-time unit step signal or sequence u(n) is defined as follows

u(n)={1 for n≥0 0 for n<0 }


Discrete Time Unit Ramp Signal : The discrete time unit ramp signal is that function which
starts from n = 0 and increases linearly. It is denoted by r(n). It is signal whose amplitude
varies linearly with time n. Mathematically, the discrete time unit ramp sequence is defined
as –
r(n)={n for n≥0 0 for n<0 }
Discrete Time Unit Impulse Signal : The discrete-time unit impulse signal is denoted by
δ(n) and is defined as –
δ(n) = { 1 for n=0 0 for n≠0 }
Discrete-Time Real Exponential Signal : A real exponential signal which is define at discrete
instants of time is called a discrete-time real exponential signal or sequence. A discrete-time
real exponential sequence is defined as –

𝑥(𝑛) = 𝑎𝑛 for all 𝑛

Depending upon the value of a the discrete time real exponential signal may be of following
type –
 When a < 1, the exponential sequence x(n) grows exponentially.
 When 0 < a < 1, the exponential signal x(n) decays exponentially.
 When a < 0, the exponential sequence x(n) takes alternating signs.
PROGRAM :

%% discrete unit step signal


subplot(2,2,1);
x= -5:5;
y=[zeros(1,5) ones(1,6)];
stem(x,y);
xlabel ['time']
ylabel ['signal']
title ['unit step signal']

%% discrete unit ramp signal


subplot(2,2,2);
x= -5:5;
y = [zeros(1,5) ones(1,6)];
f=x.*y;
stem(x,f);
xlabel ['time']
ylabel ['signal']
title ['unit ramp signal']

%% discrete impulse signal


subplot(2,2,3);
x= -5:5;
y=[zeros(1,5) ones(1,1) zeros(1,5)];
stem(x,y);
xlabel ['time']
ylabel ['signal']
title ['unit impulse signal']

%% exponential signal
subplot(2,2,4);
x= -5:5;
y=exp(x);
stem(x,y);
xlabel ['time']
ylabel ['signal']
title ['exponential signal']
OBSERVATION :
The following figure justifies for the output of the program written above.
EXPERIMENT NO. 3
AIM: To generate advanced and delayed basic elementary signals in MATLAB.

APPARATUS: MATLAB 7.1 software

THEORY:
MATLAB can be used to perform shifting of signals. A signal can be delayed as well as
advanced. Consider a discrete time signal x[n], then the time shifted version of the signal
x[n] represented as y[n] is defined as y[n] = x[n+n0]. Now, n0 can be negative or positive. If
n0 is negative, signal is shifted backwards and this is called “Time-Delayed Shifting”. If n0 is
positive, signal is shifted forward and this is called “Time- Advanced Shifting”.

Time-Delayed Signals: Suppose that we want to move this signal right by three units. Such a
signal can be mathematically written as y[n] = x[n-3]. This kind of signal is referred to as
time-delayed because we have made the signal arrive three units late .

Time-Advanced Signals: On the other hand, let's say that we want the same signal to arrive
early. Consider a case where we want our output signal to be advanced by, say, two units.
This objective can be accomplished by shifting the signal to the left by two time units, i.e.,
y[n] = x[n+2].
PROGRAMS:
subplot(2,2,1);
x= -5:5;
n= x-2;
y=[zeros(1,5) ones(1,6)];
stem(n,y);
xlabel ['time']
ylabel ['signal']
title ['advanced unit step signal']

subplot(2,2,2);
x = -5:5;
n=x-2;
y = [zeros(1,5) ones(1,6)];
f=n.*y;
stem(n,f);
xlabel ['time']
ylabel ['signal']
title ['advanced unit ramp signal']

subplot(2,2,3);
x= -5:5;
n=x-2;
y=[zeros(1,5) ones(1,1) zeros(1,5)];
stem(n,y);
xlabel ['time']
ylabel ['signal']
title ['advanced unit impulse signal']
subplot(2,2,4);
x= -5:5;
n=x-2;
y=exp(n);
stem(n,y);
xlabel ['time']
ylabel ['signal']
title ['advanced exponential signal']

subplot(2,2,1);
x= -5:5;
n= x+2;
y=[zeros(1,5) ones(1,6)];
stem(n,y);
xlabel ['time']
ylabel ['signal']
title [' delayed unit step signal']

subplot(2,2,2);
x = -5:5;
n=x+2;
y = [zeros(1,5) ones(1,6)];
f=n.*y;
stem(n,f);
xlabel ['time']
ylabel ['signal']
title [' delayed unit ramp signal']

subplot(2,2,3);
x= -5:5;
n=x+2;
y=[zeros(1,5) ones(1,1) zeros(1,5)];
stem(n,y);
xlabel ['time']
ylabel ['signal']
title [' delayed unit impulse signal']

subplot(2,2,4);
x= -5:5;
n=x+2;
y=exp(n);
stem(n,y);
xlabel ['time']
ylabel ['signal']
title ['delayed exponential signal']
OBSERVATION :
OBVSERVATION:
EXPERIMENT NO. 4
AIM: To study convolution technique of two signals.

Apparatus: A pc with MATLAB installed in it.

Theory: Convolution is a mathematical operation on two functions, or in our case on two


vectors. In this tutorial the simplest 1D convolution is to be explained, but of course this
operation works for higher dimensions as well. It can be used for several tasks, for example
signal or image processing. Convolution is commutative, the order of the operands makes
no difference. In MATLAB we use the conv function to do the convolution.
Sytax: Conv(a,b)

It outputs the convolution of input vectors a and b, simply put as two signal functions.lnput
vectors, specified as either row or column vectors. The vectors a and b can be different
lengths or data types.

Program:
To determine the convoluted output of two arbitary signals, say x[n] and h[n] with output
signal as y[n]. We have the program written in following way in the text editor window of
MATLAB environment with all labels and subplots as defined below.
%% convolution of DT sequences

x=input('enter first sequence');


nx=input('enter the time domain info of first sequence');
h=('enter second sequence');
nh=input ('enter the time domain info of second sequence');
y = conv( X,h);
a=nx(1)+ nh(1);
b=nx(length(nx))+nh(length (nh));
ny=a:b;
subplot (3,1,1);
stem(nx,x);
title('first input sequence');
subplot (3,1,2);
stemt(nh,h);
title('second input sequence');
subplot (3,1,3);
Stem(ny,y);
title ('convolution result');
OBVSERVATION:

You might also like