Digital Signal Processing Practical File
Digital Signal Processing Practical File
Digital Signal Processing Practical File
Practical File
1| UE155114
INDEX
EXP REMARK
AIM OF EXPERIMENT DATE
NO. S
2| UE155114
3| UE155114
EXPERIMENT-1
AIM: INTRODUCTION TO MATLAB
REQUIREMENTS: A PC with MATLAB installed in it.
MATLAB DESKTOP
The window that appears when we start MATLAB is called the MATLAB DESKTOP.
1. Command Window
2. Command History Window
3. Workspace
4. Current Directory Window
5. Figure Window
6. Edit Window
A. COMMAND WINDOW
The main window of the MATLAB desktop is called the Command Window. The command
window displays the command prompt >> and a cursor where commands are entered and
are executed instantaneously on pressing the Enter key of the keyboard. However, if the
output of a statement is not needed to be displayed, a semi-colon ; is added at the end of the
statement.
4| UE155114
5| UE155114
C. 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 the
Command Window and all the script files executed from the Command Window share
common workspace, so they can share all the variables. With these variables, a number of
operations can be done. All the variables that you have defined can be saved from one session
to another by using File SaveWorkspace. The extension for a workspace file is .mat.
E. 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. Thus, the editor window is opened automatically when a new M-file is created or an
existing M-file is opened.
6| UE155114
7| UE155114
F. FIGURE WINDOW
A Figure Window is a separate window with default white background and is used to display
MATLAB graphics. The result of all the graphic commands executed is displayed in the
Figure Window. The number of Figure Windows generated depends upon the system
memory.
G. HELP BROWSER
The Help Browser can be opened by selecting the Help icon from the desktop toolbar, or by
choosing the Help menu on the MATLAB desktop or by typing doc or helpdesk or
helpwin in the Command Window.
whos
It generates a list of all the variables currently in the workspace with their size (dimensions),
number of bytes, and class/type of variable. It also reports the total number of bytes used
and the number of elements in the arrays.
save
It saves the data from the current MATLAB workspace into a disk file with an extension
.mat (MAT-file). The data saved using this command is in a format which cannot be read by
the user directly i.e. in binary form.
load
This command is used to load the data saved in the MAT-file. It loads the data from the file
into the current MATLAB workspace.
format
8| UE155114
This command is used to change the data type of the result displayed. The standard format is
short. To return to the standard format, enter format short or simply format.
help
It searches for the particular function/command mentioned.
lookfor
It provides with a list of related functions/commands for the function/command mentioned.
doc
It opens the online version on the help manual.
diary
It saves a complete MATLAB session in a text editor or word processing program.
ARITHMETIC OPERATORS
Addition and subtraction
The operators + and - are used for addition and subtraction respectively. The matrices to
be operated must be of same order.
>> X=[5 10;15 20];
>> X+Y
9| UE155114
10 | UE155114
ans =
7 14
21 28
>> X-Y
ans =
3 6
9 12
Multiplication
The operator * is used for matrix multiplication. A*B is valid only if the number of columns
of A is equal to the number of rows of B.
>> X*Y
ans =
70 100
150 220
The operators / and \ are used for right and left division respectively. The result of A/B is
obtained by multiplying the matrix A with the inverse of matrix B i.e. AB-1. The result of
A\B is obtained by multiplying the inverse of matrix A with the matrix B i.e. A-1B.
>> X/Y
ans =
2.5000 0
0 2.5000
>> X\Y
ans =
0.4000 0.0000
0 0.4000
11 | UE155114
Element by element multiplication and division
MATLAB uses a period/decimal point on the left of the arithmetic operator as part of the
notation for element by element operations. The operators .*, ./, .\, are used for element-
by-element multiplication, right division and left division respectively.
>> X.*Y
ans =
10 40
90 160
>> X./Y
ans =
2.5000 2.5000
2.5000 2.5000
>> X.\Y
ans =
0.4000 0.4000
0.4000 0.4000
RELATIONAL OPERATORS
Operator Operation
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
~= Not equal to
The relational operators are <, >, <=, >=, ==, and ~=. Relational operators perform
element-by-element comparisons between two arrays. They return a logical array of the same
size, with elements set to logical 1 (true) where the relation is true, and elements set to logical
0 (false) where it is not.
12 | UE155114
13 | UE155114
The operators <, >, <=, and >= use only the real part of their operands for the comparison.
The operators == and ~= test real and imaginary parts.
a=5
>> a = 5;
ans =
1 1 1
1 1 0
0 0 0
>> x=5;
>> y=7;
>> x<y
ans =
>> x>y
ans =
>> x<=y
ans =
>> x>=y
ans =
>> x==y
ans =
14 | UE155114
15 | UE155114
0
>> x~=y
ans =
LOGICAL OPERATORS
Operator Operation Description
It returns 1 if both the
& AND elements are true (non-zero)
.
It returns 1 if either of the
| OR two values is true (non-
zero).
It complements the element
~ NOT i.e. Returns A for the value
A.
It returns 1 if only one of
Xor() Xor
the elements is true.
>> A=5;
>> B=0;
>> A&B
ans =
>> A|B
ans =
>> ~A
16 | UE155114
ans =
>> ~B
ans =
>> xor(A,B)
ans =
TRIGONOMETRIC OPERATIONS
MATLAB has some predefined functions to perform trigonometric and inverse trigonometric
operations. These functions may take real as well as complex arguments. Some of these
functions are sin, cos, tan, cot (trigonometric) and asin, acos, atan (inverse trigonometric).
>> x=[1 2 3 4 5]
x=
1 2 3 4 5
>> sin(x)
ans =
>> cos(x)
ans =
>> tan(x)
17 | UE155114
18 | UE155114
ans =
>> sec(x)
ans =
>> csc(x)
ans =
>> cot(x)
ans =
>> asin(x)
ans =
Columns 1 through 4
Column 5
1.5708 - 2.2924i
>> acos(x)
ans =
Columns 1 through 4
Column 5
0 + 2.2924i
>> atan(x)
19 | UE155114
20 | UE155114
ans =
>> acot(x)
ans =
>> asec(x)
ans =
>> acsc(x)
ans =
PLOTTING IN MATLAB
MATLAB provides tools for two-dimensional (2-D) and three-dimensional (3-D) plots. It is
possible to customize plots by adding multiple axes, changing line colors and marker, adding
annotations and legends.
>> x=[1:.1:10];
>> y=sin(x);
>> plot(x,y); title('Sine Curve'); xlabel('Time'); ylabel('Function sin(x)');
21 | UE155114
22 | UE155114
EXPERIMENT-1
AIM: TO GENERATE BASIC ELEMENTARY SIGNALS IN DISCRETE FORM
USING MATLAB.
REQUIREMENTS: A PC with MATLAB installed in it.
The basic elementary signals are:
Unit impulse signal - It is defined as:
(t) =1;t=0
0;t0
Unit step signal It is defined as:
u(t) = 0 ; t < 0
1;t0
Unit ramp signal It is defined as:
r(t) = t ; t 0
0;t<0
Exponential signal It is defined as:
x(t) = kt ; real exponential sequence
e(a+jb)t ; complex exponential sequence
These elementary functions can be represented in discrete form in MATLAB using the
stem function.
t=[-10:0.1:10];
impulse= t==0;
unitstep= t>=0;
ramp= t.*unitstep;
quad= t.^2.*unitstep;
subplot(2,2,1);
plot(t,impulse);
title('Unit-impulse function');
xlabel('Time');
ylabel('Output respone');
subplot(2,2,2);
plot(t,unitstep);
title('Unit-step function');
xlabel('Time');
ylabel('Output response');
subplot(2,2,3);
plot(t,ramp);
title('Unit-ramp function');
xlabel('Time');
ylabel('Output response');
subplot(2,2,4);
plot(t,quad);
title('Exponential function');
xlabel('Time');
23 | UE155114
ylabel('Output response');
24 | UE155114
25 | UE155114
EXPERIMENT-2
AIM: TO GENERATE THE ADVANCED AND DELAYED VERSIONS OF THE
ELEMENTARY SIGNALS IN DISCRETE FORM USING MATLAB.
REQUIREMENTS: A PC with MATLAB installed in it.
In discrete-time signals, the independent variable t may be shifted, i.e. the signal can be
either advanced or delayed in time axis. If the given signal x(n) is shifted by k, then the
resultant shifted signal is given by the expression:
a(t) = x(t-k)
>> t=[-10:0.1:10];
>> impulse = t==0;
>> unitstep = t>=0;
>> ramp = t.*unitstep;
>> quad = t.^2.*unitstep;
>> subplot(2,4,1);
>> plot(t-3,impulse);
>> title('Delayed Impulse');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,2);
>> plot(t-3,unitstep);
>> title('Delayed Unitstep');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,3);
>> plot(t-3,ramp);
>> title('Delayed Ramp');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,4);
>> plot(t-3,quad);
>> title('Delayed Quad');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,5);
>> plot(t+4,impulse);
>> title('Advanced Impulse');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,6);
26 | UE155114
>> plot(t+4,unitstep);
>> title('Advanced Unitstep');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,7);
>> plot(t+4,ramp);
>> title('Advanced Ramp');
>> xlabel('Time');
>> ylabel('Output response');
>> subplot(2,4,8);
>> plot(t+4,quad);
>> title('Advanced Quad');
>> xlabel('Time');
>> ylabel('Output response');
27 | UE155114
28 | UE155114
EXPERIMENT-3
AIM: TO PLOT THE GRAPH FOR CONVOLUTION OF TWO FUNCTIONS
USING CONV FUNCTION
REQUIREMENTS: A PC with MATLAB installed in it.
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).
%FIRST FUNCTION
x=input('enter first sequence')
nx=input('enter time domain for x')
subplot(3,1,1);
stem(nx,x);
title('FIRST FUNCTION')
xlabel('time')
ylabel('Magnitude')
% SECOND FUNCTION
y=input('enter second sequence')
ny=input('enter time domain for y')
subplot(3,1,2);
stem(ny,y);
title('SECOND FUNCTION')
xlabel('TIME')
ylabel('MAGNITUDE')
%CONVOLUTION
z=conv(x,y)
a=nx(1)+ny(1);
b=nx(length(nx))+ny(length(ny));
nz=a:b
subplot(3,1,3)
stem(nz,z);
title('CONVOLUTION')
xlabel('TIME')
ylabel('MAGNITUDE')
29 | UE155114
30 | UE155114
EXPERIMENT-4
AIM: TO PLOT THE GRAPH FOR CONVOLUTION OF TWO FUNCTIONS
WITHOUT USING CONV FUNCTION
REQUIREMENTS: A PC with MATLAB installed in it.
%FIRST FUNCTION
x=input('enter first sequence')
nx=input('enter time domain for x')
subplot(3,1,1);
stem(nx,x);
title('FIRST FUNCTION')
xlabel('time')
ylabel('Magnitude')
% SECOND FUNCTION
y=input('enter second sequence')
ny=input('enter time domain for y')
subplot(3,1,2);
stem(ny,y);
title('SECOND FUNCTION')
xlabel('TIME')
ylabel('MAGNITUDE')
%CONVOLUTION
l=length(x)+length(y)-1
z=[zeros(1,l)]
x1=[x, zeros(1,length(y))];
y1=[y,zeros(1,length(x))];
a=nx(1)+ny(1);
b=nx(length(nx))+ny(length(ny));
nz=[a:b]
for n=1:l
for k=1:n
z(n)=z(n)+[y1(k)*x1(n-k+1)]
end;
end;
subplot(3,1,3)
stem(nz,z);
title('CONVOLUTION')
xlabel('TIME')
ylabel('MAGNITUDE')
31 | UE155114
32 | UE155114
EXPERIMENT-5
AIM: TO PLOT THE GRAPH FOR CORRELATION OF TWO FUNCTIONS
USING XCORR FUNCTION
REQUIREMENTS: A PC with MATLAB installed in it.
Correlation is a measure of similarity between two signals. The general formula for
correlation is:
%FIRST FUNCTION
x=input('enter first sequence')
nx=input('enter time domain for x')
subplot(3,1,1);
stem(nx,x);
title('FIRST FUNCTION')
xlabel('time')
ylabel('Magnitude')
% SECOND FUNCTION
y=input('enter second sequence')
ny=input('enter time domain for y')
subplot(3,1,2);
stem(ny,y);
title('SECOND FUNCTION')
xlabel('TIME')
ylabel('MAGNITUDE')
%correlation
r=xcorr(x,y)
a=nx(1)-ny(length(ny));
b=nx(length(nx))-ny(1);
nr=[a:b]
subplot(3,1,3)
stem(nr,r)
title('CONVOLUTION')
xlabel('TIME')
ylabel('MAGNITUDE')
33 | UE155114
34 | UE155114
EXPERIMENT-6
AIM: TO PLOT THE GRAPH FOR CORRELATION OF TWO FUNCTIONS
WITHOUT USING XCORR FUNCTION
REQUIREMENTS: A PC with MATLAB installed in it.
%FIRST FUNCTION
x=input('enter first sequence')
nx=input('enter time domain for x')
subplot(3,1,1);
stem(nx,x);
title('FIRST FUNCTION')
xlabel('time')
ylabel('Magnitude')
% SECOND FUNCTION
y=input('enter second sequence')
ny=input('enter time domain for y')
subplot(3,1,2);
stem(ny,y);
title('SECOND FUNCTION')
xlabel('TIME')
ylabel('MAGNITUDE')
% CORRELATION
y1=fliplr(y);
ny1=-fliplr(ny);
[z,nz]=convo(x,nx,y1,ny1)
subplot(3,1,3)
stem(nz,z)
title('CORRELATION')
xlabel('TIME')
ylabel('MAGNITUDE')
35 | UE155114
36 | UE155114
EXPERIMENT-7
AIM: TO PLOT THE GRAPH FOR TARGET DETECTION USING RADAR
REQUIREMENTS: A PC with MATLAB installed in it.
37 | UE155114
38 | UE155114
EXPERIMENT-8
AIM: TO PERFORM CIRCULAR CONVOLUTION OF TWO SEQUENCES.
REQUIREMENTS: A PC with MATLAB installed in it.
The circular convolution, also known as cyclic convolution, of two aperiodic
functions (i.e. Schwartz functions) occurs when one of them is convolved in the
normal way with a periodic summation of the other function. That situation
arises in the context of the Circular convolution theorem. The identical
operation can also be expressed in terms of the periodic summations
of both functions, if the infinite integration interval is reduced to just one
period. That situation arises in the context of the discrete-time Fourier
transform (DTFT) and is also called periodic convolution. In particular, the
DTFT of the product of two discrete sequences is the periodic convolution of
the DTFTs of the individual sequences
39 | UE155114
40 | UE155114
EXPERIMENT-9
AIM: TO PERFORM DFT (DISCRETE FOURIER TRANSFORM) OF A GIVEN
SEQUENCE.
41 | UE155114
42 | UE155114
EXPERIMENT-10
AIM: TO PERFORM IDFT (INVERSE DISCRETE FOURIER TRANSFORM)
OF A GIVEN SEQUENCE.
43 | UE155114
44 | UE155114
EXPERIMENT-11
45 | UE155114
46 | UE155114
EXPERIMENT-12
AIM: TO STUDY HAMMING WINDOW AND EXECUTE FILTERS
(LPF,HPF,BPF,BSF).
instead of both constants being equal to 1/2 in the Hann window. The constants
are approximations of values = 25/46 and = 21/46, which cancel the first
sidelobe of the Hann window by placing a zero at frequency 5/(N 1)
47 | UE155114
48 | UE155114
49 | UE155114