DSP Practicle NO. 1 - 4
DSP Practicle NO. 1 - 4
Date:
EXPERIMENT NO. 1
Introduction:
The name MATLAB stands for MATrix LABoratory produced by Mathworks Inc., USA. It is a
matrix-based powerful software package for scientific and engineering computation and
visualization. Complex numerical problems can be solved in a fraction of the time that required
with other high level languages. It provides an interactive environment with hundreds of built -in
–functions for technical computation, graphics and animation. In addition to built-in-functions,
user can create his own functions. MATLAB offers several optional toolboxes, such as signal
processing, control systems, neural networks etc. It is command driven software and has online
help facility. MATLAB has three basic windows normally;
Command window,
Graphics window
Edit window.
Command window is characterized by the prompt ‘>>’.
All commands and the ready to run program filename can be typed here. Graphic window gives
the display of the figures as the result of the program. Edit window is to create program files
with an extension .m.
Some important commands in MATLAB.
Help List topics on which help is available. Help command name Provides help on the topic
selected.
Demo Runs the demo program.
Who Lists variables currently in the work space Who Lists variables currently in the work space
with their size.
Clear Clears the work space, all the variables are removed.
Clear x,y,z Clears only variables x,y,z Quit. Quits MATLAB
Some of the frequently used built-in-functions in Signal Processing Toolbox
filter(b.a.x)
Syntax of this function is:
1
Roll No. Date:
Y = filter(b,a,x)
It filters the data in vector x with the filter described by vectors a and b to create the filtered data.
y. fft (x)
It is the DFT of vector x.
ifft (x)
It is the IDFT of vector x.
conv (a,b)
Syntax of this function is:
C = conv (a,b).
It convolves vectors a and b. The resulting vector is of Length, Length (a) + Length (b)-1
butter(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the
filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients
are listed in descending powers of z. The cutoff frequency Wn must be 0.0<Wn<1.0, with 1.0
corresponding to half the sample rate.
abs(x).
It gives the absolute value of the elements of x. When x is complex, abs(x) is the complex
modulus (magnitude) of the elements of x.
angle(H).
It returns the phase angles of a matrix with complex elements in radians.
stem(y)
It plots the data sequence y as stems from the x axis terminated with circles for the data value.
stem(x,y)
It plots the data sequence y at the values specified in x.
plot(x,y)
It plots vector y versus vector x. If x or y is a matrix, then the vector is plotted versus the rows
or columns of the matrix, whichever line up.
title(‘text’) It adds text at the top of the current axis.
xlabel(‘text’)
It adds text beside the x-axis on the current axis.
ylabel(‘text’)
It adds text beside the y-axis on the current axis.
2
Roll No. Date:
EXPERIMENT NO. 2
Aim: Representation of basic signals (unit step sequence, exponential sequence, unit
impulse, ramp & sinusoidal sequence).
Program:
clc;
%Unit Impulse%
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(3,3,1);
stem(t,y);
xlabel('Time');
ylabel('Amplitude');
%Unit Step%
n=input('Enter the value of n');
t=0:1:n-1;
y=ones(1,n);
subplot(3,3,3);
stem(t,y);
xlabel('Time');
ylabel('Amplitude');
%Unit Ramp%
n1=input('Enter the value of n');
t=0:1:n1-1;
subplot(3,3,5);
stem(t,t);
xlabel('Time');
ylabel('Amplitude');
3
Roll No. Date:
% %Exponential
%Sinosoidal%
t=0:pi/5:2*pi;
y=sin(t);
subplot(3,3,9);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
INPUT:
Enter the value of n 10
Enter the value of n 10
Enter the value of A 1
Enter the value of n2 10
4
Roll No. Date:
OUTPUT PLOT:
5
Roll No. Date:
EXPERIMENT NO. 3
Program:
a=length(x);
b=length(h);
c=a+b-1;
y=conv(x,h);
n=0:1:c-1;
disp('Output Sequence');
disp(y);
subplot(1,3,1);
stem(x);
title('first sequence');
Xlabel('time');
Ylabel('amplitude');
subplot(1,3,2);
stem(h);
title('second sequence');
Xlabel('time');
6
Roll No. Date:
Ylabel('amplitude');
subplot(1,3,3);
stem(y);
title('convolution sequence');
Xlabel('time');
Ylabel('amplitude')
INPUT:
Enter the first sequence [1,2,3,4,5]
Enter the second sequence [1,2,3,4,5]
Output sequence:
1 4 10 20 35 44 46 40 25
Output plot:
7
Roll No. Date:
EXPERIMENT NO. 4
AIM: Write a program to compute the DFT of the sequence and plot magnitude and phase
response.
Program:
% discrete fourier transform%
clc;
N = input('Enter the value of N(Value of N in N-Point DFT)');
x = input('Enter the sequence for which DFT is to be calculated');
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk; % DFT sequence %
disp('DFT Sequence')
disp(Xk);
MagX=abs(Xk) % Magnitude of calculated DFT
PhaseX=angle(Xk)*180/pi % Phase of the calculated DFT
subplot(4,1,1);
stem(k,x);
title('Input sequence');
xlabel('k----->>');
ylabel('magnitude----->>');
subplot(4,1,2);
stem(k,Xk);
title('DFT sequence');
xlabel('k----->>');
ylabel('magnitude----->>');
subplot(4,1,3);
stem(k,MagX);
8
Roll No. Date:
title('magnitude plot');
xlabel('k----->>');
ylabel('magnitude----->>');
subplot(4,1,4);
plot(k,PhaseX);
title('Phase Plot');
xlabel('k----->>');
ylabel('phase----->>');
INPUT:
OUTPUT:
DFT Sequence
20.0303 -4.0303 + 4.0303i -4.0303 - 0.0303i -4.0303 - 4.0303i
MagX =
20.0303 5.6569 4.0303 5.6569
PhaseX =
0 135.0303 -180.0303 -135.0303
9
Roll No. Date:
Output plot:
10