0% found this document useful (0 votes)
63 views113 pages

DSP Lab 2019-20

The document promotes the VTU Connect app, which provides students with various academic resources such as updates, notes, question papers, and a community chat room. It also outlines the mission and vision of the Electronics and Communication Engineering department, along with program outcomes, specific outcomes, and educational objectives for students. Additionally, it details the Digital Signal Processing Laboratory syllabus, including simulation experiments and SCILAB instructions for numerical computation and visualization.

Uploaded by

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

DSP Lab 2019-20

The document promotes the VTU Connect app, which provides students with various academic resources such as updates, notes, question papers, and a community chat room. It also outlines the mission and vision of the Electronics and Communication Engineering department, along with program outcomes, specific outcomes, and educational objectives for students. Additionally, it details the Digital Signal Processing Laboratory syllabus, including simulation experiments and SCILAB instructions for numerical computation and visualization.

Uploaded by

Ullas Farm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Best VTU Student Companion App You Can Get

DOWNLOAD NOW AND GET


Instant VTU Updates, Notes, Question Papers,
Previous Sem Results (CBCS), Class Rank, University Rank,
Time Table, Students Community, Chat Room and Many
More

CLICK BELOW TO DOWNLOAD VTU CONNECT APP


IF YOU DON’T HAVE IT

* Visit https://vtuconnect.in for more info. For any queries or questions wrt our
platform contact us at: support@vtuconnect.in
VTU Connect Android App Download Now On Google Play Store

Department of Electronics and Communication Engineering

(ACADEMIC YEAR 2020-21)

LABORATORY MANUAL

SUBJECT: DIGITAL SIGNAL PROCESSING LABORATORY


SUB CODE: 18ECL57
SEMESTER: V

VTU Connect Android App Download Now On Google Play Store


VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

INSTITUTION MISSION AND VISION

MISSION:

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

VISION:

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

DEPARTMENT VISION AND MISSION

VISION

To develop highly skilled and globally competent professionals in the field of Electronics and
Communication Engineering to meet industrial and social requirements with ethical responsibility.

MISSION

• To provide State-of-art technical education in Electronics and Communication at undergraduate


and post-graduate levels to meet the needs of the profession and society.
• To adopt the best educational methods and achieve excellence in teaching-learning and research.
• To develop talented and committed human resource, by providing an opportunity for innovation,
creativity and entrepreneurial leadership with high standards of professional ethics, transparency
and accountability.
• To function collaboratively with technical Institutes/Universities/Industries and offer
opportunities for long-term interaction with academia and industry.
• To facilitate effective interactions among faculty and students, and promote networking with
alumni, industries, institutions and other stake-holders.

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 1
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

PROGRAM OUTCOMES (POS)

Engineering Graduates will be able to:

PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.

PO2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.

PO3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and
environmental considerations.

PO4. Conduct investigations of complex problems: Use research-based knowledge and


research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.

PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.

PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.

PO7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.

PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.

PO9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.

PO10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give
and receive clear instructions.

PO11. Project management and finance: Demonstrate knowledge and understanding of the
engineering 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.

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 2
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

PROGRAM SPECIFIC OUTCOMES (PSOS)

At the end of graduation the student will be able,

• To comprehend the fundamental ideas in Electronics and Communication Engineering


and apply them to identify, formulate and effectively solve complex engineering
problems using latest tools and techniques.
• To work successfully as an individual pioneer, team member and as a leader in assorted
groups, having the capacity to grasp any requirement and compose viable solutions.
• To be articulate, write cogent reports and make proficient presentations while yearning
for continuous self-improvement.
• To exhibit honesty, integrity and conduct oneself responsibly, ethically and legally;
holding the safety and welfare of the society paramount.

Program Educational Objectives (PEOs)

• Graduates will have a successful professional career and will be able to pursue higher
education and research globally in the field of Electronics and Communication
Engineering thereby engaging in lifelong learning.
• Graduates will be able to analyse, design and create innovative products by adapting to
the current and emerging technologies while developing a conscience for environmental/
societal impact.
• Graduates with strong character backed with professional attitude and ethical values will
have the ability to work as a member and as a leader in a team.
• Graduates with effective communication skills and multidisciplinary approach will be
able to redefine problems beyond boundaries and develop solutions to complex problems
of today’s society.

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 3
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

DIGITAL SIGNAL PROCESSING LABORATORY (18ECL57)

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

Hours/Week : 03 Exam Hours : 03

Total Hours : 36 Exam Marks : 60

VTU SYLLABUS

PART A : Simulation Experiments

1 Verification of sampling theorem (use interpolation function).

2 Linear and circular convolution of two given sequences, Commutative, distributive and associative property
of convolution.

3 Auto and cross correlation of two sequences and verification of their properties

4 Solving a given difference equation

5 Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum (using
DFT equation and verify it by built-in routine).

6 (i) Verification of DFT properties (like Linearity and Parseval’s theorem, etc.)
(ii) DFT computation of square pulse and Sinc function etc.

7 Design and implementation of Low pass and High pass FIR filter to meet the desired specifications
(using different window techniques) and test the filter with an audio file. Plot the spectrum of audio
8 signal
Designbefore and after filtering.
and implementation of a digital IIR filter (Low pass and High pass) to meet given
specifications and test with an audio file. Plot the spectrum of audio signal before and after filtering
PART-B : Experiments to be done using DSP kit
9 Obtain the Linear convolution of two sequences.

10 Compute Circular convolution of two sequences

11 Compute the N-point DFT of a given sequence.

12 Determine the Impulse response of first order and second order system.

13 Generation of Sine wave and standard test signals

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 4
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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 EXTERNAL
COMPUTATIONS
2-D Graphics INTERFACE
Linear Algebra
3 –D Graphics Interface with C and
Signal Processing
Animations FORTAN language
Polynomial and
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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 5
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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.

BASIC INSTRUCTIONS IN SCILAB

1. T = 0: 1:10

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 6
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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)

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 7
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 8
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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')

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 9
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 10
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

clear all; % clear workspace


close all; % close all figure windows
% to generate unit impulse signal
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);

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 11
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

xlabel('time'); % label x axis

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 12
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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 ycoordinates, 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 defines 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?

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 13
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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.
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.

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 14
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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
8. Compare the analog and reconstructed signal
9. Repeat the values experiment for different values of f and verify reconstructed and analog
signal

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 15
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

close all; % close all figure windows); % 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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 16
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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.

3. What are the applications of DSP?

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 17
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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.

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 18
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 02a Date:

LINEAR AND CIRCULAR CONVOLUTION OF GIVEN SEQUENCES,


VERIFICATION OF THE PROPERTIES OF CONVOLUTION.

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

• To find linear convolution of both 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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 19
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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
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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 20
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

%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
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.2.1: Verification of Linear convolution

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 21
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 02b 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(𝑛) = ∑𝑚=0 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁
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)

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 22
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

= 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;

end
y(n+1) =y(n+1)+hn(m+1)*xn(i+1);

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 23
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

Fig.2.2: Verification of Circular convolution

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 24
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 02c Date:

Verification of convolution Properties


