Practical File OF Digital Signal Processing Lab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

PRACTICAL FILE

OF

DIGITAL SIGNAL PROCESSING LAB

SUBMITTED TO:- SUBMITTED BY:-


Mrs. KIRTI MAM MOHIT TIWARI
ECE DEPARTMENT 251801027
UIET, KUK ECE-A (5th Sem.)

University Institute of Engineering and Technology


Kurukshetra University, Kurukshetra – 136119
INDEX

S.NO. EXPERIMENT DATE SIGNATURE


1. Introduction to MATLAB.

2. To study unit impulse , ramp and


unit step function.

3. Write a program to plot sine, cosine,


tangent, secant wave for discrete and
continuous function.
4. To study convolution and multiplication.

5. To study real ,imaginery phase and


magnitude of exponential function.

6. To write a program to study the sampling


theorem of a continuous time signal.

7. To study toolbox of various IIR (infinite


impulse response) filter.

8. To study toolbox of various FIR (finite


impulse response) filter.

9. Write a program to plot the circular


convolution of two signals
EXPERIMENT NO:1

AIM: Introduction to MATLAB

THEORY:

What is MATLAB?

MATLAB is widely used in all areas of applied mathematics, in education and research at
universities, and in the industry. MATLAB stands for MATrix LABoratory and the software is
built up around vectors and matrices. This makes the software particularly useful for linear
algebra but MATLAB is also a great tool for solving algebraic and differential equations and for
numerical integration. MATLAB has powerful graphic tools and can produce nice pictures in
both 2D and 3D. It is also a programming language, and is one of the easiest programming
languages for writing mathematical programs. MATLAB also has some tool boxes useful for
signal processing, image processing, optimization, etc.

How to start MATLAB

Mac: Double-click on the icon for MATLAB.

PC: Choose the submenu "Programs" from the "Start" menu. From the "Programs" menu, open
the "MATLAB" submenu. From the "MATLAB" submenu, choose "MATLAB".

Unix: At the prompt, type matlab.

You can quit MATLAB by typing exit in the command window.

The MATLAB environment

Note: From now on an instruction to press a certain key will be denoted by < >, e.g., pressing the
enter key will be denoted as <enter>. Commands that should be typed at the prompt, will be
written in courier font.

The MATLAB environment (on most computer systems) consists of menus, buttons and a
writing area similar to an ordinary word processor. There are plenty of help functions that you
are encouraged to use. The writing area that you will see when you start MATLAB, is called
the command window. In this window you give the commands to MATLAB. For example, when
you want to run a program you have written for MATLAB you start the program in the
command window by typing its name at the prompt. The command window is also useful if you
just want to use MATLAB as a scientific calculator or as a graphing tool. If you write longer
programs, you will find it more convenient to write the program code in a separate window, and
then run it in the command window .

In the command window you will see a prompt that looks like >> . You type your commands
immediately after this prompt. Once you have typed the command you wish MATLAB to
perform, press <enter>. If you want to interupt a command that MATLAB is running, type

<ctrl> + <c>.

The commands you type in the command window are stored by MATLAB and can be viewed in
the Command History window. To repeat a command you have already used, you can simply
double-click on the command in the history window, or use the <up arrow> at the command
prompt to iterate through the commands you have used until you reach the command you desire
to repeat.

Useful functions and operations in MATLAB

Using MATLAB as a calculator is easy.

Example: Compute 5 sin(2.53-pi)+1/75. In MATLAB this is done by simply

typing 5*sin(2.5^(3-pi))+1/75

at the prompt. Be careful with parantheses and don't forget to type * whenever you multiply!

Note that MATLAB is case sensitive. This means that MATLAB knows a difference between
letters written as lower and upper case letters. For example, MATLAB will understand sin(2) but
will not understand Sin(2).
EXPERIMENT NO:2

AIM: To study unit impulse , ramp and unit step function.

TOOL USED: MATLAB 7.6.0.

THEORY: A unit step has 1 for t ≥ 0 and 0 for t ˂ 0. A unit ramp has t for t ≥ 0 and 0 for t ˂
0.

PROGRAM:

