Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
com
EC 6511 DIGITAL SIGNAL PROCESSING LAB MANUAL
INTRODUCTION
MATLAB stands for MATrix LABoratory. It is a technical computing environment for high
performance numeric computation and visualisation. It integrates numerical analysis, matrix
computation, signal processing and graphics in an easy-to-use environment, where problems and
solutions are expressed just as they are written mathematically, without traditional programming.
MATLAB allows us to express the entire algorithm in a few dozen lines, to compute the solution
with great accuracy in a few minutes on a computer, and to readily manipulate a three-
dimensional display of the result in colour.
MATLAB is an interactive system whose basic data element is a matrix that does not require
dimensioning. It enables us to solve many numerical problems in a fraction of the time that it
would take to write a program and execute in a language such as FORTRAN, BASIC, or C. It
also features a family of application specific solutions, called toolboxes. Areas in which
toolboxes are available include signal processing, image processing, control systems design,
dynamic systems simulation, systems identification, neural networks, wavelength
communication and others. It can handle linear, non-linear, continuous-time, discrete-time,
multivariable and multirate systems. This chapter gives simple programs to solve specific
problems that are included in the previous chapters. All these MATLAB programs have been
tested under version 7.1 of MATLAB and version 6.12 of the signal processing toolbox.
MATLAB COMMANDS:
GENERATION OF SIGNALS
1.A. CONTINUOUS TIME SIGNAL
Aim
Requirements
Procedure
1. OPEN MATLAB
2. File New Script.
a. Type the program in untitled window
3. File Save type filename.m in matlab workspace path
4. Debug Run. Wave will displayed at Figure dialog box.
Theory
Common Periodic Waveforms
The toolbox provides functions for generating widely used periodic waveforms:sawtooth
generates a sawtooth wave with peaks at ±1 and a period of 2π. An optional width parameter
specifies a fractional multiple of 2π at which the signal's maximum occurs. square generates a
square wave with a period of 2π. An optional parameter specifies duty cycle, the percent of the
period for which the signal is positive.
The toolbox also provides functions for generating several widely used aperiodic waveforms:
gauspuls generates a Gaussian-modulated sinusoidal pulse with a specified time, center
frequency, and fractional bandwidth. Optional parameters return in-phase and Quadrature pulses,
the RF signal envelope, and the cutoff time for the trailing pulse envelope. chirp generates a
linear, log, or quadratic swept-frequency cosine signal. An optional parameter specifies
alternative sweep methods. An optional parameter phi allows initial phase to be specified in
degrees.
Program %
Result
Requirements
Matlab 2007
Personal computer
Procedure
1. OPEN MATLAB
Theory:
Program
clear all;
a = 10;
f = 13;
T = 0.01;
n = 0:T:1;
xs = a*sin(2*pi*f*n);
k = 0:length(n)-1;
stem(k,xs);
grid
xlabel('Time index n');
ylabel('Amplitude');
title('Discrete-time signal x[n]');
axis([0 (length(n)-1) -10.2 10.2])
Expected Graph:
Result
Apparatus :
Program :
t = -3:1:3;
y = [zeros(1,3),ones(1,1),zeros(1,3)];
subplot(2,2,1);stem(t,y);
ylabel('Amplitude------>');
xlabel('(a)n ------>');
t = -4:1:4;
y1 = ones(1,9);
subplot(2,2,2);stem(t,y1);
ylabel('Amplitude------>');
xlabel('(b)n ------>');
title('Unit step');
n1 = input('Enter the value for end of the seqeuence '); %n1 = <any value>7 %
x = 0:n1;
subplot(2,2,3);stem(x,x);
ylabel('Amplitude------>');
xlabel('(c)n ------>');
title('Ramp sequence');
t = 0:n2;
y2 = exp(a*t);
subplot(2,2,4);stem(t,y2);
ylabel('Amplitude------>');
xlabel('(d)n ------>');
title('Exponential sequence');
disp('Exponential signal');x
Output :
Exponential signal x = 0 1 2 3 4 5 6
Graph:
Amplitude------>
0.5 0.5
0 0
-4 -2 0 2 4 -4 -2 0 2 4
(a)n ------> (b)n ------>
Ramp sequence Exponential sequence
6 60
Amplitude------>
Amplitude------>
4 40
2 20
0 0
0 2 4 6 0 1 2 3 4
(c)n ------> (d)n ------>
Result
To develop program for some basic operations like addition, subtraction, shifting and folding on signal.
Apparatus :
Theory:
Basic Operations
Signal Adding:
This is a sample-by-sample addition given by and the length of x1(n) and x2(n) must be the same
n)}={x1 n)}
Signal Multiplication:
PROGRAM:
ADDITION:
x=input(„ENTER THE FIRST SEQUENCE:‟);
subplot(3,1,1);
stem(x);
title('X');
y=input(„ENTER THE SECOND SEQUENCE:‟);
subplot(3,1,2);
stem(y);
title('Y');
z=x+y;
disp(z)
subplot(3,1,3);
stem(z);
title('Z=X+Y');
OUTPUT:
EXPECTED GRAPH:
SUBTRACTION
clc;
clear all;
close all;
n1=-2:1;
x=input('ENTER THE FIRST SEQUENCE:');
n2=0:3;
y=input('ENTER THE SECOND SEQUENCE:');
subplot(3,1,1);
stem(n1,x);
xlabel ('time')
ylabel ('amplitude')
title('FIRST SEQUENCE') ;
axis([-4 4 -5 5]);
subplot(3,1,2);
stem(n2,y);
xlabel ('time')
ylabel ('amplitude')
title('SECOND SEQUENCE');
axis([-4 4 -5 5]);
n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1 ) , max ( n2 ) ); % finding the duration of output
signal
s1 =zeros(1,length (n3) );
s2 =s1;
s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1 ) )==1 ) )=x;
% signal x with the duration of output signal 'sub'
s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max ( n2 ))==1) )=y;
% signal y with the duration of output signal 'sub'
sub=s1 - s2; % subtraction
disp('subtracted sequence')
disp(sub)
subplot(3,1,3)
stem(n3,sub)
xlabel ('time')
ylabel ('amplitude')
OUTPUT:
EXPECTED GRAPH:
MULTIPLICATION
PROGRAM:
clc;
clear all;
close all;
n1=-2:1;
x=input('ENTER THE FIRST SEQUENCE:');
n2=0:3;
y=input('ENTER THE SECOND SEQUENCE:');
subplot(3,1,1);
stem(n1,x);
xlabel ('time')
ylabel ('amplitude')
title('FIRST SEQUENCE') ;
axis([-4 4 -5 5]);
subplot(3,1,2);
stem(n2,y);
xlabel ('time')
ylabel ('amplitude')
title('SECOND SEQUENCE');
axis([-4 4 -5 5]);
n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1 ) , max ( n2 ) ); % finding the duration of output
signal (out)
s1 =zeros(1,length (n3) );
s2 =s1;
s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1 ) )==1 ) )=x;
% signal x with the duration of output signal 'mul'
s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max ( n2 ))==1) )=y;
% signal y with the duration of output signal 'mul'
mul=s1 .* s2; % multiplication
disp('MULTIPLIED SEQUENCE')
disp(mul)
subplot(3,1,3)
stem(n3,mul)
xlabel ('time')
ylabel ('amplitude')
OUTPUT:
EXPECTED GRAPH:
SHIFTING
PROGRAM:
clc;
clear all;
close all;
n1=input('Enter the amount to be delayed');
n2=input('Enter the amount to be advanced');
n=-2:2;
x=input('ENTER THE SEQUENCE');
subplot(3,1,1);
stem(n,x);
title('Signal x(n)');
m=n+n1;
y=x;
subplot(3,1,2);
stem(m,y);
title('Delayed signal x(n-n1)');
t=n-n2;
z=x;
subplot(3,1,3);
stem(t,z);
title('Advanced signal x(n+n2)');
OUTPUT:
Enter the amount to be delayed 3
Enter the amount to be advanced4
ENTER THE SEQUENCE[1 2 3 4 5]
EXPECTED GRAPH:
FOLDING or REVERSING:
PROGRAM:
clc;
clear all;
close all;
n=-1:2;
x=input('ENTER THE SEQUENCE');
subplot(2,1,1)
stem(n,x);
axis([-3 3 -5 5]);
title('Signal x(n)');
c=fliplr(x);
y=fliplr(-n);
disp('FOLDED SEQUENCE')
disp(c)
subplot(2,1,2);
stem(y,c);
axis([-3 3 -5 5]);
title('Reversed Signal x(-n)') ;
OUTPUT:
FOLDED SEQUENCE
-3 2 -1 1
EXPECTED GRAPH
Result
CORRELATION
Aim :
Apparatus :
Program :
CROSS CORRELATION
% Program for computing cross-correlation of the sequences x5[1, 2, 3, 4] and h5[4, 3, 2, 1]
clc;
clear all;
close all;
x=input(„enter the 1st sequence‟);
h=input(„enter the 2nd sequence‟);
y=crosscorr(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel(„Amplitude --.‟);
xlabel(„(a) n --.‟);
title(„input sequence‟);
subplot(3,1,2);
stem(h);
ylabel(„Amplitude --.‟);
xlabel(„(b) n --.‟);
title(„impulse sequence‟);
subplot(3,1,3);
stem(fliplr(y));
ylabel(„Amplitude --.‟);
xlabel(„(c) n --.‟);
title(„Cross correlated sequence‟);
disp(„The resultant signal is‟);
fliplr(y)
OUTPUT:
EXPECTED GRAPH:
AUTO CORRELATION
OUTPUT:
EXPECTED GRAPH:
RESULT:
LINEAR CONVOLUTION
Aim
Requirements
Matlab 2007 later
Procedure
1. OPEN MATLAB
Program
% Program for linear convolution of the sequence x5[1, 2] and h5[1, 2, 4]
clc;
clear all;
close all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=conv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel('(a) n --.');
title('first sequence');
subplot(3,1,2);
stem(h);ylabel('Amplitude --.');
xlabel('(b) n --.');
title('Second sequence');
subplot(3,1,3);
stem(y);
ylabel('Amplitude --.');
xlabel('(c) n --.');
title('Convoluted sequence');
Output:
enter the 1st sequence [1 2]
enter the 2nd sequence [1 2 4]
The resultant signal is
Y= 1 4 8 8
EXPECTED GRAPHS:
Result
Thus the Linear convolution was performed using MATLAB.
CIRCULAR CONVOLUTION
Aim
Requirements
Matlab 2007 later
Procedure
1. OPEN MATLAB
Program
clc;
clear all;
a = input(„enter the sequence x(n) = ‟);
b = input(„enter the sequence h(n) = ‟);
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-n1))];
for i = 1:N
k = i;
for j = 1:n2
H(i,j)=x(k)* b(j);
k = k-1;
if (k == 0)
k = N;
end
end
end
y=zeros(1,N);
M=H‟;
for j = 1:N
for i = 1:n2
y(j)=M(i,j)+y(j);
end
end
disp(„The output sequence is y(n)= „);
disp(y);
stem(y);
title(„Circular Convolution‟);
xlabel(„n‟);
ylabel(‚y(n)„);
OUTPUT:
enter the sequence x(n) = [1 2 4]
enter the sequence h(n) = [1 2]
The output sequence is y(n)= 9 4 8
ylabel('Amplitude');
OUTPUT:
enter the first sequence [1 2 4]
enter the 2nd sequence [1 2]
The resultant signal is y=1 4 8 8
Result
Thus the Circular convolution was performed using MATLAB.