// Verification of commutative law x1*x2=x2*x1//
clc
clf
clear
x1=input('Enter First sequence')
x2=input('Enter second sequence')
a=conv(x1,x2)
b=conv(x2,x1)
N=length(a)
n1=0:length(x1)-1;
disp('a=x1*x2')
disp(a)
disp('b=x2*x1')
disp(b)
disp('x1*x2=x2*x1')
subplot(4,1,1)
plot2d3(n1,x1)
xlabel('---->n1')
ylabel('--->amplitude of x1')
title('amplitude of First sequence')
subplot(4,1,2)
n2=0:length(x2)-1;
plot2d3(n2,x2)
xlabel('--->n2')
ylabel('amplitude of x2')
title('amplitude of Second sequence')
na=0:length(a)-1
subplot(4,1,3)
plot2d3(na,a)
xlabel('---->na')
ylabel('------>amplitude of x1*x2')
title('x1*x2')
disp('x1*x2')
disp(a)
nb=0:length(b)-1
subplot(4,1,4)
plot2d3(nb,b)
xlabel('n')
ylabel('amplitude of x2*x1')
n2=0:length(x2)-1
title('x2*x1')
disp('x2*x1')
disp(b)
disp('x1*x2=x2*x1')
disp('Commutative law is verified')

OUTPUT:

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 25
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Fig.2.3: Verification of 'Commutative law under linear convolution

//Verification of Associative law [x1*x2]*x3=x1*[x2*x3] //


clc;
clf;
clear;

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 26
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

x1=[1 3 5 7]
x2=[-1 1 2 3]
x3=[2 4 -1 3]
y1=conv(x2,x3)
y2=conv(y1,x1)
disp('x1(n)*(x2(n)*x3(n))=',y2)
n1=0:1:(length(x1)-1)
n2=0:1:(length(x2)-1)
n3=0:1:(length(x3)-1)
m1=0:1:(length(y2)-1)
subplot(2,3,1)
plot2d3(n1,x1)
xlabel('samples')
ylabel('magnitude')
title('x1(n)')
subplot(2,3,2)
plot2d3(n2,x2)
xlabel('samples')
ylabel('magnitude')
title('x2(n)')
subplot(2,3,3)
plot2d3(n3,x3)
xlabel('samples')
ylabel('magnitude')
title('x3(n)')
subplot(2,3,4)
plot2d3(m1,y2)
xlabel('samples')
ylabel('magnitude')
title('x1(n)*(x2(n)*x3(n))')
y3=conv(x1,x2)
y4=conv(y3,x3)
m4=0:1:(length(y4)-1)
subplot(2,3,5)
plot2d3(m4,y4)
title('(x1(n)*x2(n))*x3(n)')
disp('x1(n)*(x2(n)*x3(n))=(x1(n)*x2(n))*x3(n)')

- 2. - 8. - 7. 13. 74. 155. 153. 133. 66. 63.

x1(n)*(x2(n)*x3(n))=

x1(n)*(x2(n)*x3(n))=(x1(n)*x2(n))*x3(n)

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 27
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

//Convolution Associative Property//


clc
clf
clear
a=[1 2 3 4]
n1=0:1:length(a)-1
subplot(4,2,1)
plot2d3(n1,a)
title('first input sequence')
xlabel('n1')
ylabel('a')

b=[1 2 3 4]
n2=0:1:length(b)-1
subplot(4,2,2)
plot2d3(n2,b)
title('second input sequence')
xlabel('n2')
ylabel('b')

c=[1 2 3 4]
n3=0:1:length(c)-1
subplot(4,2,3)
plot2d3(n3,c)
title('third input sequence')
xlabel('n3')
ylabel('c')

y1=conv(b,c)
N1=0:1:length(y1)-1
subplot(4,2,4)
plot2d3(N1,y1)
title('y1=b*c')
xlabel('y1')
ylabel('N1')
disp('b*c')
disp(y1)

y2=conv(a,y1)
N2=0:1:length(y2)-1
subplot(4,2,5)
plot2d3(N2,y2)
title('y2=a*y1')
xlabel('y2')

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 28
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

ylabel('N2')

disp('a*(b*c)')
disp(y2)
y3=conv(a,b)
N3=0:1:length(y3)-1
subplot(4,2,6)
plot2d3(N3,y3)
title('y3=a*b')
xlabel('y3')
ylabel('N3')
disp('a*b')
disp(y3)
y4=conv(c,y3)
N4=0:1:length(y4)-1
subplot(4,2,7)
plot2d3(N4,y4)
title('y4=c*y3')
xlabel('y4')
ylabel('N4')
disp('(a*b)*c')
disp(y4)
disp('a*(b*c)=(a*b)*c')
disp('Hence Associative Property is Verified')

OUTPUT:

b*c
1. 4. 10. 20. 25. 24. 16.

a*(b*c)

1. 6. 21. 56. 111. 174. 219. 204. 144. 64.

a*b

1. 4. 10. 20. 25. 24. 16.

(a*b)*c

1. 6. 21. 56. 111. 174. 219. 204. 144. 64.

a*(b*c)=(a*b)*c

Hence Associative Property is verified

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 29
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Fig.2.4: Verification of Associative Property under linear convolution

// Distributive law [a*[b+c]=[a*b]+[a*c];//


Clc
clf
clear
a=[1 2 3 4]
n1=0:1:length(a)-1
subplot(4,2,1)
plot2d3(n1,a)
title('first input sequence')
xlabel('n1')
ylabel('a')
b=[1 2 3 4]
n2=0:1:length(b)-1
subplot(4,2,2)
plot2d3(n2,b)
title('second input sequence')
xlabel('n2')
ylabel('b')
c=[1 2 3 4]
n3=0:1:length(c)-1
subplot(4,2,3)
plot2d3(n3,c)

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 30
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

title('third input sequence')


xlabel('n3')
ylabel('c')
y1=b+c
N1=0:1:length(y1)-1
subplot(4,2,4)
plot2d3(N1,y1)
title('y1=b+c')
xlabel('N1')
ylabel('y1')
disp(y1)
y2=conv(a,y1)
N2=0:1:length(y2)-1
subplot(4,2,5)
plot2d3(N2,y2)
title('y2=a*y1')
xlabel('N2')
ylabel('Y2')
disp(y2)
y3=conv(a,b)
N3=0:1:length(y3)-1
subplot(4,2,6)
plot2d3(N3,y3)
title('y3=a*b')
xlabel('N3')
ylabel('Y3')
disp(y3)
y4=conv(a,c)
N4=0:1:length(y4)-1
subplot(4,2,7)
plot2d3(N4,y4)
title('y4=a*c')
xlabel('Y4')
ylabel('N4')
disp(y4)
y5=y3+y4
N5=0:1:length(y5)-1
subplot(4,2,8)
plot2d3(N5,y5)
title('y5=y3+y4')
xlabel('y5')
ylabel('N5')
disp(y5)
Output:

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 31
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

2. 4. 6. 8.
2. 8. 20. 40. 50. 48. 32.
1. 4. 10. 20. 25. 24. 16.
1. 4. 10. 20. 25. 24. 16.
2. 8. 20. 40. 50. 48. 32.

Fig.2.5: Verification of distributive Property under linear 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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 32
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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?


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(𝑛) = ∑𝑚=0 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 33
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

periodic with period = N where N = max (L, M) where L is the length of first signal and M is
length 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.

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).

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 34
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 03.a Date:

AUTO AND CROSSS CORRELATION AND VERIFICATION OF


THIER PROPERTIES

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]

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 35
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 36
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 37
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 38
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 03.b Date:

CROSS CORRELATION AND VERIFICATION OF ITS


PROPERTIES.
AIM: Cross-correlation of a given sequence and verification of its properties.
OBJECTIVES:
This experiment enables students
1. To implement Cross correlation of the given sequence using an inbuilt SCILAB
function “XCORR” and to verify its properties.
2. To find Cross correlation of the given sequences using convolution.
3. To verify the results theoretically.

THEORY: When two independent signals are compared, the procedure is known as cross
correlation. It is given by,

Rxy (k) = ∑𝑛=−∞ x(n) y(n − k) k = 0, ±1, ±2, ±3 …
Where k is the shift parameter
Or equivalently

Ryx (k) = ∑ y(n + k) x(n)


n=−∞

Comparing above two equations, we find that, Rxy (k) = Ryx (-k), Where Ryx (-k) is the folded
version of Rxy (k) about k = 0. So, we can write Cross correlation of the two sequences is given
by,

𝑛=−∞ 𝑥(𝑛) 𝑦[−(𝑘 − 𝑛)]k = 0, ±1, ±2, ±3 …


𝑅𝑥𝑥(𝑘) = ∑∞

Rxy (k) = x(k) * y(-k) ………………..(1)

Equation (1) shows that cross correlation is the essentially the convolution of two sequences in
which one of the sequences has been reversed.

PROPERTIES OF CROSS CORRELATION:


1. Rxy(k) is always a real valued function which may be a positive or negative.
2. Rxy(-k) = Ryx(k)
3. |Rxy(k)|2 ≤ Rxx(0) Ryy(0)

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 39
VTU Connect Android App Download Now On Google Play Store
DIGITAL SIGNAL PROCESSING LAB 18ECL57

4. |Rxy(-k)| ≤[1/2] [Rxy(-k) + Rxy(-k)]


5. When Rxy(k) = 0, x(n) and y(n) are said to be uncorrelated or they said to be statistically
independent.
6. Rxy(k) may not be necessarily have a maximum at k=0 nor Rxy(k) an even function.
ALGORITHM:
1. Input the sequence as x and y.
2. Use the ‘xcorr’ function to get auto correlated output r..
3. Plot the sequences.
PROGRAM LOGIC:
1. Read the input sequence x[n]
2. Cross correlate the signal using xcorr(x,y)
3. Display the Cross correlation result on a suitable axis.
4. Verify the correlation property.

CALCULATION:

x(n) ={ 1,2,3,4} y(n)={1,2,1,2}

VTU Connect
DEPT. OF ECE, Android App
ATMECE, MYSURU Download Now On Google Play Store
Page 40
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Rxy = [2 5 10 16 12 11 4]

PROGRAM: CROSS CORRELATION USING XCORR


clc; % clear screen
clear all; % clear workspace
close all; % close all figure windows
x = input('Enter the first sequence x(n) ='); % first sequence
y = input('Enter the second sequence y(n) ='); % second sequence

r = xcorr(x,y); % calculate cross correlation


disp('Cross Correlation Output = ');
disp(r); % display the output
n1 = length(x)-1; % graphical plot of first input sequence
t1 = 0:n1;
subplot(2,2,1);
plot2d3 (t1,x);

xlabel('n');
ylabel('x(n)');
title('plot of x(n)');
n2 = length(y)-1; % graphical plot of second input sequence

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 41
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


t2 = 0:n2;
subplot(2,2,2);
plot2d3 (t2,y);
xlabel('n')
ylabel('y(n)');
title('plot of y(n)');
N = max(n1,n2); % graphical plot of output sequence
k = -N:N;
subplot(2,1,2);
plot2d3 (k,r);
xlabel('n');
ylabel('r(n)');

title('cross correlation
output');x= input(“seq1’); % Property Rxy(-k) = Ryx(k)
y = input(‘seq2’);
Rxy = xcorr(x,y);
Ryx=xcorr(y,x);
Rxy1 = fliplr(Rxy);
if Rxy1 = Ryx
OUTPUT:
Enter the first sequence x(n) = [1 5 6 7]
Enter the second sequence y(n) = [3 4 2 1]
Cross Correlation Output = 1 7 20 42 53 46 21

Fig.3.2: Verification of Cross correlation Property for given sequence

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 42
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


OUTCOMES:
• Cross-correlation and autocorrelation are used for measuring the similarity of signals
• Autocorrelation and cross correlation have been used as an effective tool pattern
recognition” and for “signal detection.

Viva Questions:

1. What is correlation?
Correlation gives a measure of similarity between two data sequences. In this process, two
signals are compared and the degree to which the two signals are similar is computed.

2. What are even and odd signals?


A discrete time signal x(n) is called even or symmetric signal if it satisfies the condition x(-
n) = x(n). A discrete time signal x(n) is called odd or anti-symmetric signal if it satisfies the
condition x-(n) = -x(n).
3. What are the applications of Correlation?

Typical applications of correlation include speech processing, image processing and radar systems.
In a radar system, the transmitted signal is correlated with the echo signal to locate the position of the
target. Similarly, in speech processing systems, different waveforms are compared for voice
recognition.

4. What are the applications of Correlation?


Typical applications of correlation include speech processing, image processing and radar
systems. In a radar system, the transmitted signal is correlated with the echo signal to locate the
position of the target. Similarly, in speech processing systems, different waveforms are compared
for voice recognition.
5. What is Cross-correlation?
It is a measure of similarity of a signal/waveform with two waveforms.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 43
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 4 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 equations looks like,y[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]

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 get
y[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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 44
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


y[-1] = 2
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
close all; % close all figure windows
clear all; % clear work space
%to find impulse response
N= input('Enter the length of response = '); % define the length of output

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 45
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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
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);

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 46
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


plot2d3 (n,h);
title('Step response');
xlabel('n');
ylabel('h(n)');
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.4.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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 47
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Fig.4.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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 48
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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.

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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 49
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

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 numbersx0,...,xN−1 is transformed into the sequence of N complex numbers X0, ...,
XN−1 by the DFT according to the formula:

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

EXAMPLE:
Let us assume the input sequence x[n] = [1 1 0 0]
We have,
𝑁−1
X(k) = ∑n=0 x(n)e − j2πnk/N k = 0,1, …. N-1
For k = 0,
3

X(0) = ∑ x(n)
𝑛=0

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


X(0) = 1+1+0+0 = 2
For k = 1,
3
X(1) = ∑𝑛=0 x(n)e − jπn/2
X(1) = x(0) + x(1) e-jπ/2 + x(2) e-jπ + x(3) e-j3π/2

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 50
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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

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


𝑛=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) = ∑𝑛=0 x(n)e − j3nπ/2
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) = ∑n=0 x(n)e − j2πnk/N k = 0,1, …. N-1
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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 51
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


PROGRAM: N POINT DFT
clc;
clf;
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 function.
disp('DFT using builtin routine,y1')

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 52
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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,y1
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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 53
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


OUTCOMES:
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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 54
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Experiment No: 06. A & b Date:

Verification of DFT Properties and Computation of DFT for Square


