Practical File OF Digital Signal Processing Lab
Practical File OF Digital Signal Processing Lab
Practical File OF Digital Signal Processing Lab
OF
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.
PC: Choose the submenu "Programs" from the "Start" menu. From the "Programs" menu, open
the "MATLAB" submenu. From the "MATLAB" submenu, choose "MATLAB".
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.
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
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');
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
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
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.
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
IIR FILTERS
LOWPASS FILTER
(I) ORDER 10:
HIGHPASS FILTER
(I) ORDER 10:
BANDPASS FILTER
(I) ORDER 10:
BANDSTOP FILTER
(I) ORDER 10:
FIR FILTERS
LOWPASS FILTER
HIGHPASS FILTER
(I) ORDER 10:
BANDPASS FILTER
(I) ORDER 10:
BANDSTOP FILTER
(I) ORDER 10:
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