Vous êtes sur la page 1sur 49

Digital signal processing

Practical File

Submitted by- VIVEK KUMAR


Roll no.-ue155114
Branch- ece (Sect 2, GROUP 5)
3rd year (5TH SEMESTER)
Submitted To Dr. SUMIT BUDHIRAJA

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.

The components of a MATLAB desktop are as follows:

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.

B. COMMAND HISTORY WINDOW


The Command History Window contains a list of all the commands that are entered at the
Command Window. It consists of commands from previous sessions also. These commands
remain in the list until they are deleted. Any command may be executed by selecting and
double-clicking it with the mouse. A program file may be created by selecting a set of
commands and right-clicking the mouse which displays a pop-up menu. A program file
containing the selected commands can be created by choosing the Create M-file option from
the menu.

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.

D. CURRENT DIRECTORY WINDOW


In the Current Directory Window, all the files and folders present in the Current Directory
are listed. To run any file, it must either be in the Current Directory or on the search path. A
quick way to view or change the Current Directory or its contents is by using the Current
Directory field in the MATLAB toolbar.

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.

MATLAB BASIC COMMANDS


clc
It clears the command window.
clear all
It clears all the variables from the workspace.
close all
It closes all the figure windows.
who
It generates a list of all the variables currently in the workspace.

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];

>> Y=[2 4;6 8];

>> 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

Left and right division

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;

>> a>=[1 2 3;4 5 6;7 8 9]

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 =

0.8415 0.9093 0.1411 -0.7568 -0.9589

>> cos(x)

ans =

0.5403 -0.4161 -0.9900 -0.6536 0.2837

>> tan(x)

17 | UE155114
18 | UE155114
ans =

1.5574 -2.1850 -0.1425 1.1578 -3.3805

>> sec(x)

ans =

1.8508 -2.4030 -1.0101 -1.5299 3.5253

>> csc(x)

ans =

1.1884 1.0998 7.0862 -1.3213 -1.0428

>> cot(x)

ans =

0.6421 -0.4577 -7.0153 0.8637 -0.2958

>> asin(x)

ans =

Columns 1 through 4

1.5708 1.5708 - 1.3170i 1.5708 - 1.7627i 1.5708 - 2.0634i

Column 5

1.5708 - 2.2924i

>> acos(x)

ans =

Columns 1 through 4

0 0 + 1.3170i 0 + 1.7627i 0 + 2.0634i

Column 5

0 + 2.2924i

>> atan(x)

19 | UE155114
20 | UE155114
ans =

0.7854 1.1071 1.2490 1.3258 1.3734

>> acot(x)

ans =

0.7854 0.4636 0.3218 0.2450 0.1974

>> asec(x)

ans =

0 1.0472 1.2310 1.3181 1.3694

>> acsc(x)

ans =

1.5708 0.5236 0.3398 0.2527 0.2014

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)

If k is positive, the signal is delayed by k-units.


If k is negative, the signal is advanced by k-units.

>> 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:

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.

%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.

REQUIREMENTS: A PC with MATLAB installed in it.

The Discrete Fourier Transform is a numerical variant of the Fourier


Transform. Specifically, given a vector of n input amplitudes such as {f0, f1, f2,
... , fn-2, fn-1}, the Discrete Fourier Transform yields a set of n frequency
magnitudes.
The DFT is defined as such:

here, k is used to denote the frequency domain ordinal, and n is used to


represent the time-domain ordinal. The big "N" is the length of the sequence to
be transformed.

x=input('enter input signal = ');


m=length(x);
w=exp((-j)*2*pi/m)
n=0:(m-1);
k=0:(m-1);
nk=(n')*k;
wn=w.^nk;
xk=x*wn
subplot(2,2,1); stem(n,x);
title('input signal');
subplot(2,2,2); stem(xk);
title('DFT Signal');
subplot(2,2,3); stem(abs(xk));
title('Absolute Modulus');

41 | UE155114
42 | UE155114
EXPERIMENT-10
AIM: TO PERFORM IDFT (INVERSE DISCRETE FOURIER TRANSFORM)
OF A GIVEN SEQUENCE.

REQUIREMENTS: A PC with MATLAB installed in it.

The Inverse DFT (IDFT) is given by the following equation:

Where WN is defined as:

"N" is the length of the transformed sequence.

x=input('enter input signal = ');


m=length(x);
n=0:(m-1);
k=0:(m-1);
nk=(n')*k;
w=exp((-j)*2*pi/m)
wnk=w.^nk;
X=(1/m).*x*wnk
subplot(2,2,1); stem(n,x);
title('Magnitude');
subplot(2,2,2); stem(angle(X));
title('Phase');
subplot(2,2,3); stem(abs(xk));
title('X(w)');

43 | UE155114
44 | UE155114
EXPERIMENT-11

AIM: TO PERFORM DTFT (DISCRETE TIME FOURIER TRANSFORM) OF A


GIVEN SEQUENCE.

REQUIREMENTS: A PC with MATLAB installed in it.

The discrete-time Fourier transform of a discrete set of real or complex


numbers x[n], for all integers n, is a Fourier series, which produces a periodic
function of a frequency variable. When the frequency variable, ,
has normalized units of radians/sample, the periodicity is 2, and the Fourier
series is:

45 | UE155114
46 | UE155114
EXPERIMENT-12
AIM: TO STUDY HAMMING WINDOW AND EXECUTE FILTERS
(LPF,HPF,BPF,BSF).

REQUIREMENTS: A PC with MATLAB installed in it.

The window with these particular coefficients was proposed by Richard W.


Hamming. The window is optimized to minimize the maximum (nearest) side
lobe, giving it a height of about one-fifth that of the Hann window.

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

Vous aimerez peut-être aussi