DSP LAB MANUAL-2024-5th Semester
DSP LAB MANUAL-2024-5th Semester
COMMUNICATION
(BEC502))
V SEMESTER
Course Objective
PSO1 PSO2
C307.1 3 3
C307.2 3 3
C307.3 3 3
C307.4 3 3
C307.5 3 3
C307.6 3 3
C307 3 3
PSO1: Ability to absorb and apply fundamental knowledge of core Electronics and Communication
Engineering in the analysis, design and development of Electronics Systems as well as to
interpret and synthesize experimental data leading to valid conclusions
PSO2: Ability to solve complex Electronics and Communication Engineering problems, using latest
hardware and software tools, along with analytical and managerial skills to arrive at appropriate
solutions, either independently or in team
• FOR 25 MARKS
1. CONTINUOUS EVALUATION 35 15
USN:
Revised Bloom’s
SL.
NAME OF THE EXPERIMENT Taxonomy (RBT)
NO
Level
Aim: Program to generate the following discrete time signals. a) Unit sample sequence, b)Unit
step sequence, c) Exponential sequence, d)Sinusoidal sequence, e) Random sequence.
Theory:
Signal is a time varying physical phenomenon which is intended to convey information. Signal is
a function of one or more independent variables, which contain some information.
Note: Noise is also a signal, but the information conveyed by noise is unwanted hence it is
considered as undesirable.
System is a device or combination of devices, which can operate on signals and produces
corresponding response. Input to a system is called as excitation and output from it is called as
response. For one or more inputs, the system can have one or more outputs.
// Unit Sample Sequence
clear;
clc;
close;
L =4; //upper Limit
n =-L:L;
x =[zeros(1,L),1,zeros(1,L)];
b =gca();
b.y_location ="middle";
plot2d3('gnn',n,x)
a=gce();
a.children(1).thickness =4;
xtitle('Unit Sample Signal','n','x[n]');
// Unit Step Signal
clear;
clc;
close;
L=100;// Upper Limit
n=-L:L;
x=[zeros(1,L),ones(1,L+1)];
a=gca();
a.y_location= "middle";
plot2d3('gnn',n,x)
title( ' Unit Step Signal')
xlabel('n');
ylabel('x[n]');
Output:
// Multiplication of Signals
clc ;
clear ;
n1=[2 3 5 6 7]
n2=[3 4 -5 -6 4]
n3=n1.*n2
disp('Multiplication output',n3)
// Scaling of Signals
i=0:5;
n1=0.5*(i);
subplot(3,1,1);
plot2d3(i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Signal1',"fontsize" ,4);
subplot(3,1,2);
plot2d3(2*i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Expanded Signal',"fontsize" ,4);
subplot(3,1,3);
plot2d3(0.5*i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Compressed Signal',"fontsize" ,4);
// Shifting
i=0:15;
n1=2*i;
subplot(3,1,1);
plot2d3(i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Signal1',"fontsize" ,4);
subplot(3,1,2);
plot2d3(i-2,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Left Shift',"fontsize" ,4);
subplot(3,1,3);
plot2d3(i+3,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Right shift',"fontsize" ,4);
// Folding of Signals
clc ;
clf;
i=0:5;
n1=0.5*(i+2);
subplot(2,1,1);
plot2d3(i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Signal1',"fontsize" ,4);
subplot(2,1,2);
plot2d3(-i,n1);
xlabel('n',"fontsize",4);
ylabel('Amplitude',"fontsize",4);
title('Folded Signal',"fontsize" ,4);
Experiment –3
Aim: Program to perform convolution of two given sequences (without using built-in function) and
display the signals.
Theory:
// A GENERALAZED CONVOLUTION COMPUTING CODE IN MATLAB WITHOUT USING
MATLAB BUILTIN FUNCTION conv(x,h)
clc;
clear;
x=[1 2 3 4];
h=[1 2 3 4];
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
disp(Y)
Output:
// Experiment number 4
clear ;
clc ;
close;
s=poly(0,'s');
n=[s];
d=[s-0.9];
h=syslin('c',n./d);
plzr(h);
figure
gainplot(h)
figure
phaseplot(h)
Aim: Computation of N point DFT of a given sequence (without using built-in function) and to
plot the magnitude and phase spectrum
Theory: In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of
equally-spaced samples of a function into a same-length sequence of equally-spaced samples of
the discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency.
The interval at which the DTFT is sampled is the reciprocal of the duration of the input sequence.
An inverse DFT is a Fourier series, using the DTFT samples as coefficients
of complex sinusoids at the corresponding DTFT frequencies. It has the same sample-values as
the original input sequence. The DFT is therefore said to be a frequency domain representation of
the original input sequence. If the original sequence spans all the non-zero values of a function, its
DTFT is continuous (and periodic), and the DFT provides discrete samples of one cycle. If the
original sequence is one cycle of a periodic function, the DFT provides all the non-zero values of
one DTFT cycle.
Example
clc
close
clf
i=sqrt(-1);
disp('The Input sequence is')
xn=[1 2-i -i -1+2*i]
ln=length(xn);
xk=zeros(1,ln);
i=sqrt(-1);
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*%pi*k*n/ln));
end
end
disp('The DFT sequence is',xk)
n=0:1:ln-1;
xbs=abs(xk);
subplot(121),plot2d3(n,xbs);
xlabel('Length');
ylabel('Magnitude of X(k)');
title('Magnitude Spectrum');
an=phasemag(xk);
subplot(122),plot2d3(n,an);
xlabel('Length');
ylabel('Phase of X(k)');
title('Phase Spectrum');
xbs =
2. 2.8284271 2. 5.6568542
an =
Aim: Using the DFT and IDFT, compute the following for any two given sequences a) Circular
convolution b) Linear convolution
3. 11. 14. 8.
Proof :
a) Linearity property
The linearity property of the discrete Fourier transform (DFT) states that:
For any two sequences x and y, and any two scalars a and b, the DFT of the sequence (ax
+ by) is equal to (aX) + (bY), where X and Y are the DFTs of x and y, respectively.
Mathematically, it can be expressed as:
DFT(ax + by) = aDFT(x) + bDFT(y)
This property makes the DFT a useful tool for analyzing and processing linear systems.
The circular time shift property of the discrete Fourier transform (DFT) states that:
For any sequence x of length N, and an integer k such that 0 <= k < N, the DFT of the
circularly shifted sequence x_shift, where x_shift[n] = x[(n-k) mod N], is equal to the
element-wise multiplication of the DFT of x by a complex exponential sequence.
Mathematically, it can be expressed as:
DFT(x_shift) = DFT(x) * exp(-j * 2 * π * k * n / N)
where j is the imaginary unit, π is the mathematical constant pi, and * represents element-
wise multiplication.
This property makes the DFT a useful tool for analyzing and processing signals that have
undergone circular time shifts.
c) Circular frequency shift property
The circular frequency shift property of the discrete Fourier transform (DFT) states that:
For any sequence x of length N, and an integer k such that 0 <= k < N, the inverse DFT (IDFT) of
the element-wise multiplication of the DFT of x by a complex exponential sequence, is equal to
the circularly shifted sequence x_shift, where x_shift[n] = x[(n+k) mod N].
where j is the imaginary unit, π is the mathematical constant pi, and * represents element-wise
multiplication.
This property makes the DFT a useful tool for analyzing and processing signals that have
undergone circular frequency shifts.
Properties of DFT:
i) Linearity:
dft(ax(n)+by(n))=a dft(x(n))+b dft(y(n))
clc
close all
N = 4;
x =[1 4 5 7]
g = [3 6 4 2]
a=2;
b=3;
LHS= fft(a*x+b*g)
RHS= a*fft(x)+b*fft(g)
Result: x = 1 4 5 7
g= 3 6 4 2
Output:
15. + 0.i
15.
4.045085 - 1.3143278i
4.045085 - 1.3143278i
-1.545085 - 2.126627i
-1.545085 - 2.126627i
-1.545085 + 2.126627i
-1.545085 + 2.126627i
Output:
"lhs"
"rhs"
15. 4.253254 2.6286556 2.6286556 4.253254
Experiment –8
Aim: Develop decimation in time radix-2 FFT algorithm without using built-in functions
Theory: In DIT radix -2 FFT the time domain sequence is decimated into 2-point sequences.
For each 2-point sequence,2 -point DFT can be computed. From the result of 2-point DFT the 4-
point DFT can be calculated. From the result of 4-point DFT the 8- point DFT can be calculated.
x(1)= X(1);
x(2)= X(3);
x(3)= X(2);
x(4)= X(4);
//disp(x)
j=sqrt(-1);
N=4; // N-Point DFT
w = cos(2*%pi/N*[0:(N/2-1)])-j*sin(2*%pi/N*[0:(N/2-1)]);
//disp(w)
Y1=zeros(1,2);
Y1(1)=x(1)+x(2)
Y1(2)=x(1)-x(2)
Y2=zeros(1,2);
Y2(1)=x(3)+x(4)
Y2(2)=x(3)-x(4)
//disp(Y1)
//disp(Y2)
Z=zeros(1,4);
Z(1)=Y1(1)+Y2(1)
Z(2)=Y1(2)+Y2(2).*w(2)
Z(3)=Y1(1)-Y2(1)
Z(4)=Y1(2)-Y2(2).*w(2)
p=fft(X);
disp(p,'FFT using inbuilt function')
Output:
6. 1. + i 0. 1. - i
6. 1. + i 0. 1. - i
Experiment 9
Aim: Design and implementation of digital low/High pass FIR filter using a window to meet the
given specifications
Theory:
Output:
Output:
Aim: Design and implementation of digital low/High pass IIR filter using a window to meet the
given specifications
Theory:
//Design and implementation of digital IIR Butterworth low pass filter to meet the given
specifications.
//Frequency Response
clc ;
clear ;
close ;
fp=1000 // pass band edge frequency(HZ);
fs=1500 // Enter the stop band edge (Hz)
kp=-1 // pass band attenuation(db);
ks=-3 //Stop band attenuation(db) ;
Fs=8000 //sampling rate sample/sec;
d1=10^(kp/20);
d2 =10^(ks/20);
d=sqrt((1/(d2^2))-1);
E=sqrt((1/(d1^2))-1);
// Digital Filter specifications(rad/samples)
wp =2*%pi*fp*1/Fs ;
ws =2*%pi*fs*1/Fs ;
disp(wp,'Digital Pass band edge freq in rad/samples wp=')
disp(ws,'Digital Stop band freq in rad/samples ws=')
// Pre warping
op=2*Fs*tan(wp/2);
os =2*Fs*tan(ws/2);
disp(op,'Analog Pass Band Edge Freq in rad/sec op=')
disp(os,'Analog Stop band Edge Freq in rad/sec os=')
N = log10(d/E)/log10(os/op);
oc = op/((E^2)^(1/(2* N)));
N = ceil(N); // rounded to nearest integer
disp(N,'IIR Filter order N =');
disp(oc ,'cutof frequency in rad/seconds OC =')
[pols,gn] = zpbutt(N,oc) ;
disp(gn ,'Gain of analog filter =')
disp(pols,'poles of analog IIR butterworth LPF poles=')
HS=poly(gn,'s','coeff')/real(poly(pols ,'s')) ;
disp(HS,'Transfer function of Analog IIR BButterworth LPF H(S)=')
z = poly(0,'z')
Hz=horner(HS,(2*Fs*(z-1)/(z+1)))
num = coeff(Hz(2))
den = coeff(Hz(3))
Hz(2)=Hz(2)./den(3);
Hz(3)=Hz(3)./den(3);
disp(Hz,'Transfer function of Digital IIR Butterworth LPF H(z)')
[Hw,w] = frmag(Hz,256) ;
figure(1)
plot(2*w*%pi,20*log10(abs(Hw))) ;
xlabel('Digital Frequency w−−−>')
ylabel('Magnitude in dB 20log |H(w)|=')
title('Magnitude Response of IIR LPF')
xgrid(1)
Output:
poles of analog IIR butterworth LPF poles= -11329.809 + 11329.809i -11329.809 - 11329.809i
2.567D+08
---------------------------
2.567D+08 + 22659.618s + s2
//Design and implementation of digital IIR Butterworth high pass filter to meet the given
specifications.
//Frequency Response
clc ;
clear ;
close ;
fp=1000 // pass band edge frequency(HZ);
fs=1500 // Enter the stop band edge (Hz)
kp=-1 // pass band attenuation(db);
ks=-3 //Stop band attenuation(db) ;
Fs=8000 //sampling rate sample/sec;
d1=10^(kp/20);
d2 =10^(ks/20);
d=sqrt((1/(d2^2))-1);
E=sqrt((1/(d1^2))-1);
// Digital Filter specifications(rad/samples)
wp =2*%pi*fp*1/Fs ;
ws =2*%pi*fs*1/Fs ;
disp(wp,'Digital Pass band edge freq in rad/samples wp=')
disp(ws,'Digital Stop band freq in rad/samples ws=')
// Pre warping
op=2*Fs*tan(wp/2);
os =2*Fs*tan(ws/2);
disp(op,'Analog Pass Band Edge Freq in rad/sec op=')
disp(os,'Analog Stop band Edge Freq in rad/sec os=')
N = log10(d/E)/log10(os/op);
oc = op/((E^2)^(1/(2* N)));
N = ceil(N); // rounded to nearest integer
disp(N,'IIR Filter order N =');
disp(oc ,'cutof frequency in rad/seconds OC =')
[pols,gn] = zpbutt(N,oc) ;
disp(gn ,'Gain of analog filter =')
z = poly(0,'z')
Hz=horner(HS,(2*Fs*(z-1)/(z+1)))
num = coeff(Hz(2))
den = coeff(Hz(3))
Hz(2)=Hz(2)./den(3);
Hz(3)=Hz(3)./den(3);
disp(Hz,'Transfer function of Digital IIR Butterworth LPF H(z)')
[Hw,w] = frmag(1-Hz,256) ;
figure(1)
plot(2*w*%pi,20*log10(abs(Hw))) ;
xlabel('Digital Frequency w−−−>')
ylabel('Magnitude in dB 20log |H(w)|=')
title('Magnitude Response of IIR LPF')
xgrid(1)
Output
poles of analog IIR butterworth LPF poles= -7572.3383 + 7572.3383i -7572.3383 - 7572.3383i
1.147D+08
---------------------------
1.147D+08 + 15144.677s + s2
0.2094074 - 0.4610781z + z2
Digital Signal Processing LAB VIVA Questions
27) Compute the linear convolution of finite duration sequences h(n) = {1,2} and x(n) = {1,
2, -1, 2, 3, -2, -3, -1, 1, 1, 2, -1} by Overlap add method?
28) Perform the linear convolution of the sequence x(n) = {1, -1, 1, -1} and h(n) = {1,2,3,4} using
DFT method
29) Compare Butterworth with Chebyshev filters?
30) What is known as pre warping in digital filters?
31) List the properties of Chebyshev filter?
32) Draw the direct form structure of IIR filter?
33) Why do we go for analog approximation to design a digital filter?
34) What is the advantage of direct form II realization when compared to direct form I
realization?
35) Why the Butterworth response is called a maximally flat response?
36) . Mention the advantages of cascade realization?
37) Write the properties of Butterworth filter?
38) What is bilinear transformation?
39) What are the advantages and disadvantages of bilinear transformation?
40) Distinguish between recursive realization and non recursive realization?
41) What is meant by impulse invariance method of designing IIR filter?
42) Give the expression for location of poles of normalized Butterworth filter?
43) What are the parameters that can be obtained from Chebyshev filter specification?
44) Explain the procedure for designing analog filters using the Chebyshev approximation.
45) What are advantages and disadvantages of FIR filter?
46) What is the reason that FIR filter is always stable?
47) State the condition for a digital filter to be causal and stable?
48) Compare Hamming window with Kaiser window.
49) What is the principle of designing FIR filter using frequency sampling method?
50) What is window and why it is necessary?