Lab Manual-Dsp
Lab Manual-Dsp
of
Electronics & Communication Engineering
Laboratory Manual
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
UNIVERSITY INSTITUTE OF TECHNOLOGY, RGPV, BHOPAL
Certificate
ending in 2014.
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
INDEX
2 Implementation of operations on
sequences(addition, multiplication,
folding etc)
3 Implementation of linear-time-
invariant (LTI) systems and testing
them for stability and causality.
4 Computation and plot of DTFT
of sequences.
5 Computation and plots of
Z-transform.
6 Computation and plot of DFT of
sequences.
7 Computation and plots of
linear/circular convolution of two
sequences.
8 Implementation of various window
design techniques (Rectangular,
Bartlett, Hann, Hamming etc)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-1
Objective: Generation, analysis and plots of discrete-time signals.
(A) Unit Impulse Signal:
MATLAB SCRIPT:
t=-2:1:2;
y=[zeros(1,2), ones(1,1), zeros(1,2)]; % Expression
stem(t,y);
xlabel('time');
ylabel('Amplitude');
title('unit impulse signal');
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(B) Unit Step Signal:
MATLAB SCRIPT:
n=-5:5;
y=[zeros(1,5),ones(1,6)];
stem(n,y)
xlabel('Sequence');
ylabel('Amplitude');
title('unit step signal');
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(C) Ramp Signal:
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(D) Sine Signal:
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(D) Cosine Signal:
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(E) Real Exponential Signal:
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
a= 0.8, K=20, N=20 (Decaying)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
a= -1.2, K=20, N=20
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(F) Complex Exponential Signal:
MATLAB SCRIPT:
Gain constant: 1
Length of sequence: 40
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-2
Objective: Implementation of operations on sequences (addition,
multiplication, folding etc.)
(A) Addition of two sequences:
MATLAB SCRIPT:
n=-3:3;
a=[1,3,5,6,7,9,2];
b=[2,4,7,2,9,5,6];
c=a+b;
stem(n,c,'r');
xlabel ( 'Sequences n') ;
ylabel ('Amplitude') ;
title ('addition of two sequences')
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(B) Multiplication of two sequences:
MATLAB SCRIPT:
n=-3:3;
a=[1,3,5,6,7,9,2];
b=[2,4,7,2,9,5,6];
c=a.*b;
stem(n,c,'r');
xlabel ( 'Sequences n') ;
ylabel ('Amplitude') ;
title ('Multiplication of two sequences')
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(C) Folding operation on sequence:
MATLAB SCRIPT:
n=-3:3;
a=[1,3,5,6,7,9,2];
b=fliplr(a);
stem(n,b,'r');
xlabel ( ' n') ;
ylabel ('x(-n)') ;
title ('folding of sequence')
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-3
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(B) Time shift Invariance property:
MATLAB SCRIPT:
n=0:40;D=10;
x=3*cos(2*pi*0.1*n)-2*cos(2*pi*0.4*n);
xd=[zeros(1,D) x];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
ic=[0 0];
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D:41+D);
subplot(3,1,1),stem(y),grid;ylabel ('y') ;
subplot(3,1,2),stem(yd),grid;ylabel ('yd') ;
subplot(3,1,3),stem(d),grid;grid;ylabel ('d') ;
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(C) To check stability of a system:
MATLAB SCRIPT:
num=[1 0.8];
den=[1 1.5 .9];
N=200;
h=impz(num,den,N+1);
sum=0;
n=0:N;
for k=1:N+1
if abs(h(k))<10^(-6);
break
end
sum=sum+h(k);
end
stem(n,h); grid;
disp('Value='),
disp(sum)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-4
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
xlabel('\omega/\pi'); ylabel('Magnitude')
subplot(2,2,4)
plot(w/pi,angle(h));grid
title('Phase Spectrum')
xlabel('\omega/\pi'); ylabel('Phase, radians')
Input data:
k = 256
num = [0.008 -0.033 0.05 -0.033 0.008]
den = [1 2.37 2.7 1.6 0.41]
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-5
Input data:
Type in the numerator coefficients = [2 16 44 56 32]
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Output Data:
zeros are at
-4.0000
-2.0000
-1.0000 + 1.0000i
-1.0000 - 1.0000i
Poles are at
-3.2361
1.2361
0.5000 + 0.8660i
0.5000 - 0.8660i
Gain constant
0.6667
Radius of poles
3.2361
1.2361
1.0000
1.0000
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Therefore the factored form of the z-transform is given by:
(0.6667 + 0.4z-1 + 0.5333z-2) (1.0 + 2.0z-1 + 2.0z-2)
G(z) = ----------------------------------------------------------------
(1.0 + 2.0z-1- 4z-2) (1 – z-1 + z-2)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(B) Determine the partial-fraction expansion of the z-transform G(z) given by:
18z 3
G(z)
18z 3 3z 2 4z 1
MATLAB SCRIPT:
Input data:
Num=[18]
Output data:
Residues
Poles
Constants
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Note also that z-transform has double poles at z = -0.3333. The first entry in
both the residues and poles given above corresponds to the simple pole factor
(1 0.5z 1 ) ,the second entry corresponds to the simple pole factor
(1 0.3333z 1 ) ,and the third entry corresponds to the factor (1 0.3333z 1 ) 2 , in
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-6
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Input data:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-7
clear all;
close all;
clc;
x1 = input ('enter the first sequence = ');
subplot (2,2,1);
stem (x1,'r');
ylabel ('amplitude');
title ('plot of the first sequence');
grid on;
x2 = input ('enter 2nd sequence = ');
subplot (2,2,2);
stem (x2, 'r');
ylabel ('amplitude');
title ('plot of 2nd sequence');
grid on;
f = conv (x1,x2);
disp ('output of linear conv is');
disp (f);
subplot (2,2,3);
stem (f,'m');
xlabel ('sequences n');
ylabel ('amplitude f');
title('linear conv of sequence');
grid on;
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
(B) Circular convolution of two sequences.
MATLAB SCRIPT:
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Experiment-8
(A) Plot magnitude response and phase response of digital FIR Filter using
Rectangular window :
a. Low pass Filter
b. High pass Filter
c. Bandpass Filter
d. Bandstop Filter
a. Low Pass FIR Filter Designing:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N, wc/pi, rectwin(N+1));
freqz(h);
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
b. High Pass FIR Filter Designing:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi, 'high',rectwin(N+1));
freqz(h);
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
c. Band Pass FIR Filter Designing:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
d. Band Stop FIR Filter Designing:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi, 'stop',rectwin(N+1));
freqz(h);
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)
Hanning Window:
1. h=fir1(N,wc/pi,hanning(N+1)); - Low Pass FIR Filter
2. h=fir1(N,wc/pi, 'high',hanning(N+1)); - High Pass FIR Filter
3. h=fir1(N,wc/pi,hanning(N+1)); - Band Pass FIR Filter
4. h=fir1(N,wc/pi, 'stop', hanning(N+1)); - Band Stop FIR Filter
Hamming Window:
1. h=fir1(N,wc/pi,hamming(N+1)); - Low Pass FIR Filter
2. h=fir1(N,wc/pi, 'high',hamming(N+1)); - High Pass FIR Filter
3. h=fir1(N,wc/pi,hamming(N+1)); - Band Pass FIR Filter
4. h=fir1(N,wc/pi, 'stop', hamming(N+1)); - Band Stop FIR Filter
Dept. Of Electronics and Comm. UIT, RGPV BE (Electronics & Communication Engineering - Lab Manual)