and Sync Function
PROGRAM: Linearity Property
clc;
clf;
x=[1 1 2 2]//To verify the properties define 2 input sequence.
y=[1 2 3 4]
disp('x=')
disp(x)
disp('y=')
disp(y)
X=fft(x)//Calculate the DFTs of the 2 defined Sequences.
Y=fft(y)
z=x+y//Obtain the LHS side of the Linearity property of DFT equation.
Z=fft(z)
Z1=X+Y//Obtain the RHS side of the Linearity property of DFT equation.
disp('DFT(x(n)+y(n))=')
disp(Z)//Display the numerical values of LHS side
disp('X(k)+Y(k)=')
disp(Z1) )//Display the numerical values of RHS side
disp('DFT(x(n)+y(n))=X(k)+Y(k).Hence linearity property is verified')
x=
1. 1. 2. 2.

y=
1. 2. 3. 4.

DFT(x(n)+y(n))=
16. - 3. + 3.i - 2. - 3. - 3.i

X(k)+Y(k)=
16. - 3. + 3.i - 2. - 3. - 3.i
DFT(x(n)+y(n))=X(k)+Y(k).Hence linearity property is verified.
//Verification of Parsevals theorem//
clc;
clf;
x=[1 1 2 2] ) ]//To verify the properties define 2 input sequence.
y=[1 2 3 4]
X=fft(x) )//Calculate the DFTs of the 2 defined Sequences.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 55
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Y=fft(y)
disp(X)
disp(Y)
z=sum(x.*conj(y)) //Obtain the LHS side of the Parsevals property of the given sequence.
Z=sum(X.*conj(Y))/length(X) )) //Obtain the RHS side of the Parsevals property of the sequence.
disp('sum (x(n).y*(n))=')
disp(z) )//Display the numerical values of LHS side
disp('sum(X(k).Y*(k))/N=')
disp(Z) //Display the numerical values of RHS side
disp('DFT(x(n).y*(n))=X(k).Y*(k).Hence,parsevals theorem is verified')
OUTPUT:
6. - 1. + i 0 - 1. - i

10. - 2. + 2.i - 2. - 2. - 2.i

sum (x(n).y*(n))=
17.
sum(X(k).Y*(k))/N=
17.
DFT(x(n).y*(n))=X(k).Y*(k).Hence,Parsevals theorem is verified
// circular convolution in time domain is same as multiplication in frequency domain
clc;
clf;
function [y]=circ(x1, x2)
N=max(length(x1),length(x2))
for n=0:1:N-1
y(n+1)=0
for m=0:1:N-1
i=pmodulo((n-m),N)
if i<0 then
i=i+N;
end
y(n+1)=y(n+1)+(x1(m+1)*x2(i+1));
end
end
endfunction
x=[1 1 2 2] ]//To verify the properties define 2 input sequence.
y=[1 2 3 4]
disp(x)
disp(y)
d1=circ(x,y)//Obtain the circular convolution of 2 sequences
d2=circ(y,x)

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 56
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


disp('x(n).(*)y(n)=')
disp(d1)
X=fft(x) //Calculate the DFTs of the 2 defined Sequences.
Y=fft(y)
Z=X.*Y
z=ifft(Z) //Calculate the IDFTs of the 2 defined Sequences.
disp('ifft(X(k).Y(k)=')
disp(z)
disp('x(n)(*)y(n)=ifft(X(k).Y(k)).Hence,circular convolution in time domain is same as
multiplication in frequency domain')
OUTPUT:
1. 1. 2. 2.
1. 2. 3. 4.
x(n).(*)y(n)= 15. 17. 15. 13.
ifft(X(k).Y(k)= 15. 17. 15. 13.
x(n)(*)y(n)=ifft(X(k).Y(k)).Hence,circular convolution in time domain is same as multiplication
in frequency domain.

//DFT of square wave.//


clc
clf
clear
t=(0:1:4*2);
x1=squarewave(t) ]//define square wave as an input sequence.
N=length(x1)
disp(N)
disp(x1)
x1k=fft(x1)//obtain the DFT of a Square wave
k=0:1:N-1;
subplot(3,1,1)
plot2d3('onn',t,[squarewave(t)])//plot a graph of square wave.
xlabel('n')
ylabel('Magx1')
title('Input sequence')
Magx1k=abs(x1k) //calculate a magnitude of square wave.
disp(abs(x1k))
subplot(3,1,2)
plot2d3(Magx1k) )/ /plot a graph of magnitude of square wave.
xlabel('k')
ylabel('Magx1k')
title('The Mangnitude sequence x1k')
disp('The Mangnitude sequence x1k is,')
disp('The Phase angle sequence(Radians) is,')
Phase_rad=atan(imag(x1k),real(x1k)) //calculate a phase of square wave.
disp(Phase_rad) )/ display a graph of Phase of square wave.
subplot(3,1,3)

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 57
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


plot2d3(Phase_rad) //plot a graph of Phase of square wave.
xlabel('k')
ylabel('Phase_rad')
title('Phase spectrum in radains')

OUTPUT:

9.

1. 1. 1. 1. - 1. - 1. - 1. 1. 1.

The Mangnitude sequence x1k is,

column 1 to 9

3. 5.0641778 2.6945927 0. 1.7587705 1.7587705 0. 2.6945927 5.0641778

The Phase angle sequence(Radians) is,

column 1 to 9

0. - 0.3490659 2.443461 0. - 1.3962634 1.3962634 0. - 2.443461 0.3490659

Fig.6.1: Plot of DFT magnitude and phase of a square sequence.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 58
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

//DFT of sync function


clc
clf
clear
x1=linspace(-10,10,50); ]//define sync wave as an input sequence.
N=length(x1)
disp(N)
disp(x1)
x1k=fft(x1) /obtain the DFT of a Sync wave
k=0:1:N-1;
subplot(3,1,1)
plot2d3(x1,sinc(x1)) plot a graph of sync wave.
xlabel('n')
ylabel('Magx1')
title('Input sequence')
disp('The Mangnitude sequence x1k is,')
Magx1k=abs(x1k) //calculate a magnitude of sync wave.
disp(abs(x1k))
subplot(3,1,2)
plot2d3(Magx1k)
xlabel('k')
ylabel('Magx1k')
title('The Mangnitude sequence x1k')
disp('The Mangnitude sequence x1k is,')
disp('The Phase angle sequence(Radians) is,')
Phase_rad=atan(imag(x1k),real(x1k)) //calculate a phase of sync wave.
disp(Phase_rad)
subplot(3,1,3)
plot2d3(Phase_rad)//plot a phase of sync wave.
xlabel('k')
ylabel('Phase_rad')
title('Phase spectrum in radains')

OUTPUT:

50.

column 1 to 7

- 10. - 9.5918367 - 9.1836735 - 8.7755102 - 8.3673469 - 7.9591837 - 7.5510204

column 8 to 14

- 7.1428571 - 6.7346939 - 6.3265306 - 5.9183673 - 5.5102041 - 5.1020408 - 4.6938776

column 15 to 21

- 4.2857143 - 3.877551 - 3.4693878 - 3.0612245 - 2.6530612 - 2.244898 - 1.8367347

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 59
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


column 22 to 28

- 1.4285714 - 1.0204082 - 0.6122449 - 0.2040816 0.2040816 0.6122449 1.0204082

column 29 to 35

1.4285714 1.8367347 2.244898 2.6530612 3.0612245 3.4693878 3.877551

column 36 to 42

4.2857143 4.6938776 5.1020408 5.5102041 5.9183673 6.3265306 6.7346939

column 43 to 49

7.1428571 7.5510204 7.9591837 8.3673469 8.7755102 9.1836735 9.5918367

