0% found this document useful (0 votes)
85 views44 pages

Atme College of Engineering: Lab Manual

This document contains a lab manual for the Digital Signal Processing Laboratory course with course code 18EEL67 at ATME College of Engineering. It includes an introduction with the college and department vision and mission statements. The lab manual then lists 12 experiments related to key digital signal processing topics like sampling theory, impulse response, convolution, DFT, FFT, and filter design. It provides the objectives and procedures for students to perform the experiments and learn how to apply digital signal processing concepts.

Uploaded by

Gangadhar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views44 pages

Atme College of Engineering: Lab Manual

This document contains a lab manual for the Digital Signal Processing Laboratory course with course code 18EEL67 at ATME College of Engineering. It includes an introduction with the college and department vision and mission statements. The lab manual then lists 12 experiments related to key digital signal processing topics like sampling theory, impulse response, convolution, DFT, FFT, and filter design. It provides the objectives and procedures for students to perform the experiments and learn how to apply digital signal processing concepts.

Uploaded by

Gangadhar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

ATME COLLEGE OF ENGINEERING

13th KM Stone, Bannur Road, Mysore - 570 028

DEPARTMENT OF ELECTRICAL & ELECTRONICS


ENGINEERING

LAB MANUAL

COURSE TITLE: DIGITAL SIGNAL PROCESSING LABORATOTY

COURSE CODE: 18EEL67

SEMESTER: VI

Prepared by

Department of EEE,
ATME College of Engineering
INSTITUTIONAL VISION AND MISSION

VISION:
• Development of academically excellent, culturally vibrant, socially responsible and
globally competent human resources.

MISSION:
• To keep pace with advancements in knowledge and make the students
competitive and capable at the global level.
• To create an environment for the students to acquire the right physical, intellectual,
emotional and moral foundations and shine as torchbearers of tomorrow's society.
• To strive to attain ever-higher benchmarks of educational excellence.

Department Vision and Mission

Vision:

To produce Electrical & Electronics Engineers through greatest quality of technical


education, technical skill training and intellectual capacity building of individuals.

Mission:

• To provide knowledge to students that builds a strong foundation in the basic


principles of electrical engineering, problem solving abilities, analytical skills, soft
skills and communication skills for their overall development.
• To offer outcome based technical education.
• To encourage faculty in training & development and to offer consultancy through
research & industry interaction.
Program Educational Objectives (PEOs)
PEO1:
To produce Electrical and Electronics Engineers who will exhibit the technical and
managerial skills with professional ethics for the societal progress.
PEO2:
To make students continuously acquire, enhance their technical and socio-economic skills
and also to be globally competent.
PEO3:
To impart the experience of research and development to students so that they develop
abilities in offering solutions to relevant diverse career path.
PEO4:
To produce quality engineers with a team leading capabilities, also show good coordination
to contribute towards real time application of projects

Program Outcomes (POs)

Engineering Graduates will be able to:

PO1: Engineering Knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals and an engineering specialization to the solution of complex
engineering problems.
PO2: Problem Analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3: Design / Development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge
to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual and as a member
or leader in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations, and
give and receive clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of
the engineering management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for and have the preparation and ability to
engage in independent and lifelong learning in the broadest context of technological
change.

Program Specific Outcomes (PSOs)

The students will develop an ability to produce the following engineering traits:

PSO1: Apply the concepts of Electrical & Electronics Engineering to evaluate the
performance of power systems and also to control industrial drives using power electronics.

PSO2: Demonstrate the concepts of process control for Industrial Automation, design
models for environmental and social concerns and also exhibit continuous self- learning.
DIGITAL SIGNAL PROCESSING LABORATORY

Subject Code : 18EEL67 I.A. Marks : 40


Hours/Week : 03 Exam Hours : 03
Total Hours : 16 Exam Marks : 100

LIST OF EXPERIMENTS
Exp
Name of the Experiment
No
1. Verification of Sampling Theorem both in time and frequency domains
2. Evaluation of impulse response of a system
3. To perform linear convolution of given sequences
4. To perform circular convolution of given sequences using (a) the convolution summation
formula (b) the matrix method and (c) Linear convolution from circular convolution with zero
padding.
5. Computation of N –point DFT and to plot the magnitude and phase spectrum.
6. Linear and circular convolution by DFT and IDFT method.
7. Solution of a given difference equation.
8. Calculation of DFT and IDFT by FFT
9. Design and implementation of IIR filters to meet given specification (Low pass, high pass, band
pass and band reject filters)
10. Design and implementation of FIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters) using different window functions
11. Design and implementation of FIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters) using frequency sampling technique.
12. Realization of IIR and FIR filters

TEXT BOOKS:
1. Introduction to Digital Signal Processing, Jhonny R. Jhonson, Pearson, 1 st Edition, 2016.
2. . Digital Signal Processing – Principles, Algorithms, and Applications, Jhon G. ProakisDimitris
G. Manolakis, Pearson 4th Edition, 2007.
3. Digital Signal Processing, A.NagoorKani, McGraw Hill, 2 nd Edition, 2012.

COURSE OUTCOMES

At the end of the course the student will be able to:


1. Explain the physical interpretation of sampling theorem in time and frequency domain.
[L2]
2. Evaluate the impulse response of systems. [L5]
3. Perform Convolution of given sequences to evaluate the response of systems. [L3]
4. Construct DFT and IDFT of a given sequences using basic definition. [L3]
5. Construct a solution for a given difference equation and implement IIR & FIR filters
[L3]
Table of Contents

Exp
Name of the Experiment Page no.
no
1. Verification of Sampling Theorem both in time and frequency domains 1
2. Evaluation of impulse response of a system 3
3. To perform linear convolution of given sequences 5
4. To perform circular convolution of given sequences using (a) the convolution
summation formula (b) the matrix method and (c) Linear convolution from 7
circular convolution with zero padding.
5. Computation of N –point DFT and to plot the magnitude and phase spectrum. 10
6. Linear and circular convolution by DFT and IDFT method. 12
7. Solution of a given difference equation. 15
8. Calculation of DFT and IDFT by FFT 17
9. Design and implementation of IIR filters to meet given specification (Low pass,
20
high pass, band pass and band reject filters)
10. Design and implementation of FIR filters to meet given specification (Low pass,
24
high pass, band pass and band reject filters) using different window functions
11. Design and implementation of FIR filters to meet given specification (Low pass,
31
high pass, band pass and band reject filters) using frequency sampling technique.
12. Realization of IIR and FIR filters 35
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment no. 1

Verification of Sampling Theorem both in time and frequency Domains


Aim: To Verify sampling theorem both in time and frequency domains.

Objective: To learn the physical interpretation of sampling theorem.

Theory: In digital signal processing, the sampling theorem is the basic bridge between
continuous-time signals and discrete-time signals.

Statement: A continuous time signal can be represented in its samples and can be recovered
back when sampling frequency fs is greater than or equal to the twice the highest frequency
component of message signal i.e.
fS≥2fm

Program:

clc;
clear;
f=50
t=0:0.00001:0.04
y=sin(2*pi*f*t);
subplot(3,3,1);
plot(t,y);

% for sampling frequency=supply frequency (fs=f)


fs1=50;
n=0:1;
y1=sin(2*pi*f*n/fs1);
subplot(3,3,2);
stem(n,y1);
hold on
subplot(3,3,3)
plot(n,y1)

% for sampling frequency=2*supply frequency (fs>2*f)


fs2=500;
n=0:20;
y2=sin(2*pi*f*n/fs2);
subplot(3,3,4);
stem(n,y2);
hold on
subplot(3,3,5)
plot(n,y2)
fs3=1000;
n=0:40;
Department of EEE, ATMECE, Mysore Page 1
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

y3=sin(2*pi*f*n/fs3);
subplot(3,3,6);
stem(n,y3);
hold on
subplot(3,3,7);
plot(n,y3);

Fig. 1.1: waveforms for sampling frequency = 50Hz, 500Hz and 1000 Hz.

Result: sampling theorem is verified in both time and frequency domain.

Outcome: student will be able to give physical interpretation of sampling theorem in time and
frequency domains

Department of EEE, ATMECE, Mysore Page 2


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment no. 2

Evaluation of impulse response of a system


Aim: To evaluate impulse response of a system.

Objectives: to verify the response of a system for a impulse input using simulation tool.

Theory: The impulse response of a system is the output of the system when the input signal is an
impulse function.

Fig. 2.1: generalized system with input and output

The impulse response and frequency response are two attributes that are useful for characterizing
linear time-invariant (LTI) systems.

Example: Given: y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)


y(n) - y(n-1) - y(n-2) = x(n) + 0.5x(n-1) + 0.85x(n-2)
Taking Z transform on both sides,
Y(Z) − Z −1 Y(Z) − Z −2 Y(Z) = X(Z) + 0.5Z−1 X(Z) + 0.85Z−2 X(Z)
Y(Z)[1 − Z −1 − Z −2 ] = X(Z)[1 + 0.5Z−1 + 0.85Z−2 ]
Y(Z)
H(Z) =
X(Z)
Y(Z [1 + 0.5Z−1 + 0.85Z−2 ]
H(Z) = =
X(Z) [1 − Z −1 − Z −2 ]

By power series method


H(Z) = 1 + 1.5 Z-1 + 3.35 Z-2 + 4.85 Z-3
h(n) = [1 1.5 3.35 4.85]

Program:

clc;
clear all;
b=input('enter the coefficients of x(n),x(n-1)-----');
a=input('enter the coefficients of y(n),y(n-1)----');
N=input('enter the number of samples of impulse response ');
[h,t]=impz(b,a,N);
disp(h);

Department of EEE, ATMECE, Mysore Page 3


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

stem(t,h);

Output Windows

enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85]


enter the coefficients of y(n),y(n-1)----[1 -1 -1]
enter the number of samples of impulse response 4
1.0000 1.5000 3.3500 4.8500

Fig. 2.2: output waveform of the impulse response of the given system

Result: Impulse response of the system is determined and verified manually.

Outcome: student will be able to evaluate the impulse response of a system.

Department of EEE, ATMECE, Mysore Page 4


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 3

To Perform Linear Convolution of given Sequences


Aim: To perform linear convolution of the given two sequences.

Objective: to verify the linear convolution using simulation tool.

Theory: convolution relates the input signal and impulse response of the system to the output of
the system. Convolution is a mathematical operation which is used to express the input-output
relationship of an LTI system.
Linear convolution is the basic operation to calculate the output for any linear time
invariant system given its input and its impulse response. Linear convolution is given by

y(n) =  x(k)h(n − k)
k =−

Example: x(n) = (1 2 3 5 7 8 9) h(n) = (1 2 3)

1 2 3 5 7 8 9
1 1 2 3 5 7 8 9
2 2 4 6 10 14 16 18
3 3 6 9 15 21 24 27

y(n) = (1 4 10 17 26 37 46 42 27)

Program
clc;
clear;
x1=input('enter the first sequence');
subplot(3,1,1);
stem(x1);
title('plot of the first sequence');
x2=input('enter 2nd sequence');
subplot(3,1,2);
stem(x2);
title('plot of 2nd sequence');
f=conv2(x1,x2);
disp('output of linear convolution is');
disp(y);

Department of EEE, ATMECE, Mysore Page 5


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

xlabel('time index n');


ylabel('amplitude f');
subplot(3,1,3);
stem(y);
title('linear conv of sequence');

Output Windows

Enter the first sequence[1 2 3 5 7 8 9]


Enter 2nd sequence[1 2 3]
Output of linear convolution is [1 4 10 17 26 37 46 42 27]

Fig. 3.1: input and output waveform of the given sequence.

Result: Linear convolution is performed and verified manually.

Outcome: To perform convolution of given sequences to evaluate the response of a system.

Department of EEE, ATMECE, Mysore Page 6


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 4

Circular Convolution of the Given two Sequences

Aim: To perform circular convolution of given sequences using


(a) The convolution summation formula.
(b) The matrix method.
(c) Linear convolution from circular convolution with zero padding.

Objectives: to verify the circular convolution by various methods using simulation tool.

i. The convolution summation formula:

Program:

clc;
clear;
x1=input('enter x1(n):');
n1=length(x1);
x2=input('enter x2(n):');
n2=length(x2);
N=max(n1,n2);
T=1:N;
x1=[x1 zeros(1,N-n1)];
x2=[x2 zeros(1,N-n2)];
y=zeros(1,N);
for m=1:N
for n=1:N
i=m-n+1;
if(i<=0)
i=N+i;
end
y(m)=y(m)+x1(n)*x2(i);
end
end
disp(y);
stem(y);

Output Windows

enter x1(n):[0 1 2 3]
enter x2(n):[2 1 2 1]
circular convolution of the given sequences is
8 10 8 10

Department of EEE, ATMECE, Mysore Page 7


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 4.1: Output waveform for the given sequence using convolution summation formula.

ii. To perform circular convolution of given sequences using matrix method

Program:

clc;
clear;
a=input('Enter the first sequence x1(n):');
b=input('Enter the first sequence x2(n):');
c=circshift(a,1);
d=circshift(a,2);
e=circshift(a,3);
m=[a c d e];
y=m*b;
disp(m);
disp('Circular Convolution of x1(n) & x2(n) is:');
disp(y);
n=0:3;
stem(n,y);
title('circulation convolution using matrix method');

Department of EEE, ATMECE, Mysore Page 8


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Output Windows
Enter the first sequence x1(n):[2;1;2;1]
Enter the first sequence x2(n):[1;2;3;4]
2 1 2 1
1 2 1 2
2 1 2 1
1 2 1 2
Circular Convolution of x1(n) & x2(n) is:
14
16
14
16

Fig. 4.2: Output waveform for the given sequence using matrix method

Result: Circular Convolution is verified for the given sequence using various methods.

Outcome: student will be able to perform circular convolution of given sequences using various
methods

Department of EEE, ATMECE, Mysore Page 9


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 5:
Computation of N – point DFT and to Plot the Magnitude and Phase
Spectrum

Aim: To perform N-point DFT computation and plot the magnitude and phase spectrum.

Objectives: To explain the use of MATLAB software in evaluating the DFT of given sequence

Theory: DFT is the process of conversation of time domain continuous signal into frequency
domain discrete signal. DFT of an N-point sequence is given by
N −1 − j2π nk
X(k) =  x(n)e
n =0
N

Example: Find the DFT of 4-pint sequence x(n)=(0,1,2,3)

1 1 1 1  0   6 
1 − j − 1 j  1 − 2 + j2
X(k) =  *  =  
1 − 1 1 − 1 2  − 2 
     
1 j − 1 − j 3 − 2 − j2
X(k)=(6,-2+j2,-2,-2-j2)

Magnitude spectrum: X(k) = (6, 2.8284,2, 2.8284)


Phase angle spectrum: X(k) = (0, 2.356, - 3.14, - 2.356) rad

Program:
clc;
close all;
clear all;
xn = input('enter the sequence x(n) =');
xn=xn';
N=length(xn);
n=0:N-1;
for k=0:N-1
Xk(k+1)=exp(-j*2*pi*k*n/N)*xn;
end
disp('DFT of the given sequence is:');
disp(Xk);
k = 0:N-1;
disp('magnitude of the sequence is:')
disp(abs(Xk))
subplot(2,1,1)
stem(k,abs(Xk));
xlabel('k');

Department of EEE, ATMECE, Mysore Page 10


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

ylabel('|X(k)|');
title('Magnitude spectrum');
subplot(2,1,2);
stem(k,angle(Xk));
disp('phase angle of the sequence in radians is:');
disp(angle(Xk));
xlabel('k');
ylabel('<X(k)');
title('Phase spectrum');

Output Window:
enter the sequence x(n) =[0 1 2 3]
DFT of the given sequence is:
6.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i
magnitude of the sequence is:
6.0000 2.8284 2.0000 2.8284
phase angle of the sequence in radians is:
0.00000 2.35619 -3.14159 -2.35619

Fig. 5.1: Magnitude and phase angle spectrum.

Result: N-point DFT was computed for given signal and its magnitude and phase spectrum was
plotted.

Outcome: student will be able to Compute DFT and find its magnitude and phase angle
spectrum

Department of EEE, ATMECE, Mysore Page 11


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 6:
Linear and circular convolution by DFT and IDFT method.

Aim: To perform Linear & Circular convolution by DFT & IDFT Method.

Objective: to verify the Linear and circular convolution by DFT & IDFT method using
simulation tool

Theory: DFT and IDFT method is also known as stockham's method used to find the Circular
convolution of the given sequences.
y(n) = x(n)  N h(n)

Applying DFT for x(n) and h(n)


X(k)=DFT(x(n)) and H(k)=DFT(h(n))
Y(K) = X(K)*H(K)
Apply IDFT
y(n) =IDFT(Y(K))

i. Circular Convolution using DFT and IDFT

clc;
clear all;
close all;
xn = input('enter the first sequence x(n) = ');
hn = input('enter the second sequence h(n) = ');
N = max(length(xn),length(hn));
Xk = fft(xn,N);
Hk = fft(hn,N);
Yk = Xk.*Hk;
yn = ifft(Yk,N);
disp('Circular convolution of x(n) and h(n) =');
disp(yn);
subplot(2,2,1);
stem(xn);
xlabel('n');
ylabel('x(n)');
title('plot of x(n)');
subplot(2,2,2);
stem(hn);
xlabel('n');
ylabel('h(n)');
title('plot of h(n)');
subplot(2,2,3);
stem(yn);
xlabel('n');
Department of EEE, ATMECE, Mysore Page 12
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

ylabel('y(n)');
title('Circular convolution Output');

Output Screen
Enter the first sequence x(n) = [1 2 3 4]
Enter the second sequence h(n) = [4 5 6 1]
Circular convolution of x(n) and h(n) = 44 40 32 44

Fig. 6.1: Input and output waveforms of the given sequence using DFT and IDFT method.

ii. Linear Convolution using DFT and IDFT


clc;
clear all;
close all;
xn = input('enter the first sequence x(n) = ');
hn = input('enter the second sequence h(n) = ');
N = length(xn)+length(hn)-1;
Xk = fft(xn,N);
Hk = fft(hn,N);
Yk = Xk.*Hk;
yn = ifft(Yk,N);
disp('Linear convolution of x(n) and h(n) =');
disp(yn);
subplot(2,2,1);
stem(xn);

Department of EEE, ATMECE, Mysore Page 13


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

xlabel('n');
ylabel('x(n)');
title('plot of x(n)');
subplot(2,2,2);
stem(hn);
xlabel('n');
ylabel('h(n)');
title('plot of h(n)');
subplot(2,2,3);
stem(yn);
xlabel('n');
ylabel('y(n)');
title('Convolution Output');

Output window:
Enter the first sequence x(n) = [1 5 7 8]
Enter the second sequence h(n) = [3 1 5 6]
'Linear Convolution of given sequences = 3 16 31 62 73 82 48

Fig. 6.2: Input and output waveforms of the given sequence using DFT and IDFT method

Result: Linear & circular convolution was computed using DFT and IDFT method.
Outcomes: student will be able to perform linear & circular convolution using DFT & IDFT
method

Department of EEE, ATMECE, Mysore Page 14


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 7:
Solution of a given difference equation

Aim: To find solution for difference equation.

Objectives: to verify the solution of difference equation using simulation tool.

Theory: An LTI discrete system can also be described by a linear constant coefficient difference
equation of the form.

N M

 a k y(n − k) =  b m x(n − m)
K =0 m =0
n

Where x(n) is input and y(n) is output

Example:
let y(n) - 3 y(n − 1) + 1 y(n − 2) = x(n)
2 2
( )
Given x(n) = 1 u(n)
4
n

Initial conditions are y(-1)=4 y(-2)=10


( )
x(n) = 1 u(n)
4
n

For n=0 x(0)=1


n=1 x(1)=0.25
n=2 x(2)=0.0625
n=3 x(3)=0.0156
n=4 x(4)=0.0039
y(n) - 3 y(n − 1) + 1 y(n − 2) = x(n)
2 2
y(n) = 3 y(n − 1) − 1 y(n − 2) = x(n)
2 2

For n=0 y(0)=1.5*y(0-1)-0.5*y(0-2)+x(0)=1.5*4-0.5*10+1=2


n=1 y(1)=1.5*y(0)-0.5*y(-1)+x(1)=1.25
n=2 y(2)=0.9375
n=3 y(3)=0.7969
n=4 y(4)=0.7365

Program:

clc;
clear;
b=input('enter the co-effencient of x(n):');
a=input('enter the co-effencient of y(n):');
y=input('enter the initial conditions:');

Department of EEE, ATMECE, Mysore Page 15


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

n1=input('enter the value of n:');


z=filtic(b,a,y);
n=0:n1-1;
x=(1/4).^n;
yo=filter(b,a,x,z);
disp(yo);
stem(n,yo);

enter the co-effencient of x(n):[1]


enter the co-effencient of y(n):[1 -3/2 1/2]
enter the initial conditions:[4 10]
enter the value of n:5
2.00000 1.25000 0.93750 0.79688 0.73047

Fig. 7.1: Waveform for the solution of the given difference equation

Result: solution of difference equation is evaluated.

Outcomes: student will be able to find the solution of difference equation using simulation tool.

Department of EEE, ATMECE, Mysore Page 16


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 8:
Calculation DFT & IDFT by FFT

Aim: To find DFT & IDFT using FFT.

Objectives: Evaluating the DFT and IDFT using simulation tool.

Theory: as discussed earlier DFT is the process of conversation of time domain continuous
signal into frequency domain discrete signal. DFT of an N-point sequence is given by
N −1 − j2π nk
X(k) =  x(n)e
n =0
N

IDFT is the process of conversation of frequency domain discrete signal into time domain
continuous signal. IDFT of an N-point sequence is given by

N −1 j2π nk
x(n) =  X(k)e
k =0
N

a. DFT of a N-point sequence

Example: find the DFT of x(n)=(1,2,3,4,4,3,2,1)

N=input('How many point DFT do you want?');


x =input('Enter the first sequence=');
n = length(x)
x = [x zeros(1,N-n)]
X = fft(x,N)
X_mag = abs(X)
subplot(2,1,1)
stem(X_mag)
title('Magnitude plot')
X_ang = angle(X)
subplot(2,1,2)
stem(X_ang)
title('Angle plot')

How many point DFT do you want?8


Enter the first sequence=[1 2 3 4 4 3 2 1]
n= 8
x=
1 2 3 4 4 3 2 1
X=
Columns 1 through 3:
20.00000 + 0.00000i -5.82843 - 2.41421i 0.00000 + 0.00000i
Columns 4 through 6:

Department of EEE, ATMECE, Mysore Page 17


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

-0.17157 - 0.41421i 0.00000 + 0.00000i -0.17157 + 0.41421i


Columns 7 and 8:
0.00000 - 0.00000i -5.82843 + 2.41421i
X_mag = 20.00000 6.30864 0.00000 0.44834 0.00000 0.44834 0.00000 6.30864

Fig. 8.1: Magnitude and phase angle plot for 8-point sequence.

b. Calculation of IDFT by FFT

Program:
clc;
clear all;
N=input('Enter the value of N: ');
X =input('Enter the first sequence=');
x = ifft(X,N);
disp('IDFT of the given sequence is');
disp(x);
stem(x);
title('IDFT of given sequence');

Enter the value of N: 4


Enter the first sequence=[6 -2+2i -2 -2-2i]
IDFT of the given sequence is
0 1 2 3

Department of EEE, ATMECE, Mysore Page 18


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 8.2: output waveform of the IDFT for the given sequence

Result: DFT of the N-point sequence is determined.

Outcomes: student will be able to compute DFT and IDFT using FFT command.

Department of EEE, ATMECE, Mysore Page 19


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 9:
Design and implementation of IIR filters to meet given specification

Aim: To Design and implement IIR filter for given specification.

Objective: to verify the IIR filter design using simulation tool.

Theory: filer enhances a wanted signal and eliminates to unwanted signals. IIR filters are digital
filters with infinite impulse response. They have the feedback and are known as recursive digital
filters therefore. IIR filters have much better frequency response than FIR filters of the same
order. There are mainly two types of IIR filter, Butterworth and Chebyshev filter.

The frequency response of the various filters is shown below.

Fig. 9.1: Frequency response curve

Design procedure:
Finding the value of N:
 −KP 
10 10 − 1
log − K 
S
 10 10 − 1 
N=  
Ω 
2log P 
 ΩS 
Finding the poles of the transfer function
SK = 1θ K Where k=0,1,2,3…2N-1

Department of EEE, ATMECE, Mysore Page 20


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

πk π π
θK = + +
N 2N 2
Finding Transfer function:
1
H N (s) =
 (s − s k )
LHP only

Example: Design a low pass Butterworth filter to satisfy the following specifications;
Pass band cutoff = 500 Hz; Pass band ripple = 3.01 db;
Stop band cutoff = 750 Hz; Stop band ripple = 15 db;

Program:

clc; % clear screen


clear all; % clear screen
close all; % close all figure windows
fp = input('Enter the Pass band frequency in Hz = ' ); % input specifications
fs = input('Enter the Stop band frequency in Hz = ');
Fs = input('Enter the Sampling frequency in Hz = ');
Ap = input('Enter the Pass band ripple in db:');
As = input('Enter theStop band ripple in db:');
wp=2*fp/Fs; % Analog frequency
ws=2*fs/Fs;
Up = 2*tan(wp/2);% Prewrapped frequency
Us = 2*tan(ws/2);
[n,wn]= buttord (Up,Us,Ap,As,'s'); %Calculate order and cutoff freq
disp('order of the filter N =');
disp(n);
[num, den] = butter(n,wn,'s'); % analog filter transfer
[b,a] = bilinear(num, den,1); % conversion of analog filter to digital filter
Freqz(b,a,512,Fs); % frequency response of the filter
Printsys(b,a,'z'); % print the H(z) equation obtained on screen

Output Window
Enter the Pass band frequency in Hz = 500
Enter the Stop band frequency in Hz = 750
Enter the Sampling frequency in Hz = 2000
Enter the Pass band ripple in db:3.01
Enter theStop band ripple in db:15
order of the filter N =
4
num/den =
0.0022316 z^4 + 0.0089263 z^3 + 0.013389 z^2 + 0.0089263 z + 0.0022316
----------------------------------------------------------------------
z^4 - 2.6932 z^3 + 2.8684 z^2 - 1.4042 z + 0.26461

Department of EEE, ATMECE, Mysore Page 21


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 9.2: Magnitude and phase angle curve of low pass filter

Example: Design a high pass Butterworth filter to satisfy the following specifications;
Pass band cutoff = 32 Hz; Pass band ripple = 2 db;
Stop band cutoff = 16 Hz; Stop band ripple = 20 db;

clc;
clear all;
close all;
rp=input('Enter the pass band ripple:rp=');
rs=input('Enter the stop band ripple:rs=');
fp=input('Enter the pass band freq:wp=');
fs=input('Enter the stop band freq:ws=');
Fs=input('Enter the sampling freq fs=');
wp=2*fp/Fs;
ws=2*fs/Fs;
Up = 2*tan(wp/2);% Prewrapped frequency
Us = 2*tan(ws/2);
[N,wn]=buttord(Up,Us,rp,rs,'s');
Disp(‘ Order of the filter is: ‘);
disp(N);
disp('freq resp of iir high pass filter is:');
[b,a]=butter(N,wn,'high','s');
disp('Normalized cut off frequency = ');
disp(wn);
[num, den] = butter(N,wn,'high','s'); % analog filter transfer
[b,a] = bilinear(num, den,1); % conversion of analog filter to digital filter

Department of EEE, ATMECE, Mysore Page 22


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Freqz(b,a,512,Fs); % frequency response of the filter


Printsys(b,a,'z'); % print the H(z) equation obtained on screen.

Enter the sepecifications of iir filter


Enter the pass band ripple:rp=2
Enter the stop band ripple:rs=20
Enter the pass band freq:wp=32
Enter the stop band freq:ws=16
Enter the sampling freq fs=2000
Order of the filter is:
4
num/den =
0.96355 z^4 - 3.8542 z^3 + 5.7813 z^2 - 3.8542 z + 0.96355
----------------------------------------------------------
z^4 - 3.9257 z^3 + 5.78 z^2 - 3.7827 z + 0.92843

Fig. 9.3: Magnitude and phase angle curve of high pass filter

Result: IIR filter was designed was verified using simulation tool.

Outcomes: students will be able to design and implement the IIR Filter.

Department of EEE, ATMECE, Mysore Page 23


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 10:
Design and Implementation of FIR Filters Using Different Window Functions

Aim: To Design and implement FIR filter using various window techniques.

Theory:FIR Filter Design


Digital filters with finite-duration impulse response (all-zero, or FIR filters) have both
advantages and disadvantages compared to infinite-duration impulse response (IIR) filters.
FIR filters have the following primary advantages:
➢ They can have exactly linear phase.
➢ They are always stable.
➢ The design methods are generally linear.
➢ They can be realized efficiently in hardware.
➢ The filter startup transients have finite duration.
The primary disadvantage of FIR filters is that they often require a much higher filter order than
IIR filters to achieve a given level of performance. Correspondingly, the delay of these filters is
often much greater than for an equal performance IIR filters.

Problem:

Design FIR lowpass filter to meet the following specifications:


Passband attenuation = 0.01
Stopband attenuation = 0.02
Passband frequency = 1000 Hz
Stopband frequency = 1500 Hz
Sampling frequency = 8000 Hz

Program:

clc;
clear all;
Rp=input('Enter the passband attenuation in dB: ');
Rs=input('Enter the stopband attenuation in dB: ');
fp=input('Enter the passband frequency in Hz: ');
fs=input('Enter the stopband frequency in Hz: ');
Fs=input('Enter sampling frequency in Hz: ');
Wp=2*pi*fp/Fs;
Ws=2*pi*fs/Fs;
%Rectangular Window
if Rs<=21
M = ceil(4*pi/(Ws-Wp))+1
y = rectwin(M);
figure, subplot(2,1,1),stem(y);
title('Rectangular Window');
end
%Bartlett Window
Department of EEE, ATMECE, Mysore Page 24
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

if Rs<=25 &Rs>21
M =ceil(8*pi/(Ws-Wp)) +1
y=bartlett(M);
figure, subplot(2,1,1),stem(y);
title('Bartlett Window');
end
%Hanning Window
if Rs<=44 &Rs>25
M =ceil(8*pi/(Ws-Wp)) +1
y=hanning(M);
figure, subplot(2,1,1),stem(y);
title('Hanning Window');
end
%Hamming Window
if Rs<=53 &Rs>44
M = ceil(8*pi/(Ws-Wp)) +1
y=hamming(M);
figure, subplot(2,1,1),stem(y);
title('Hamming Window');
end
% Blackman Window
if Rs<=74 &Rs>53
M = ceil(12*pi/(Ws-Wp))+1
y=blackman(M);
figure, subplot(2,1,1),stem(y);
title('Blackman Window');
end
wc = (Ws +Wp)/2
%Ideal lowpass filter
alpha = (M-1)/2
n = [0 : 1 : (M-1)];
m = n - alpha + eps;
hd = sin(wc*m)./(pi*m);
h = hd.*y';
subplot(2,1,2), stem(h);
title('Impulse response of FIR filter');
%w = logspace(-1,1);
figure, freqz(h)
title('Frequency response of FIR lowpass filter')

Output Window:
Enter the passband attenuation in dB: 0.01
Enter the stopband attenuation in dB: 0.02
Enter the passband frequency in Hz: 1000
Enter the stopband frequency in Hz: 1500
Enter sampling frequency in Hz: 8000
M = 33
Department of EEE, ATMECE, Mysore Page 25
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

wc = 0.98175
alpha = 16

Fig. 10.1: Rectangular window and Impulse response curve of FIR filter

Fig. 10.2: Magnitude and phase angle curve of lowpass FIR filter

Department of EEE, ATMECE, Mysore Page 26


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Problem:
Design a bandpass filter with the given specifications:
Lower stopband edge = 0.2π
Lower Passband edge = 0.35π
Upper passband edge = 0.65π
Upper stopband edge = 0.8π
Passband attenuation = 1db
Stopband attenuation = 60db

Program:

clc;
clear all;
Rp=input('Enter the passband attenuation in dB: ');
Rs=input('Enter the stopband attenuation in dB: ');
Wp=input('Enter the passband frequency in pi rad: ');
Ws=input('Enter the stopband frequency in pi rad: ');
tr_width = min((Wp(1)-Ws(1)),(Ws(2)-Wp(2)))
%Rectangular Window
if Rs<=21
M = ceil(4*pi/tr_width)+1
y = rectwin(M);
figure, subplot(2,1,1),stem(y);
title('Rectangular Window');
end
%Bartlett Window
if Rs<=25 &Rs>21
M =ceil(8*pi/tr_width) +1
y=bartlett(M);
figure, subplot(2,1,1),stem(y);
title('Bartlett Window');
end
%Hanning Window
if Rs<=44 &Rs>25
M =ceil(8*pi/tr_width) +1
y=hanning(M);
figure, subplot(2,1,1),stem(y);
title('Hanning Window');
end
%Hamming Window
if Rs<=53 &Rs>44
M = ceil(8*pi/tr_width) +1
y=hamming(M);
figure, subplot(2,1,1),stem(y);
title('Hamming Window');
end
% Blackman Window

Department of EEE, ATMECE, Mysore Page 27


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

if Rs<=74 &Rs>53
M = ceil(12*pi/tr_width)+1
y=blackman(M);
figure, subplot(2,1,1),stem(y);
title('Blackman Window');
end
wc1 = (Ws(1) +Wp(1))/2
wc2 = (Ws(2)+Wp(2))/2
%Ideal bandpass filter
alpha = (M-1)/2
n = [0 : 1 : (M-1)];
m = n - alpha + eps;
hd = (sin(wc2*m)./(pi*m))- (sin(wc1*m)./(pi*m));
h = hd.*y';
subplot(2,1,2), stem(h);
title('Impulse response of FIR filter');
%w = logspace(-1,1);
figure, freqz(h)
title('Frequency response of FIR Bandpass filter')

Output window
Enter the passband attenuation in dB: 1
Enter the stopband attenuation in dB: 60
Enter the passband frequency in pi rad: [0.35*pi 0.65*pi]
Enter the stopband frequency in pi rad: [0.2*pi 0.8*pi]
tr_width = 0.47124
M = 81
wc1 = 0.86394
wc2 = 2.2777
alpha = 40

Department of EEE, ATMECE, Mysore Page 28


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 10.3: Blackman window and Impulse response curve of FIR filter

Fig. 10.4: Magnitude and phase angle curve of bandpass FIR filter

Department of EEE, ATMECE, Mysore Page 29


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Note:

1. For highpass filter change the hd line in lowpass filter program to line specified below
hd = sin(pi*m)./(pi*m)- sin(wc*m)./(pi*m)
2. For bandstop filter change the hd line in bandpass filter program to line specified below
hd = (sin(wc1*m)./(pi*m)) + (sin(pi*m)./(pi*m)) - (sin(wc2*m)./(pi*m))

Result: FIR Filter design was verified using different windows.

Outcomes: students will be able to design and implement the FIR Filter using various windows.

Department of EEE, ATMECE, Mysore Page 30


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 11:
Design and Implementation of FIR Filters using Frequency Sampling
Technique

Aim: To design and implement FIR filters using frequency sampling technique to meet given
specifications

Problem: Design an FIR low-pass filter for the given specification using frequency
sampling approach
Wp = 0.28π; Pass band attenuation = 0.25db;
Ws = 0.57π; stop band attenuation = 20db;

M = 7;
alpha = (M-1)/2;
l = 0:M-1
wl = (2*pi/M)*l
%Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hrs = [1,1,0,0,0,0,1]
Hdr = [1,1,0,0];%Ploting ideal response i;e 1 in passband and 0 in stopband
wdl = [0,0.42,0.42,1]; %Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2)
k2 = floor((M-1)/2)+1:M-1
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]
H = Hrs.*exp(j*angH)
h = real(ifft(H,M))
subplot(2,2,1)
plot(wl(1:4)/pi,Hrs(1:4),'o',wdl,Hdr)
title(„Frequency samples M=7)
fvtool(h)

Output:
l=[0123456]
wl = [0 0.8976 1.7952 2.6928 3.5904 4.4880 5.3856]
Hrs = [1 1 0 0 0 0 1]
k1 = [0 1 2 3]
k2 = [4 5 6]
angH = [0 -2.6928 -5.3856 -8.0784 8.0784 5.3856 2.6928]
H=
[ 1.0000 + 0.0000i -0.9010 - 0.4339i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i -0.9010 + 0.4339i ]
h = [-0.1146 0.0793 0.3210 0.4286 0.3210 0.0793 -0.1146]

Department of EEE, ATMECE, Mysore Page 31


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Output Waveform

Fig. 11.1: frequency samples for M=7

Fig. 11.2: magnitude response curve of lowpass filter

Design the FIR high-pass filter with following specifications frequency sampling technique.
Stop band edge: ws = 0.6π, As = 50db;
Pass band edge: wp = 0.8π, Rp = 1db;

M = 10;
alpha = (M-1)/2;
l = 0:M-1
wl = (2*pi/M)*l
%Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hrs = [0,0,0,0,1,1,1,0,0,0]
Hdr = [0,0,1,1];%Ploting ideal response i;e 1 in passband and 0 in stopband
wdl = [0,0.6,0.8,1]; %Ideal Amp Res for plotting

Department of EEE, ATMECE, Mysore Page 32


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