t=-10:1:10;
x=[zeros(1,10) ones(1,10)];
subplot(2,2,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title('step function');

x=[(t)];
subplot(2,2,2);
stem(x);
xlabel('time');
ylabel('amplitude');
title('ramp function');

x=[exp(t)];
subplot(2,2,3);
stem(x);
xlabel('time');
ylabel('amplitude');
title('exponential function');

x=[zeros(1,10) ones(1,1) zeros(1,10)];


subplot(2,2,4);
stem(x);
xlabel('time');
ylabel('amplitude');
title('impulse function');
FIGURE:
EXPERIMENT NO:3
AIM: Write a program to plot sine, cosine, tangent, secant wave for discrete and continuous
function.

TOOL USED: MATLAB 7.6.0

THEORY: The sine function starts from 0. Maximum value of sine function is 1.
Range of cosine is -1 to 1. Range of tangent is from -∞ to ∞.

Range of secant is -1 to 1.

PROGRAM:
t=[-pi:00.2:pi];

x=sin(t);
subplot(3,3,1);
plot(x);
xlabel('time');
,ylabel('amplitude');
title('sine wave');
subplot(3,3,2);
stem(x);
xlabel('time');
ylabel('amplitude');
title('sine wave');

y=cos(t);
subplot(3,3,3);
plot(y);
xlabel('time');
ylabel('amplitude');
title('cosine wave');
subplot(3,3,4);
stem(y);
xlabel('time');
ylabel('amplitude');
title('cosine wave');

z=tan(t);
subplot(3,3,5);
plot(z);
xlabel('time');
ylabel('amplitude');
title('tangent wave');
subplot(3,3,6);
stem(z);
x l a b e l (' t i m e ') ;
y l a b e l (' a m p l i t u d e ') ;
t i t l e (' t a n g e n t w a v e ') ;

m=sec(t);
subplot(3,3,7);
plot(m);
x l a b e l (' t i m e ') ;
y l a b e l (' a m p l i t u d e ') ;
t i t l e (' s e c a n t w a v e ') ;
subplot(3,3,8);
stem(m);
x l a b e l (' t i m e ') ;
y l a b e l (' a m p l i t u d e ') ;
t i t l e (' s e c a n t w a v e ') ;

FIGURE:
EXPERIMENT NO:4

AIM: To study convolution and multiplication.


TOOL USED: MATLAB7.6.0

THEORY: In mathematics, the convolution theorem states that under suitable conditions the
fourier transform of a convolution is the pointwise product of fourier transforms. In other words,
convolution in one domain (e.g. time domain) equals point wise multiplication in other domain
(e.g frequency domain). Convolution syntax is denoted by conv(x,y). Multiplication syntax is
denoted by x.*y .

PROGRAM:
x=[1 2 3];
y=[4 5 6];

z=x.*y;
subplot(2,2,1);
plot(z);
xlabel('time');
ylabel('amplitude');
title('multiplication');
subplot(2,2,2);
stem(z);
xlabel('time');
ylabel('amplitude');
title('multiplication');

p=conv(x,y);
subplot(2,2,3);
plot(p);
xlabel('time');
ylabel('amplitude');
title('convolution');
subplot(2,2,4);
stem(p);
xlabel('time');
ylabel('amplitude');
title('convolution');
FIGURE:
EXPERIMENT NO:5

AIM:To study real ,imaginery phase and magnitude of exponential function.


TOOL USED:MATLAB 7.6.0
THEORY: Exponential function is a form of function in which the input variable x occurs as
an exponent .A function f(x)=b^x is considered as an exponential function .When the real part is
0 ,it is considered as a imaginary and when img. part is 0 it is considered as real part.

PROGRAM:

t=0:0.5:10;
m=10+j*90;

y=exp(m.*t)a;
subplot(2,2,1);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('exponential');

z=real(y);
subplot(2,2,2);
plot(t,z);
xlabel('time');
ylabel('amplitude');
title('real');

i=imag(y);
subplot(2,2,3);
plot(t,i);
xlabel('time');
,ylabel('amplitude');
title('imaginary');

a=abs(y);
subplot(2,2,4);
plot(t,a);
xlabel('time');
ylabel('amplitude');
title('absolute');
FIGURE:
EXPERIMENT NO. 6

AIM: To write a program to study the sampling theorem of a continuous time signal.

TOOL USED: MATLAB 7.6.0.

THEORY: A continuous time signal can be represented in its samples and can be recovered
back when sampling frequency fs is greater than or equal to the twice the highest frequency
component of the message signal. i.e. fs ≥ 2fm

PROGRAM:
f1=3;
f2=23;
t=-0.4:0.0001:0.4;
x=cos(2*pi*f1*t)+cos(2*pi*f2*t);
figure(1);
plot(t,x,'-.g');
xlabel('time ---');
ylabel('amp --');
title('the original signal');

%case1: (fs<2fm)
fs1=1.5*f2;
ts1=1/fs1;
n1=-0.4:ts1:0.4;
xs1=cos(2*pi*f1*n1)+cos(2*pi*f2*n1);
figure(2);
stem(n1,xs1);
hold on;
plot(t,x,'-.g');
hold off;
legend('fs<2fm');

%case2: (fs=2fm)
fs1=2*f2;
ts2=1/fs1;
n2=-0.4:ts2:0.4;
xs2=cos(2*pi*f1*n2)+cos(2*pi*f2*n2);
figure(3);
stem(n2,xs2);
hold on;
plot(t,x,'-.g');
hold off;
legend ('fs=2fm');

%case3: (fs>2fm)
fs3=7*f2;
ts3=1/fs3;
n3=-0.4:ts3:0.4;
xs3=cos(2*pi*f1*n3)+cos(2*pi*f2*n3);
figure(4);
stem(n3,xs3);

hold on;
plot(t,x,'-.g');
hold off;
legend('fs>2fm');

FIGURE 1:

FIGURE 2:

FIGURE 3
FIGURE 4:
EXPERIMENT NO. 7

AIM: To study toolbox of various IIR (infinite impulse response) filter.

TOOL USED: MATLAB 7.6.0

IIR FILTERS

LOWPASS FILTER
(I) ORDER 10:

(II) ORDER 50:

HIGHPASS FILTER
(I) ORDER 10:

(II) ORDER 50:

BANDPASS FILTER
(I) ORDER 10:

(II) ORDER 50:

BANDSTOP FILTER
(I) ORDER 10:

(II) ORDER 50:


EXPERIMENT NO. 8

AIM: To study toolbox of various FIR (finite impulse response) filter.

TOOL USED: MATLAB 7.6.0

FIR FILTERS

LOWPASS FILTER

(I) ORDER 10:

(I) ORDER 50:

HIGHPASS FILTER
(I) ORDER 10:

(II) ORDER 50:

BANDPASS FILTER
(I) ORDER 10:

(II) ORDER 50:

BANDSTOP FILTER
(I) ORDER 10:

(II) ORDER 50:


EXPERIMENT NO.9

AIM : Write a program to plot the circular convolution of two signals.

TOOL USED: MATLAB 7.6.0

THEORY: The circular convolution also known as cyclic convolution , of two aperiodic
functions occurs when one of them is convolved in normal way with a periodic summation of
other function.

Program :
x=input('enter the sequence 1');
h=input('enter the sequence 2');
m=length(x);
n=length(h);
N=max(m,n);
s=m-n;
j=1;
z=[];
if(s==0)
h=[h,zeros(1,s)];
else
x=[x,zeros(1,-s)];
h=[h,zeros(1,s)];
end
for n=1:N
y=0;
for i=1:N
j=(n-i)+1;
if(j<=0)
j=N+j;
end
y=y+(x(i)*h(j));
end
z=[z y];
end
subplot(3,1,1),stem(x),title('signal 1'),
xlabel('samples'),ylabel('amplitude');
subplot(3,1,2),stem(h),title('signal 2'),
xlabel('samples'),ylabel('amplitude');
subplot(3,1,3),stem(z),title('circular convolution output'),
xlabel('samples'),ylabel('amplitude');

FIGURE 1
FIGURE 2

You might also like