column 50

10.

The Mangnitude sequence x1k is,

column 1 to 7

1.776D-15 162.50991 81.41561 54.456239 41.031349 33.021102 27.719101

column 8 to 14

23.96566 21.181118 19.04362 17.360221 16.008311 14.906325 13.997971

column 15 to 21

13.243227 12.612939 12.085448 11.644418 11.277383 10.974768 10.729206

column 22 to 28

10.53506 10.388083 10.285183 10.224257 10.204082 10.224257 10.285183

column 29 to 35

10.388083 10.53506 10.729206 10.974768 11.277383 11.644418 12.085448

column 36 to 42

12.612939 13.243227 13.997971 14.906325 16.008311 17.360221 19.04362

column 43 to 49

21.181118 23.96566 27.719101 33.021102 41.031349 54.456239 81.41561

column 50 162.50991

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 60
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


The Mangnitude sequence x1k is,

The Phase angle sequence(Radians) is,

column 1 to 7

3.1415927 1.6336282 1.69646 1.7592919 1.8221237 1.8849556 1.9477874

column 8 to 14

2.0106193 2.0734512 2.136283 2.1991149 2.2619467 2.3247786 2.3876104

column 15 to 21

2.4504423 2.5132741 2.576106 2.6389378 2.7017697 2.7646015 2.8274334

column 22 to 28

2.8902652 2.9530971 3.0159289 3.0787608 3.1415927 - 3.0787608 - 3.0159289

column 29 to 35

- 2.9530971 - 2.8902652 - 2.8274334 - 2.7646015 - 2.7017697 - 2.6389378 - 2.576106

column 36 to 42

- 2.5132741 - 2.4504423 - 2.3876104 - 2.3247786 - 2.2619467 - 2.1991149 - 2.136283

column 43 to 49

- 2.0734512 - 2.0106193 - 1.9477874 - 1.8849556 - 1.8221237 - 1.7592919 - 1.69646

column 50

- 1.6336282

Fig.6.2: Plot of DFT magnitude and phase of a Sync function.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 61
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

OUTCOMES:

This experiment enables students to frequency spectrum of various signals.


Viva Questions:

1. DFT gives discrete spectrum or continuous spectrum? Justify?


DFT gives discrete spectrum. If the signal is periodic then spectrum is discrete and if the
signal is non-periodic then spectrum is continuous. DFT assumes that input signal is periodic and
therefore DFT gives discrete spectrum.

2. How to find energy of signal from its DFT?


According to Parseval's energy theorem, Energy of the signal is given by.

3. What is the need of FFT?


It may be noted that the number of complex multiply and add operations required by the
simple forms both the DFT and IDFT is of order N2. This is because there are N data points to
calculate, each of which requires N complex arithmetic operations. In computer science jargon, we
say they have algorithmic complexity O(N2). This is not good news. If we can't do any better than
this then the DFT will not be very useful for the majority of practical DSP applications.
Fortunately, there are a number of different 'Fast Fourier Transform' (FFT) algorithms that enable
us to do very much better than this.

4. What is FFT? What is difference between DIT and DIF FFT?


A fast Fourier transform (FFT) is an efficient algorithmto compute the discrete
Fourier transform (DFT) and it’s inverse.The most significant difference between simple DIF and
DIT algorithms is that DIF starts with normal order input and generates bit reversed order output.
In contrast, DIT starts with bit reversed order input and generates normal order output. So if both
forward and inverse transforms are required and bit reversed addressing isn't available, then the
choice would seem clear. Use DIF for the forward transform and DIT for the inverse transform.
(For the inverse transform you will need to conjugate the twiddle factors.) Unfortunately, the issue
isn't quite so simple. If your performing FFT's on pure real data it may be simpler to use a
modified DIT for the forward transform and a modified DIF for the inverse transform
5. How efficient is the FFT?

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 62
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


The DFT takes N2 operations for N points. Since at any stage the computation required to
combine smaller DFTs into larger DFTs is proportional to N, and there are log2(N) stages (for
radix 2), the total computation is proportional to N log2(N). Therefore, the ratio between a DFT
computation and an FFT computation for the same N is proportional to N / log2(N). In cases where
N is small this ratio is not very significant, but when N becomes large, this ratio gets very large.
(Every time you double N, the numerator doubles, but the denominator only increases by 1.
6. FFT is faster than DFT. Justify.
FFT produces fast results because calculations are reduced by decomposition technique. In
FFT, N point DFT is decomposed into two N/2 point DFT’s, N/2 point DFT is decomposed into
N/$ point DFT’s and so on.. Decomposition reduces calculations. FFT algorithms are
implemented using parallel processing techniques. Because calculations are done in parallel, FFT
produces fast computations.
7. What do you mean by Decimation?
Decimation means Sampling
8. Which algorithm is more powerful: DIT-FFT or DIF-FFT?
Computationally, both the algorithms are exactly same
9. Why Radix-2 algorithms are fast compared to radix-3 algorithms. ?
In FFT, N pt DFT is decomposed into two N/2 pt DFT's, N/2 pt DFT is decomposed into
N/4 pt DFT's and so on... Decomposition reduces calculations this process continues till further
decomposition is not possible. In radix-2 last level of decomposition is when the length of signal
becomes 2 pt. For minimum calculations there must be maximum levels of decompositions. In
Radix-2 algorithms, we get maximum levels of decompositions and therefore a radix-2 algorithm
requires less calculation. Radix-2 algorithms are fast algorithms.
10. What is the drawback in Fourier Transform and how it is overcome?
The draw back in Fourier Transform is that it is a continuous function of ω and so it cannot
be processed by digital system. This drawback is overcome by using Discrete Fourier Transform.
The DFT converts the continuous function of ω to a discrete function of ω
11. Mention the importance of DFT
DFT is used for spectral analysis of signals using digital computer and to perform filtering
operations on signals using digital computer.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 63
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 7 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,

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 64
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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;
close all;
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);

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 65
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 66
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 67
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

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?

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 68
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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.

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?

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 69
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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.
In real time applications, output of FIR filter is obtained using overlap add method /
overlap save method.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 70
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 8 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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 71
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


fs = input('Enter the Stop band frequency in Hz = ');
Fs = input(‘Enter the Sampling frequency in Hz = ‘);
Ap = input(' Enter the Pass band ripple in db:');
As = input('Enter theStop band ripple in db:');
wp=2*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

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 72
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Fig.8.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
Disp(‘order of the filter N =’);

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 73
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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
Normalised cutoff frequency = 0.1574
num/den =
0.0037904 z^2 + 0.0075808 z + 0.0037904

---------------------------------------

z^2 - 1.8625 z + 0.88157

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 74
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Fig.8.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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 75
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

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 byevaluating 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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 76
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

PART-B
INTRODUCTION TO DSP PROCESSORS (TMS320C6743DSK)
The C6747™ DSK builds on TI's industry-leading line of low cost, easy-to-use DSP Starter
Kit (DSK) development boards. The high-performance board features the VSK-6747 floating-
point DSP. Capable of performing 1350 million floating-point operations per second (MFLOPS),
the VSK-6747 DSP makes the VSK-6747 DSK the most powerful DSK development board. The
DSK is USB port interfaced platform that allows efficiently developing and testing applications for
the VSK-6747. The DSK consists of a VSK-6747 -based printed circuit board that will serve as a
hardware reference design for TI’s customers’ products. With extensive host PC and target DSP
software support, including bundled TI tools, the DSK provides ease-of-use and capabilities that
are attractive to DSP engineers.
The VSK comes with a full complement of on board devices that suit a wide variety of
Application environments. Key features include:

VSK – 6747 Module

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 77
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


A Texas Instruments TMS320C6747 device with a DSP floating point processor and processor
operating up to 300 MHz
64 Megabytes SDRAM SPI Boot EEPROM
TLV320AIC3106 Stereo Codec RS-232 Interface
On chip real time clock
Configurable boot load options
8 user LEDs/8 position user DIP switch Single voltage power supply (+5V)
Expansion connectors for SPI/GPIO termination. Embedded JTAG Emulation.

INTRODUCTION TO CODE COMPOSER STUDIO


Code Composer is the DSP industry's first fully integrated development environment (IDE)
with DSP-specific functionality. With a familiar environment liked MS-based C++TM, Code
Composer lets you edit, build, deug, profile and manage projects from a single unified
environment. Other unique features include graphical signal analysis, injection/extraction of data
signals via file I/O, multi-processor debugging, automated testing and customization via a C-
interpretive scripting language and much more.

Code composer features include:

• IDE
• Debug IDE
• Advanced watch windows
• Integrated editor
• File I/O, Probe Points, and graphical algorithm scope probes
• Advanced graphical signal analysis
• Interactive profiling
• Automated testing and customization via scripting
• Visual project management system
• Compile in the background while editing and debugging
• Multi-processor debugging
• Help on the target DSP

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 78
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Execute the programs by using TMS320C6747 VSK Module.
Initial Software Setups:

• Click Start Menu All Programs Texas Instruments Code Compos-er Studio3.3
Setup Code Composer Studio V3.3.

• Then Select Family C67XX and Platform XDS100 USB Emulator

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 79
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


• Next Double Click the C6747 XDS Emulator. Then Click Save and Quit Button. CCS
Setup window dialogue box can be display on screen, now click yes button. Suddenly
setup window discarded and CCS can be Open.

• Now CCS Window will open without work space.

CCS Software Working Procedure:

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 80
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Project Creating Method:

• Click Start Menu All Programs Texas Instruments Code Composer Studio

• Now the CCS window will open without Project.

• Then switch ON the TMS320C6747 VSK module and plug the USB Emulator to
the module. Now press Debug option and then select the connect option.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 81
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

• Now TMS320C6747 VSK module and CCS software will be connected. Then click
Project and select new. Now open the new project.

• Save the project in specific location and give Project Name. Then click finish but-
ton. Now project will be added in CCS work space.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 82
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

• Select the File New Source File. Now new untitled window will be open.

• Next click File and select save option. Now give a name for opened file with dot C.
Copy the Linker cmd, ViDSKC6747-BSL-Lib file path and then paste the copied file into
our project folder.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 83
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Build and Executing Method


• Write a program in editor window and save the file.

• Now Right click the Source file in project window and select Add file to project.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 84
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Now click the project file, linker command file and then select Open button.

• Then click Project Rebuild All. (Alt + P + R)

Now an editor file will be builded.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 85
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

• Click File option and Load the Program.(Ctrl + L)

• Then double click the debug option and click out file and select the Open button.
Now program will be loaded.

• Finally select the debug option and click Run (F5). Now run the program.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 86
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

This is the basic procedure for create a project, build and executing methods.
Program Implementation and Input / Output View Procedure:
• Then click View option and select the Memory.

• Now enter the specific Memory address (like 0xc0000100) then press Enter
and Select a Particular Data type (Ex 32 bit signed integer).

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 87
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

• Now double click the data near the specific memory address and enter the
inputs.

• Then select Debug Run(F5)

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 88
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

• Now click Debug Halt. See the Output for the particular memory window.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 89
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Experiment No: 9 Date:

LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES


AIM: To obtain the Linear Convolution of the two given sequences.

OBJECTIVES: After completing this lab, student will be able to find the linear convolution and
the results can be verified by implementing the C-code on the TMS320 DSP processor.

THEORY: 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. In linear convolution
length of output sequence is, Length (y(n)) = length(x(n)) + length(h(n)) – 1

PROGRAM: LINEAR CONVOLUTION


#include<fastmath67x.h>
//void Vi_DSKC6747_init( );
void main()
{

int *Xn,*Hn,*Yout;
int *xnlen,*hnlen;
int i,k,n,l,m;
Xn=(int *)0xc0000100;//[1,2,1,1] reserve a memory location for input ,sequence length and output.
Hn=(int *)0xc0000200;//[1,1,1]
xnlen = (int *)0xc0000300;//[4]

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 90
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


hnlen = (int *)0xc0000304;//[3]
Yout=(int *)0xc0000400;//[1,3,4,4,2,1]
// Vi_DSKC6747_init( );

l = *xnlen;
m = *hnlen;

for(i=0;i<50;i++)
{
Yout[i]=0;//Clear 50 memory locations to store the respective sequence.
Xn[l+i]=0;
Hn[m+i]=0;
xnlen[2+i]=0;
}
for(n=0;n<(l+m-1);n++)

{
for(k=0;k<=n;k++)
{
Yout[n]=Yout[n]+(Xn[k]*Hn[n-k]);//obtain a
linear convolution using formula.

}
}
OUTPUT:
1 3 4 4 2 1

OUTCOME:

• To Study the importance of linear convolution with its mathematical expression.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 91
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 10 Date:

CIRCULAR CONVOLUTION

AIM: To implement circular convolution of two sequences.

OBJECTIVE: After completing this lab, student will be able to find the circular convolution of
the sequence using TMS320 DSP processor.

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

𝑥3(𝑛) = ∑ 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁


𝑚=0

PROGRAM: CIRCULAR CONVOLUTION


#include<fastmath67x.h>
//void Vi_DSKC6747_init( );
void main()
{
int Xn[4]= {2,1,2,1}; // define input ,sequence length. xn and hn
int Hn[4] = {1,2,3,4}; //n & h must need same value
int xn = 4;
int hn= 4;
int *Yn;
int i,n,m,l;

Yn=(int *)0xc0000100;

// Vi_DSKC6747_init( );

for(i=0;i<xn+hn;i++)
Yn[i]=0;

for(n=0;n<xn;n++)

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 92
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


{
for(m=0;m<hn;m++)
{
l=n-m;
if(l<0)
{
l=l+xn;
}
Yn[n]=Yn[n]+(Xn[m]*Hn[l]); //obtain a circular convolution using formula.

}
}

OUTPUT:
14 16 14 16

OUTCOME:

• To Study the importance of circular convolution with its mathematical expression.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 93
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Experiment No: 11 Date:

N-POINT DFT
AIM: To compute n-point DFT of a given sequence and to plot

OBJECTIVE: After completing this lab, student will be able to find the DFT of the sequence
using TMS320 DSP processor.

THEORY: The 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) = ∑n=0 x(n)e − j2πnk/N k = 0,1, …. N-1

PROGRAM: N POINT DFT


include<fastmath67x.h>
#include<math.h>
#include<stdio.h>
#define m 3.14159
//void Vi_DSKC6747_init( );
void main()
{

int N = 4;//Define a required DFT length of a sequence.


int *XinSeq; //defi9ne atype of a pointer to store input ,intermediate and output.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 94
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


float *RealOut,*ImagOut;
float Real,Imag;
int n,k,i;
// INPUT //
XinSeq=(int *)0xc0000100; //Initialize a pointer to store input ,intermediate and output.
// Output //
RealOut=(float *)0xc0000300;
ImagOut=(float *)0xc0000400;
//Vi_DSKC6747_init( );
for(i=0;i<50;i++)
{
RealOut[i]=0;
XinSeq[N+i]=0;
ImagOut[i]=0;
}
for(k=0;k<N;k++)
{
for(n=0;n<N;n++)
{
Real=cos((2*m*n*k)/N);
Imag=sin((2*m*n*k)/N);
RealOut[k]=RealOut[k]+(XinSeq[n]*Real);
ImagOut[k]=ImagOut[k]-(XinSeq[n]*Imag);
}

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 95
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


OUTPUT:

RealOut[k]= 0xc0000300
14.0000
-1.0000
-8.0000
-1.0000
ImagOut[k]= 0xc0000400

0.0000

3.0000

- 0.0000

- 3.0000

80001000 - 00000002 80002000 - 00000002


80001004 - 00000002 80002004 - 00000008
80001008 - 00000002 80002008 - 00000018
8000100C - 00000002 8000200C - 00000044

OUTCOME:

• To Study the importance of DFT with its mathematical expression.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 96
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 12 Date:

IMPULSE RESPONSE

AIM: To find Impulse response of a first order and second order system.

1) OBJECTIVE: After completing this lab, student will be able to find the impulse response
for the system using TMS320 DSP processor. To find the Impulse response of second order
systems.
2) To prove the results theoretical and implement the same using DSP Hardware module.

THEORY:
A discrete time system performs an operation on an input signal based on predefined criteria to
produce a modified output signal. The input signal x(n) is the system excitation, and y(n) is the
system response. The transform operation is shown as,

The convolution sum can be represented by, y(n) = x(n) * h(n)


For Example let’s find out an impulse response of a difference equation.
The general form of difference equation is,
𝑚 𝑚

𝑦(𝑛) = ∑ ak y(n − k) + ∑ bk x(n − k)


𝑘=1 𝑘=0

Find out the impulse response of second order difference equation.

PROGRAM: N POINT DFT


#include<stdio.h>
#include<math.h>
float x[60], y[60];
void main()

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 97
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


{
float a0, a1, a2, b0, b1, b2;
int i, j, N=7;
b0 = 0.1311, b1 = 0.2622, b2 = 0.1311;//Define the input and output coefficients of a
difference equation.
a0 = 1, a1 = -0.7478, a2 = 0.2722;
x[0]= 1;
for (i=1; i< N; i++)
x[1] = 0;
for(j=0;j<N;j++)
{
y[j] = b0 * x[j];
if(j>0)
y[j] = y[j] + b1* x[j-1] – a1 * y[j-1];
if((j – 1)>0)
y[j] = y[j] + b2 * x[j-2] – a2 * y[j-2];
}
Printf ("%f \t", y[j]);
}
}

