LOKESH - DSP Practical File (251901018 ECE A)
LOKESH - DSP Practical File (251901018 ECE A)
PRACTICAL FILE
of
SUBMITTED TO:-
SUBMITTED BY:-
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 : 02
AIM: Write a program to plot Sine, Cosine, Tangent, Secant wave for Discrete and Continuous
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);
xlabel('time');
ylabel('amplitude');
title('tangent wave');
m=sec(t);
subplot(3,3,7);
plot(m);
xlabel('time');
ylabel('amplitude');
title('secant wave');
subplot(3,3,8);
stem(m);
xlabel('time');
ylabel('amplitude');
title('secant wave');
FIGURE:
EXPERIMENT NO : 03
AIM: To study Unit Step, Unit Impulse and Unit Ramp function.
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: 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 : 05
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 : 06
AIM: To write a program to find Linear Convolution and Multiplication of the given signal.
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 : 07
AIM: To write a program to plot the Circular Convolution of two given signals.
THEORY: Circular convolution, also known as cyclic convolution, is a special case of periodic
convolution, which is the convolution of two periodic functions that have the same period. Periodic
convolution arises, for example, in the context of the discrete-time Fourier transform.
Program :
x = [1,2,3,4];
y = [5,6,7,8];
n = 4;
z = cconv(x,y,n);
subplot(2,1,1);
stem(x);
xlabel('samples');
ylabel('amplitude');
title('signal1');
subplot(2,1,2);
stem(z);
xlabel('samples');
ylabel('amplitude');
title('circular
convolution output');
Note :- Here x,y and n should be of same length.
FIGURE 1:
FIGURE 2:
EXPERIMENT NO. 8
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: