Download as pdf or txt
Download as pdf or txt
You are on page 1of 77

SSET’S

S. G. BALEKUNDRI INSTITUTE OF TECHNOLOGY


BELAGAVI
NBA Accredited and an ISO: 21001:2018 Certified Institute

LABORATORY MANUAL
2021-2022
VI Semester B.E. (Electrical & Electronics Engg.)

DIGITAL SIGNAL PROCESSING LABORATORY

SUBJECT CODE: 18EEL67

Prepared by: ----------------------------- Approved by: --------------------


Name & dated signature Name & dated signature
S. S. Education Trust’s CET Code: E-175 (UG)/T-942 (PG)

S. G. BALEKUNDRI INSTITUTE OF TECHNOLOGY


Shivabasavanagar, Belagavi- 590 010, Karnataka- India
Office: 0831-2407172, 2554559 Fax: 0831-2407152 Website: www.sgbit.edu.in
Five UG branches
An ISO 21001:2018 (CV, ME, EEE, ECE &
certified institution
Department of Electrical and Electronics Engineering CSE)
Email: hod-ee@sgbit.edu.in Department Extension: 512 are accredited by NBA,
New Delhi

Digital Signal Processing Laboratory


Do’s
1. All the interfacing kits should be handled carefully.
2. Maintain an observation notebook and bring it to lab regularly.
3. Get the programs verified by respective lab in charge and then execute.
4. Before you leave the computer laboratory, make sure you have done the following things:
a. Quit all applications
b. Shut down your system properly.
c. Clean the area around your system, this includes discarding paper, ball pen etc.
5. In emergency (short circuit, fire, shock etc.) rush and put off main switch. Use fire extinguisher
and first aid box whenever necessary.

Don’ts
1. Download and /or installation of any software / program/game on any of the computers is
PROHIBITED without taking permission from your laboratory instructor/ teaching staff.
2. Students should not attempt to repair, open, tamper or interfere with any of the computers,
printers cabling or any other equipment in the laboratory.
3. Do not tamper the equipment in lab.
4. Do not damage the connecting pins.
5. Do not plug in external devices (e.g. pen drive, cell phone etc)
S. S. Education Trust’s CET Code: E-175 (UG)/T-942 (PG)

S. G. BALEKUNDRI INSTITUTE OF TECHNOLOGY


Shivabasavanagar, Belagavi- 590 010, Karnataka- India
Office: 0831-2407172, 2554559 Fax: 0831-2407152 Website: www.sgbit.edu.in
Five UG branches
An ISO 21001:2018 (CV, ME, EEE, ECE &
certified institution
Department of Electrical and Electronics Engineering CSE)
Email: hod-ee@sgbit.edu.in Department Extension: 512 are accredited by NBA,
New Delhi

Course Name: Digital Signal Processing Laboratory (18EEL67)


Course Learning Objectives:

To explain the use of standard software package:


(Ex: MATLAB/C or C ++/Scilab/ Octave/Python software)
• To explain the use of MATLAB/Scilab/Python software in evaluating
the DFT and IDFT of given sequence.
• To verify the convolution property of the DFT
• To design and implementation of IIR and FIR filters for given frequency
specifications.
• To realize IIR and FIR filters.
• To help the students in developing software skills.

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


Explain physical interpretation of sampling theorem in time and frequency
C307.1
domains.
C307.2 Evaluate the impulse response of a system.
C307.3 Perform convolution of given sequences to evaluate the response of a system.
Compute DFT and IDFT of a given sequence using the basic definition and/or
C307.4
fast methods.
C307.5 Provide a solution for a given difference equation.
C307.6 Design and implement IIR and FIR filters.

CO-PO/PSO Mapping

CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2

C307.1 1 - - - 1 - - 1 1 1 - - - -

C307.2 1 2 2 - 1 - - 1 1 1 - - - -

C307.3 1 2 2 - 1 - - 1 1 1 - - - -

C307.4 1 2 2 - 1 - - 1 1 1 - - - -

C307.5 1 2 2 - 1 - - 1 1 1 - - - -

C307.6 1 2 2 - 1 - - 1 1 1 - - - -

C307 1 2 2 - 1 - - 1 1 1 - - - -
Index
Sl. No Experiment Page No
Verification of Sampling Theorem both in time and
1. 15-18
frequency domains.

Evaluation of Impulse Response of First Order and Second


2. 19-21
Order Systems.

3. To perform linear convolution of given sequences. 22-24


To perform circular convolution of given sequences using
(a) the convolution summation formula (b) the matrix
4. 25-30
method and (c) Linear convolution from circular
convolution with zero padding.
Computation of N – point DFT and to plot the magnitude
5. 31-35
and phase spectrum.

6. Linear and circular convolution by DFT and IDFT method. 36-40


7. Solution of a given difference equation. 41-46
8. Calculation of DFT and IDFT by FFT 47-56

To Design and implementation of FIR filter to meet given


9. 57-63
specifications (low pass filter using hamming window).

Design and implementation of IIR filter to meet given


10. 64-69
specifications.

11. Auto and Cross Correlation 70-73


DIGITAL SIGNAL PROCESSING LAB 18EEL67

INSTITUTION MISSION AND VISION


VISION:

To impart Quality Education with Human values and emerge as one of the Nation’s leading Institutions
in the field of Technical Education and Research.

MISSION:

▪ Strive to encourage ideas, talents and value systems.


▪ Guide students to be successful in their endeavors with moral and ethical values.
▪ Build relation with Industries and National Laboratories to support in the field of Engineering and
Technology.
▪ Inculcate a thirst for knowledge in students and help them to achieve Academic Excellence and
Placement.
▪ Train and develop the faculty to achieve Professional, Organizational objectives, and excel in
Research and Development

DEPARTMENT VISION AND MISSION

VISION

To impart quality Electrical and Electronics Engineering education and empower students with
technical, innovative and professional skills to compete with rapid changing global challenges.

MISSION

Mission 1: To develop creativity, innovation, problem solving skills and academic excellence in
Electrical and Electronics Engineering.
Mission 2: To foster research and development activities in the fields of Electrical and Electronics
Engineering.
Mission 3: To inculcate leadership qualities and team spirit by encouraging participation in various
events in Electrical and Electronics Engineering.
Mission 4: To encourage development of entrepreneurial skills and professional ethics in the field of
Electrical and Electronics Engineering.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 1


DIGITAL SIGNAL PROCESSING LAB 18EEL67

PROGRAM OUTCOMES (PO’s)

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, andsynthesis
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 responsibilitiesrelevant
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 and 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 life-long learning in the broadest context of technological change.
EEE DEPT, S.G.B.I.T, BELAGAVI-10 2
DIGITAL SIGNAL PROCESSING LAB 18EEL67

PROGRAM SPECIFIC OUTCOMES (PSO’s)

At the end of graduation, the student will be able,

PSO1: Demonstrate in-depth understanding of components of electric vehicles.


PSO2: Demonstrate skills of using higher level languages for VLSI and Embedded systems design to
be participatory in multidisciplinary environment.

Program Educational Objectives (PEO’s)

PEO1: Be successful in their professional career, higher studies and research in the field of Electrical
and Electronics Engineering by providing contextually relevant academic environment.
PEO2: Adapt to the changing technologies and market trends in the field of Electrical and Electronics
Engineering by providing appropriate awareness and practices.
PEO3: Present technological concepts and theories in Electrical and Electronics Engineering by
enabling logical thinking, leadership qualities and entrepreneurial skills through effective
communication.
PEO4: Practice Engineering profession with ethics to serve the society.
PEO5: Demonstrate leadership qualities and managerial skills in a heterogeneous team globally.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 3


DIGITAL SIGNAL PROCESSING LAB 18EEL67

DIGITAL SIGNAL PROCESSING LABORATORY (18EEL67)

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

Hours/Week : 03 Exam Hours : 03

Total Hours : 36 Exam Marks : 60

VTU SYLLABUS

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

EEE DEPT, S.G.B.I.T, BELAGAVI-10 4


DIGITAL SIGNAL PROCESSING LAB 18EEL67

DSP USING SCILAB

SCILAB: SCILAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for technical
computation, graphics and animation. The diagram 1 shows the main features and capabilities of
SCILAB.

SCILAB

GRAPHICS COMPUTATIONS EXTERNAL


2-D Graphics Linear Algebra INTERFACE
3 –D Graphics Signal Processing Interface with C and
Animations Polynomial and FORTAN language
interpolation
Quadrature solution
of ODE’S

TOOL BOX
Signal Processing Image Processing
Statistics Control Systems
Neural Network Communications

Fig.1: Main features and capabilities of SCILAB


At its core ,SCILAB is essentially a set (a “toolbox”) of routines (called “m files” or
“mex files”) that sit on your computer and a window that allows you to create new variables with
names (e.g. voltage and time) and process those variables with any of those routines (e.g. plot
voltage against time, find the largest voltage, etc.)

It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at some
later time. Furthermore, it allows you to run such lists of commands such that you pass in data
and/or get data back out (i.e. the list of commands is like a function in most programming

EEE DEPT, S.G.B.I.T, BELAGAVI-10 5


DIGITAL SIGNAL PROCESSING LAB 18EEL67

languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you as
if it were part of the basic toolbox that you started with).

For those with computer programming backgrounds: Note that SCILAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It simply reads
through each line of the function, executes it, and then goes on to the next line. (In practice,a form
of compilation occurs when you first run a function, so that it can run faster the next time you run
it.

SCILAB Windows:
SCILAB works with through three basic windows
Command Window: This is the main window. It is characterized by SCILAB command prompt
>> when you launch the application program SCILAB puts you in this window all commands
including those for user-written programs ,are typed in this window at the SCILAB prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called M
files.

INPUT-OUTPUT:
SCILAB supports interactive computation taking the input from the screen and flushing,
the output to the screen. In addition, it can read input files and write output files

Data Type: the fundamental data –type in SCILAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells. There is no
need to declare variables as real or complex, SCILAB automatically sets the variable to be real.
Dimensioning: Dimensioning is automatic in SCILAB. No dimension statements are required for
vectors or arrays. We can find the dimensions of an existing matrix or a vector with the size and
length commands.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 6


DIGITAL SIGNAL PROCESSING LAB 18EEL67

BASIC INSTRUCTIONS IN SCILAB

1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an increment
of 1. Therefore T = [0 1 2 3 4 5 6 7 8 9 10]

2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 ……… 100]

3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]

4. Zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]

5. Ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 1 1
11
11
11
11

6. Zeros (2, 4)
Output = 0 0 0 0
0000

7. a = [ 1 2 3] , b = [4 5 6]
THEN a.*b = [4 10 18]
i.e. [4*1 5*2 6*3]

8. if C= [2 2 2] and b = [4 5 6]
b.*C results in [8 10 12]

9. Plot (t, x)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 7


DIGITAL SIGNAL PROCESSING LAB 18EEL67

If x = [6 7 8 9] and t = [1 2 3 4]; this instruction will display a figure window which indicates the
plot of x versus t as shown in the figure 2

Fig.2: Linear Graph

10. Plot2d3 (t,x)


If x(n) = [0 1 2 3]; This instruction will display a figure window as shown in the figure 3.

Fig.3: Discrete Sequence Graph

11. Filter: Syntax: y = filter(b,a,X)


Description: y = filter(b,a,X) filters the data in vector X with the filter described by numerator
coefficient vector b and denominator coefficient vector a. If a(1) is not equal to 1, filter normalizes
the filter coefficients by a(1). If a(1) equals 0, filter returns an error.
12. Subplot: This function divides the figure window into rows and columns Subplot (2 2 1)
divides the figure window into 2 rows and 2 columns 1 represent number of the figure 4

EEE DEPT, S.G.B.I.T, BELAGAVI-10 8


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.4: Graph window

13. Fliplr: Syntax: B = fliplr(A)


Description: B = fliplr(A) returns A with columns flipped in the left-right direction, that is,
about a vertical axis. If A is a row vector, then fliplr(A) returns a vector of the same length with
the order of its elements reversed. If A is a column vector, then fliplr(A) simply returns A.

14. Conv: Syntax: w = conv(u,v)


Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.

15. Impz: Syntax: [h,t] = impz(b,a,n)


Description: [h,t] = impz(b,a,n) computes the impulse response of the filter with numerator
coefficients b and denominator coefficients a and computes n samples of the impulse response
when n is an integer (t = [0: n-1]'). If n is a vector of integers, impz computes the impulse response
at those integer locations, starting the response computation from 0 (and t = n or t = [0 n]).If,
instead of n, you include the empty vector for the second argument, the number of samples is
computed automatically by default.
16. Disp: Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable. Note that disp does not display empty
arrays.

17. xlabel: Syntax: xlabel('string')


Description: xlabel('string') labels the x-axis of the current axes.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 9


DIGITAL SIGNAL PROCESSING LAB 18EEL67

18. ylabel: Syntax: ylabel('string')


Description: ylabel('string') labels the y-axis of the current axes.

19. Title: Syntax: title('string')


Description: title('string') outputs the string at the top and in the center of the current axes.

20. Grid on: Syntax: grid on


Description: grid on adds major grid lines to the current axes.

SAMPLE PROGRAM WITH RESULT


GENERATION OF ELEMENTARY SIGNALS
Impulse Signal

Unit Step Signal

Ramp Signal

Exponential Signal

Sine wave
x(n) = Sin n
x(n) = Sin t

Cosine wave
x(n) = Cos n
x(n) = Cos t

PROGRAM
clc; % clear screen
clear all; % clear workspace
close all; % close all figure windows
% to generate unit impulse signal

EEE DEPT, S.G.B.I.T, BELAGAVI-10 10


DIGITAL SIGNAL PROCESSING LAB 18EEL67

t = -2:1:2; % Define time vector


y = [zeros (1,2), ones (1), zeros (1,2)]; % define amplitude values
subplot (2,2,1);
Plot2d3(t,y); % plot the discrete time impulse signal
xlabel('time'); % label x axis
ylabel('amplitude'); % label y axis
title ('Unit Impulse signal'); % graph title
% to generate unit step
N = input ('enter the value of N = '); % define the length of unit step signal
t = 0: N-1; % Define time vector
y1=ones (1, N); % Define amplitude values
subplot (2,2,2);
Plot2d3(t, y1); %plot the discrete time unit step signal
xlabel('time'); % label x axis
ylabel('amplitude'); % label y axis
title ('Unit Step signal'); % graph title
% to generate ramp signal
N1 = input ('enter the value of N1 = '); % Define the length of unit ramp signal

t = 0: N1; % Define time vector

subplot (2,2,3);

Plot2d3 (t,t); %plot the discrete time impulse signa

xlabel('time'); % label x axis

ylabel('amplitude'); % label y axis

title ('Ramp signal'); % graph title

% to generate exponential

N2 = input ('enter the length N2 = '); % define the length of unit step signal

t = 0:1/4: N2; % Define time vector

a = input ('enter the value of a = '); % if a is +ve –Rising exponential, a is –ve decaying

Exponential

y2 = exp(a*t); % Define amplitude values


subplot (2,2,4);

plot2d3 (t, y2); %plot the discrete time impulse signal


xlabel('time'); % label x axis

EEE DEPT, S.G.B.I.T, BELAGAVI-10 11


DIGITAL SIGNAL PROCESSING LAB 18EEL67

ylabel('amplitude'); % label y axis


title ('Exponential signal'); % graph title

% to generate sine wave

t = 0:1/32:2; % Define time vector


x = sin(2*pi*t); % define amplitude values
figure (2); % Open new figure window
subplot (2,1,1);
Plot2d3 (t,x); %plot the discrete time impulse signa
xlabel('time'); %label x axis
ylabel('amplitude'); % label y axis
title ('Sine wave'); % graph title
% to generate Cosine wave
t = 0:1/32:2; % Define time vector
x = cos(2*pi*t); % Define amplitude values
subplot (2,1,2);
Plot2d3 (t,x); ` %plot the discrete time impulse signal
xlabel('time'); % label x axis
ylabel('amplitude') ; % label y axis
title ('Cosine wave'); % graph title

OUTPUT:
Enter the value of N = 10
enter the value of N1 = 10
enter the length N2 = 6
enter the value of a = 3

EEE DEPT, S.G.B.I.T, BELAGAVI-10 12


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.5: Generation of Waveforms

OUTCOME: Acquire the knowledge of various elementary signals.

VIVA QUESTIONS:
1. Define Signal.

A signal is defined as any physical quantity that varies with time, space or any other
independent variable or variables

2. What is multi-dimensional signal? Give example.

A signal which is a function of two or more independent variables is called multi-


dimensional signal and can be denoted as I (x, y). The intensity or brightness of black and white
photograph at each point is a function of two independent special coordinates x and y. hence it
is a two-dimensional signal. The intensity of black and white motion picture is a function of x
and coordinates, and time. Hence it is a three-dimensional signal.
3. What is analog signal?

The analog signal is a continuous function of an independent variable such as time,


space etc. the analog signal is defining for every instant of the independent variable and so the
magnitude of analog signal is continuous in the specified range. Here both the magnitude of the
signal and the independent variable are continuous.
4. What is discrete signal?

The discrete signal is a function of a discrete independent variable which is an integer. The
independent variable is divided into uniform intervals and each interval is represented by an integer.
The discrete signal is defined for every integer value of the independent variable. The magnitude of

EEE DEPT, S.G.B.I.T, BELAGAVI-10 13


DIGITAL SIGNAL PROCESSING LAB 18EEL67
discrete signal can take any discrete value in the specified range. Here both the value of the signal
and the independent variable are discrete.
5. What is digital signal?

The digital signal is same as discrete signal except that the magnitude of the signal is
quantized. The magnitude of the signal can take one of the values in a set of quantized values.
Here quantization is necessary to represent the signal in binary codes.
6. How will you classify the discrete time signals?

The discrete time signals are classified depending on their characteristics. Some ways
of classifying discrete time signals are (a) Energy signals and Power signals, (b) Periodic and
Aperiodic signals, (c) Symmetric and Anti symmetric signals.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 14


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 01 Date:

SAMPLING THEOREM
AIM: Verification of sampling theorem.

Objectives:
• After completing this experiment, student will be able to verify sampling theorem using
SCILAB.
• Study the importance of Sampling Theorem with its conditions.
• Study the plotting of frequency spectrum for all the cases of sampling theorem.

THEORY:
Sampling: Is the process of converting a continuous time signal into a discrete time signal. It is
the first step in conversion from analog signal to digital signal.
Sampling theorem: Sampling theorem states that “Exact reconstruction of a continuous time base-
band signal from its samples is possible, if the signal is band-limited and the sampling frequency
is greater than twice the signal bandwidth” i.e., fs> 2W, where W is the signal bandwidth.
Nyquist Rate Sampling: The Nyquist rate is the minimum sampling rate required to avoid
aliasing, equal to the highest modulating frequency contained within the signal. In other words,
Nyquist rate is equal to two-sided bandwidth of the signal (Upper and lower sidebands) i.e., fs =
2W. To avoid aliasing, the sampling rate must exceed the Nyquist rate. i.e., fs>fN, where fN =2W.

PROGRAM LOGIC:
1. Select the frequency of analog signal f Hz
2. To generate sine wave of f Hz define a closely spaced time vector

3. Generate the sinusoid and plot the signal Select the sampling frequency fs= 10f samples/sec.
Generate a suitable time scale for this sampling signal
4. Sample the analog signal at the instant specified by n.

5. Modify the time vector n used for discrete simulation

6. Reconstruct the analog signal from its discrete samples

7. Compare the analog and reconstructed signal


8. Repeat the values experiment for different values of f and verify reconstructed and analog
signal

EEE DEPT, S.G.B.I.T, BELAGAVI-10 15


DIGITAL SIGNAL PROCESSING LAB 18EEL67

PROGRAM: SAMPLING THEOREM IN TIME DOMAIN


clc; % clear screen
clear all; % clear workspace
tfinal = 0.05; % define final value of time vector

t= 0:0.00005: tfinal; % define time vector for analog signal

% enter the analog frequency


fd= input ('enter the analog frequency'); % define analog signal
% define analog signal for comparison
xt = sin(2*pi*fd*t); % define analog signal
% simulate condition for under sampling
fs1 = 1.3*fd;
n1= 0: 1/fs1: tfinal; % define time vector for discrete signal
xn = sin(2*pi*n1*fd); % to generate under sampled signal
% plot the analog and sampled signal
subplot (3,1,1);
plot (t, xt,'b', n1, xn,'r*');
title ('under sampling');
% simulate condition for Nyquist rate
fs2= 2*fd; % simulate condition for nyquist rate
n2= 0:1/fs2: tfinal; % define time vector for discrete signal.
xn = sin(2*pi*n2*fd); % to generate under sampled signal
subplot (3,1,2);
plot (t, xt,'b', n2, xn,'r*-'); % plot the analog and sampled signal
title ('nyquist rate');
% simulate condition for over sampling
fs3 = 2.5*fd;
n3= 0:1/fs3: tfinal;
xn = sin(2*pi*n3*fd); %generate over sampling signal
subplot (3,1,3);
plot (t, xt,'b', n3, xn,'r*-'); % plot the analog and sampled signal
title ('over sampling');
OUTPUT:
enter the analog wave frequency = 500

EEE DEPT, S.G.B.I.T, BELAGAVI-10 16


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.1.1: Verification of sampling theorem.

OUTCOMES:

This experiment enables students to acquire the knowledge about


• The conversion of an analog signal to a discrete-time sequence via sampling
• The signal reconstruction (without information lost) in the communication system.
Viva Questions:
1. What is DSP?

Digital Signal Processing refers to processing of signals by digital systems. DSP is a


technique that converts signals from real world sources (usually in analog form) into digital data
that can then be analyzed. Analysis is performed in digital form because once a signal has been
reduced to numbers; its components can be isolated, analyzed and rearranged more easily than in
analog form. Eventually, when the DSP has finished its work, the digital data can be turned back
into an analog signal, with improved quality.

2. What are the advantages of DSP?

The advantages of DSP are (i) programs can be modified easily for better performance;
(ii) Better accuracy can be achieved by using adaptive algorithms, (iii) digital signals can be
easily stored and transported, (iv)digital systems are cheaper than analog equivalent.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 17


DIGITAL SIGNAL PROCESSING LAB 18EEL67

3. What are the applications of DSP?


Speech coding & decoding Audio mixing & editing, speech encryption & decryption
Image compression & decompression, Speech recognition, Image compression and processing.

4. When a discrete time signal is called periodic?

When a discrete time signal x(n) satisfies the condition x(n) = x(n+N), then it is
called periodic, with periodicity of N samples.

5. What is discrete signal?


The discrete signal is a function of a discrete independent variable which is an integer. The
independent variable is divided into uniform intervals and each interval is represented by an integer.
The discrete signal is defined for every integer value of the independent variable. The magnitude of
discrete signal can take any discrete value in the specified range. Here both the value of the signal and
the independent variable are discrete.
6. What is antialiasing filter? Can it be Digital filter? Justify.

When processing the analog signal using DSP System, it is sampled at some rate depending
upon the bandwidth. The rate of sampling is decided by the Nyquist criterion. However, signals that
are found in physical systems will never be strictly band limited. To eliminate signal content beyond
the desired bandwidth, anti-aliasing filter is used. The filter cannot be a digital filter. This is because
anti-alias filtering is required to be performed in the analog domain prior to applying the signal to
A/D converter where aliasing would take place.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 18


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 02 Date:

IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER SYSTEMS

AIM: Write a program to find the impulse response of first order and second order systems

OBJECTIVES: To implement circular convolution impulse response of coefficients in time domain


using SCILAB and to verify the result theoretically

THEORY:
• The impulse response of a system is an important response. The impulse response is the response
to a unit impulse.
• The unit impulse has a Laplace transform of unity (1). That gives the unit impulse a unique stature.
If a system has a unit impulse input, the output transform is G(s), where G(s) is the transfer function
of the system. The unit impulse response is therefore the inverse transform of G(s), i.e. g(t), the
time function you get by inverse transforming G(s). If you haven't begun to study Laplace
transforms yet, you can just file these last statements away until you begin to learn about Laplace
transforms. Still there is an important fact buried in all of this.
• Knowing that the impulse response is the inverse transform of the transfer function of a system can
be useful in identifying systems (getting system parameters from measured responses).

ALGORITHM:

1. Input the coefficients of first and second order system

2. Generate the impulse input function

3. Plot the impulse response graph.

PROGRAM LOGIC:

1.Read the first input sequence and its coefficient value.


2.Read the second input sequence and its coefficient value
3.Enter the upper and lower input values.
4. Display and plot the output.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 19


DIGITAL SIGNAL PROCESSING LAB 18EEL67

PROGRAM
clc;
clear;
Impulse Response of first order system described by difference equation y(n)+2y (n-1) = x(n)
a1= input ('enter the coefficients of input vector of first order system a1=');
b1= input ('enter the coefficients of output vector of first order system b1=');
n1= input ('enter the lower of impulse response n1=');
n2= input ('enter the upper of impulse response n2=');
n=n1: n2
//generate the impulse input function
x=zeros (1, length (n));
for i=1: length (n)
if n(i) ==0
x(i)=1;
end
end
h1= filter (a1, b1, x); // find the impulse response of first order system
disp (h1); // display the values of impulse response in console window
subplot (2 ,1 ,1)
plot2d3 (n, h1); // to plot the impulse response of system in graphical window
xlabel ('discrete time n');
ylabel ('amplitude');
title ('impulse response of first order system h1 (n)');
// Impulse Response of Second order system described by difference equation
// y(n)+0.5y(n-1) + 0.3 y(n-2) = x (n)+5x (n-1)
a2= input ('enter the coefficients of input vector of second order system a2=');
b2= input ('enter the coefficients of output vector of second order system b2=');
h2= filter (a2, b2, x); // find the impulse response of system
disp (h2); // display the values of impulse response in console window
subplot (2 ,1 ,2)
plot2d3 (n, h2); // to plot the impulse response of system in graphical window
xlabel ('discrete time n');
ylabel ('amplitude');
title ('impulse response of second order system h2(n)');

EEE DEPT, S.G.B.I.T, BELAGAVI-10 20


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Output:
// enter the coefficients of input vector of first order system a1 = [ 1]
// enter the coefficients of output vector of first order system b1 = [12]
// enter the lower of impulse response n1=0
// enter the upper of impulse response n2=5
// 1. -2. 4. -8. 16. -32.
// enter the coefficients of input vector of second order system a2 = [15]
// enter the coefficients of output vector of second order system b2 = [1 0.5 0.3]
// column 1 to 5
// 1. 4.5 -2.55 -0.075 0.8025
// column 6
// -0.37875

Fig.2.1: Impulse response of second order system.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 21


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 03 Date:

LINEAR CONVOLUTION OF GIVEN SEQUENCES

AIM: To implement linear convolution of two given sequences

OBJECTIVES: This experiment enables students


• To find linear convolution of right sided sequence using inbuilt SCILAB function “CONV” and
its theoretical method to verify the result

THEORY: Convolution is an integral concatenation of two signals. It has many applications in


numerous areas of signal processing. The most popular application is the determination of the
output signal of a linear time-invariant system by convolving the input signal with the impulse
response of the system. Note that convolving two signals is equivalent to multiplying the Fourier
transform of the two signals. In linear systems, convolution is used to describe the relationship
between three signals of interest: the input signal, the impulse response, and the output signal. n
linear convolution length of output sequence is, length(y(n)) = length(x(n)) + length(h(n)) – 1

Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by

For discrete time signals x(n) and h(n), is defined by

Where x(n) is the input signal and h(n) is the impulse response of the system.
ALGORITHM:
1. Input the two sequences x1 and x2
2. Use conv to get convoluted output.
3. Plot the sequences.
PROGRAM LOGIC:
The convolution Sum is given by

1. The impulse response h[k] is time reversed (that is reflected about the origin) to obtain h[-k]
and then shifted by n to form h[n-k] = h[-(k-n)] which is a function of K with Parameter n.
2. Two sequences x[k] and h[n-k] are multiplied together for all values of k with n fixed at some

EEE DEPT, S.G.B.I.T, BELAGAVI-10 22


DIGITAL SIGNAL PROCESSING LAB 18EEL67

value
3. The product x[k]h[n-k] is summed over all k to produce a single output sample y[n]
4. Steps 1 to 3 are repeated as n varies over -∞ to +∞ o produce the entire output y[n]

CALCULATION:

On simplification we get,

PROGRAM: LINEAR CONVOLUTION OF RIGHT SIDED SEQUENCES


PROGRAM
clc; % clear screen
clear all; % clear workspace
close all; % close all figure windows
x1 = input ('enter the first sequence x1(n) = '); % define first sequence
x2 = input ('enter the second sequence x2(n) = '); % define second sequence
y = conv (x1, x2); % convolute first and second sequences
disp ('Linear convolution of x1 and x2 is = ');
disp(y); % display the output
% Graphical display
subplot (2,2,1); % divide the display screen in four sections and choose the first one to display
plot2d3 (x1); % plot the first sequence
xlabel('n'); % label x axis
ylabel('x1(n)'); % label y axis

EEE DEPT, S.G.B.I.T, BELAGAVI-10 23


DIGITAL SIGNAL PROCESSING LAB 18EEL67

title ('plot of x1(n)'); % graph title


subplot (2,2,2); %divide the display screen in four sections and choose the first second to display
plot2d3 (x2); % plot the second sequence
xlabel('n'); % label x axis
ylabel('x2(n)'); % labely axis
title ('plot of x2'); % graph title
subplot (2,1,2); %divide the display screen in four sections and choose the first second to
display
plot2d3 (x2); % plot the second sequence
xlabel('n'); % label x axis
ylabel('y(n)'); % label y axis
title ('convolution output'); % graph title

OUTPUT:
enter the first sequence x1(n) = [1 2 3 4]
enter the second sequence x2(n) = [3 6 7 2]
Linear convolution of x1 and x2 is = 3 12 28 46 49 34 8

Fig.3.1: Verification of Linear convolution

EEE DEPT, S.G.B.I.T, BELAGAVI-10 24


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 04 Date:

CIRCULAR CONVOLUTION

AIM: To implement circular convolution of two given sequences

OBJECTIVES: To implement circular convolution of given sequences in time domain using


SCILAB and to verify the result theoretically.

THEORY: Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)] where X3(k) = X1(k) X2(k)
𝑁−1
𝑥3(𝑛) = ∑ 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁
𝑚=0

ALGORITHM:
1. Input the two sequences x and h
2. Circularly convolve both to get the output of y.
3. Plot the sequences.
PROGRAM LOGIC:
1.Read the first input sequence, x[n] and plot.

2.Read the second input sequence, h[n] and plot

3.Find the length of x[n] and y[n], l1 and l2 respectively

4. Check, if l1=l2. Proceed only if equal.

5.If l1 not equal to l2, zero padding is done to make l1=l2.

6.Initialize a loop variable for the number of output points.

7. For each output sample access the samples of y[n] in cyclic order.

8. Find the sum of products of x[n] and cyclically folded and shifted h[n] to get circular
convoluted output.
9. Display and plot the output.

EXAMPLE:
Let’s take x1(n) = {1, 1, 2, 1} and x2(n) = {1, 2, 3, 4}
x3(0) = x1(m) x2(-m)
EEE DEPT, S.G.B.I.T, BELAGAVI-10 25
DIGITAL SIGNAL PROCESSING LAB 18EEL67

= x1(0) x2(0) + x1(1) x2(3) + x1(2) x2(2) + x1(3) x2(1)


= 1 + 4 + 6 +2 = 13
x3(1) = x1(m) x2(1-m)
= x1(0) x2(1) + x1(1) x2(0) + x1(2) x2(3) + x1(3) x2(2)
= 2 + 1 + 8 + 3= 14
x3(2) = x1(m) x2(2-m)
= x1(0) x2(2) + x1(1) x2(1) + x1(2) x2(0) + x1(3) x2(3)
= 3 + 2 + 2+ 4= 11
x3(3) = x1(m) x2(3-m)
= x1(0) x2(3) + x1(1) x2(2) + x1(2) x2(1) + x1(3) x2(0)
= 4 + 3 + 4 + 1= 12

The convoluted signal is,


x3(n) = {13, 14, 11, 12}

PROGRAM: CIRCULAR CONVOLUTION IN TIME DOMAIN


clc; % clear screen
clear all; % clear workspace
close all; % close all figure windows
xn= input ('enter the first sequence x(n) = '); % define first sequence
hn=input ('enter the second sequence h(n) = '); % Define second sequence
l1 = length(xn); % length of first sequence
l2 = length(hn); % length of second sequence
N = max (l1, l2); % Define the length of the output
xn = [xn, zeros (1, N-l1)]; % zero padding is done to make l1=l2.
hn = [hn, zeros (1, N-l2)]; % zero padding is done to make l1=l2.
for n=0: N-1; % loop to calculate circular convolution
y(n+1) = 0;
for m=0: N-1
i =pmodulo ((n-m), N);
if i<0 then

i=i+N;

EEE DEPT, S.G.B.I.T, BELAGAVI-10 26


DIGITAL SIGNAL PROCESSING LAB 18EEL67

end
y(n+1) =y(n+1) + hn(m+1) * xn(i+1);
end
end
disp ('Circular convolution in Time Domain =');
disp(y); % display the output
subplot (2,2,1); % graphical plot the first input sequence
plot2d3 (xn);
xlabel('n');
ylabel('x(n)');
title ('Plot of x(n)');
subplot (2,2,2); % graphical plot the second input sequence
plot2d3 (hn);
xlabel('n');
ylabel('h(n)');
title ('Plot of h(n)');
subplot (2,2,3); % graphical plot the output sequence
plot2d3 (y);
xlabel('n');
ylabel('y(n)');
title ('Circular Convolution Output');
OUTPUT:
enter the first sequence x(n) = [1 2 3]
enter the second sequence h(n) = [1 5 6 7]
Circular convolution in Time Domain =
33 28 19 34

EEE DEPT, S.G.B.I.T, BELAGAVI-10 27


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.4.1: Verification of Circular convolution

OUTCOMES:
• To Study the importance of linear and circular convolution with its mathematical
expression.
• To calculate the output for any linear time invariant system given its input and its impulse
response linear convolution is used as basic operation.
Viva Questions:
1. What is the length of linearly convolved signals?
Length of linearly convolved signal is always equal to N = L + M - 1 where L is length of
first signal and M is length of second signal.

2. What are linear and non-linear systems?


A system is linear, if the response of the system to a weighted sum of the signals is equal
to the corresponding weighted sum of the response of the system to each of the individual input
signals i.e., if H[a1x1(n) + a2x2(n)] = a1H[x1(n)] +a2H[x2(n)]. If the system does not satisfy the
above condition then it is non-linear.

3. What is meant by discrete convolution?


The convolution of two discrete time signals is called discrete convolution. The discrete
convolution of two discrete time signals x1(n) and x2(n) is defined as

4. Why linear convolution is important in DSP?

EEE DEPT, S.G.B.I.T, BELAGAVI-10 28


DIGITAL SIGNAL PROCESSING LAB 18EEL67

The response or output of LTI discrete time system for any input x(n) is given by linear
convolution of the input x(n) and the impulse response h(n) of the system. This means that if the
impulse response of a system is known, then the response of the system for any input can be
determined by convolution operation.

5. Write properties of linear convolution.


The linear convolution satisfies the following properties;
• Commutative Property: x(n) * h(n) = h(n) * x(n)
• Associative Property: [x(n) * h(n)] * g(n) = x(n) * [h(n) * g(n)]
• Distributive Property: [x(n) + h(n)] * g(n) = [x(n) * h(n)] + [x(n) * g(n)]

6. What is Circular Convolution?


The convolution of two periodic sequences with periodicity N is called circular convolution. If
x1(n) and x2(n) are two periodic sequences with N samples in a period, then the circular convolution
of x1(n) and x2(n) is defined as,
𝑁−1
𝑥3(𝑛) = ∑ 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁
𝑚=0

7. What do you mean by aliasing in circular convolution?


In circular convolution if value of N < L+M-1 then last M-1 values of y[n] wraps around
gets added with first M-1 values of y[n]. This is called aliasing.

8. What is the difference between circular convolution and periodic convolution?


In periodic convolution input signals are originally periodic with common value of
period. In circular convolution, if input signals are not periodic then they are assumed to
be periodic with period = N where N = max (L, M) where L is the length of first signal and
M islength of second signal.

9. Why circular convolution is important in DSP?

The Discrete Fourier Transform (DFT) is used for the analysis and design of discrete time
systems using digital computers. The DFT supports only circular convolution. Hence when
DFT techniques are employed, the results of linear convolution are obtained only via circular
convolution.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 29


DIGITAL SIGNAL PROCESSING LAB 18EEL67

10. How to perform linear convolution using circular convolution?


If two signals x (n) and y (n) are of length n1 and n2, then the linear convoluted output z(n)
is of length n1+n2-1. Each of the input signals is padded with zeros to make it of length n1+n2-1.
Then circular convolution is done on zero padded sequences to get the linear convolution of original
input sequences x (n) and y (n).

EEE DEPT, S.G.B.I.T, BELAGAVI-10 30


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 05 Date:

N-point DFT
AIM: To compute N-point DFT of a given sequence and to plot magnitude and phase spectrum.

OBJECTIVES:
After completion of this experiment the students are able to compute the N point DFT of a given sequence
and to plot magnitude and phase spectrum.

THEORY: Discrete Fourier Transform is a powerful computation tool which allows us to evaluate
the Fourier Transform X(ejω) on a digital computer or specially designed digital hardware. Since
X(ejω) is continuous and periodic, the DFT is obtained by sampling one period of the Fourier
Transform at a finite number of frequency points. Apart from determining the frequency content of
a signal, DFT is used to perform linear filtering operations in the frequency domain. The sequence
of N complex numbers x0,...,xN−1 is transformed into the sequence of N complex numbers X0, ..., XN−1
by the DFT according to the formula:
𝑁−1
X(k) = ∑ x(n)e − j2πnk/N
n=0

k = 0,1, …. N-1
EXAMPLE:
Let us assume the input sequence x[n] = [1 1 0 0] we have, For k = 0

𝑁−1
X(k) = ∑ x(n)e − j2πnk/N
k = 0,1, …. N-1
For k = 1, 3
X(0) = ∑ x(n)
𝑛=0

X(0) = x(0) + x(1) + x(2) + x(3)X(0) = 1+1+0+0 = 2


3
X(1) = ∑ x(n)e − jπn/2
𝑛=0

X(1) = x(0) + x(1) e-jπ/2 + x(2) e-jπ + x(3) e-j3π/2


X(1) = 1 + cos(π/2) - jsin(π/2) = 1 – j

For k = 2
3

X(2) = ∑ x(n)e − jπn

EEE DEPT, S.G.B.I.T, BELAGAVI-10 31


DIGITAL SIGNAL PROCESSING LAB 18EEL67

𝑛=0

X(2) = x(0) + x(1) e-jπ + x(2) e-j2π + x(3) e-j3π

X(2) = 1 + cosπ – jsin π = 1-1 = 0


For k = 3,
3
X (3) = ∑ x(n)e − j3nπ/2
𝑛=0

X (3) = x (0) + x (1) e-j3π/2 + x (2) e-j3π + x (3) e-j9π/2

X (3) = 1 + cos(3π/2) - jsin(3π/2) = 1 + j


The DFT of the given sequence is,
X(k) = {2, 1-j, 0, 1+j}
To find Magnitude of X(k):
Magnitude= (a2+b2)1/2
Where a and b are real and imaginary parts respectively
to fine Phase of X (k):
Phase=tan-1(b/a)
ALGORITHM:
1. Input the sequence for which DFT to be computed.
2. Input the length of the DFT required (say 4,8>length of the sequence).
3. Compute the DFT using the fft command.
4. Plot the magnitude and phase spectra.

PROGRAM LOGIC:
The analysis equations for Calculating DFT is given by
𝑁−1
X(k) = ∑ x(n)e − j2πnk/N k = 0,1, …. N-1
n=0

The frequency domain signals are calculated according to the formula


𝑁−1 2πnk
ReX(k) = ∑ x(n)cos ( ) k = 0,1, …. N-1
n=0 N

𝑁−1
j2πnk
ImX(k) = − ∑ x(n)sin ( ) k = 0,1, …. N-1
n=0 N

EEE DEPT, S.G.B.I.T, BELAGAVI-10 32


DIGITAL SIGNAL PROCESSING LAB 18EEL67
PROGRAM: N POINT DFT
clc;
clear all;
x= [1 2 3 4] //Define a sequence
disp ('input sequence')
disp(x)//Display the input sequence
N=length(x)
for k=0: 1: N-1
y (k+1) = 0
for n=0: 1: N-1
y(k+1) = y(k+1) + (x(n+1) * exp (-(%i*2*%pi*n*k)/N))//Obtain a N point DFT using equation.
end
end
disp ('DFT using formula,y')
disp(y)
mag_res=abs(y)//Obtain a magnitude of the DFT
disp ('magnitude response')
phase_res=atan(imag(y), real(y) //Obtain a Phase of the DFT in terms of radians
disp(mag_res)
disp ('phase response')
disp(phase_res)//display the numerical phase values on the console window
phase_res_deg=phase_res*(180/%pi)) //Obtain a Phase of the DFT in terms of Degrees
disp ('phase response in deg')
disp(phase_res_deg)) //display the numerical phase values in terms of degrees
n=0: 1: N-1
subplot (3,1,1)
plot2d3(n,x) //Plot a graph of input sequence with suitable label
xlabel('samples')
ylabel('magnitude')
title ('input sequence')
subplot (3,1,2)
plot2d3(n,mag_res) )//plot a graph of magnitude of the DFT
xlabel('samples')
ylabel('magnitude')
title ('magnitude response')
subplot (3,1,3)
plot2d3(n,phase_res_deg) //plot a graph Phase of the DFT in terms of Degrees
xlabel('samples')
ylabel('magnitude')
title ('phase response in deg')
y1=fft(x))) //Obtain a N point DFT using built in

EEE DEPT, S.G.B.I.T, BELAGAVI-10 33


DIGITAL SIGNAL PROCESSING LAB 18EEL67
function.disp ('DFT using builtin routine, y1')
disp (y1)
disp ('the obtained DFT is same as that of DFT using built in routine')

OUTPUT:
input sequence
1. 2. 3. 4.
DFT using formula,y
10.
- 2. + 2.i
- 2. - 9.797D-16i
- 2. - 2.i
magnitude response
10.
2.8284271
2.
2.8284271
phase response
0.
2.3561945
- 3.1415927
- 2.3561945
phase response in deg
0.
135.
- 180.
- 135.
DFT using builtin routine, y
10. - 2. + 2.i - 2. - 2.- 2.i
the obtained DFT is same as that of DFT using built in routine

Fig.5.1: Plot of DFT magnitude and phase of a given sequence.OUTCOMES:

EEE DEPT, S.G.B.I.T, BELAGAVI-10 34


DIGITAL SIGNAL PROCESSING LAB 18EEL67
This experiment enables students to learn the importance of DFT and IDFT used in DSP.

Viva Questions:

1. What is correlation property of DFT?


If x[n] X[k] and h[n] H[k] Then DFT {x[n] o h[n]} = X[k] H*[k]
2. What are the applications of FFT?
Linear filtering i.e. to find output of digital filter for any given input sequence (ii) Spectral Analysis
i.e. to find magnitude spectrum and phase spectrum (iii) Circular Correlation i.e., to find degree of
similarity between two signals.
3. How to find output of the filter using DFT?
Output of the filter is linear convolution of impulse response with the input of the signal. To find
output means to find linear convolution by DFT.
4. What is DTFT?
DTFT is Fourier Transform of DT signal that converts the sampled DT signal from time domain to
frequency domain. Frequency domain representation parameters are magnitude and phase. DTFT
gives frequency response that includes magnitude response and phase response.
5. If DTFT is Fourier Transform of DT signal then what is DFT?
DFT is frequency sampling of DTFT. When DTFT is sampled in frequency domain we get DFT.
6. Find DTFT and Energy Density Spectrum of x[n] = u[n].
Energy of u[n] is infinite. Therefore u[n] is not energy signal. Fourier Transform is defined only
for energy signal.
7. DTFT gives continuous spectra or discrete spectra?
When signal is periodic spectrum is Discrete. If the signal is not- periodic then spectrum is always
continuous. DTFT is Fourier transform of Non-periodic signals. Therefore, DTFT gives continuous
spectra.
8. Differentiate between DTFT and DFT. Why it is advantageous to use DFT in computers rather
than DTFT?
In DTFT, frequency appears to be continuous. But, in DFT, frequency is discrete. This property is
useful for computation in computers.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 35


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 6a Date:

CIRCULAR CONVOLUTION BY DFT AND IDFT METHOD.

AIM: To perform Circular Convolution Using DFT - IDFT method

OBJECTIVES: To implement circular convolution using DFT and IDFT in time domain
using SCILAB and to verify the result theoretically.

THEORY: Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)] where X3(k) = X1(k) X2(k)
𝑁−1
𝑥3(𝑛) = ∑ 𝑥1(𝑚) 𝑥2((𝑛 − 𝑚)) 𝑁
𝑚=0

ALGORITHM:
1. Input the two sequences x and h
2. Circularly convolve both to get the output of y.
3. Plot the sequences.

PROGRAM LOGIC:
1.Read the first input sequence, x[n] and plot.
2.Read the second input sequence, h[n] and plot
3.Find the length of x[n] and y[n], l1 and l2 respectively
4. Check if l1=l2. Proceed only if equal.
5.If l1 not equal to l2, zero padding is done to make l1=l2.
6.Initialize a loop variable for the number of output points.
10. For each output sample access the samples of y[n] in cyclic order.
11. Find the sum of products of x[n] and cyclically folded and shifted h[n] to get
circularconvoluted output.
12. Display and plot the output.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 36


DIGITAL SIGNAL PROCESSING LAB 18EEL67

PROGRAM
clc;
clear all;
L=4; // Length of the Sequence
N=4; // N −point DFT
x1 = [2, 1, 2,1];
x2 = [1, 2, 3, 4];
//Computing DFT
X1=fft (x1, -1);
X2=fft (x2, -1);
disp (X1,’DFT of x1[n] is X1(k)=’)
disp (X2,’DFT of x1[n] is X2(k)=’)
// Multiplication of 2 DFTs
X3=X1. * X2;
disp (X3,’DFT of x3[n] is X3(k)=’)
// Circular Convolution Result
x3=abs (fft (X3,1))
disp (x3,’Circular Convolution Result x3[n]=’)
//Result
//DFT of x1[n] is X1(k)=
//6 0 2 0
// DFT of x1[n] is X2(k)=
//10 −2+2i −2 −2−2i
// DFT of x3[n] is X3(k)=
// 60 0 −4 0
// Circular Convolution Result x3[n]=
//14 16 14 16

EEE DEPT, S.G.B.I.T, BELAGAVI-10 37


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 6b Date:

LINEAR CONVOLUTION BY DFT AND IDFT METHOD.

AIM: To perform Linear Convolution Using Circular Convolution method

OBJECTIVES: This experiment enables students


• To find linear convolution of right sided sequence using inbuilt SCILAB function “CONV” and
its theoretical method to verify the result

THEORY: Convolution is an integral concatenation of two signals. It has many applications in


numerous areas of signal processing. The most popular application is the determination of the
output signal of a linear time-invariant system by convolving the input signal with the impulse
response of the system. Note that convolving two signals is equivalent to multiplying the Fourier
transform of the two signals. In linear systems, convolution is used to describe the relationship
between three signals of interest: the input signal, the impulse response, and the output signal. n
linear convolution length of output sequence is, length(y(n)) = length(x(n)) + length(h(n)) – 1

Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by

For discrete time signals x(n) and h(n), is defined by

Where x(n) is the input signal and h(n) is the impulse response of the system.
ALGORITHM:
1.Input the two sequences x1 and x2
2.Use conv to get convoluted output.
3.Plot the sequences.

PROGRAM LOGIC:
The convolution Sum is given by

EEE DEPT, S.G.B.I.T, BELAGAVI-10 38


DIGITAL SIGNAL PROCESSING LAB 18EEL67

• The impulse response h[k] is time reversed (that is reflected about the origin) to obtain h[-k]
and then shifted by n to form h[n-k] = h[-(k-n)] which is a function of K with Parameter n.
• Two sequences x[k] and h[n-k] are multiplied together for all values of k with n fixed at some
value
• The product x[k]h[n-k] is summed over all k to produce a single output sample y[n]
• Steps 1 to 3 are repeated as n varies over -∞ to +∞ o produce the entire output y[n]

PROGRAM:
clc;
clear all;
h = [1, 2, 3]; // Impulse Response of LTI System
x = [1, 2, 2, 1]; // Input Response of LTI System
N1=length(x);
N2=length(h);
N=N1+N2-1
disp (N, ’Length of Output Response y(n)’)
//Padding zeros to Make Length of ‘h’and ‘x’
//Equal to length of output response ‘y’
h1= [h, zeros (1, N-N2)];
x1= [x, zeros (1, N-N1)];
//Computing FFT
H=fft (h1, -1);
X=fft (x1, -1);
//Multiplication of 2 DFTs
Y=X.*H
//Linear Convolution Result
y= abs(fft(Y,1))
disp (X, ‘DFT of i/p X(k)=’)
disp (H, ‘DFT of impulse sequence H(k)=’)
disp (Y, ’DFT of Linear Filter o/p Y(k)=’)
disp (y,’ Linear Convolution result y[n]=’)
//Result
//Length of Output Response y(n)
//6.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 39


DIGITAL SIGNAL PROCESSING LAB 18EEL67
//DFT of i/p X(k)=
//6 −3.4641016i 0 0 0 3.4641016i
//DFT of impulse sequence H(k)=
//6 0.5−4.330127i −1.5+0.8660254i 2 −1.5−0.8660254i 0.5+4.330127i
//DFT of Linear Filter o/p Y (k) =
//36 −15−1.7320508i 0 0 0 −15+1.7320508i
// Linear Convolution result y[n]=
// 1 4 9 11 8 3

EEE DEPT, S.G.B.I.T, BELAGAVI-10 40


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 7 Date:

SOLVING A GIVEN DIFFERENCE EQUATION


AIM: To solve a given difference equation
OBJECTIVES:

1. To solve the given difference equation (response of the filter) by varying the input
sequences as “Impulse input, Exponential input and Sinusoidal input” with and without
initial conditions using an inbuilt SCILAB FILTER function.

2. To verify the results theoretically.

THEORY: A General Nth Order Difference equation looks likely [n] + a1y[n-1] + a2y[n-2] + …+
aNy[n-N) = b0x[n] + b1x[n-1] + …. + bMx[n-M]. Here y[n] is “Most advanced” output sample and
y[n-m] is “Least advanced” output sample. The difference between these two index values is the
order of the difference equation. Here we have: n-(n-N) = N
We can rewrite the above equation as,
y[n] + ∑aiy[n-i] = ∑bi x[n-i]
y[n] becomes,
y[n] = -∑aiy[n-i] + ∑bi x[n-i]

EXAMPLE:
y[n-2] – 1.5y[n-1] + y[n] = 2x[n-2]

In general, we start with the “Most advanced” output sample. Here it is y [n+2].
So, here we need to subtract 2 from each sample argument. Thus, we
gety[n] – 1.5y[n-1] + y[n-2] = 2x[n-2]
 y[n] = 1.5y[n-1] - y[n-2] + 2x[n-2]
Let us assume our input x[n] = u[n] = 0 x<0
1 x≥0
In our example we have taken x[n] = u[n] = 0 x<0
1 0 ≤ x < 10
We need N past values to solve Nth order difference equation.
y [-2] = 1
y [-1] = 2

EEE DEPT, S.G.B.I.T, BELAGAVI-10 41


DIGITAL SIGNAL PROCESSING LAB 18EEL67
Compute y[n] for various values of n
y [0] = 1.5y[-1] – y [-2] + 2x [-2]
= 1.5*2 – 1 + 2*0 = 2
y [1] = 1.5y[0] – y [-1] + 2x [-1]
= 1.5*2 - 2 + 2*0 = 1
y [2] = 1.5y[1] – y [0] + 2x [0]
= 1.5*1 – 2 + 2*1 = 1.5
And so on…
ALGORITHM:
1. Input the two sequences as a and b representing the coefficients of y and x.
2. If IIR response, then input the length of the response required (say 100, which can be made
constant).
3. Compute the output response using the filter command.
3. Plot the input sequence and impulse response (and also step response, etc if required).
PROGRAM LOGIC:
1. For the given difference equation, rewrite the equation so that y[n] and its delayed
samples are on the LHS and x[n] and its delayed samples are on the RHS
2. Create a matrix A for the coefficients of y[n] and its delayed versions
3. Create a matrix B for the coefficients of x[n] and its delayed versions
4. Define the input signal unit impulse, unit step, exponential and sinusoidal

5. Find the response y[n] of the system defined by A and B coefficients to the input
excitation using filter command
6. Display and plot the impulse, step, exponential and steady state response y[n]

PROGRAM: SOLUTION OF DIFFERENCE EQUATION WITHOUT INITIAL


CONDITIONS
clc; % clear screen
clear all; % clear work space
%to find impulse response
N= input ('Enter the length of response = '); % define the length of output
b = [-2 5/4]; %coefficients of x(n)
a = [1 1/4 -1/8]; % coefficients of y(n)
x = [1, zeros (1, N-1)]; % define the impulse signal
EEE DEPT, S.G.B.I.T, BELAGAVI-10 42
DIGITAL SIGNAL PROCESSING LAB 18EEL67
n = 0: N-1; % define x axis
h = filter(b,a,x); % calculate the response of the system
disp('Response of filter =');
disp(h);
subplot (2,1,1);
plot2d3 (n,x); % graphical plot of input and output
title('Impulse input');
xlabel('n');
ylabel('x(n)');
subplot (2,1,2);
plot2d3 (n,h);
title('Impulse response');
xlabel('n');
ylabel('h(n)');
% to find step response
N = input ('Enter the length of response = '); % define the length of output
b = [-1 2]; % coefficients of x(n)
a = [1 -1/4 -3/8]; % coefficients of y(n)
x = [ones (1, N)]; % define the unit step signal
n = 0: 1: N-1; % define the x axis
h = filter(b,a,x); % calculate the step response
disp ('Response of filter =');
disp(h); % display the output
subplot (2,1,1); % graphical plot of input and output
plot2d3 (n,x);
title('Step input');
xlabel('n');
ylabel('x(n)');
subplot (2,1,2);
plot2d3 (n,h);
title ('Step response');
xlabel('n');
ylabel('h(n)');

EEE DEPT, S.G.B.I.T, BELAGAVI-10 43


DIGITAL SIGNAL PROCESSING LAB 18EEL67
OUTPUT:
Impulse Response:
Enter the length of response = 10
Response of filter =
-2.0000 1.7500 -0.6875 0.3906 -0.1836 0.0947 -0.0466 0.0235 -0.0117
0.0059

Fig.7.1: Impulse response for a given difference equation.

Step Response:
Enter the length of response = 10
Response of filter =
-1.0000 0.7500 0.8125 1.4844 1.6758 1.9756 2.1223 2.2714 2.3637 2.4427

EEE DEPT, S.G.B.I.T, BELAGAVI-10 44


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.7.2: Step response for a given difference equation.

OUTCOMES:
Acquire the knowledge of construction of different types of digital filters.

Viva Questions:
1. What is Infinite Impulse Response?
When length of h[n] is infinite it is called infinite impulse response. E.g. h[n] = (½)n u[n]

2. What is Steady State Response?


Everlasting response of the system that depends on magnitude response and phase response
of the system is steady state response of the system.

3. What is Finite Impulse Response?


When length of h[n] is finite it is called finite impulse response.

4. What is Finite Impulse Response?


When length of h[n] is finite it is called finite impulse response.

5. What is zero input response?


If the initial state of the system is NOT zero and the input x[n] = 0 to all n, then the output
of the system with zero input is called the zero-input response or natural response or free
response of the system. When length of h[n] is finite it is called finite impulse response.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 45


DIGITAL SIGNAL PROCESSING LAB 18EEL67
6. What is zero state step response?
If the initial state of the system is zero and the input x[n]=u[n] then the output of the
system is called zero step response of the system.
7. What is impulse response and what is its significance?
The response or output of an LTI system for unit impulse input δ(n) is called impulse
response. It is denoted by h(n). The response y(n) of an LTI system for any arbitrary input x(n) is
given by convolution of impulse response and input i. e. y(n) = x(n)* h(n)

8. Define the transfer function of an LTI system


The transfer function of an LTI system is defined as the ratio of Z transform of output to Z
transform of input.

9. What is BIBO stability? What is the condition to be satisfied foe stability?


A system is said to be BIBO stable if and only if every bounded input produces a bounded
output. The condition to be satisfied for the stability of an LTI system is that the impulse response
of the system should be absolutely summable.
10. Define the transfer function of an LTI system

The transfer function of an LTI system is defined as the ratio of Z transform of output to Z
transform of input.

11. What do you mean by real time signal? Give example.

Signal is processed with the same speed it is captured. Signal is captured, sampled and
processed with the same speed. Signal is not stored before processing. Entire input signal never
available before processing. Processed signal can be stored. For example, in digital telephone system,
Signal is captured, Sampled, Processed, and Transmitted and made it available to the end user. Real
Time Processing is Online Processing.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 46


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 8 Date:

Calculation of DFT and IDFT by FFT

a. AIM: N=8; DIT−FFT without using in built Sci-lab FFT function

OBJECTIVES:
After completing this lab, student will be able to Study the importance of DFT using Fast Fourier
Transform (FFT) method.

THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\displaystyle O\left(N^{2}\right)}{\displaystyle
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\displaystyle
O(N\log N)}O(N\log N), where {\displaystyle N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.

PROGRAM:
clc;
clear;
Let x(n) = {1, 2, 1, 2, 0, 2, 1, 2}
Let us begin with the programming for understanding, let us write the given data as
x (0) = 1; x (1) = 2, x (2) = 1, x (3) = 2, x (4) = 0, x (5) = 2, x (6) = 1, x (7) = 2
x0=1; //DIT−FFT, so arranging the input in bit−reversed order
x4=0; //DIT−FFT, so arranging the input in bit−reversed order
x2=1; //DIT−FFT, so arranging the input in bit−reversed order
EEE DEPT, S.G.B.I.T, BELAGAVI-10 47
DIGITAL SIGNAL PROCESSING LAB 18EEL67
x6=1; //DIT−FFT, so arranging the input in bit−reversed order
x1=2; //DIT−FFT, so arranging the input in bit−reversed order
x5=2; //DIT−FFT, so arranging the input in bit−reversed order
x3=2; //DIT−FFT, so arranging the input in bit−reversed order
x7=2; //DIT−FFT, so arranging the input in bit−reversed order
//Stage I computation
x0a=x4+x0; //Computing Stage−I output at line 1
disp (x0a, ’Stage−I output at line 1=’)
x4b = (x4 - x0) * (-1); //Computing Stage−I output at line 2
disp (x4b, ’Stage−I output at line 2=’)
x2c=x6+x2; //Computing Stage−I output at line 3
disp (x2c, ’Stage−I output at line 3=’)
x6d = (x6 - x2) * (-1); //Computing Stage−I output at line 4
disp (x6d, ’Stage−I output at line 4=’)
x1e=x5+x1; //Computing Stage−I output at line 5
disp (x1e, ’Stage−I output at line 5=’)
x5f = (x5 - x1) * (-1); // Computing Stage−I output at line 6
disp (x5f, ’Stage−I output at line 6=’)
x3g=x7+x3; //Computing Stage−I output at line 7
disp (x3g, ’Stage−I output at line 7’)
x7h = (x7 - x3) * (-1); //Computing Stage−I output at line 8
disp (x7h, ’Stage−I output at line 8=’)
Stage−I output at line 4 and line 8 is to be multiplied by twiddle factor having value (−j)
x6d1=(x6d) * (-sqrt (-1));
x7h1=(x7h) * (-sqrt (-1));
disp (x6d1, ’Stage−I output (i.e. input to stage −II) after multiplication by twiddle factor value of
(−j) at line 4=’)
disp (x7h1, ’Stage−I output (i.e. input to stage −II) after multiplication by twiddle factor value of
(−j) at line 8=’)
//Stage−II Computations
x0a_stageII_output=x2c+x0a; //Computing Stage−II output at line 1
disp (x0a_stageII_output, ’Stage−II output at line 1=’)
x4b_stageII_output=x6d1+x4b; //Computing Stage−II output at line 2
disp (x4b_stageII_output, ’Stage−II output at line 2=’)
x2c_stageII_output = (x2c - x0a) * (-1); // Computing Stage−II output at line 3
disp (x2c_stageII_output, ’Stage−II output at line 3=’)
x6d_stageII_output = (x6d1 - x4b) * (-1); // Computing Stage−II output at line 4

EEE DEPT, S.G.B.I.T, BELAGAVI-10 48


DIGITAL SIGNAL PROCESSING LAB 18EEL67
disp (x6d_stageII_output, ’Stage−II output at line 4=’)
x1e_stageII_output=x3g+x1e; //Computing Stage−II output at line 5
disp (x1e_stageII_output, ’Stage−II output at line 5=’)
x5f_stageII_output = x7h1+x5f; //Computing Stage−II output at line 6
disp (x5f_stageII_output, ’Stage−II output at line 6=’)
x3g_stageII_output = (x3g - x1e) *(-1); //Computing Stage−II output at line 7
disp (x3g_stageII_output, ’Stage−II output at line 7=’)
x7h_stageII_output= (x7h1 - x5f) *(-1); //Computing Stage−II output at line 8
disp (x7h_stageII_output, ’Stage−II output at line 8=’)
//Stage−II output at line 6, line 7 and line 8 are to be multiplied by twiddle factor having value
(0.707 − j0.707), (−j) and (−0.707− j0.707) respectively
x5f_stgII_op_multi_by_tw = (x5f_stageII_output) *(0.707 -(sqrt (-1)) *(0.707));
disp (x5f_stgII_op_multi_by_tw, ’Stage−II output at line 6 after multiplication by twiddle factor=’)
x3g_stgII_op_multi_by_tw = (x3g_stageII_output) *(-(sqrt (-1)));
disp (x3g_stgII_op_multi_by_tw, ’Stage−II output at line 7 after multiplication by twiddle factor=’)
x7h_stgII_op_multi_by_tw =(x7h_stageII_output) *(-0.707-(sqrt (-1)) *(0.707));
disp (x7h_stgII_op_multi_by_tw, ’Stage−II output at line 8 after multiplication by twiddle factor=’)
//Stage−III Computations (i.e. Computations for the final stage)
X0=x1e_stageII_output + x0a_stageII_output; //Computing X (0) at last stage
X1=x5f_stgII_op_multi_by_tw + x4b_stageII_output; //Computing X (1) at last stage
X2=x3g_stgII_op_multi_by_tw + x2c_stageII_output; //Computing X (2) at last stage
X3=x7h_stgII_op_multi_by_tw + x6d_stageII_output; //Computing X (3) at last stage
X4 = (x1e_stageII_output - x0a_stageII_output) *(-1); //Computing X (4) at last stage
X5 = (x5f_stgII_op_multi_by_tw - x4b_stageII_output) *(-1); //Computing X (5) at last stage
X6 = (x3g_stgII_op_multi_by_tw - x2c_stageII_output) *(-1); //Computing X (6) at last stage
X7 = (x7h_stgII_op_multi_by_tw - x6d_stageII_output) *(-1); //Computing X (7) at last stage
disp (X0, ’X (0) =’)
disp (X1, ’X (1) =’)
disp (X2, ’X (2) =’)
disp (X3, ’X (3) =’)
disp (X4, ’X (4) =’)
disp (X5, ’X (5) =’)
disp (X6, ’X (6) =’)
disp (X7, ’X (7) =’)
disp ({, X0, X1, X2, X3, X4, X5, X6, X7,}, ’So, the DFT of x(n) using Decimation−in−Time Fast
Fourier Transform (DIT−FFT) is X(k)=’)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 49


DIGITAL SIGNAL PROCESSING LAB 18EEL67

b. AIM: N=8; IDIT−FFT without using in built Sci-lab FFT function.


OBJECTIVES:
After completing this lab, student will be able to Study the importance of DFT using Fast Fourier
Transform (FFT) method.

THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.

PROGRAM:
clc;
clear;
//Let X(k) = {11, 1, −1, 1, −5, 1, −1, 1}
//Let us begin with the programming for understanding, let us write the given data as
X (0) = 11; X (1) = 1, X (2) = −1, X (3) = 1, X (4) = −5, X (5) = 1, X (6) = −1, X (7) = 1
X0_conj =11; //IDIT−FFT, so arranging the input in bit−reversed order
X4_conj =-5; //IDIT−FFT, so arranging the input in bit−reversed order
X2_conj = -1; //IDIT−FFT, so arranging the input in bit−reversed order
X6_conj = -1; //IDIT−FFT, so arranging the input in bit−reversed order
X1_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X5_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X3_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X7_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order

EEE DEPT, S.G.B.I.T, BELAGAVI-10 50


DIGITAL SIGNAL PROCESSING LAB 18EEL67
Disp (X0_conj, ’X∗ (0) =’)
disp (X4_conj, ’X∗ (4) =’)
disp (X2_conj, ’X∗ (2) =’)
disp (X6_conj, ’X∗ (6) =’)
disp (X1_conj, ’X∗ (1) =’)
disp (X5_conj, ’X∗ (5) =’)
disp (X3_conj, ’X∗ (3) =’)
disp (X7_conj, ’X∗ (7) =’)
//Stage I computation
X0a = X4_conj + X0_conj; //Computing Stage−I output at line 1
disp (X0a, ’Stage−I output at line 1=’)
X4b = (X4_conj - X0_conj) *(-1); //Computing Stage−I output at line 2
disp (X4b, ’Stage−I output at line 2=’)
X2c = X6_conj + X2_conj; //Computing Stage−I output at line 3
disp (X2c, ’Stage−I output at line 3=’)
X6d = (X6_conj - X2_conj) *(-1); //Computing Stage−I output at line 4
disp (X6d, ’Stage−I output at line 4=’)
X1e = X5_conj + X1_conj; //Computing Stage−I output at line 5
disp (X1e, ’Stage−I output at line 5=’)
X5f = (X5_conj - X1_conj) *(-1); //Computing Stage−I output at line 6
disp (X5f, ’Stage−I output at line 6=’)
X3g = X7_conj + X3_conj; //Computing Stage−I output at line 7
disp (X3g, ’Stage−I output at line 7’)
X7h = (X7_conj - X3_conj) *(-1); //Computing Stage−I output at line 8
disp (X7h, ’Stage−I output at line 8=’)
//Stage−I output at line 4 and line 8 is to be multiplied by twiddle factor having value (−j)
X6d’= (X6d) *(-sqrt (-1));
X7h’= (X7h) *(-sqrt (-1));
disp (X6d’, ’Stage−I output (i.e. input to stage−II) after multiplication by twiddle factor value of
(−j) at line 4 =’)
disp (X7h’, ’Stage−I output (i.e. input to stage−II) after multiplication by twiddle factor value of
(−j) at line 8 =’)
//Stage−II Computations
X0a_stageII_output = X2c + X0a; //Computing Stage−II output at line 1
disp (X0a_stageII_output, ’Stage−II output at line 1=’)
X4b_stageII_output = X6d’+ X4b; //Computing Stage−II output at line 2
disp (X4b_stageII_output, ’Stage−II output at line 2=’)
X2c_stageII_output = (X2c - X0a) *(-1); //Computing Stage−II output at line 3

EEE DEPT, S.G.B.I.T, BELAGAVI-10 51


DIGITAL SIGNAL PROCESSING LAB 18EEL67
disp (X2c_stageII_output, ’Stage−II output at line 3=’)
X6d_stageII_output = (X6d’ - X4b) *(-1); //Computing Stage−II output at line 4
disp (X6d_stageII_output, ’Stage−II output at line 4=’)
X1e_stageII_output = X3g + X1e; //Computing Stage−II output at line 5
disp (X1e_stageII_output, ’Stage−II output at line 5=’)
X5f_stageII_output = X7h’+ X5f; //Computing Stage−II output at line 6
disp (X5f_stageII_output, ’Stage−II output at line 6=’)
X3g_stageII_output = (X3g - X1e) *(-1); //Computing Stage−II output at line 7
disp (X3g_stageII_output, ’Stage−II output at line 7=’)
X7h_stageII_output = (X7h’ - X5f) *(-1); //Computing Stage−II output at line 8
disp (X7h_stageII_output, ’Stage−II output at line 8=’)
//Stage−II output at line 6, line 7 and line 8 are to be multiplied by twiddle factor having value
(0.707 − j0.707), (−j) and (−0.707− j0.707) respectively
X5f_stageII_output_multiplied_by_twiddle = (X5f_stageII_output) *(0.707 -(sqrt (-1)) *(0.707));
disp (X5f_stageII_output_multiplied_by_twiddle, ’Stage−II output at line 6 after multiplication by
twiddle factor=’)
X3g_stageII_output_multiplied_by_twiddle = (X3g_stageII_output) *(-(sqrt (-1)));
disp (X3g_stageII_output_multiplied_by_twiddle, ’Stage−II output at line 7 after multiplication by
twiddle factor=’)
X7h_stageII_output_multiplied_by_twiddle = (X7h_stageII_output) *(-0.707-(sqrt (-1)) *(0.707));
disp (X7h_stageII_output_multiplied_by_twiddle, ’Stage−II output at line 8 after multiplication by
twiddle factor=’)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 52


DIGITAL SIGNAL PROCESSING LAB 18EEL67

c. AIM: Four-point DIF−FFT without using in built Sci-lab FFT function


OBJECTIVES:
After completing this lab, student will be able to Study the importance of DFT using Fast Fourier
Transform (FFT) method.

THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.

PROBLEM:
Computing four-point DFT for x(n) = {1, 2, 3, 4} using Decimation in Frequency−Fast Fourier
transform (i. e. DIF−FFT) without using readymade in-built Sci-lab functions for DFT/FFT.

PROGRAM:
clc;
clear;
x0=1;
x1=2;
x2=3;
x3=4;
//Stage I computation
x0a = x2+x0; //Computing Stage−I output at position 1
disp(x0a, ’Stage−I output at position 1’)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 53


DIGITAL SIGNAL PROCESSING LAB 18EEL67
x1b = (x3+x1); //Computing Stage−I output at position 2
disp(x1b, ’Stage−I output at position 2’)
x2c = (x2 - x0) *(-1); //Computing Stage−I output at position 3
disp(x2c, ’Stage−I output at position 3’)
x3d = (x3 - x1) *(-1); //Computing Stage−I output at position 4
disp(x3d, ’Stage−I output at position 4’)
//Stage−II computation
x3d1 = x3d *(-sqrt (-1)); //Multiply by (−j) in the last line
disp(x3d1, ’Stage−II input at the fourth line’)
X0 = x1b + x0a; //Computing final stage output value X (0)
disp(X0, ’The final stage output X(0)=’)
X2 = (x1b - x0a) *(-1); //Computing final stage output value X (1)
disp(X2, ’The final stage output X(2)=’)
X1 = (x3d1 + x2c); //Computing final stage output value X (2)
disp(X1, ’The final stage output X(1)=’)
X3 = (x3d1 - x2c) *(-1); //Computing final stage output value X (3)
disp(X3, ’The final stage output X(3)=’)
disp({,X0, X1, X2, X3,}, ’So, the DFT of x(n) using Decimation−in−Frequency Fast Fourier
Transform (DIF−FFT) is X(k)=’)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 54


DIGITAL SIGNAL PROCESSING LAB 18EEL67

d. AIM: Four-point IDIF−FFT without using in built Sci-lab FFT function


OBJECTIVES:
After completing this lab, student will be able to Study the importance of DFT using Fast Fourier
Transform (FFT) method.

THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.

PROBLEM:
Computing four-point IDFT for X(k) = {10, −2+2j, −2, −2−2j} using Inverse Decimation in
Frequency−Fast Fourier transform (i. e. IDIF−FFT) without using readymade in- built Sci-lab
functions for IDFT/IFFT.

PROGRAM:
clc;
clear;
//Let us begin with the programming for understanding, let us write the given data as
//X (0) = 10; X (1) = −2+2j, X (2) =−2, X (3) = −2−2j
X0c = 10; //X0c means complex conjugate of XO
X1c = (-2) +((-1) *(2) *(sqrt (-1))); //X1c means complex conjugate of X1
X2c = -2; //X2c means complex conjugate of X2
X3c = (-2) -((-1) *(2) *(sqrt (-1))); //X3c means complex conjugate of X3

EEE DEPT, S.G.B.I.T, BELAGAVI-10 55


DIGITAL SIGNAL PROCESSING LAB 18EEL67
disp(X0c, ’X∗(0)=’)
disp(X1c, ’X∗(1)=’)
disp(X2c, ’X∗(2)=’)
disp(X3c, ’X∗(3)=’)
x0_star = ((X3c + X1c) *(1) +(X2c + X0c) *(1)) *(1/4); //Computing x∗ (0)
disp(x0_star, ’x∗(0)=’)
x2_star = ((((X3c + X1c) *(1)) -((X2c + X0c) *(1))) *(-1)) *(1/4); //Computing x∗ (2)
disp(x2_star, ’x∗(2)=’)
x1_star = ((X3c - X1c) *(-1) *(- sqrt (-1)) +(X2c - X0c) *(-1)) *(1/4); //Computing x∗ (1)
disp(x1_star, ’x∗(1)=’)
//Computing x∗ (3)
x3_star = ((((X3c - X1c) *(-1) *(- sqrt (-1)) -(X2c - X0c) *(-1))) *(-1)) *(1/4);
disp(x3_star, ’x∗(3)=’)
disp({,x0_star, x1_star, x2_star, x3_star,}, ’x ∗(n)=’)
//The computed value is x∗(n). But we need x(n) as final output.
//We will separate real part of x∗(n)
//We will separate imaginary part of x∗(n) and take its complex conjugate by multiplying by a factor
of (−1)
x0_star_real = real(x0_star);
x0_star_conj = (-1) *(imag(x0_star));
x1_star_real = real(x1_star);
x1_star_conj = (-1) *(imag(x1_star));
x2_star_real = real(x2_star);
x2_star_conj = (-1) *(imag(x2_star));
x3_star_real = real(x3_star);
x3_star_conj = (-1) *(imag(x3_star));
//Finally, we will add the real part and the imaginary part whose complex conjugate is taken to get
x (0), x (1), x (2) and x (3)
x0 = x0_star_real + x0_star_conj; //Computing x (0)
x1 = x1_star_real + x1_star_conj; //Computing x (1)
x2 = x2_star_real + x2_star_conj; //Computing x (2)
x3 = x3_star_real + x3_star_conj; //Computing x (3)
disp({,x0, x1, x2, x3,}, ’So, the IDFT of X(k) using Inverse Decimation−in−Frequency Fast Fourier
Transform (IDIF−FFT) is x(n)=’)

EEE DEPT, S.G.B.I.T, BELAGAVI-10 56


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 9 Date:

DESIGN AND IMPLEMENTATION OF FIR FILTER


AIM: To Design and implementation of FIR filter to meet given specifications (low pass filter
using hamming window).

OBJECTIVES:
After completing this lab, student will be able to Study the importance of windows to design FIR filter
THEORY: The FIR filters are of non-recursive type, whereby the present output sample is
depending on the present input sample and previous input samples. The transfer function of a FIR
causal filter is given by,
𝑁−1
𝐻(𝑍) = ∑ 𝑛=0 h(n)z-n

Where h(n) is the impulse response of the filter.

The Fourier transform of h(n) is


𝑁−1
−𝑗𝜔𝑛
H(ejw) = ∑ 𝑛=0 ℎ(𝑛)𝑒

In the design of FIR filters most commonly used approach is using windows. The desired frequency
response Hd(ejw) of a filter is periodic in frequency and can be expanded in Fourier series. The
resultant series is given by,
𝜋
hd(n) = (1/2𝜋) ∫ H(ejw)𝑒𝑗𝑤𝑛𝑑𝑤
−𝜋

This is known as Fourier series coefficients having infinite length. One possible way of obtaining
FIR filter is to truncate the infinite Fourier series at n = ± [(N-1)/2] Where N is the length of the
desired sequence.

The Fourier coefficients of the filter are modified by multiplying the infinite impulse response with
a finite weighing sequence w(n) called a window.
Where w(n) = w(-n) ≠ 0 for |n| ≤ [(N-1)/2]
=0 for |n| > [(N-1)/2]
After multiplying w(n)with hd(n), we get a finite duration sequence h(n) that satisfies the desired
magnitude response,

EEE DEPT, S.G.B.I.T, BELAGAVI-10 57


DIGITAL SIGNAL PROCESSING LAB 18EEL67
h(n) = hd(n) w(n) for |n| ≤ [(N-1)/2]
=0 for |n| > [(N-1)/2]
The frequency response H(ejw) of the filter can be obtained by convolution of Hd(ejw) and W(ejw)
is given by,
𝜋
H(ejw) = (1/2𝜋) ∫−𝜋 Hd(ejθ) W(ej(w − θ) dθ

H(ejw) = Hd(ejw) * W(ejw)

EXAMPLE:
Here we design a low pass filter using hamming window. Hamming window function is given by,
wH(n) = 0.54 + 0.46 cos ((2πn)/(N-1)) ;–(N-1)/2 ≤ n ≤ (N-1)/2
=0 ; otherwise
The frequency response of Hamming window is,
WH(ejw) = 0.54[(sin(wN/2))/(sin(w/2)) + 0.23[sin (wN/2 – πN/N – 1)/sin (w/2 – π/N -1)]+ 0.23[sin
(wN/2 + πN/N – 1)/sin (w/2 + π/N – 1)]

ALGORITHM:
1. Input the Pass and Stop band edge in radians.
2. Compute N=order of the filter.
3. Obtain cutoff frequency of the filter.
4. Obtain Impulse response of FIR filter
5. Plot the Response of the filter.

PROGRAM: DESIGN AND IMPLEMENTATION OF FIR FILTER


clc;
clear all;
wp = input (‘Enter the 'Pass band edge in radians = '); //Define pass and stop band frequency
ws = input ('Enter the Stop band edge in radians = ');
wt = ws-wp;
n1 = ceil (8*pi/wt); //Round off the order of the filter nearest to integer value
N = n1 + rem (n1-1, 2);
disp(‘order of the FIR filter N =’);
disp(N);

EEE DEPT, S.G.B.I.T, BELAGAVI-10 58


DIGITAL SIGNAL PROCESSING LAB 18EEL67
wn = (hamming(N));
Wc1 = wp + wt/2;
Wc = Wc1/pi;
disp (‘cut off frequency =’);
disp(Wc);
h = fir1(N-1, Wc, wn); //obtain the frequency response using the built-in function
disp ('Impulse Response of FIR filter=');
disp(h);
fiqure(1);
freqz(h);
figure(2);
n = 0:1: N-1;
plot2d3 (n,h);
xlabel(‘n’);
ylabel(‘h(n)’);
title (‘Impulse Response of Filter’);

OUTPUT:
enter the Pass band edge in radians = 0.375*pi
enter the stop band edge in radians = 0.5*pi
Order of the FIR filter N = 65

Impulse response of FIR filter =


-0.0000 -0.0008 -0.0007 0.0004 0.0013 0.0006 -0.0014 - 0.0022 0.0000 0.0032
0.0029 -0.0019 -0.0058 -0.0026 0.0056 0.0086 -0.0000 -0.0115 -0.0101 0.0063
0.0190 0.0084 -0.0179 -0.0272 0.0000 0.0377 0.0346 -0.0231 -0.0769 -0.0398
0.1117 0.2938 0.3754 0.2938 0.1117 -0.0398 -0.0769 -0.0231 0.0346 0.0377
0.0000 -0.0272 -0.0179 0.0084 0.0190 0.0063 -0.0101 -0.0115 -0.0000 0.0086
0.0056 -0.0026 -0.0058 -0.0019 0.0029 0.0032 0.0000 -0.0022 -0.0014 0.0006
0.0013 0.0004 -0.0007 -0.0008 -0.0000

EEE DEPT, S.G.B.I.T, BELAGAVI-10 59


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.9.1: Plot of Frequency response of FIR filter.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 60


DIGITAL SIGNAL PROCESSING LAB 18EEL67

OUTCOME:

This experiment enables the students to acquire the knowledge of advantage and disadvantages of filter
design using various windows techniques.

Viva Questions:

1. What is Finite Impulse Response?


When length of h[n] is finite it is called finite impulse response.

2. What is Finite Impulse Response?


When length of h[n] is finite it is called finite impulse response.

3. What is a digital filter?


Digital filters are a very important part of DSP. Filters have two uses: signal separation and
signal restoration. These problems can be attacked with either analog or digital filters. Digital filters
are used for two general purposes: separation of signals that have been combined, and restoration of
signals that have been distorted in some way.

4. How to find output of the FIR filter using FFT?


In FIR filter length of h[n] is finite. Output of the filter is always linear convolution of
impulse response with the input of the signal. To find output i.e. to find LC by FFT

5. What is frequency response?


Frequency response means magnitude response and phase response.

6. How to find output of FIR filter for long input sequence.


In FIR filter length of h[n] is finite. Output of the filter is always Linear Convolution of
impulse response with the input of the signal. To find output of digital FIR filter FFT technique is
used. But for Long data sequence, direct FFT technique is not suitable. For long data sequence,
Overlap Add Method using FFT or Overlap Save Method using FFT is used.

7. How to find output of FIR filter for real time input signal?
In real time application entire input is not available and input signal has to be processed
online. Length of input signal depends on application. It can be long sequence also. In FIR filter
length of h[n] is finite. Output of the filter is always Linear Convolution of impulse response with
the input of the signal. To find output of digital FIR filter, Overlap Add Method using FFT or
Overlap Save Method using FFT is used.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 61


DIGITAL SIGNAL PROCESSING LAB 18EEL67

8. What are the disadvantages of FIR Filters (compared to IIR filters)?


Compared to IIR filters, FIR filters sometimes have the disadvantage that they require more
memory and/or calculation to achieve a given filter response characteristic.

9. Explain the concept of Linear Phase and its importance.


If the Phase Response is Linear the output of the Filter during pass-band is delayed input.
II. If the phase Response is non-Linear the output of the filter during pass-band is distorted one. The
linear Phase characteristic is important when the phase distortion is not tolerable. FIR Filter can be
designed with linear phase characteristic. In application like data transmission, speech processing
etc phase distortion cannot be tolerated and here linear phase characteristic of FIR filter is useful.

10. What is the role of window in the design of FIR filter? Name the few types of windows.
FIR filter is designed by truncating infinite samples of hd[n] by using window function.
Examples of window function include, Hamming window, Bartlet Window, Hanning window,
Blackman window etc.

11. Why rectangular window is not preferred for FIR filter design?
Rectangular window function has As = 21 db which is very small compared to other window
function. Larger value of as desired.

12. Explain how to find output of digital FIR filter in real time application.
In real time applications, output of FIR filter is obtained using overlap add method /
overlap save method.

13. What are the desirable characteristics of window Function?


The Fourier Transform of the window function W(ejw) should have a small width of the
linear Phase characteristic is important when the phase distortion is not tolerable. FIR Filter can be
designed with linear phase characteristic. In application like data transmission, speech processing
etc. phase distortion cannot be tolerated and here linear phase characteristic of FIR filter is useful.

14. Why FIR filters are called as Non-recursive filters?


In FIR filter output depends only on input values. It doesn't depend on output values. e.g.
y[n] = x[n] + x[n-1] Therefore FIR filters are also called as Non-Recursive Filters.

15. Explain how to find output of digital FIR filter in real time application.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 62


DIGITAL SIGNAL PROCESSING LAB 18EEL67
In real time applications, output of FIR filter is obtained using overlap add method /
overlap save method.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 63


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Experiment No: 10 Date:

DESIGN AND IMPLEMENTATION OF IIR FILTER


AIM: Design and implementation of IIR filter to meet given specifications.

OBJECTIVES:
After completing this lab, student will be able to Study the importance of Butterworth filter and
Chebyshev filter approximation to design IIR filter.

THEORY: Basically, digital filter is a linear time-invariant discrete time system.


Infinite Impulse Response (IIR) filter: IIR filters are of recursive type, whereby the present output
sample depends on the present input, past input samples and output samples. The impulse response
h(n) for a realizable filter is, h(n) = 0 for n≤0. And for stability, it must satisfy the condition,

∑|h(n)| < ∞
𝑛=0

ALGORITHM:
1. From the given specifications find the order of the filter N.
2. Round off it to the next higher integer.
3. Find the transfer function H(s) for Ωc = 1rad/sec for the value of N.
4. calculate the value of cutoff frequency Ωc
5. find the transfer function Ha(s) for the above value of Ωc by substituting
s→ (s/ Ωc) in H(s).
6. Plot the frequency response of the filter.

PROGRAM: DESIGN AND IMPLEMENTATION OF BUTTERWORTH FILTER


clc;
clear all;
close all;
fp = input (‘Enter the Pass band frequency in Hz = '); //Define pass stop and ripple frequency
fs = input ('Enter the Stop band frequency in Hz = ');

EEE DEPT, S.G.B.I.T, BELAGAVI-10 64


DIGITAL SIGNAL PROCESSING LAB 18EEL67
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*pi*Fp/ws;// Analog frequency
ws=2*pi*Fs/ws;
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);
disp(‘Normalized cut off frequency = ‘);
disp(wn);
[num, den] = butter (n, wc,'s'); // analog filter
transfer[b,a] = bilinear(num, den,1);
Freqz (b, a, 512, Fs);
printsys(b,a,’z’);

OUTPUT:
enter the Pass band edge frequency in Hz = 500
enter the stop band frequency in Hz = 750
enter the sampling frequency in Hz = 2000
enter the pass band ripple n db = 3.01
enter the stop band attenuation in db = 15
order of the filter N = 2
Normalised cutoff frequency = 2.052
num/den = 0.30053 z^2 + 0.60106 z + 0.30053

z^2 + 0.030385 z + 0.17174

EEE DEPT, S.G.B.I.T, BELAGAVI-10 65


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.10.1: Plot of Frequency response of IIR filter.

PROGRAM: DESIGN OF CHEBYSHEV FILTER


clc;
clear all;
close all;
fp = input (‘Enter the Pass band frequency in Hz = '); //Define pass stop and ripple frequency
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 the Stop band ripple in db:');
wp=2*pi*Fp/ws;// Analog frequency
ws=2*pi*Fs/ws;
Up = 2*tan(wp/2);
// Prewrapped frequency
Us = 2*tan(ws/2);
[N,wn]= cheb1ord (Up,Us,Ap,As,'s'); //Calculate order and cutoff freq

EEE DEPT, S.G.B.I.T, BELAGAVI-10 66


DIGITAL SIGNAL PROCESSING LAB 18EEL67
Disp(‘order of the filter N =’);
disp(N);
disp (‘Normalized cut off frequency = ‘);
disp(Wn);
% analog filter transfer
[num, den] = cheby1(N, Ap, Wn,'s');
[b,a] = bilinear(num, den,1);
Freqz (b, a, 512, Fs);
Printsys(b,a,’z’);

OUTPUT:
enter the Pass band edge frequency in Hz = 100
enter the stop band frequency in Hz = 500
enter the sampling frequency in Hz = 4000
enter the pass band ripple n db = 2
enter the stop band attenuation in db = 20
order of the filter N = 2
Normalized cutoff frequency = 0.1574
num/den =
0.0037904 z^2 + 0.0075808 z + 0.0037904

z^2 - 1.8625 z + 0.88157

EEE DEPT, S.G.B.I.T, BELAGAVI-10 67


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Fig.10.2: Plot of Frequency response of IIR filter.

OUTCOME:
This experiment enables students to design and implement various IIR filters using less memory
and calculations.
Viva Questions:
1. What is Infinite Impulse Response (IIR) filter?
If the impulse response of the system is of infinite duration, the system is said to be IIR
filter system.

2. How to find output of IIR filter for real time input signal?
In real time application entire input is not available and input signal has to be processed
online. Length of input signal depends on application. It can be long sequence also. In IIR filter
length of h[n] is infinite. Output of the filter is always Linear Convolution of impulse response with
the input of the signal. To find output of digital IIR filter, Overlap Add Method using FFT or Overlap
Save Method using FFT cannot be used. Output of digital IIR filter is calculated using difference
equation recursively.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 68


DIGITAL SIGNAL PROCESSING LAB 18EEL67

3. How to find output of IIR filter for long input sequence?


In IIR filter length of h[n] is infinite. Output of the filter is always Linear Convolution of
impulse response with the input of the signal. To find output of digital IIR filter, Overlap Add
Method using FFT or Overlap Save Method using FFT cannot be used. Output of digital IIR filter is
calculated using difference equation recursively.

4. Explain how to find output of digital IIR filter in real time application.
In real time applications, output of IIR filter can be obtained by evaluating difference
equation.

5. Why IIR filters are called as recursive filters?


In IIR filter output depends on output values. e.g. y[n] = x[n] + x[n-1] + y[n] + y[n-1].
Therefore, IIR filters are also called as Recursive Filters.

6. Explain how to find output of digital IIR filter in real time application.
In real time applications, output of IIR filter can be obtained by evaluating difference
equation.

7. What are the advantages of IIR filters (compared to FIR filters)?


IIR filters can achieve a given filtering characteristic using less memory and calculations
than a similar FIR filter.

EEE DEPT, S.G.B.I.T, BELAGAVI-10 69


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Behind the Syllabus Experiment


Experiment No: 11 Date:

AUTO AND CROSSS CORRELATION

AIM: Autocorrelation of a given sequence and verification of its properties

OBJECTIVES: This experiment enables students to


• Learn how to find autocorrelation of input signal.
• Learn the properties of autocorrelation

THEORY: Correlation: Correlation determines the degree of similarity between two signals. If
the signals are identical, then the correlation coefficient is 1; if they are totally different, the
correlation coefficient is 0, and if they are identical except that the phase is shifted by exactly
1800(i.e. mirrored), then the correlation coefficient is -1.
Autocorrelation: The Autocorrelation of a sequence is correlation of a sequence with itself. The
autocorrelation of a sequence x(n) is defined by,

𝑅𝑥𝑥(𝑘) = ∑∞𝑛=−∞ 𝑥(𝑛) 𝑥(𝑛 − 𝑘)k = 0, ±1, ±2, ±3…


Where k is the shift parameter
or equivalently
𝑅𝑥𝑥(𝑘) = ∑𝑛=−∞
∞ 𝑥(𝑛 + 𝑘) 𝑥(𝑛)k = 0, ±1, ±2, ±3 …

Properties of Autocorrelation:
1. Periodicity: Rxx(k0) = Rxx(0) then Rxx(k) is periodic with period k0
2. Autocorrelation function is symmetric. i.e. Rxx(m) = Rxx(-m)
3. Mean square value: autocorrelation function at k=0, is equal to mean square value of the
process. Rxx(0) = E{|x(n)|2}≥0

ALGORITHM:
1. Input the sequence as x.
2. Use the ‘xcorr’ function to get auto correlated output r.
3. Plot the sequences.
PROGRAM LOGIC:
1. Read the input sequence x[n]

EEE DEPT, S.G.B.I.T, BELAGAVI-10 70


DIGITAL SIGNAL PROCESSING LAB 18EEL67

2. Auto correlate the signal using xcorr(x,x)

3. Display the auto correlation result on a suitable axis.

4. Verify the correlation property Rxx(0)= energy(x)

5. Verify the symmetric property

CALCULATION:

X(n) ={ 3, 4, 5, 6}

Put K=0 in the above equation, we get

Put K=1 in the above equation, we get

Put K=2 in the above equation, we get

Put K=3 in the above equation, we get

Put K=-1 in the above equation, we get

EEE DEPT, S.G.B.I.T, BELAGAVI-10 71


DIGITAL SIGNAL PROCESSING LAB 18EEL67

Put K=-2 in the above equation, we get

Put K=-3 in the above equation, we get

Rxx = [ 18 39 62 86 62 39 18]

PROGRAM: AUTO CORRELATION


clc; % clear screen
clear all; % clear work space
close all; % close all figure windows
%computation of autocorrelation of sequences
% define the amplitude for the input
x=input('Enter First sequence')
% define the x axis for input sequence
n= -(length(x1)-1):0:(length(x1)-1);
[Rxx,lag] = xcorr(x, x); % calculate the autocorrelation
disp ('Auto correlation sequence r(n) is ');
disp(r); % display the output
subplot(2,1,1); % plot the input and output sequences
plot2d3 (n,x);
xlabel('n');
ylabel('x(n)');
title('Plot of x(n)');
subplot(2,1,2);
plot2d3 (lag,r);
title('Autocorrelation output');
xlabel('n');
ylabel('r(n)');
//Verificaion of the auto correlation properties//
// property 1: Rxx(0)gives the energy of the signal//
Energy = sum(x.^2); % calculate the energy of input signal
center_index= ceil(length(Rxx)/2); % find the center index
Rxx_0=Rxx(center_index); ` % take the center value of output
if Rxx_0==Energy
disp('Rxx(0) gives energy -- proved');// display the resultelse

EEE DEPT, S.G.B.I.T, BELAGAVI-10 72


DIGITAL SIGNAL PROCESSING LAB 18EEL67

disp('Rxx(0) gives energy -- not proved');


% display the result
end
//property 2: Rxx is even

Rxx_Right = Rxx(center_index:1:length(Rxx));
% take the right side values

Rxx_left = Rxx(center_index:-1:1);
% take the left side values

if Rxx_Right == Rxx_left
disp('Rxx is even');
% display the resultelse
disp('Rxx is not even'); % display the result
end

OUTPUT:
Enter the input signal x[n] [3 4 5 6]
Rxx = [ 18 39 62 86 62 39 18]
Rxx_0 = 30
Rxx(0) gives energy -- proved
Rxx is even

Fig.3.1: Verification of auto correlation Property for given sequence

EEE DEPT, S.G.B.I.T, BELAGAVI-10 73

You might also like