k1 = 0:floor((M-1)/2)
k2 = floor((M-1)/2)+1:M-1
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]
H = Hrs.*exp(j*angH)
h = real(ifft(H,M))
subplot(2,2,1)
plot(wl(1:6)/pi,Hrs(1:6),'o',wdl,Hdr)
title('Frequency samples M=10')
fvtool(h)

Output:
l = [0 1 2 3 4 5 6 7 8 9]
k1 = [0 1 2 3 4]
k2 = [5 6 7 8 9]
angH = [0 -2.8274 -5.6549 -8.4823 -11.3097 14.1372 11.3097 8.4823 5.6549 2.8274]
H = Columns 1 through 7
[0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.3090 + 0.9511i
0.0000 + 1.0000i 0.3090 - 0.9511i]
Columns 8 through 10
[0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i]
h = [0.0618 -0.1618 0.2000 -0.1618 0.0618 0.0618 -0.1618 0.2000 -0.1618 0.0618]

Output Waveform:

Fig. 11.3: frequency samples for M=10

Department of EEE, ATMECE, Mysore Page 33


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 11.4: magnitude response curve of highpass filter

Result: FIR Filter design was verified using frequency sampling technique.

Outcomes: students will be able to design and implement the FIR Filter using frequency
sampling technique.

Department of EEE, ATMECE, Mysore Page 34


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Experiment 12:
Realization of IIR and FIR Filters

Aim: to realize the IIR and FIR filters..

Objective: to verify the digital filter realization using simulation tool.

Theory:
The realization of a discrete filter can be done in hardware or in software. In either case, the
implementation of the transfer function H(z) of a discrete filter requires delays, adders, and
constant multipliers as actual hardware or as symbolic components. Figure depicts the operation
of each of these components as block diagrams.

Fig 12.1: a) delay block b) multiplication block c) addition block

Realization of IIR Filters:


The structures commonly used to realize IIR filters are:
• Direct forms I and II
• Cascade
• Parallel

FIR realization using Lattice structure:


Lattice Structure For a discrete Nth order all-pole or all-zero filter described by the polynomial
coefficients a(n), n = 1, 2, …,N+1, there are N corresponding lattice structure coefficients k(n), n
= 1, 2, …,N. The parameters k(n) are also called the reflection coefficients of the filter. Given
these reflection coefficients, you can implement a discrete filter as shown below.

Fig. 12.2: FIR filter lattice structure

Department of EEE, ATMECE, Mysore Page 35


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Fig. 12.3: IIR filter lattice structure

Problem: A filter is described by the following difference equations:


16y(n)+12y(n-2)+2y(n-2)-4y(n-3)-y(n-4)=x(n)-3x(n-1)+11x(n-2)-27x(n-3)+18x(n-4)
Determine its cascaded form structure and verify by converting to direct form.

Program:
function [b0,B,A] = dir2cas(b,a)
%compute gain coefficients
b0 = b(1);
b = b/b0;
a0 = a(1);
a = a/a0;
b0 = b0/a0;
M = length(b);
N = length(a);
if N > M
b = [b zeros(1,N-M)]
elseif M > N
a = [a zeros(1,M-N)]
N= M;
else
NM = 0;
end
K = floor(N/2)
B = zeros(K,3)
A = zeros(K,3)
if K*2 == N
b = [b 0]
a = [a 0]
end
broots = cplxpair(roots(b))
aroots = cplxpair(roots(a))
fori = 1:2: 2*K
Brow = broots(i : 1 : i+1,:)
Brow = real(poly(Brow))
B(fix((i+1)/2),:) = Brow
Arow = aroots(i : 1 : i+1,:)
Arow = real(poly(Arow))
A(fix((i+1)/2),:) = Arow
Department of EEE, ATMECE, Mysore Page 36
DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

end
%Realization of IIR filters direct to cascade structure
b = [1 -3 11 -27 18]
a = [16 12 2 -4 -1]
[b0,B,A] = dir2cas(b,a)
%Realization of IIR filters cascade to direct structure
[b,a] = cas2dir(b0,B,A)

Output:
%direct to cascade realization
b0 =[0.0625]
B = [1.0000 0.0000 9.0000
1.0000 -3.0000 2.0000]
A = [1.0000 1.0000 0.5000
1.0000 -0.2500 -0.1250]
%cascade to direct realization
b = [0.0625 -0.1875 0.6875 -1.6875 1.1250]
a = [1.0000 0.7500 0.1250 -0.2500 -0.0625]

Problem;
Determine the coefficients km of the lattice filter corresponding to FIR filter described by
the system function:

.H(Z)=1+2Z-1+0.33Z-2

Program:
b = [1 2 1/3]
k = tf2latc (b)

Output:
k =[1.5000 0.3333]

Result: Realization of filter was verified.

Outcomes: student will be able to realize IIR and FIR filters.

Department of EEE, ATMECE, Mysore Page 37


DIGITAL SIGNAL PROCESSING LABORATORY 18EEL67

Viva questions:

1. Define signal and system


2. Differentiate between analog and digital signal
3. List the advantages and disadvantages of digital signal processing
4. What is DFT?
5. What are the different types of filters based on impulse response?
6. What are the different types of filters based on frequency response?
7. Distinguish between FIR and IIR filters.
8. What are the advantages and disadvantages of FIR filter
9. What are the techniques of designing FIR filters?
10. What are the advantages of Kaiser window?
11. What are the techniques used to analog to digital transformation?
12. What is prewarping?

Department of EEE, ATMECE, Mysore Page 38

You might also like