Digital Signal Processing Lab Manual: Subject Code: ECE 3161
Digital Signal Processing Lab Manual: Subject Code: ECE 3161
Digital Signal Processing Lab Manual: Subject Code: ECE 3161
LAB MANUAL
Subject Code: ECE 3161
For
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINNEERING
Prepared by Approved by
Date: 01-12-2020
1
Instructions to the Students:
1. All the students are required to come prepared for the experiments to be done in the
lab.
2. Students should try to analyze and understand the solved problems and then try to
solve the unsolved problems of the experiment in the lab.
3. Maintaining an observation copy is compulsory for all, where the programs (codes)
and results of the unsolved-problems (exercise) are to be noted down.
4. Students have to get their results verified and observation copies checked by the
instructor before leaving the lab.
5. Maintain a separate folder in the computer you use, where you save all the programs
you do in the lab.
6. Use of external storage media during lab is not allowed.
7. Maintain the timings and the discipline of the lab.
8. Students will be evaluated in every lab based on individual performance, observation
copy and involvement in the lab.
Evaluation plan
2
Lab Session 1: Working with signals in time domain
Objective:
The signals we use in the real world (such as voice signal) are "analog"
signals. To process these signals in computing devices, we need to
convert them in to "digital" form. While an analog signal is continuous
in both time and amplitude, a digital signal is discrete in both time and
amplitude. To convert a signal from continuous time to discrete time,
sampling is used. The value of the signal is taken at certain intervals
in time to get discrete samples of the signal.
Objective: To design and study analog infinite-duration impulse response (IIR) filters.
Theory: Digital IIR filters are mainly designed from analog filters (classical techniques).
The widely used IIR filters are Butterworth, Chebyshev l (Type I and II), and Elliptic.
Butterworth filters:
| ( Ω)| =
Here N is the order of the filter and Ωc = 3dB cut-off frequency (rad/sec).
In the above figure, Rp and Rs represent the pass band and stop band attenuations,
respectively, and Ω and Ω are the corresponding edge frequencies in rad/sec.
Figure 4.3 Magnitude response of type-1 Chebyshev filter with N even Elliptic:
They have ripples in both pass band and stop-band.
Figure 4.4 Magnitude response of elliptic filter
Implementation in MATLAB:
The following functions are available in MATLAB to design an analog low pass
filters.
cheb1ord/cheby1,
cheb2ord/cheby2,
omegac = 0.2*pi;
[z, p, k ] = buttap(N);
k1 = k* omegac ^N;
B = real(poly(z));
b0 = k1;
b = k1*B;
a = real(poly(p1));
Solution:
b=
0.0979
Solution:
clc;
clear all;
close all;
rp = 1;
%Pass-band attenuation
rs = 40;
%Stop-band attenuation
wp = 2*pi*100;
Exercise
Plot the frequency response for each case and compare them.
2. Given the following filter specifications: Passband edge: 1kHz; Rp= 1dB;
Stopband edge: 200Hz; Rs= 50 dB.
a. Design an analog high pass Butterworth filter
b. Design an analog high pass Chebyshev Type 1 filter
Note: Refer “butter” function to design high pass and other filters.
Lab session 5: IIR Filter Design – 2
Theory: The analog filters designed in the previous experiment can be transformed into
digital filter using impulse invariance or bilinear transformation (BLT) methods.
1. [bz, az] = impinvar(b, a, Fs) creates a digital filter with numerator and
denominator coefficients bz and az, respectively, whose impulse response is
equal to the impulse response of the analog filter with coefficients b and a, scaled
by 1/Fs (Fs = sampling frequency).
2. [numd, dend] = bilinear(num, den, Fs) convert an s-domain transfer function
given by num and den to a discrete equivalent using BLT method.
Note: The functions buttord and butter can also be used to design a digital filter directly.
For example, the following function returns the order N and the cutoff frequency of
digital filter with specifications, wp, ws, rp, rs.
Here rp and rs must be in dB & wp and ws must be normalized to π or half the sampling
frequency. (e.g. If fp is 100Hz, then wp = 2*fp/Fs). Therefore, the range for wp and ws
is always 0 to 1.
4. Similarly,
cheb1ord/cheby1,
cheb2ord/cheby2,
ellipord/ellip functions can be used to design Chebyshev lowpass (Type 1 and
2), and Elliptic digital IIR filters respectively.
Example-1: Design a low-pass digital filter using an analog Butterworth filter to satisfy
= 0.2 , = 0.3 , = 1 , = 15 .
Use the impulse invariance technique to digitize (use impinvar function).
Solution:
% Analog design
T = 1;
% assumed
wa_p = wp/T;
wa_s = ws/T;
Example-2: Simulate a signal with 50Hz and 200 Hz frequency. Filter the signal through
a 3rd order digital Butterworth LPF with 3-dB cutoff frequency 100 Hz. Plot the spectrum
of the input and the filtered signal.
Solution:
% Filter testing
yb = filter(b,a,x) ;
% Getting spectrum and plot
N = 512;
w = [0:N/2 - 1]* (Fs/N) ;
1. Transform
3. Transform the system function given in Question 1 above using the bilinear
transformation assuming T = 1s.
Note: Refer MATLAB functions to design high pass and other filters.
Lab session 6: FIR Filter Design
For an Nth order filter, there are N+1 coefficients or filter length is N+1.
Important design methods are window based design and frequency sampling design.
Window based Design: The commonly used windows are hamming window and Kaiser
Window.
Hamming window,
The normalized transition width is δw, (transition width divided by sampling frequency or
(ws-wp) divided by 2π) and filter length are related by δw=3.3/ , and the designed filter
will have a stop band attenuation of 53 dB.
Kaiser window,
Where I0[.] is modified zero order Bessel function and β is a parameter that depends on
N.
The other windows are rectangular, hanning, Bartlett, Blackman and raised cosine.
2 −1
− ( ), = 0,1, … 2
∠ [ ]={ 2 ( − ) −1 and
{ }, = +1
2 ,…, +1
For BPF:
+ 5 log10 + 6]
Example-1: Design, using window based approach, a low-pass digital FIR filter whose
desired specifications are: wp = 0.2π rad, ws = 0.3π rad, Rp = 0.2dB, As = 50dB.
a) Hamming window
Solution:
clc, clear all, close all;
wp = 0.2*pi; ws = 0.3*pi;
N = ceil(6.6*pi/(ws-wp));
Solution:
Normalized Frequency
Normalized Frequency
Figure 6.3 FIR filter frequency response
Exercise:
1. Design, using Kaiser window based approach, a low-pass digital FIR filter whose
desired specifications are: wp = 0.2π rad, ws = 0.3π rad, Rp = 0.2dB, As = 50dB.
2. Design and plot the frequency response of a linear phase band-pass filter whose
specifications are as follows: Lower pass band edge = 400Hz, upper pass-band
edge = 500Hz, lower stop- band edge = 300Hz and upper stop-band edge = 600Hz,
Rp = 0.5dB and As = 40dB. The sampling frequency is 2 kHz.
a. using hamming window
b. using Kaiser window
3. Design the same filter in sample problem 2 with M = 25 and compare them.
4. The attenuation in stop band was observed to be not adequate in the above
problem. To improve, a few non-zero points are considered in the transition band.
These values are normally estimated by optimization techniques. In the above
problem, use Hrs(k) = [ 1, 1, 1, 0.5, 0.1 , zeros(1,11), 0.1,0.5,1,1] Compare the
results and find out whether there is any improvement. If there is, then at what
cost?
5. Design the filter specified in problem 2 using frequency sampling designing
technique.
6. Certain signal has 10Hz, 30Hz and 50Hz components. Simulate this signal. Design
suitable FIR filter using the following methods to select only 30Hz component.
Filter the signal using the filters, and plot the spectrum of the input and the filtered
signal. Hence compare the performance of the filters. a) Window method
b) Frequency sampling designing
Reference
1. Sanjit K. Mitra ,“Digital Signal Processing Laboratory Using Matlab”,
Mcgraw-Hill College, 2005.
2. D.G. Manolakis and Vinay K. Ingle, “Applied Digital Signal Processing”,
Cambridge University Press, 2012.
3. MATLAB help