OUTPUT:
0.131100 0.360237 0.364799 0.174741 0.031373

OUTCOME:
Student can obtain dynamic system response to some external change.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 98
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Experiment No: 13 Date:

FIR FILTER

AIM: Realization of fir filter (any type) to meet given specifications. The input can be a signal
from function generator/speech signal

OBJECTIVE: After completing this lab, student will be able to design FIR filter using CODEC
and TMS320 DSP processor.

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.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 99
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


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,
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)

PROGRAM: FIR FILTER


/* FIR Low Pass Filter */

************************************************************************

FIR LOW PASS FILTER

************************************************************************

#include<fastmath67x.h>
#include<math.h>
#define PI 3.14
void Vi_DSKC6747_init( );
void main()
{

const float Fsamp = 5000;// Sampling Frequency


int Fcut = 1000; // Cutoff Frequency
int N = 125; // N of Order
float Fc = Fcut/Fsamp;
float Wc = 2 * PI * Fc;

unsigned short *AdcValue;


unsigned short *SocValue,*AdcStore;
unsigned short *DacOut;
unsigned short AdcOut;

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 100
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

unsigned short OutValue;


int Count,Inc;
float *Hd,*Hm;
float Val;

/* Inputs */
SocValue = (unsigned short *)0x60000558;
AdcValue = (unsigned short *)0x60000554;

Hd = (float *)0xc0010000;
Hm = (float *)0xc0020000;
AdcStore = (unsigned short *)0xc0030000;

/* Output */

DacOut = (unsigned short *)0x60000554;

Vi_DSKC6747Rev1_init( ); // Board Initialization

for(Count = -2 * N; Count < 2 * N; Count++)//MEMORY CLEAR


{
AdcStore[ Count ] = 0;
Hd[ Count ] = 0;
Hm[ Count ] = 0;
}

for(Count = -N/2; Count < N/2; Count++) // FILTER COEFFICIENTS

{
if(Count == 0)
Hd[Count] = 2 * Fc;

else
{
Val = sin(Wc * Count);
Hd[Count] = Val / (Count * PI);
}
}

Inc=0;
for(Count = -N/2; Count < N/2; Count++)
{

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 101
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Hm[Inc] = Hd[Count];
Inc++;
}
while(1)
{

*SocValue = 0x00;
for(Count = 0; Count < 100; Count++);

AdcOut = *AdcValue;
*AdcStore = AdcOut;

OutValue = 0;

for(Count = 0; Count < N; Count++)


OutValue += (*(AdcStore + Count) * *(Hm + Count));

for(Count = (N-1); Count >= 0; Count--) *(AdcStore


+ Count + 1) = *(AdcStore + Count);

OutValue |=0x1000;

*DacOut = OutValue;

Input & Output:

Sequence Memory Address Values


Fsamp – Sampling Frequency - 7500
Fcut – Cutoff Frequency - 1000
N – Order of the filter - 40
SocValue – (Start of conversion) 0x60000558 -
AdcValue(Adc Input fromFG) 0x60000554 -
DacOut(GRO Output from Dac) 0x60000554 -

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 102
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


/* //-------- NOTE --------- //

Note 1: To increase the CUTOFF Freq means Sampling Freq also increase.
Note 2: The Length of the Filter N will be decrease
*/
************************************************************************

FIR HIGH PASS FILTER

************************************************************************

#include<fastmath67x.h>
#include<math.h>
#define PI 3.14
void Vi_DSKC6747_init( );
void main()
{

const float Fsamp = 5000;// Sampling Frequency


int Fcut = 1000; // Cutoff Frequency
int N = 118; // N of Order
float Fc = Fcut/Fsamp;
float Wc = 2 * PI * Fc;

unsigned short *AdcValue;


unsigned short *SocValue,*AdcStore;
unsigned short *DacOut;
unsigned short AdcOut;

unsigned short OutValue;


int Count,Inc;
float *Hd,*Hm;
float Val;

/* Inputs */

SocValue = (unsigned short *)0x60000558;


AdcValue = (unsigned short *)0x60000554;

Hd = (float *)0xc0010000;
Hm = (float *)0xc0020000;

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 103
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


AdcStore =(unsigned short *)0xc0030000;

/* Output */

DacOut = (unsigned short *)0x60000554;

Vi_DSKC6747Rev1_init( ); // Board Initialization

for(Count = -2 * N; Count < 2 * N; Count++)


{
AdcStore[ Count ] = 0;
Hd[ Count ] = 0;
Hm[ Count ] = 0;
}

for(Count = -N/2; Count < N/2; Count++)

{
if(Count == 0)
Hd[Count] = 1 - (2 * Fc);

else
{
Val = (-1) * sin(Wc * Count);
Hd[Count] = Val / (Count * PI);
}
}

Inc=0;
for(Count = -N/2; Count < N/2; Count++)
{
Hm[Inc] = Hd[Count];
Inc++;
}

while(1)
{

*SocValue = 0x00;
for(Count = 0; Count < 100; Count++);

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 104
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


AdcOut = *AdcValue;
*AdcStore = AdcOut;

OutValue = 0;

for(Count = 0; Count < N; Count++)


OutValue += (*(AdcStore + Count) * *(Hm + Count));

for(Count = (N-1); Count >= 0; Count--) *(AdcStore


+ Count + 1) = *(AdcStore + Count);

OutValue +=0x0800;
OutValue |=0x1000;

*DacOut = OutValue;

Input & Output:

Sequence Memory Address Values


Fsamp – Sampling Frequency - 7500
Fcut –Cutoff Frequency - 1500
N – Order of the filter - 32
SocValue – (Start of conversion) 0x60000558 -
AdcValue(Adc Input fromFG) 0x60000554 -
DacOut(GRO Output from Dac) 0x60000554 -

Note 1: To increase the CUTOFF Freq means Sampling Freq also increase.
Note 2: The Length of the Filter N will be decrease
*/
************************************************************************

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 105
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


FIR BAND PASS FILTER

************************************************************************

#include<fastmath67x.h>
#include<math.h>
#define PI 3.14
void Vi_DSKC6747_init( );

void main()

const float Fsamp = 25000;


int Fps = 1000;
int Fst = 3000;
int N = 25;
float Fc1 = Fps/Fsamp;
float Fc2 = Fst/Fsamp;
float Wc1 = 2 * PI * Fc1;
float Wc2 = 2 * PI * Fc2;

unsigned short *SocValue,*AdcValue;


unsigned short *AdcStore;
unsigned short *DacOut;
unsigned short AdcOut;

unsigned short OutValue;


int Count,Inc;
float *Hd,*Hm;
float Val;
SocValue = (unsigned short *)0x60000558;
AdcValue = (unsigned short *)0x60000554;

Hd = (float *)0xc0010000;
Hm = (float *)0xc0020000;
AdcStore = (unsigned short *)0xc0030000;

DacOut = (unsigned short *)0x60000554;

Vi_DSKC6747Rev1_init( ); // Board Initialization

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 106
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


for(Count = -2 * N; Count < 2 * N; Count++)

{
AdcStore[ Count ] = 0;
Hd[ Count ] = 0;
Hm[ Count ] = 0;
}

for(Count = -N/2; Count < N/2; Count++)

{
if(Count == 0)
Hd[Count] = 2 * (Fc2 - Fc1);

else
{
Val = sin(Wc2 * Count) - sin(Wc1 * Count);
Hd[Count] = Val / (Count * PI);
}
}

Inc=0;
for(Count = -N/2; Count < N/2; Count++)
{

Hm[Inc] = Hd[Count];
Inc++;

while(1)
{

*SocValue = 0x00;
for(Count = 0; Count < 100; Count++);

AdcOut = *AdcValue;
*AdcStore = AdcOut;

OutValue = 0;

for(Count = 0; Count < N; Count++)


OutValue += (*(AdcStore + Count) * *(Hm + Count));

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 107
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

for(Count = (N-1); Count >= 0; Count--) *(AdcStore


+ Count + 1) = *(AdcStore + Count);

OutValue +=0x0800;
OutValue |= 0x1000;

*DacOut = OutValue;

Input & Output:

Sequence Memory Address Values


Fsamp – Sampling Frequency - 8500
Fps –Pass Band Frequency - 1000
Fst –Stop Band Frequency - 2000
N – Order of the filter - 34
SocValue – (Start of conversion) 0x60000558 -
AdcValue(Adc Input fromFG) 0x60000554 -
DacOut(GRO Output from Dac) 0x60000554 -

Note 1: To increase the CUTOFF Freq means Sampling Freq also increase.
Note 2: The Length of the Filter N will be decrease
*/

************************************************************************

FIR BAND REJECT FILTER

************************************************************************

#include<fastmath67x.h>

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 108
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


#include<math.h>
#define PI 3.14
void Vi_DSKC6747_init( );
void main()
{

const float Fsamp = 16500;


int Fps = 1000;
int Fst = 3000;
int N = 37;
float Fc1 = Fps/Fsamp;
float Fc2 = Fst/Fsamp;
float Wc1 = 2 * PI * Fc1;
float Wc2 = 2 * PI * Fc2;

unsigned short *SocValue,*AdcValue;


unsigned short *AdcStore;
unsigned short *DacOut;
unsigned short AdcOut;

unsigned short OutValue;


int Count,Inc;
float *Hd,*Hm;
float Val;

SocValue = (unsigned short *)0x60000558;


AdcValue = (unsigned short *)0x60000554;

Hd = (float *)0xc0010000;

Hm = (float *)0xc0020000;
AdcStore = (unsigned short *)0xc0030000;

DacOut = (unsigned short *)0x60000554;

Vi_DSKC6747Rev1_init( ); // Board Initialization

for(Count = -2 * N; Count < 2 * N; Count++)


{
AdcStore[ Count ] = 0;
Hd[ Count ] = 0;

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 109
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57


Hm[ Count ] = 0;
}

for(Count = -N/2; Count < N/2; Count++)

{
if(Count == 0)
Hd[Count] = 1 - (2 * (Fc2 - Fc1));

else
{
Val = sin(Wc1 * Count) - sin(Wc2 * Count);
Hd[Count] = Val / (Count * PI);
}
}

Inc=0;
for(Count = -N/2; Count < N/2; Count++)
{
Hm[Inc] = Hd[Count];
Inc++;
}

while(1)
{

*SocValue = 0x00;
for(Count = 0; Count < 100; Count++);

AdcOut = *AdcValue;
*AdcStore = AdcOut;

OutValue = 0;

for(Count = 0; Count < N; Count++)


OutValue += (*(AdcStore + Count) * *(Hm + Count));

for(Count = (N-1); Count >= 0; Count--) *(AdcStore


+ Count + 1) = *(AdcStore + Count);

OutValue |= 0x1000;

*DacOut = OutValue;

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 110
VTU Connect Android App Download Now On Google Play Store

DIGITAL SIGNAL PROCESSING LAB 18ECL57

Input & Output:

Sequence Memory Address Values


Fsamp – Sampling Frequency - 8500
Fps –Stop Band Frequency - 1000
Fst –Pass Band Frequency - 2500
N – Order of the filter - 33
SocValue – (Start of conversion) 0x60000558 -
AdcValue(Adc Input fromFG) 0x60000554 -
DacOut(GRO Output from Dac) 0x60000554 -

Note 1: To increase the CUTOFF Freq means Sampling Freq also increase.
Note 2: The Length of the Filter N will be decrease
*/

OUTCOME:

FIR filter structure is used to implement almost any sort of frequency response digitally.

VTU Connect Android App Download Now On Google Play Store


DEPT. OF ECE, ATMECE, MYSURU Page 111

You might also like