0% found this document useful (0 votes)
7 views19 pages

DSP_UE205018

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views19 pages

DSP_UE205018

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

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 plot time shift and time reversed sequence of given sequence using MATLAB.
Apparatus: A pc with MATLAB installed in it.
THEORY:
Time Shifting: In signals and system amplitude scaling, time shifting and time scaling are
some important properties. If a continuous time signal is defined as x(t) = s(t - t1). Then we
can say that x(t) is the time shifted version of s(t).
Time Reversal:
one can make it negative just by multiplying it by -1. This causes the original signal to flip
along its y-axis. That is, it results in the reflection of the signal along its vertical axis of
reference. As a result, the operation is known as the time reversal.
Program:
 clear all;
 clc;
 x=[1 2 3 -4 6]; % sequence
 nx = -2:2; % range of the sequence
 s=2; % size of the shift
 nx1=nx-s;
 subplot(3,1,1);
 stem (nx, x); % axis declaration
 title('Time sequnce');
 subplot (3,1,2);
 stem (nx1,x);
 title('Time shift sequnce');
 x1= fliplr(x);
 nx2 = -fliplr (nx);
 subplot (3,1,3)
 stem (nx2, x1)
 title('time reversed seq')

MATLAB CODE:
RESULT:
EXPERIMENT NO. 4
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. 5

AIM: : To find convolution of two input signals using conv function in MATLAB.

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)
If y(n) is a sequence whose values are a function of the two sequences h(n) and x(n) , then
y(n) is called convolution of x(n) with h(n):

y(n) = ∑ x(n)*h(n)
k=-∞
The convolution is represented as:
y(n) = x(n)*h(n)
The operation of discrete-time convolution takes two sequences x(n) and h(n) as input and
produces a third sequence y(n).
In MATLAB, convolution of any two causal signals (that depend only on present and future
samples) can be done using “conv” command as:
conv(x,h)
where x and h represent discrete-time causal sequences x(n) and h(n).

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

 clear all;
 clc;
 close all;
 x = [ 1/2 1/2 1/2 ]; % Declare 1st sequence using MATLAB commands
 nx=0:2; % Declare time axis of 1st sequence
 h=[3 2 1]; % Declare 2nd sequence using MATLAB commands
 nh= 0:2; % Declare time axis information of 2nd sequence
 y=conv(x,h); % Inbuilt convolution function
 a=nx(1)+nh(1); % Identify the starting point of o/p sequence
 b=nx (length (nx))+nh (length (nh)); % Identify the ending point
 ny=0:4; % Enter the obtained x axis information of y(n) sequence
 subplot (3,1,1);
 stem (nx, x); % Plot graph of 1st sequence
 title ('First input seq');
 subplot (3,1,2);
 stem (nh, h); % Plot graph of 2nd sequence
 title('second input seq');
 subplot (3,1,3);
 stem(ny,y); % Plot graph of output sequence y(n)
 title('convolution result');

OBVSERVATION:
EXPERIMENT NO. 6
AIM: : To find convolution of two input signals without using conv function in MATLAB .
Apparatus: A pc with MATLAB installed in it.
THEORY:
If y(n) is a sequence whose values are a function of the two sequences h(n) and x(n) , then
y(n) is called convolution of x(n) with h(n):

y(n) = ∑ x(n)*h(n)
k=-∞
The convolution is represented as:
y(n) = x(n)*h(n)
The operation of discrete-time convolution takes two sequences x(n) and h(n) as input and
produces a third sequence y(n).
In MATLAB, convolution of any two causal signals (that depend only on present and future
samples) can be done using “conv” command as:
conv(x,h)
where x and h represent discrete-time causal sequences x(n) and h(n).

% convolution of DT sequences
 clear all;
 clc;
 close all;
 x=input('enter first sequence'); % declare 1st sequence using MATLAB command
 nx=input('enter the time domain info of first sequence');
 % declare time axis of 1st sequence using MATLAB command
 h=input('enter second sequence'); % declare 2st sequence using MATLAB command
 nh=input ('enter the time domain info of second sequence ');
 % declare time axis of 2st sequence using MATLAB
 hf = fliplr(h); % command to flip second input sequence
 x1= [zeros(1,(length(h)-1)) x];
 hf1= [hf zeros(1, (length(x)-1))]; %To place 0 in blank spaces
 N= length (x) +length (h)-1 ;
 for i =1:N % loop to shifting position of sequence to right side
 y(i)=sum(x1.*hf1);
 hf1=[0 hf1]; % Add 0 before elements after shifting
 hf1=hf1(1 : N ); %new hf1 to multiply new value after shifting
 end
 y a=nx(1)+nh(1); % Identifying starting point of o/p sequence
 b=nx (length (nx))+ nh (length (nh)); % Identifying ending point of o/p sequence
 ny=a:b; % range of ny start from a and end at b
 subplot (3,1,1)
 stem (nx, x) % plot graph of 1st sequence
 title('first input seq')
 subplot (3,1,2)
 stem (nh, h) % plot graph of 2st sequence
 title('second input seq')
 subplot (3,1,3)
 stem (ny, y) % plot graph of output sequence
 title('convolution result')

MATLAB CODE:
RESULT:

EXPERIMENT NO. 7
AIM: : To find correlation of two input signals using xcorr function in MATLAB.
REQUIREMENTS: A PC with MATLAB installed in it.
THEORY:
Correlation is a measure of similarity between two signals. The general formula for
correlation is:

There are two types of correlation:


 Auto-correlation – It is defined as the correlation of a signal with itself. It is a
measure of similarity between a signal and its time-delayed version.

 Cross-correlation – It is the measure of similarity between two different signals.

Program:
 clear all;
 clc;
 x= input('enter the first input sequence'); % declare 1st sequence
 nx=input('enter the time domain info of first input sequence');
 % declare time axis of 1st sequence
 h = input('enter the second input sequence'); % declare 2nd sequence
 nh = input('enter the time domain info of second input sequence');
 % declare time axis of 2nd sequence
 y= xcorr(x, h); %command to find correlation
 a= nx(1)+ nh(1);
 b=nx(length(nx))+nh(length(nh));
 ny=a:b;
 subplot(3,1,1);
 stem(nx,x); % plot graph of 1st sequence
 title('first input sequence');
 subplot(3,1,2);
 stem(nh,h); % plot graph of 2nd sequence
 title('second input sequence');
 subplot(3,1,3);
 stem(ny,y); % plot graph of output sequence
 title('correlation result');

You might also like