0% found this document useful (0 votes)
106 views

Latest - Updated Manual

Uploaded by

zeeshan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Latest - Updated Manual

Uploaded by

zeeshan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 138

COMSATS University Islamabad, Lahore Campus

Department of Electrical & Computer Engineering

EEE 324–Digital Signal Processing


Lab Manual For Spring 2020

Lab Resource Person


Engr. Abu bakar Talha Jalil

Theory Resource Person


Dr. Khurram Ali

Dr. Ejaz Ansari


Engr. Usman Iqbal

Name: ZEESHAN ASHRAF_ Registration Number:C IIT/FA17-BEE-147


/LHR

Program: __ DSP Batch: Spring

Semester 6
Revision History

S.No. Update Date Performed by

1 Lab Manual Preparation Sep-2014 Mr. M. Usman Iqbal

Dr. Hafiz M
Asif Dr.
Khurram Ali
2 Lab Manual Review Feb-2015
3 Layout Modifications Feb-2015 Mr. M Usman Iqbal

4 Lab Manual Modifications Nov-2015 Mr. Haad Akmal


Mr. Abdul
Quddious Mr.
Jawad Ali

5 Lab Manual Modifications Aug-2016 Engr. Maida


Farooq Engr.
Jawad Ali
6 Lab Manual Modifications Aug-2017 Mr. Mukhtar Hussain

7 Lab Manual Modifications Nov-2017 Mr. M Usman Iqbal


Mr. Mukhtar Hussain

8 Lab Manual Modifications Nov-2018 Mr. Abu bakar Talha

9 Lab Manual Modifications Feb-2020 Mr. Abu bakar Talha

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual i


Preface

This course builds on the basic concepts learned in the course ‘Signal and Systems', with emphasis on `digital
and discrete-time signals'. The realm of DSP extends over a multitude of disciplines, ranging from
communications, space exploration, computer vision, remote sensing, and even entertainment. This course,
therefore, holds vital importance. Moreover, a sound knowledge of DSP is imperative in undertaking numerous
other courses, offered in the subsequent semesters during the course of the study towards the award of Bachelors
in Telecom/Computer engineering.

Following are the major topics covered in this course.


• Digital Signals in Time and Frequency Domains
• Discrete Time LTI Systems
• LTI Systems Analysis in Time and Frequency Domains and stability
• Z-Transform
• Sampling and Quantization of Signals
• A/D and D/A Signal Transformation
• Frequency domain analysis of signals and systems
• Discrete Fourier Transform and Fast Fourier Transform
• Digital Filters, IIR, FIR

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual ii


Books

Text Books

1. Digital Signal Processing: Principles, Algorithms and Applications by John G. Proakis and Dimitris Manolakis
(P&M)

Reference Books

1. Discrete-Time Signal Processing by Alan V. Oppenheim, Ronald. W. Schafer, Pearson Education (OS)

2. Signals and Systems by Alan V. Oppenheim, Alan S. Willsky and with S. Hamid (OW&N)

3. Digital Signal Processing and Applications with the C6713 and C6416 DSK by Rulph Chassaing

Reference Books for Manual

1. Digital Signal Processing: A Computer-based approach by Sanjit K. Mitra, McGraw-Hill Science (SKM)

2. Digital Signal Processing using MATLAB by Vinay K. Ingle, Jhon G. Proakis.

3. Digital Signal Processing Fundamentals and Applications by Li-Tan, Jean Jiang

Learning Outcomes

Theory CLOs

After successfully completing this course, the students will be able to:

1. Apply all the concepts of the signal and systems, their mathematical description/ representation and

transformations in discrete domain to understand and analyze discrete time LTI systems. (PLO1-C3)

2. Analyze the discrete systems using Fast Fourier Transform (FFT) and filter realization techniques for

discrete time signal processing. (PLO2-C4)

3. Design the digital filter using analog and digital techniques for discrete time signal processing (PLO3-C5)

Lab CLOs

After successfully completing this course, the students will be able to:

1. Manipulate the concepts of digital signal processing using software and hardware tools.(PLO5-P5)

2. Explain the concepts of digital signal processing by justifying the lab experiments performed using software
and hardware tools. (PLO10-A4)

3. Demonstrate the concepts of digital signal processing by completing the lab tasks through effective
individual and team work. (PLO9-A3)
CLOs-PLOs Mapping

PLO COGNITIVE DOMAIN Affective Domain Psychomotor Domain

PLO 10
PLO 1

PLO 2

PLO 3

PLO 5
PLO 9
CLO

CLO 1 X C3

CLO 2 X C4

CLO 3 X C5

CLO 4 X P5

X A4
CLO 5

CLO 6 X A3
Grading Policy
The final marks for lab would comprise of Lab Assignment (25%), Lab S1 (10%), Lab S2 (15 %) and Lab
Terminal (50%).
S- I 0.5*(S-I Exam Result) + 0.5*(average of Lab evaluation 1-4)
S- II 0.5*(S-I Exam Result) + 0.5*[(average of Lab evaluation 5-8)*1.5]
Terminal 0.5*(Terminal marks out of 50) +0.25*[(average of lab evaluation of Lab 9-12) *5] +
0.10*[(average of lab evaluation of Lab 5-8) *5] + 0.15*[(average of lab evaluation of Lab 1-4) *5]
Lab Assignment Mark s:
Lab Assignment 1 marks=Lab report marks from experiment 1-3
Lab Assignment 2 marks=Lab report marks from experiment 4-6
Lab Assignment 3 marks=Lab report marks from experiment 7-9
Lab Assignment 4 marks=Lab report marks from experiment 10-14

List of Eq uipment
TMS320C6713 DSP Starter Kit (DSK)

Softw are Resources


MATLAB® (R2014)
CODE COMPOSER STUDIO (CCS) v3.1

Lab Instructions
• This lab activity comprises of three parts: Pre-lab, Lab Tasks, Lab Report and Conclusion and Viva
session.
• The students should perform and demonstrate each lab task separately for step-wise evaluation.
• Only those tasks that are completed during the allocated lab time will be credited to the students.
• Students are however encouraged to practice on their own in spare time for enhancing their skills.

Lab Report Instructions


All questions should be answered precisely to get maximum credit. Lab report must ensure following items:
• Lab objectives
• MATLAB codes
• Results (graphs/tables) duly commented and discussed
• Conclusion

iv

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual


Safety Instructions

1. Conduct yourself in a responsible manner at all times in the laboratory.


2. Know the location of electrical panels and disconnect switches in or near your laboratory so that power
can be quickly shut down in the event of a fire or electrical accident
3. Report any damages to equipment, hazards, and potential hazards to the laboratory instructor/staff
available at the time.
4. If in doubt about electrical safety, see the laboratory instructor.
5. Make sure that the computers should be properly logged off when you complete your lab task.
6. Make sure that the software used in Lab is properly handled.
7. During any problem regarding software consult the Lab instructor/staff available.
8. Do not eat food, drink beverages or chew gum in the laboratory and do not use laboratory glassware as
containers for food or beverages. Smoking is strictly prohibited in lab area.
9. Do not plug in a flash drive on lab computers.
10. Do not upload, delete or alter any software on the lab PC.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual v


Table of Contents
Revision History ........................................................................................................................................................... i

Preface ......................................................................................................................................................................... ii

Books .......................................................................................................................................................................... iii

Learning Outcomes .................................................................................................................................................... iii

CLOs – PLOs Mapping .............................................................................................................................................................iii

Grading Policy ............................................................................................................................................................ iv

List of Equipment ....................................................................................................................................................... iv

Software Resources .................................................................................................................................................... iv

Lab Instructions ......................................................................................................................................................... iv

Lab Report Instructions ............................................................................................................................................. iv

Safety Instructions ....................................................................................................................................................... v

CLO- Lab Experiment Mapping ..............................................................................................................................................ix

LAB # 1 ...................................................................................................................................................................... 10

To sketch the basic Discrete Time Signals for Digital Signal Processing using MATLAB....................................... 10
Objectives ............................................................................................................................................................. 10
Pre-Lab ................................................................................................................................................................... 10
Lab Tasks ............................................................................................................................................................... 13
Lab Assessment ................................................................................................................................................... 16

LAB # 2 ...................................................................................................................................................................... 17

To construct Analog-to-Digital conversion experiment for discrete time signal operations using MATLAB.......... 17
Objectives ............................................................................................................................................................... 17
Pre-Lab ................................................................................................................................................................... 17
Lab Tasks ............................................................................................................................................................... 19
Lab Assessment ................................................................................................................................................... 23

LAB # 3 ...................................................................................................................................................................... 24

To sketch the response of the Linear Time Invariant system for arbitrary discrete time inputs using MATLAB .. 24
Objectives ............................................................................................................................................................... 24
Pre-Lab ................................................................................................................................................................... 24
Lab Tasks ............................................................................................................................................................... 25
Lab Assessment ................................................................................................................................................... 29

LAB # 4 ...................................................................................................................................................................... 30

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual vi


To study the z-Transform, properties of z-Transform and to analyze the Linear Time Invariant system in z-
Domain using MATLAB ............................................................................................................................................ 30
Objectives ................................................................................................................................................................ 30
Pre-Lab .................................................................................................................................................................... 30
Lab Tasks ................................................................................................................................................................ 31
Lab Assessment ........................................................................................................................................................................................ 34

LAB # 5 ....................................................................................................................................................................... 35

To begin with the practical implementation of Digital Signal Processing concepts using hardware (DSP Starter
Kits TMS320C6713) ................................................................................................................................................... 35
Objectives ................................................................................................................................................................ 35
Pre-Lab .................................................................................................................................................................... 35
Lab Tasks ................................................................................................................................................................ 38
Lab Assessment ........................................................................................................................................................................................ 50

LAB # 5 ....................................................................................................................................................................... 51

To explain Frequency domain analysis of Discrete Time signals using Discrete Fourier Transform (DFT) on
MATLAB ................................................................................................................................................................... 51
Objectives ................................................................................................................................................................ 51
Pre-Lab .................................................................................................................................................................... 51
Lab Tasks ................................................................................................................................................................ 51
Lab Assessment ........................................................................................................................................................................................ 55

LAB # 7 ....................................................................................................................................................................... 56

To explain the efficient computation of the DFT and its applications in Linear Filtering for Digital Signal
Processing using MATLAB ........................................................................................................................................ 56
Objectives ................................................................................................................................................................ 56
Pre-Lab .................................................................................................................................................................... 56
Lab Task .................................................................................................................................................................. 58
Lab Assessment ........................................................................................................................................................................................ 61

LAB # 8 ....................................................................................................................................................................... 62

To perform Sampling and reconstruction of continuous time signals; different Sampling and Interpolation
techniques using MATLAB and SIMULINK ............................................................................................................ 62
Objectives ................................................................................................................................................................ 62
Pre Lab .................................................................................................................................................................... 62
Lab Tasks ................................................................................................................................................................ 63
Lab Assessment ........................................................................................................................................................................................ 65

LAB # 9 ....................................................................................................................................................................... 66

To perform Sampling and Quantization of real time Audio Signals on DSP Kit TMS320C6713; analyze the effect
of Aliasing and Quantization Noise ............................................................................................................................ 66
Objectives ................................................................................................................................................................ 66
Pre-Lab .................................................................................................................................................................... 66
Lab Task .................................................................................................................................................................. 66
Lab Assessment ........................................................................................................................................................................................ 70

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual vii
LAB # 10 .................................................................................................................................................................... 71

To develop FFT Algorithm with Radix-2 on DSP Kit TMS320C6713 ..................................................................... 71


Objective ................................................................................................................................................................ 71
Pre-Lab Task........................................................................................................................................................... 71
Lab Task ................................................................................................................................................................. 71
Lab Assessment ................................................................................................................................................... 74

LAB # 11 .................................................................................................................................................................... 75

To study the realization of Discrete Time Systems, Structures for FIR and Structure for IIR, using MATLAB .... 75
Objectives ............................................................................................................................................................... 75
Pre Lab ................................................................................................................................................................... 75
Direct Form............................................................................................................................................................. 76
Cascade Form ......................................................................................................................................................... 76
Lab Task ................................................................................................................................................................. 78
Lab Assessment ................................................................................................................................................... 80

LAB # 12 .................................................................................................................................................................... 81

To design Digital IIR filters using Analog Prototype ................................................................................................ 81


Objectives ............................................................................................................................................................... 81
Pre Lab ................................................................................................................................................................... 81
Lab Tasks ............................................................................................................................................................... 82
Lab Assessment ................................................................................................................................................... 85

LAB # 13 .................................................................................................................................................................... 86

To design Linear Phase FIR filters based on Windows ............................................................................................ 86


Objectives ............................................................................................................................................................... 86
Pre Lab ................................................................................................................................................................... 86
Lab Tasks ............................................................................................................................................................... 88
Lab Assessment ................................................................................................................................................... 90

LAB # 14 .................................................................................................................................................................... 91

To implement FIR and IIR filters on DSP Kit TMS320C6713 for real time processing .......................................... 91
Objectives ............................................................................................................................................................... 91
Pre-Lab Task........................................................................................................................................................... 91
Lab Tasks ............................................................................................................................................................... 91
Lab Task 3: Implement FIR filter............................................................................................................................. 94
Lab Assessment ................................................................................................................................................... 96

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual viii
CLO – Lab Experiment Mapping

LAB

LAB #10

LAB #11

LAB #12
LAB #1

LAB #2

LAB #3

LAB #4

LAB #5

LAB# 6

LAB #7

LAB #8

LAB #9
CLOs`
CLO 4 X X X X X X X X X X X X
X X X X X X X X X X X X
CLO 5
CLO 6 X X X X X X X X X X X X
Lab Experiment No. | 1

LAB # 1
To sketch the basic Discrete Time Signals for Digital Signal Processing using
MATLAB
Objectives

 To explain basics of signal processing using MATLAB


 To explain user defined functions and its significance using MATLAB

Pre-Lab
1. Revising the previous concepts
Here we briefly describe the basic sequence operation and their MATLAB equivalents.

1. Signal Addition
This is sample by sample addition given by
x1(n) + x2(n) = { x1(n) + x2(n)}

It is implemented in MatLab by the arithmetic operation “+”. However the length of the sequence x1(n) and
x2(n ) should be same. If the sequences are of unequal lengths, or if the sample positions are different for the
equal length sequences then we cannot directly use the operator “+”. So while adding such sequences, MatLab’s
indexing operation requires attention.

2. Signal Multiplication
This is sample by sample multiplication or “dot” multiplication given by

{ x1(n)}.{x2(n)} = {x1(n)x2(n)}

It is implemented in MatLab by the array operator “.*”. Once again similar restrictions apply for the .* operator
as for the “+” operator. Therefore we have to develop the MatLab function ‘signal_multi’, which is similar to
the ‘signal_add’.

3. Scaling
It this operation each sample is multiplied by a scalar ‘𝛼′

𝛼{x(n)} = {𝛼x(n)}

An arithmetic operation * is used to implement this operation.

4. Shifting
In this operation, each sample of x(n) is shifted by an amount of k to obtain a shifted sequence y(n)

y(n) = {x(n − k)}

if we let N = n − k, the n = N + k and the above operation is given by

y(N + k) = {x(N)}

Hence this operation has no effect on the vector x, but the vector n is changed by adding k to each element.

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 10
Lab Experiment No. | 1

5. Folding
In this operation each sample of x(n) is flipped around n = 0 to obtain a folded sequence y(n).

y(n) = { x(−n)}

6. Sample Summation
This operation differs from signal addition operation. It adds all sample values of x(n) between n1 and n2.

It is implemented by the suN(x(n1: n2)) function.

7. Sample Products
This operation also differs from signal multiplication operation. It multiplies all sample values of x(n) between
n1 and n2.

It is implemented by the erod(x(n1: n2)

8. Signal Energy
The energy of a sequence x(n) is given by

Where superscript * denotes the operation of complex conjugation. The energy of finite duration sequence x(n)
can be computed in MatLab using

>> Ex = sum (x .* conj (x)) ; % one approach


>> Ex = sum (abs (x) .^2) ; % another approach

9. Signal Power
The average power of a periodic sequence with fundamental period N is given by

Pre-Lab Task
Task 1
Generate and plot each of the following sequences over the interval −n ∶ n, determined by your roll number
as shown below.

a. x1(n) = 2 𝛼(n + 2) − 𝛼(n − 4),


b. x2(n) = n [u(n) − u(n − 10) + 10 e−0.3(n−10)[u(n − 10) − u(n − 20)]

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 11


Lab Experiment No. | 1

c. x3(n) = x1(n) ∗ x2(n) + x1(−n) ∗ x2(−n)

Task 2
Generate the following complex valued signal and plot its magnitude, phase and the real part and the imaginary
part in four separate subplots.
x4(n) = e(−0.1+j0.3)n
Where the value of n is same as in the lab task 1.

2. Use of Help Command


>> help ‘command’

which will provide information on the inputs, outputs, usage, and functionality of the ‘command’. A complete
listing of commands sorted by functionality can be obtained by typing help at the prompt.

Functions

A function is a group of statements that together perform a task. Functions operate on variables within their own
workspace, which is also called the local workspace, separate from the workspace you access at the MATLAB
command prompt which is called the base workspace. Functions can accept more than one input arguments and
may return more than one output arguments.

Use help command to find out how you can create and call the function. Explain it in your words

3. Plotting using MATLAB


Plot the following two signals together in the same plot.

wℎ ere t = 0 → 2sec
Use proper indicators, legends, title and label the axis. Use help command if require

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 12


Lab Experiment No. | 1

Write your MATLAB code

Plot the signal x(t) = 3 cos(3𝛼t + 𝛼/3) in four periods.

Lab Tasks
Lab Task 1: Creating a user defined Function
Write a MATLAB functions for following basic sequences. Function should take input variables no, n1, n2 and
returns ‘x’ and ‘n’. As given by equations

1. Unit Sample Sequence


1, n = no
𝛼(n − n o) = { , wℎ ere n1 ≤ n ≤ n2
0, n ≠n o
2. Unit Step Sequence
1, n ≤ no
u(n − n o) = { , wℎ ere n1 ≤ n ≤ n2
0, n <n o
3. Exponential Growing Sequence
x(n − no) = e(n−n𝛼), wℎ ere n1 ≤ n ≤ n2
4. Exponential Decaying Sequence

x(n − no) = e−(n−n𝛼), wℎ ere n1 ≤ n ≤ n2

All plots should be properly commented, titled, labelled. All three different signals corresponding to same basic
sequence should be plotted in one figure and should be differentiated by different colors and other methods.
Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 13


Lab Experiment No. | 1

Function 1 MATLAB Code Function 2 MATLAB Code

function [x,n] = impseq(n0,n1,n2)


% Generates x(n) = delta(n-n0); n1 <= n <= n2
%
% [x,n] = impseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) == 0];
end

Function 3 MATLAB Code Function 4 MATLAB Code

Write MATLAB code to call all the functions and plot it on one figure with proper labelling

Lab Task 2: Recursive Function


Write a MATLAB recursive function code to compute factorial of number. Also verify your function.

Solution

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 14
Lab Experiment No. | 1

Lab Task 3: Random Number Generation


In practice, random number generators are often used to simulate the effect of noiselike signals and other random
phenomenon encountered in the physical world. Such noise is present in electronic devices and systems and
usually limits our ability to communicate over large distance. By generating such noise on computer, we can
study its effect through simulation.
Write a MATLAB code to generate uniformly distributed noise in an interval [-R, R], where R is your CIIT
Registration number.

Solution

Write a MATLAB code to generate a noise signal from gauss distribution of mean=B.M and variance=R, where
B.M is your birth month and R is your CIIT Registration number.

Solution

|EEE324 | Digital Signal Processing Lab Manual


Muhammad Usman Iqbal 15
Lab#1
Prelab(task 1)
Code:

Prelab(task 2)
Code:

Prelab(task 3)
Code:
Inlab(task 1)
Code:
Unit Sample
function [x,n] = impseq( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[(n-n0)==0]%logical operation for comparison
stem(n,x)
end
Unit Step
function [x,n] = impseq( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[(n-n0)>=0]
stem(n,x)
end
Exponential function
function [x,n] = exp1( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[exp(n-n0)]
stem(n,x)
end
Decay funtion
function [x,n] = exp1( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[exp(-1.*(n-n0))]
stem(n,x)
end
Calling code
clc
clear all
close all
n1=-4
n2=4
n0=2
[y,n]=exp1( n0,n1,n2 )
[z,n]=impseq(n0,n1,n2)
subplot(121)
stem(n,y)
xlabel('Time')
ylabel('Amplitude of y')
title('plot of y')
legend('Magnitude')
subplot(122)
stem(n,z)
xlabel('Time')
ylabel('Amplitude of z')
title('plot of z')
legend('Magnitude')
Output:

Inlab(task 3)
Code:
function [y] =fact( x )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
if x>1
n=1
y=x*fact(x-1)
else
y=1
end
clc
close all
clear all
x=5
[z] =fact( x )

Inlab(task 3)
Code:
Randome number
Noise signal

Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 2

LAB # 2
To construct Analog-to-Digital conversion experiment for discrete time signal
operations using MATLAB
Objectives
 To explain conversion of continuous time signal to discrete time signal using MATLAB
 To explain quantization of continuous amplitude signal using MATLAB

Pre-Lab
To process analog signals by digital means, it is first necessary to convert them into digital form. The procedure
is called analog-to-digital (A/D) conversion. A/D conversion is viewed as three step processes shown in Figure
1.

Analog Signal Digital Signal


Sampler Quantizer Coder
x(t) x[n]

Figure 2.1: Analog to Digital Converter

Here we first develop concepts of sampling processing in the time domain. Figure 2.2shows an analog
(continuous-time) signal (solid line) defined at every point over the time axis (horizontal line) and amplitude
axis (vertical line). Hence, the analog signal contains an infinite number of points. It is impossible to digitize an
infinite number of points. The infinite points cannot be processed by the digital signal (DS) processor or
computer, since they require an infinite amount of memory and infinite amount of processing power for
computations. Sampling can solve such a problem by taking samples at a fixed time interval as shown in Figure
3.2and Figure 3.3, where the time T represents the sampling interval or sampling period in seconds.

Figure 2.2 : Analog Signals and Discrete Time samples

For a given sampling interval T, which is defined as the time span between two sample points, the sampling rate
is therefore given by

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 17


Lab Experiment | 2

For example, if a sampling period is 𝑇 = 125 microseconds, the sampling rate is .


After obtaining the sampled signal whose amplitude values are taken at the sampling instants, the processor is
able to process the sample points. Next, we have to ensure that samples are collected at a rate high enough that
the original analog signal can be reconstructed or recovered later. In other words, we are looking for a minimum
sampling rate to acquire a complete reconstruction of the analog signal from its sampled version. If an analog
signal is not appropriately sampled, aliasing will occur, which causes unwanted signals in the desired frequency
band.

Figure 2.3: Quantized Discrete Time Signal

The sampling theorem guarantees that an analog signal can be in theory perfectly recovered as long as the
sampling rate is at least twice as large as the highest-frequency component of the analog signal to be sampled.
The condition is described as

fs ≥ 2fNAx

Where fNax is the maximum-frequency component of the analog signal to be sampled. For example, to sample a
speech signal containing frequencies up to 4 kHz, the minimum sampling rate is chosen to be at least 8 kHz,
or 8,000 samples per second; to sample an audio signal possessing frequencies up to20 kHz, at least 40,000
samples per second, or 40 kHz, of the audio signal are required.

Figure 2.4illustrates sampling of two sinusoids, where the sampling interval between sample points is T=0.01
second, and the sampling rate is thus fs = 100 Hz. The first plot in the figure displays a sine wave with a
frequency of 40 Hz and its sampled amplitudes. The sampling theorem condition is satisfied since 2fNax = 80 < fs.
The samples amplitude are labelled using the circles shown in the first plot.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 18


Lab Experiment | 2

Figure 2.4: Plots of the appropriately sampled signals and non-appropriately sampled (aliased) signals.

We notice that the 40-Hz signal is adequately sampled, since the sampled values clearly come from the analog
version of the 40-Hz sine wave. However, as shown in the second plot, the sine wave with a frequency of 90 Hz
is sampled at 100 Hz. Since the sampling rate of 100 Hz is relatively low compared with the 90-Hz sine wave,
the signal is under sampled due to 2fNax = 80 < fs. Hence, the condition of the sampling theorem is not satisfied.
Based on the sample amplitudes labelled with the circles in the second plot, we cannot tell whether the sampled
signal comes from sampling a 90-Hz sine wave (plotted using the solid line) or from sampling a 10-Hz sine
wave (plotted using the dot-dash line). They are not distinguishable. Thus, they are aliases of each other. We
call the 10-Hz sine wave the aliasing noise in this case, since the sampled amplitudes actually come from
sampling the 90-Hz sine wave.

The process of converting analog voltage with infinite precision to finite precision is called the quantization
process. For example, if the digital processor has only a 3-bit word, the amplitudes can be converted into eight
different levels. A unipolar quantizer deals with analog signals ranging from 0 volt to a positive reference
voltage, and a bipolar quantizer deals with analog signals ranging from a negative reference to a positive
reference. The notations and general rules for quantization are as follows:

L = 2N

Where XNAx and XNIN are the maximum value and minimum values, respectively, of the analog input signal
x. The symbol L denotes the number of quantization levels, which is determined by above equation. Where is
the number of bits used in ADC. The symbol ∆ the step size of the quantizer or the ADC resolution.

Lab Tasks
Lab Task 1 a)
Consider the following continuous-time sinusoidal signal

x𝑇 (t) = cos(2𝑇ft) , 0 ≤t ≤ 2

Plot the discrete time signal x(n), 0 ≤ n ≤ 19 for sampling frequency FS = 100 Hz and f = 10, 50 and 90 (Hz).
Compare the graphs by identifying similarities and differences.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 19


Lab Experiment | 2

Lab Task 1 b)
Quantize signal x(n) (for f = 10Hz) using 4 bits and plot sampled, quantized and error signal on same figure.

Solution

Lab Task 1 c)
Quantize the sampled signal x(n) (for f = 100Hz) using 4, 5 and 6 bits respectively. Comment the difference in
output by computing SQNR

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 20


Lab Experiment | 2

Lab Task 2
Given the digital speech signal in the file guitatune.wav, Write a MATLAB program to

a) Read the audio file and find sampling frequency.


b) Quantize x(t) using 4-bit quantizers to obtain the quantized signal xq, assuming the signal range is from
−1 to 1 volts
c) plot the original speech, quantized speech, and quantization error.

d) Calculate the SQNR.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 21


Lab Experiment | 2

Lab Task 3
1. Write your own custom function which is able to simulate a uniform quantizer. The inputs should contain
sampled signal, number of bits used in quantization and return quantized and error signals

2. Write your own custom function which able to the SQNR due to quantization.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 22


Lab#2
Inlab(task#1a)
Code:
clc
clear all
close all
Fs=100
t=1/Fs
n=0:t:19.*t
f=10
f1=50
f2=90
x1=cos(2.*pi.*f.*n)
x2=cos(2.*pi.*f1.*n)
x3=cos(2.*pi.*f2.*n)
subplot(3,1,1)
stem(n,x1)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f.*n)')
title('GRAPH OF x1')
subplot(3,1,2)
stem(n,x2)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f1.*n)')
title('GRAPH OF x2')
subplot(3,1,3)
stem(n,x3)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f2.*n)')
title('GRAPH OF x3')
output:

Inlab(task#1b)
Code:
clc
clear all
close all
f=10
n=4
L=2^n
t=0:1/(2*f):2
x=cos(2*pi*f*t)
D=[(max(x)-min(x))]/L
xq=quant(x,D)
error=x-xq
figure
stairs(t,xq)
ylim([-5 5])
xlabel('Time')
ylabel('Amplitude')
legend('Quantized')
title('GRAPH OF xq')
figure
stem(t,error)
ylim([-5 5])
xlabel('Time')
ylabel('Amplitude')
legend('Error')
title('GRAPH OF ERROR')
figure
stairs(t,x)
ylim([-5 5])
xlabel('Time')
ylabel('Amplitude')
legend('Sample')
title('GRAPH OF SAMPLE')
ouput:

Inlab(task#2)
Code:
clc
clear all
close all
[x,fs]=audioread('guitartune.wav')
n=4
L=2.^n
t=0.1:length(x-1)
D=[1-(-1/L)]
xq=quant(x,D)
error=x-xq
subplot(3,1,1)
stairs(t,xq)
xlabel('Time')
ylabel('Amplitude')
legend('Quantized')
title('GRAPH OF xq')
subplot(3,1,2)
stem(t,error)
xlabel('Time')
ylabel('Amplitude')
legend('Error')
title('GRAPH OF ERROR')
subplot(3,1,3)
stem(t,x)
xlabel('Time')
ylabel('Amplitude')
legend('Sample')
title('GRAPH OF SAMPLE')
SQNR=6.03*n+1.74
Output:

Inlab(task#3)
Code:
clc
clear all
close all
f=10
n=4
t=0:1/(2*f):2
x=cos(2*pi*f*t)
[ xq,error,SQR ] = qunt( x,n,f,t )
subplot(311)
stem(t,xq,'g')
xlabel('samples')
ylabel('Amplitude')
title('Quantized Signal')
subplot(312)
stem(t,error,'r')
xlabel('samples')
ylabel('Amplitude')
title('Error Signal')
subplot(313)
stem(t,x)
xlabel('samples')
ylabel('Amplitude')
title('Original Signal')
function [ xq,error,SQR ] = qunt( x,n,f,t )
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
L=2.^n
D=[(max(x)-min(x))/(L-1)]
xq=quant(x,D)
error=x-xq
SQR=10.*log10(sum(x.^2)/sum(error.^2))
end
clc
clear all
close all
f=100;
n=10;
L=2^n;
t=0:1/(2*f):2;
x=cos(2*pi*f.*t);
D=[(max(x)-min(x))/(L-1)];
xq=quant(x,D);
error=x-xq;
SQR=10.*log10(sum(x.^2)./sum(error.^2))
Output:

Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 3

LAB # 3
To sketch the response of the Linear Time Invariant system for arbitrary discrete
time inputs using MATLAB

Objectives
 To explain discrete time convolution sum using MATLAB
 To verify the properties of LTI system using MATLAB

Pre-Lab
Discrete Time LTI System and Convolution Sum
Discrete Time Systems
The function of a discrete time system is to process a given input sequence to generate an output sequence. In
the most applications, the discrete time system used is single input and single output system, as shown in the
diagram below.

Discrete Time
x(n) y(n)
System

Figure 1: Schematic representation of discrete time systems

Mathematically, a discrete time system is described as an operator T{.} that takes a sequence x(n) and transforms
it into another sequence y(n). That is

y(𝛼) = 𝛼[x(𝛼)]

In practical discrete time system, all the signals are digital signals and operations on such signals also leads to
the digital signals. Such a discrete time is usually called “Digital Filter”. We shall refer to discrete time system
as a digital filter whether or not it has been implemented using finite precision arithmetic.

Linear System
A discrete time system is a linear if and only if it satisfies the principle of superposition

Linear Time Invariant System


A linear system in which an input-output pair x(n) and y(n) is invariant to a shift n in time is called a linear time
invariant system. For an LTI system the liner operator and shift operators are reversible. The impulse response
of the LTI system is given by h(n). Mathematical operation shown in the below equation is called linear
convolution sum.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 24


Lab Experiment | 3

L {.} Shift By

Shift By L {.}

Simple Discrete Time System


A simple example of discrete time system is the accumulator defined by the input relationship.

It accumulates all input sample values from −∞ to n.

Pre-Lab Tasks
(Attach extra A4 White page if needed)

Let the following rectangular pulse x(𝛼) be an input to an LTI system with impulse response ℎ (n), determine
the outputy(𝛼). Plot the input signal and output signal.

x(n) = u(n) − u(n − 10)

ℎ (n) = (0.9)n u(n)

Lab Tasks

Lab Task 1
Given the following two sequences, determine the convolution y(n). Plot each step in the subplot.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 25


Lab Experiment | 3

Lab Task 2
Write a MATLAB function to systematically develop the sequence y[𝛼] generated by the convolution of the
two-finite length sequence x[𝛼] and 𝛼[𝛼]. Program should be able to handle causal and non- casual
sequences. You should verify this functionality of the program. Program should call for the input sequences and
their indices vectors.

|EEE324 | Digital Signal Processing Lab Manual 26


Muhammad Usman Iqbal
Lab Experiment | 3

Lab Task 3
Show that the convolution of a length-M sequence with a length-N sequence leads to a sequence of length (M+N-
1).

Lab Task 4
Verify Properties of LTI Systems
1. Commutative Law
2. Associative Law
3. Distributive Law
4. Linearity
5. Time Invariance

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 27


Lab Experiment | 3

Lab 3 prelab

clc
clear all
close all
n=-10:10
x=[n>=0]-[(n-10)>=0]
h=(0.9).*[n>=0]
y=conv(x,h)
subplot(311)
stem(n,x)
subplot(312)
stem(n,h)

subplot(313)
stem(y)

Lab3Task1
clc
clear all
close all
x=[3 11 7 0 -1 4 2]
nx=-3:3
h=[2 3 0 -5 2 1]
nh=-1:4
y=conv(x,h)
subplot(311)
stem(nx,x)
subplot(312)
stem(nh,h)
subplot(313)
stem(y)

Lab3Task2
function [y,ny] = conv_m(x,nx,h,nh)

% Modified convolution routine for signal processing

% --------------------------------------------------

% [y,ny] = conv_m(x,nx,h,nh)

% y = convolution result

% ny = support of y

% x = first signal on support nx

% nx = support of x

% h = second signal on support nh

% nh = support of h
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];

y = conv(x,h);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 28


Lab Experiment | 3

clc
clear all
close all
nx=-3:3
x=[3 11 7 0 -1 4 2]
nh=-4:1
h=[9 5 3 4 5 6]
[y,ny] = conv_m(x,nx,h,nh)
y1=conv(x,h)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 28


Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 4

LAB # 4
To study the z-Transform, properties of z-Transform and to analyze the Linear
Time Invariant system in z-Domain using MATLAB.
Objectives
 To study the signals and systems in Z Domain.

Pre-Lab
Z-Transform

In this Lab we introduce the z-transform, z-transform is counterpart of Laplace transform when dealing with
Discrete-Time signals. It is employed to transform difference equations that describe the input /output
relationships of discrete time systems into algebraic equations and is very useful tool for the analysis and design
of discrete-time systems.

Mathematical Definition

As Laplace transformation is a more general transform as compared to Fourier Transform for continuous-time
signals, z-Transform is a more general transform than discrete-time Fourier Transform when dealing with
discrete-time signal. A discrete-time signal is defined in the discrete time domain n; that is, it is given by a
function f[n], n ∈ Z. z-Transform is denoted by the symbol Z{. } and expresses a signal in z-domain, i.e., the
signal is given by a function F(z). The mathematical expression is

F(z) = Z{f[n]}

In other words, the z-transform of a function f[n] is f(z). The mathematical expression of the two-sided
(orbilateral) z-transform is

Where z is a complex variable. Setting the lower limit of the sum from minus infinity to zero yields the onesided
(or unilateral) z-transform whose mathematical expression is

In order to return from the z-domain back to the discrete-time domain, the inverse z-transform is applied. The
inverse z-transform is denoted by the symbol Z − 1{. }; that is, one can write

f[n] = Z−1{F(z)}.

The mathematical expression of the inverse z-transform is

MATLAB Commands Related with Z Transform


[H , ω] = freqz (B, A, N);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 30


Lab Experiment | 4

[H,T] = impz(B,A,N)
zplane(z,p);

[z, P, k] = tf2zp(B,A);

[B,A] = zp2tf(z,P,k);

[R,P,K]= residuez(B,A);

Pre Lab Tasks


(Attach extra A4 White page if needed) A z-

Transform H(z) is given below.

Write a MATLAB program that take two vectors ‘n’ & ‘d’ that are the numerator and denominator coefficients.
Program should find the following.

a) z-Transform in the factored form

b) Pole and Zero plot

c) Partial fraction expansion of the z transform

Lab Tasks
Lab Task 1
Determine the rational Z-Transform from its poles and zero locations. The zeros are at

ζ1 = 0.21, ζ2 = 3.14 , ζ3 = −0.3 + j 0.5 , ζ4= −0.3 − j0.5

And poles are at

𝛼1 = −0.45 , 𝛼2 = −0.67, 𝛼3 = 0.81 + j 0.72 , 𝛼4 = 0.81 − j0.72 and the gain constant is 2.2.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 31


Lab Experiment | 4

Lab Task 2
Using MATLAB, determine the partial fraction expansion of the z transform G(z), given by

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 32


Lab Experiment | 4

Lab Task 3
Determine the rational form of z transform from its partial fraction expansion of the following z transforms and
then determine their inverse z transform. Write down your analysis.

a)

b)

c)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 33


Lab Experiment | 4

Lab4Prelab
clc
clear all
close all
syms z
n=[4 3 9];
d=[4 3 -4];
% a part of prelab
[Z,P,K] = tf2zp(n,d);
[SOS,G] = zp2sos(Z,P,K);
factoredform =((1)+.75*(z.^-1)+2.25*z.^(-2))/(1 +0.75*z.^(-1)-z.^-2)
pretty(factoredform );
% b part of prelab
% partial fraction form
zplane(Z,P);
% c part of prelab
[R,P,K]=residuez(n,d);

Lab4Task1
clc
clear all
close all
% zeros vector
z=[.21 ,3.14, -.3+j*0.5, -0.3-j*0.5]
p=[-0.45,-.67,0.81+j*0.72,0.81-j*0.72]
% gain constant
k=2.2
[B,A]=zp2tf(z,p,k);
a=tf(B,A,-1);
disp('transfer function')
simplify(a)

Lab4Task2
clc
clear all
close all
syms z
B=[18 0 0 0 ];
A=[18 3 -4 -1];
[R,P,K]=residuez(B,A)

Lab4task3
clc
clear all
close all
syms z
n=[1 -1 0]
d=[1 1.3 0.3]

f= (z^2-z)/(z^2+1.3*z+0.3)
iztrans(f)
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 5

LAB # 5
To begin with the practical implementation of Digital Signal Processing concepts
using hardware (DSP Starter Kits TMS320C6713)
Objectives
 To assemble first experiment on DSP Kit 6713 using Code Composer Studio.
 To identify and troubleshoot the problems in the hardware implementation of first experiment.

Pre-Lab
Digital signal processing is one of the core technologies, in rapidly growing application areas, such as wireless
communications, audio and video processing and industrial control. The number and variety of products that
include some form of digital signal processing has grown dramatically over the last few years. DSP has become
a key component, in many of the consumer, communications, medical and industrial products which implement
the signal processing using microprocessors, Field Programmable Gate Arrays (FPGAs), Custom ICs etc. Due
to increasing popularity of the above-mentioned applications, the variety of the DSP-capable processors has
expanded greatly. DSPs are processors or microcomputers whose hardware, software, and instruction sets are
optimized for high-speed numeric processing applications, an essential for processing digital data, representing
analog signals in real time. The DSP processors have gained increased popularity because of the various
advantages like reprogram ability in the field, cost-effectiveness, speed, energy efficiency etc.

The hardware experiments in the DSP lab are carried out on the Texas Instruments TMS320C6713 DSP Starter
Kit (DSK), based on the TMS320C6713 floating point DSP running at 225 MHz. The basic clock cycle
instruction time is 1/(225 MHz)= 4.44 nanoseconds. During each clock cycle, up to eight instructions can be
carried out in parallel, achieving up to 8×225 = 1800 million instructions per second (MIPS).

Features of DSK6713
Key features of TMS320C6713 DSP Starter Kit (DSK6713) are:
 Operate at 225 MHz
 AIC23 stereo codec
 16 MB of synchronous DRAM
 512 KB of non-volatile Flash memory
 4 user accessible LEDs and DIP switches
 Software board configuration through registers implemented in CPLD
 Configurable boot options
 Standard expansion connectors for daughter card use
 JTAG emulation through on-board JTAG emulator with USB host
 Interface or external emulator
 Single voltage power supply (+5V)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 35


Lab Experiment | 5

Complex Programmable Logic Device (CPLD)


A Complex Programmable Logic Device (CPLD) is a combination of a AND/OR array. The AND/OR array
can be reprogrammed to implement different logic functions. The CPLD logic is used to implement
functionality specific to the DSK. The CPLD eliminate the need for additional discrete devices to be used with
DSK. CPLDs provide following features:
 Reprogrammable Device
o Lowers development cost
o Saves time
o High performance, low power operation
 Simple and easy to use
o Fits easily into existing design flow
 Low cost
o Reprogram ability: No need to purchase new equipment every time
o Lowers design cost, system cost, and maintenance cost
 Nonvolatile
o Save data even on power down
o CPLD functions available instantly on system power up
 Security
o Almost impossible to steal stored design
Peripherals
The TMS320C6713 devices contain peripherals for communication with off-chip memory, co-processors, host
processors and serial devices. Peripherals of DSK6713 are described below.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 36


Lab Experiment | 5

Host Port Interface


The Host-Port Interface (HPI) is a 16-bit wide parallel port through which a host processor can directly access
the CPUs memory space. The host device functions as a master to the interface, which increases ease of access.
The host and CPU can exchange information via internal or external memory. The host also has direct access to
memory-mapped peripherals. The HPI is connected to the internal memory via a set of registers.

General Purpose Input/Output (GPIO)


This is a 16-bit port provide general purpose pins that can be configured as input or output. When configured as
an output, data can be written to an internal register to control the state driven on the output pin. When
configured as an input, the state of the input pin can be detected by reading the state of an internal register. In
addition, the GPIO peripheral can produce CPU interrupts in different interrupt generation modes.

External Memory Interface


The External Memory Interface (EMIF) supports several external memory devices. This feature allows
additional data and program memory space than that is available on-chip.
 The devices supported are:
 Synchronous burst SRAM (SBSRAM) and Synchronous DRAM (SDRAM)
 Asynchronous SRAM, ROM, and FIFOs
 External shared-memory devices like microcontrollers

Multichannel Buffered Serial Port


The multichannel buffered serial port (McBSP) is based on the standard serial port interface. It provides:
 Full-duplex communication
 Double-buffered data registers, which allow a continuous data stream
 Independent framing and clocking for reception and transmission
 Direct interface to industry-standard codecs, analog interface chips (AICs)
 Multichannel transmission and reception of up to 128 channels
 An element sizes of 8-, 12-, 16-, 20-, 24-, or 32-bit
 µ-Law and A-Law companding

Multichannel Audio Serial Port


The DSK6713 includes two Multichannel Audio Serial Ports (McASP). The McASP interface modules support
one transmit and one receive clock zone. Each of the McASP has eight serial data pins which can be individually
allocated to any of the two zones.

Audio Codec
“The DSK6713 uses a Texas Instruments AIC23 (part #TLV320AIC23) stereo codec for input and output of
audio signals”. Audio codec provides two input and two output ports for analog signal as shown in fig4.1. It
provide two way communications as, it samples the audio signal from mic-in or line-in and convert back sample
into analog signal.

Timers
The DSK6713 has two 32-bit general-purpose timers that can be used to:
 Time events
 Count events

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 37


Lab Experiment | 5

 Generate pulses
 Interrupt the CPU
 Send synchronization events to the EDMA controller

Code Composer Studio (CCS)


CCS provides an IDE to incorporate the software tools. CCS includes tools for code generation, such as a C
compiler, an assembler, and a linker. It has graphical capabilities and supports real time debugging. It provides
an easy-to-use software tool to build and debug programs.
The C compiler compiles a C source program with extension .c to produce an assembly source file with
extension.asm. The assembler assembles an .asm source file to produce a machine language object file with
extension.obj. The linker combines object files and object libraries as input to produce an executable file with
extension.out. This executable file can be loaded and run directly on the C6713 processor.
In the lab we will use Code Composer Studio v3.1 run on Win XP.

Types of Files
There are a number of files with different extensions useful in building project. These are discussed below:
 file.pjt: file needed to create and build project
 file.c: C source program created by user
 file.asm: Assembly source program created by either user or by the C compiler
 file.h: file needed to support different functions in C source program
 file.lib: library file, such as the DSK6713 board support library file dsk6713.lib
 file.cmd: linker command file that maps sections to memory
 file.obj: file created by the assembler
 file.out: file created by the linker to be loaded on the C6713 processor to run C source program
functionality.
 file.cdb: configuration file when using DSP/BIOS (different for each family of kits)

Header Files
There are a number of header files that should be included in project. It contains some special function to be
performed. Following are some header files discussed. These files are useful in working with DSP kits
 dsk6713.h: It contains the definitions of macros require for the functionality of DSP board. No project
can be built without it.
 dsk6713_led.h: It contains the definitions of macros require for the LEDs on board.
 dsk6713_dip.h: It contains the definitions of macros require for the DIP switches available on board.
 dsk6713_aic23.h: It contains the definitions of macros require for the functionality of Audio Codec.
 csl.h: It contains the definitions of macros require for the Chip Support Library functions.
 csl_mcbsp.h: It contains the definitions of macros require for the operation of MCBSP.
 csl_gpio.h: It contains the definitions of macros require for the operation of GPIO
 csl_irq.h: It contains the definitions of Interrupt requests, mapping, reset, enable and disable it.

Lab Tasks
Task 1: Build your first project
Join DSP Kit to PC with USB JTAG interface. Power the kits with 5V standard adapter for DSK6713.
Precaution: DSK6713 are very sensitive to static charges. So don’t touch kit after power up it might damage it.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 38


Lab Experiment | 5

When DSK6713 is powered up it execute Power On Self-Test (POST) program stored in its flash. POST take
10-15 seconds to execute. POST checks all the subsystems of DSK6713. Output 1 kHz sinusoid to Audio Codec
for one second. If POST is successful it will blink all 4-leds for three times and then stabilize.

Verification
To verify if the kit is connected correctly with host and functioning properly “6713 DSK Diagnostic” is used.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 39


Lab Experiment | 5

Creating a Project
After verification of DSK6713 open Code Composer Studio v3.1. Following window will appear.

To create a new project, in the menu Project  New


A window will open, type the name of Project and select the specific DSP kit you are working and press Finish.
As shown below

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 40


Lab Experiment | 5

Window on the left side of CCS will appear like

To set DSP BIOS Configuration, menu File  New  DSP/BIOS Configuration. A window will appear as
configuration1. Save it with the same name as of your project in the project folder. As shown below.

Load the BIOS configuration of DSK board in the project. Right click on DSP/BIOS Configuration  Add
Files to Project select the DSP/BIOS configuration file saved in above step.

In menu Project Build Options. A window will appear select Compiler  category Preprocessor and enter
the path of dsk header files (to load kit header files) and predefined symbol as DSP kit name i.e. CHIP_6713.
It will look like as below

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 41


Lab Experiment | 5

Note: In general path of DSK header files is “C:\CCStudiov3.1\C6000\dsk6713\include”.

In menu Linker category Basic and set Library Search Path and Include Libraries.

Note: In general path of DSK Library files is “C:\CCStudiov3.1\C6000\dsk6713\lib”. Libraries to include is


“dsk6713bsl.lib”

Writing Code in CCS


File  New  Source File. A window will open write your code there and save it in the Project Folder with
the same name of Project with the extension “.c”. As shown below

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 42


Lab Experiment | 5

Load C Code to CCS. Right click on Source  Add Files to Project select the C Code file saved before

Sinewave C Code
#include<dsk6713.h>
#include <stdio.h>
#include<math.h>

float a[500];
void main() {
int i=0, junk=1;
for(i=0;i<500;i++) {
a[i]=sin(2*3.14*10000*i);
}

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 43


Lab Experiment | 5

junk=0;
}

Build the Project


In menu Project  Build or press F7.

If there is no Error in the code CCS IDE will create a hex file of extension “.out”. Name of file will be same as
of project.
To run the project on DSK6713, connect CCS with DSK6713. In menu Debug  Connect or press Alt+C.
 File Load Program ...: Select the “.out” file under debug folder.
 Debug Reset Cpu
 Debug Restart
 Debug Go Main
 Debug Run
To stop the processing menu Debug  Halt or Shift+F5.

Plot Graphs
Code Composer Studio IDE provides a tool to plot figures in time and frequency domain to visualize the data.
In this lab you will learn how to plot graphs.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 44


Lab Experiment | 5

Break Point

Run the project. The program runs


completely and temporarily halts
at the junk statement.

Add to Watch Window


To see or change the values in variables, you can use the watch window. To add a variable to the watch window,
right-click on the variable and select “Add to watch window”

You can see the values and changes in the watch window at the bottom right of the CCS

Plot Graph
Go to View > graph > time/frequency.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 45


Lab Experiment | 5

On the pop up window, fill:


 Start Address: Name of the array (to be plotted).
 Acquisition Buffer Size: Size of the array.
 Display Data Size: Size of the data to be displayed on the graph.
 DSP Data Type: Type of the array (integer or float).
 Sampling Rate: Sampling rate of the signal in the array.

To view spectrum of signal set Display Type to “FFT Magnitude”

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 46


Lab Experiment | 5

Lab Task 2: Write a code to toggle led


Here are some functions to help you
Function
Details of C function require is given below
 DSK6713_init(); /* To Initialize DSP Starter Kit DSK6713 */
o Require header dsk6713.h
o Input type Null
o Return Type Null
o To initialize DSK6713 kit

 DSK6713_LED_init(); /* To Initialize LEDs on DSK6713 */


o Require header dsk6713_led.h
o Input type Null
o Return Type Null
o To initialize LEDs on DSK6713 kit
 DSK6713_DIP_init(); /* To Initialize DIP Switches on DSK6713 */
o Require header dsk6713_dip.h
o Input type Null
o Return Type Null
o To initialize DIP switches on DSK6713 kit
 DSK6713_LED_on(int); /* To turn on specific LED on DSK6713 */
o Require header dsk6713_led.h
o Input type integer (0-3)
o Return Type Null
o To turn on LED specified by input number DSK6713 kit
 DSK6713_LED_off(int); /* To turn on specific LED on DSK6713 */

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 47


Lab Experiment | 5

o Require header dsk6713_led.h


o Input type integer (0-3)
o Return Type Null
o To turn off LED specified by input number DSK6713 kit
 int DSK6713_DIP_get(int); /* To check if switch on/off DSK6713 */
o Require header dsk6713_dip.h
o Input type int
o Return Type int /* Return 1 if switch is off and 0 if switch is on */
o To check the state of DIP switches on DSK6713 kit (return 0 when pressed, return 1 when not
pressed)
 DSK6713_waitusec(int); /* To halt the kit in the same position */
o Require header csl_timer.h and time.h
o Input type integer (define time delay in micro seconds)
o Return Type Null
o Set kit in same state for defined time interval

Lab Task 3
Write a code to turn on LED

Lab Task 4
Write a code to turn on LED according to user instruction by DIP Switch

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 48


Lab Experiment | 5

Topic: - This lab has been designed for student to familiarize with DSP Starter Kits
TMS320C6713.
Objectives:-

 Familiarization with DSP Starter Kits TMS320C6713.

 To assemble first experiment on DSP Kit 6713 using Code Composer Studio.

 To identify and troubleshoot the problems in the hardware implementation of first experiment
Required equipment:
Software: MATLAB.
Methodology:
1. Digital signal processing is one of the core technologies, in rapidly growing application areas, such as
wireless communications, audio and video processing and industrial control.
2. DSP has become a key component, in many of the consumer, communications, medical and industrial
products which implement the signal processing using microprocessors, Field Programmable Gate Arrays
(FPGAs), Custom ICs etc.
3. DSPs are processors or microcomputers whose hardware, software, and instruction sets are optimized for
high-speed numeric processing applications, an essential for processing digital data, representing analog
signals in real time.
4. The DSP processors have gained increased popularity because of the various advantages like reprogram
ability in the field, cost-effectiveness, speed, energy efficiency.
5. The hardware experiments in the DSP lab are carried out on the Texas Instruments TMS320C6713 DSP
Starter Kit (DSK), based on the TMS320C6713 floating point DSP running at 225 M Hz. The basic clock
cycle instruction time is 1/ (225 MHz) = 4.44 nanoseconds. During each clock cycle, up to eight instructions
can be carried out in parallel, achieving up to 8×225 = 1800 million instructions per second (MIPS).
6. CCS provides an IDE to incorporate the software tools.
7. CCS includes tools for code generation, such as a C compiler, an assembler, and a linker.
8. It has graphical capabilities and supports real time debugging.
9. It provides an easy-to-use software tool to build and debug programs.

Results and conclusion:


 In This lab we learnt how to use DSP Starter Kits TMS320C6713.
 We assembled some experiments on DSP Kit 6713 using Code Composer Studio.
 Code Composer Studio is quite efficient. Helps to in debugging and built-in code help to check
DSP kit.
 We also learnt how to identify and troubleshoot the problems in the hardware implementation.
 Lab task 3
 % Write a code to turn on LED.
 #include <dsk6713.h>
 #include <dsk6713_led.h>
 void main()
 {
 DSK6713_LED_on(0);
 }

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 49


Lab Experiment | 5

Lab task 4
% Write a code to turn on LED according to user instruction by
% DIP Switch.
#include <dsk6713.h>
#include <dsk6713_led.h>
void main() {
while (DSK6713-DIP-get(0)) /*
To turn on LED # 0* /
{
DSK6713_LED_on(0);
}
while (DSK6713-DIP-get(1))/*
To turn on LED # 1* /
{
DSK6713_LED_on(1);
}
while (DSK6713-DIP-get(2))/*
To turn on LED # 2 */
{
DSK6713_LED_on(2);
}
while (DSK6713-DIP-get(3))/*
To turn on LED # 3 */ {
DSK6713_LED_on(3);
}
}

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 50


Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 6

LAB # 6
To explain Frequency domain analysis of Discrete Time signals using Discrete
Fourier Transform (DFT) on MATLAB

Objectives
 To construct user defined functions for the computation of N-point DFT using MATLAB.
 To identify the properties of discrete time signals in the frequency domain.
 To verify the properties of DFT using MATLAB

Pre-Lab
Discrete Fourier Transform
In the case of a finite length sequence x[n], 0 ≤ n ≤ N − 1, there is a simpler relation between the sequence and
its discrete time Fourier Transform (DTFT, X(ejw)). In fact a length-N sequence, only N values of X(ejw), called
frequency samples at N distinct frequency points, 𝛼 = 𝛼k,0 ≤ k ≤ N − 1, are sufficient to determine x[𝛼], and
hence, 𝛼(𝛼𝛼w), uniquely. This leads to the concepts of the discrete Fourier transform, a second transform
domain representation that is applicable to the finite length sequence.

The simplest relation between a finite length sequence x[𝛼], defined for 0 ≤ n ≤ N − 1, and its DTFT 𝛼(𝛼𝛼w) is
obtained by uniformly sampling 𝛼(𝛼𝛼w) on the w-axis between 1

X[k] is also a finite length sequence in the frequency domain and is of length N. The sequence X[k] is called the
Discrete Fourier Transform (DFT) of the sequence x[n].

The inverse discrete Fourier Transform (IDFT) is given by

Pre-Lab Tasks
(Attach extra A4 White page if needed)

Write a MATLAB function to compute K-point DFT and IDFT of N-point sequence. The function should take
sequence (array), integer value K and binary value switch to decide if to compute DFT or IDFT. The function
should return the sequence after computation.

Lab Tasks
Lab task 1
Compute the M-point DFT of the following N-point sequence. (Properly label your plots)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 51


Lab Experiment | 6

Solution
Lab Task 2
Verify the following properties of DFT

a) Linearity
b) Circular Time Shift
c) Circular Frequency Shift
d) Duality
e) N-Point Circular Convolution
f) Modulation
g) Parseval’s Relation
Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 52


Lab Experiment | 6

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 53


Lab Experiment | 6

Lab Task 3 In this lab, we write MATLAB function for computing DFT
Write a MATLAB program to compute the of input signal. Then we write MATLAB code to compute the
circular convolution of two length- N properties of DFT like Linearity,Circular Time
sequences via DFT based approach. Using Shift,Circular Frequency Shift,Duality,N-Point Circular
this program determine the circular
Convolution,Modulation and Parseval’s Relation. In last
lab task we learnt about how to convolve the given function
convolution of the following pairs of
using the DFT approach.Then we write code to generate
sequences.
circular convolution.By using the built-in command for DFT
like FFT we also verify our results.
a) g[n] = {3 ,4 − 2 ,0 , 1 , −4} , ℎ [n]
= { 1,−3, 0,4 , −2 , 3}
CRITICAL ANALYSIS
In this lab,we learnt about properties of DFT system.We also
b) learnt convolution. In convolution input is passing through a
discrete time fourier transform system which convolved the
input signal.We also verified that in convolution of length-M
sequence with a length-N sequence.This lab is to recall our
LAB REPORT #06 previous knowledge about MATLAB and signals.
RESULT
We successfully did our required task in the lab. We wrote
OBJECTIVES required code for how we can convert time domain signal into
 To construct user defined frequency domain signal.
functions for the computation of
N-point DFT using MATLAB.
 To identify the properties of
discrete time signals in the Pre lab
frequency domain.
 To verify the properties of DFT
using MATLAB. Code:
function [y]=dft_idft(xn,N,b,K) n=[0:1:N-
1]; %row vector for n k=[0:1:N-1];
if b==0
METHODOLOGY
WN=exp(-j*2*pi/N) %Wn factor
nk=n'*k %creates a N by N matrix of nk values
WNnk=WN.^nk %DTFT matrix
fprintf('dft matrix')
y=xn*WNnk %row vectors for DFT coefficients
else b==1
WN=exp(-j*2*pi/N); %Wn factor
nk=n'*k; %creates a N by N matrix of nk values
WNnk=WN.^(-nk); %IDFT matrix
fprintf('idft matrix')
y=(xn*WNnk)/N; %row vectors for IDFT values
end
end

Results:
b =0
>> [y]=dft_idft(xn,N,b,K)
WN =0.3090 - 0.9511i

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 54


Lab Experiment | 6

nk =

0 0 0 0 0
0 1 2 3 4

0 2 4 6 8
0 3 6 9 12
0 4 8 12 16

WNnk =
1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i
1.0000 + 0.0000i 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i 0.3090 + 0.9511i
1.0000 + 0.0000i -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i -0.8090 + 0.5878i
1.0000 + 0.0000i -0.8090 + 0.5878i 0.3090 - 0.9511i 0.3090 + 0.9511i -0.8090 - 0.5878i
1.0000 + 0.0000i 0.3090 + 0.9511i -0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 - 0.9511i
dft matrix
y=

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 55


Lab Experiment | 6

15.0000 - 0.0000i -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i
y=
15.0000 - 0.0000i -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i
>> b=1
b =1
>> [y]=dft_idft(xn,N,b,K)
ans =1
idft matrix
y=
3.0000 - 0.0000i -0.5000 - 0.6882i -0.5000 - 0.1625i -0.5000 + 0.1625i -0.5000 + 0.6882i
InLab task#1

InLab task#2

Code:
clc
clear all
close all
%verify properties of DFT
N = 8; % N is length of the sequence(s)
gamma = 0.5;
k = 0:1:N-1;
g = exp(-gamma*k);
h = cos((pi*k)/N);
G = fft(g);
H=fft(h);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 56


Lab Experiment | 6

% Property 1

x1 = rand(1,11);
x2 = rand(1,11); n = 0:10;
alpha = 0.5;
beta = 0.25;
w = (pi/500)*k;
X1 = x1 * (exp(-j*pi/500)).^(n'*k); % DTFT of x1
X2 = x2 * (exp(-j*pi/500)).^(n'*k); % DTFT of x2
x = alpha*x1 + beta*x2; % Linear combination of x1 & x2
X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x
% verification
X_check = alpha*X1 + beta*X2; % Linear Combination of X1 & X2
error = max(abs(X-X_check)) % Difference

%Since maximum error between fourier transform of two arrays is less than
%10^-14 so both are identical

% Verify X1=alpha*G+beta*H
% Property 2
n0 = N/2; % n0 is the amount of shift
x2 = [g(n0+1:N) g(1:n0)];
X2 = fft(x2)
% Verify X2(k)= exp(-j*pi*k)G(k)
% Property 3
k0 = N/2;
x3 = exp(-j*2*pi*k0*k/N).*g;
X3 = fft(x3)
G3 = [G(k0+1:N) G(1:k0)]
% Verify X3=G3
% Property 4
x4 = G;
X4 = fft(G)
G4 = N*[g(1) g(8:-1:2)] % This forms N*(g mod(-k))
% Verify X4 = G4;
% Property 5
% To calculate circular convolution between
% g and h use eqn (3.67)
h1 = [h(1) h(N:-1:2)];
T = toeplitz(h',h1);
x5 = T*g';
X5 = fft(x5')
% Verify X5 = G.*H
% Property 6
x6 = g.*h;
X6 = fft(x6)
H1 = [H(1) H(N:-1:2)];
T = toeplitz(H.', H1); % .' is the nonconjugate transpose
G6 = (1/N)*T*G.'

Results :
error =
8.8818e-16
X2 =
Columns 1 through 6

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 57


Lab Experiment | 6

2.4949 + 0.0000i -1.0991 + 0.8254i 0.7177 - 0.4353i -0.6302 + 0.1892i 0.6111 + 0.0000i -0.6302
- 0.1892i
Columns 7 through 8
0.7177 + 0.4353i -1.0991 - 0.8254i X3
=
Columns 1 through 6
0.6111 - 0.0000i 0.6302 + 0.1892i 0.7177 + 0.4353i 1.0991 + 0.8254i 2.4949 + 0.0000i 1.0991 -
0.8254i
Columns 7 through 8
0.7177 - 0.4353i 0.6302 - 0.1892i G3 =
Columns 1 through 6
0.6111 + 0.0000i 0.6302 + 0.1892i 0.7177 + 0.4353i 1.0991 + 0.8254i 2.4949 + 0.0000i 1.0991
- 0.8254i
Columns 7 through 8
0.7177 - 0.4353i 0.6302 - 0.1892i X4 =

8.0000 0.2416 0.3983 0.6567 1.0827 1.7850 2.9430 4.8522


G4 =
8.0000 0.2416 0.3983 0.6567 1.0827 1.7850 2.9430 4.8522
X5 =
Columns 1 through 6
2.4949 + 0.0000i -1.5932 - 4.4105i 0.2465 - 1.2121i 0.5482 - 0.4624i 0.6111 + 0.0000i 0.5482 +
0.4624i
Columns 7 through 8
0.2465 + 1.2121i -1.5932 + 4.4105i X6
=
Columns 1 through 6
1.8114 + 0.0000i 1.3383 - 0.7939i 0.7751 - 0.4715i 0.6617 - 0.2032i 0.6385 + 0.0000i 0.6617 +
0.2032i
Columns 7 through 8

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 58


Lab Experiment | 6

0.7751 + 0.4715i 1.3383 + 0.7939i G6


=
1.8114 - 0.0000i
1.3383 - 0.7939i
0.7751 - 0.4715i
0.6617 - 0.2032i
0.6385 - 0.0000i
0.6617 + 0.2032i
0.7751 + 0.4715i
1.3383 + 0.7939i

InLab task#3(a)
Code:
clc
clear all
close all
g=[3,4,-2,0,1,-4]
h=[1,-3,0,4,-2,3]
c=cconv(g,h,6)
stem(c)

Results:
g=
3 4 -2 0 1 -4
h=
1 -3 0 4 -2 3
c=
31.0000 -7.0000 -32.0000 29.0000 -1.0000 -14.0000

Plot :

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 59


Lab Experiment | 6

InLab task#3(b)
Code:
clc
clear all
close all
n=0:4
N=5
g=sin((n*pi)/2)
h=[18].^n
G=dft(g,N)
H=dft(h,N)
GH=G.*H
CC=idft(GH,N)
chota=cconv(gi,hi,N)

Results:
n=
0 1 2 3 4
N=
5
g=
0 1.0000 0.0000 -1.0000 -0.0000
h=
1 18 324 5832 104976
idft matrix
G=
-0.0000 + 0.0000i 0.2236 + 0.3078i -0.2236 - 0.0727i -0.2236 + 0.0727i 0.2236 - 0.3078i

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 60


Lab Experiment | 6

idft matrix H =
1.0e+04 *
2.2230 + 0.0000i 0.5493 - 2.0612i -1.6608 - 1.1291i -1.6608 + 1.1291i 0.5493 + 2.0612i GH =
1.0e+03 *
-0.0000 + 0.0000i 7.5719 - 2.9183i 2.8933 + 3.7313i 2.8933 - 3.7313i 7.5719 + 2.9183i
CC=idft(GH,N)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 61


Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 7

LAB # 7
To explain the efficient computation of the DFT and its applications in Linear
Filtering for Digital Signal Processing using MATLAB
Objectives
 To choose FFT Algorithm for efficient computation of DFT using MATLAB.
 To explain block convolution for filtering long data sequence using MATLAB.
 To construct efficient algorithm for the block convolution methods using MATLAB.

Pre-Lab
Fast Fourier Transform
The DFT introduced earlier is the only transform that is discrete in both the time and the frequency domains,
and is defined for finite-duration sequences. Although it is a computable transform, the straightforward
implementation of equation studied in Lab#6 is very inefficient, especially when the sequence length N is large.
In 1965 Cooley and Tukey showed a procedure to substantially reduce the amount of computations involved in
the DFT. This led to the explosion of applications of the DFT, including in the digital signal processing area.
Furthermore, it also led to the development of other efficient algorithms. All these efficient algorithms are
collectively known as fast Fourier transform (FFT) algorithms. Clearly, the number of DFT computations for
an N-point sequence depends quadratically on N, which will be denoted by the notation

𝑇𝑇 = o(N2)

For large N, o(N2) is unacceptable in practice. Generally, the processing time for one addition is much less than that
for one multiplication. Hence from now on we will concentrate on the number of complex multiplications,
which itself requires 4 real multiplications and 2 real additions.

This procedure is shown in Figure 7.1 can be repeated again and again. At each stage the sequences are
decimated and the smaller DFTs combined. This decimation ends after v stages when we have N one-point
sequences, which are also one-point DFTs. The resulting procedure is called the decimation-in-time FFT (DIT-
FFT) algorithm, for which the total number of complex multiplications is

𝑇𝑇 = o(Nlog2N)

Clearly, if N is large, then CN is approximately linear in N, which was the goal of our efficient algorithm. The
approach in Fig 7.2 is called a decimation-in-frequency FFT (DIF-FFT) algorithm. Its signal flowgraph is a
transposed structure of the DIT-FFT structure, and its computational complexity

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 56


Lab Experiment | 7

Figure 7.1 Decimation-in-Time FFT

Figure 7.1 Decimation-in-Frequency FFT

FAST CONVOLUTIONS
The conv function in MATLAB is implemented using the filter function (which is written in C) and is very
efficient for smaller values of N (< 50). For larger values of N it is possible to speed up the convolution using
the FFT algorithm. This approach uses the circular convolution to implement the linear convolution, and the
FFT to implement the circular convolution. The resulting algorithm is called a fast convolution algorithm.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 57


Lab Experiment | 7

The linear convolution x1 (n) ∗ x2 (n) can now be implemented by two N-point FFTs, one N-point IFFT, and one
N-point dot-product.
x1 (n) ∗ x2 (n) = IFFT [FFT [x1 (n)] · FFT[x2 (n)]]

MATLAB IMPLEMENTATION
MATLAB provides a function called fft to compute the DFT of a vector x. It is invoked by X = fft(x,N), which
computes the N-point DFT. If the length of x is less than N, then x is padded with zeros. If the argument N is
omitted, then the length of the DFT is the length of x. If x is a matrix, then fft(x,N) computes the N-point DFT
of each column of x.

Lab Task
Lab Task 1
Write MATLAB code that determines and plot the N-point Discrete Fourier Transform of defined by the
following equations:

Compute and plot 16-point DFT using two 8-point FFTs and combining techniques.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 58


Lab Experiment | 7

Lab Task 2
Write MATLAB code to compare the efficiency linear convolution and the high-speed convolution times for 5
≤ N ≤ 150

Solution

Lab Task 3
Write a MATLAB function to implement a block convolution algorithm called the overlap-and-save method
(and its companion the overlap-and-add method), which is used to convolve a very large sequence with a
relatively smaller sequence.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 59


Lab Experiment | 7

Lab Task 4
Using the function of task 3, write a MATLAB program to implement length-N moving average filter to filter a
noise corrupted signal. Where N is class Roll Number.
Lab Report
Objectives :
 To choose FFT Algorithm for efficient computation of DFT using MATLAB.
 To explain block convolution for filtering long data sequence using MATLAB.
 To construct efficient algorithm for the block convolution methods using MATLAB.

Required Equipment:
Software:
 MATLAB

Methodology:
 The DFT we studied in lab #06 that was discrete in both the time and the frequency
domains, and was defined for finite-duration sequences.
 We also studied that it was a computable transform but was very inefficient, especially
when the sequence length N is large.
 For this in lab#07 we studied the efficient algorithms all these efficient algorithms are
collectively known as fast Fourier transform (FFT) algorithms. We learnt that the
number of DFT computations for an N-point sequence depends quadratically on N,
which will be denoted by the notation 𝐶𝐶= For large N, is unacceptable in practice.
 As the processing time for one addition is much less than that for one multiplication.
Hence for the number of complex multiplications, which itself requires 4 real
multiplications and 2 real additions.
 Then the resulting procedure is called the decimation-in-time FFT (DITFFT) algorithm,
for which the total number of complex multiplications is 𝐶𝐶=NlogN which means if N
is large, then CN is approximately linear in N, which was the goal of our efficient
algorithm.
 We implemented fast convolution using FFT approach for larger values of N it is
possible to speed up the convolution using the FFT algorithm. This approach uses the
circular convolution to implement the linear convolution, and the FFT to implement the
circular convolution.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 60


Lab Experiment | 7

 We wrote a MATLAB program to compute the high-speed circular convolution of


length- N sequences via FFT based approach. We also wrote a MATLAB code to
compare the efficiency linear convolution and the high-speed convolution times for 5 ≤
N ≤ 150.

Conclusion:
We concluded that using MatLab we can compute FFT which is fast Fourier transform (FFT) is a
computationally efficient method of generating a Fourier transform. The main advantage of an
FFT is speed, which it gets by decreasing the number of calculations needed to analyze a
waveform. FFT convolution uses the overlap-add method together with the Fast Fourier
Transform, allowing signals to
be convolved by multiplying their frequency spectra. For filter kernels longer than about 64
points, FFT convolution is faster than standard convolution, while producing exactly the same
result.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 61


Lab Experiment | 7

Lab Tasks
Pre-Lab Tasks:
No Pre-Lab Tasks.
In-LAB tasks :
Task#01:
Write MATLAB code that determines and plot the N-point Discrete Fourier Transform of defined by the
following equations:
Compute and plot 16-point DFT using two 8-point FFTs and combining techniques.
Input/Output:
clc
clear all
close all
a=16
n=0:15
x=sin(0.5*pi*n)
f1=fft(x)
subplot(211)
stem(abs(f1))
title('matlab fft')
f2=fft16(x)
subplot(212)
stem(abs(f2))
title('self made function fft')

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 62


Lab Experiment | 7

Task#02:
Write MATLAB code to compare the efficiency linear convolution and the high-speed convolution times
for 5 ≤ N ≤ 150
Input/Output:
clc
clear all
close all
conv_time = zeros(5,150); fft_time = zeros(5,150);
for L = 5:150
tc = 0; tf=0;
N = 2*L-1; I=1
nu = ceil(log10(N*I)/log10(2)); N = 2^nu;
for I=1:100
h = randn(1,L); x = rand(1,L);
t0 = clock; y1 = conv(h,x); t1=etime(clock,t0); tc = tc+t1;
t0 = clock; y2 = ifft(fft(h,N).*fft(x,N)); t2=etime(clock,t0);
tf = tf+t2;
end
%
conv_time(L)=tc/100; fft_time(L)=tf/100
end

Task#03:
Write a MATLAB function to implement a block convolution algorithm called the overlap- and-save
method (and its companion the overlap-and-add method), which is used to convolve a very large sequence
with a relatively smaller sequence.
Input/Output:
clc
close all
clear all
L=20:50:100
K=length(L)
conv_time=zeros(1,K);
fft_time=zeros(1,K);
Nav=10;
for k=1:K
tc=0;
tf=0
Lk=L(k)
N=2*Lk-1;
nu=ceil(log2(N));
N=2^nu;
for i=1:Nav
Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 63
Lab Experiment | 7

h=rand(1,Lk);
x=rand(1,Lk)
t0=clock;
y1=conv(h,x);
t1=etime(clock,t0);
tc=tc+1
t0=clock;
y2=ifft(fft(h,N).*fft(x,N))
t2=etime(clock,t0)
tf=tf+t2
end
conv_time(k)=tc/Nav;
fft_time(k)=tf/Nav;
end

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 64


Lab Experiment | 7

Task#04:
Using the function of task 3, write a MATLAB program to implement length-N moving average filter to
filter a noise corrupted signal. Where N is class Roll Number.
Input/Output:
clc
clear all
close all
n=1:21
s=n*pi
subplot(221)
stem(s)
title('original signal')
d=rand(1,21)
subplot(222)
stem(d)
title('noise ')
p=ovrlpsav(s,d,21),
subplot(223)
stem(p)
title('corrupted signal')
m=5
xu=0
for i=1:m
x=s+d
xu=xu+x
end
xu=xu/m
subplot(224)
stem(xu)
title('filtered signal')

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 65


Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 8

LAB # 8
To manipulate Sampling and reconstruction of continuous time signals; different
Sampling and Interpolation techniques using MATLAB and SIMULINK

Objectives
 To construct and sketch analog signal from digital signal
 To construct and sketch the effect of different interpolation schemes

Pre Lab
In Lab#2, we studied the sampling of continues-time signals and demonstrate that if the signals are bandlimited,
it is possible to reconstruct the original signal from the samples. In this lab we will construct analog signal

Reconstruction
Consider a system that constructs a continuous-time signal x from a discrete-time signal y,
DiscToContT: DiscSignals → ContSignals
This is illustrated in figure 8.1. Systems that carry out such ‘discrete-to-continuous’ conversion can be realized
in any number of ways. Some common examples are illustrated below:
Analog to Digital Converter Digital to Analog Converter

Analog Signal x[n] Reconstruction Reconstructed Analog


Sampler Quantizer Coder Decoder
x(t) Filter Signal x (t)

Figure 8.1: Sampling and Reconstruction

• zero-order hold: This means simply that the value of the each sample y(n) is held constant for duration T,
so that x(t) = y(n) for the time interval from t = nT to t = (n+ 1)T, as illustrated. Let this system be denoted

ZeroOrderHoldT:DiscSignals → ContSignals.

• linear interpolation: Intuitively, this means simply that we connect the dots with straight lines.
Specifically, in the time interval from t = nT to t = (n+1)T, x(t) has values that vary along a straight line
from y(n) to y(n+1). Linear interpolation is sometimes called first-order hold. Let this system be denoted

LinearInterpolatorT:DiscSignals → ContSignals.

• ideal interpolation: It is not yet clear what this should mean, but intuitively, it should result in a smooth
curve that passes through the samples. We will give a precise meaning below. Let this system be denoted

IdealInterpolatorT:DiscSignals → ContSignals.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 62


Lab Experiment | 8

Lab Tasks
Task 1 SIMULINK Model
Build a SIMULINK model for Sampling and Reconstruction of analog signal

x(t)  3cos( ft)  2sin(0.5 ft) where f  R KHz


where,
R = Your Reg. Number
i) Sample the analog signal x(t) at 8 times the Nyquist rate.
ii) Non-uniformly quantize the discrete time signal using µ-law companding method, µ=255 and number
of quantization levels = 16.
iii) Encode and Decode the signal into binary.
iv) Reconstruct the analog signal.
v) Show both time and frequency domain results.
Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 63


Lab Experiment | 8

Lab Task 2 MATLAB Code


Write MATLAB Code to
i) Plot discrete time sampled signal x[n] sampled at FS = 8R
ii) Non-uniformly quantize the discrete time signal using µ-law companding method, µ=100 and number
of bits = 8
iii) Encode the signal into discrete levels.
iv) Decode the signal from discrete level and reconstruct using spline and cubic interpolation to reconstruct
the analog signal x(t) from the discrete time signal using t  0.001 .
v) Analyze which interpolation method performs better.
Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 64


Lab report

Topic: - This lab has been designed for student to familiarize with Analog to Digital converters and
Interpolation techniques.
Objectives:-
 To construct and plot the analog signal form digital signal.
 To familiarize with different interpolation techniques.
Required equipment:
Software: MATLAB.
Methodology:

 An analog signal is a continuous signal that contains time-varying quantities. An analog is
continuous in both x-axis and y-axis.

 A digital signal is a signal that is being used to represent data as a sequence of discrete
values; at any given time it can only take on one of a finite number of values. An analog-to-
digital converter (ADC, A/D, or A-to-D) is a system that converts an analog signal into a digital
signal.

 A digital-to-analog converter (DAC) performs the reverse function; it converts a digital signal
into an analog signal.

 Interpolation is a method of constructing new data points within the range of a discrete set of
known data points. In digital signal

processing, the term interpolation refers to the process of converting a sampled digital signal to that of a
higher sampling rate using various digital filtering techniques. Interpolation has three types:

 Zero-order hold: This means simply that the value of the each sample y(n) is held constant for
duration T, so that x(t) = y(n) for the time interval from t = nT to t = (n+ 1)T, as illustrated. Let this
system be denoted ZeroOrderHoldT:DiscSignals → ContSignals.

 Linear interpolation: Intuitively, this means simply that we connect the dots with straight lines.
Specifically, in the time interval from t = nT to t = (n+1)T, x(t) has values that vary along a
straight line from y(n) to y(n+1). Linear interpolation is sometimes called first-order hold. Let this
system be denoted LinearInterpolatorT:DiscSignals → ContSignals.

 Ideal interpolation: It is not yet clear what this should mean, but intuitively, it should result in
a smooth curve that passes through the samples. We will give a precise meaning below. Let this
system be denoted IdealInterpolatorT:DiscSignals → ContSignals

Results and conclusion:


 I learned how to convert analog signal to digital signal converter and digital to analog
converter.
 The Analog-to-Digital converter helped to convert the signal in digital signal by which
processing had done very easily.
 Interpolation helped to convert discrete signal to continuous in an easy steps.

Lab Task 1:
% f - The frequency of analog sinosoid signal
% F - Sampling Rate
% qbits - Number of Quantizations bits
% A - Amplitude of sinusoid signal
% L - Number of quantization levels based on qbits
% I - Quantization Interval
% sim_time - Simultaion Time
% span - x-axis range of frequency plot 1 & 3 (spectrum scope 1 & 3)
% span1 - x-axis range of frequency plot 2 (spectrum scope 2)
% NFFT - Number of FFT points

clc;
clear;
close all;
f = input('Enter the frequency of signal = ');
F = input('Enter the sampling frequency = ');
A = input('Enter max amplitude of signal = ');
qbits = input('Enter the number of quantization bits = ');
fc = input('Enter the lowpass filter cutoff frequency = ');

L = 2^qbits;
I = 2*A/(L-1);
% Settings for Spectrum Scope
span = 8*F;
span1 = 8*F;
NFFT = 256;

% To run simulink model


t = 1/f;
sim_time = 10*t;
sim('sampling.slx');

Original Signal

Sampled Signal

Reconstructed Signal
Lab Task 2:
clc
clear all
close all
t=0:0.001:1
fm=21

fs=168
N=8
L=2.^N

%message signals
x=sin(2*pi*fm*t)
figure
subplot 211
plot(t,x)
title('message signal')
xlabel('time')
ylabel('amplitude')
%pulse traain
d=0:1/50:1
y=pulstran(t,d,'rectpuls',0.001)
subplot 212
plot(t,y)
title('pulse train')
xlabel('time')
ylabel('amplitude')

%sampling
z=x.*y
figure
subplot 211
plot(t,z)
title('sampled signal')
xlabel('time')
ylabel('amplitude')

%quantization
D=[max(x)-min(x)]/(L-1)
xq=quant(x,D)
subplot 212
plot(t,xq)
title('quantized signal')
xlabel('time')
ylabel('amplitude')

%encoder
H_e=dsp.UniformEncoder(max(xq),N)
encoder=step(H_e,xq)
figure
subplot 211
plot(t,encoder)
title('encoded signal')
xlabel('time')
ylabel('amplitude')
%decoder
H_d=dsp.UniformDecoder(max(xq),N)
decoder=step(H_d,encoder)
subplot 212
plot(t,decoder)
title('decoded sig')
xlabel('time')
ylabel('amplitude')
%interpolation
time=0:1/(2*fs):5
interpolation=interp1(t,decoder,time)
figure
subplot 211
plot(time,interpolation)
title('interpolation')
%SC interpolation
subplot 212
xx=0:0.001:1
sc=spline(t,x,xx)
plot(t,sc)
title('s&c interpolation')
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 9

LAB # 9
To assemble the experiment of Sampling and Quantization of real time Audio
Signals on DSP Kit TMS320C6713; analyze the effect of Aliasing and
Quantization Noise

Objectives
 To assemble the experiment of sampling theorem using real time audio signal on DSK 6713
 To measure the effect of quantization using real time audio signal on DSK 6713

Pre-Lab
The following block diagram depicts the overall operations involved in all of the hardware experiments in the
DSP lab. Processing is interrupt-driven at the sampling rate fs, as explained below.

Figure 9.1 Block diagram of process on DSK6713

The AIC23 codec is configured (through CCS) to operate at one of the above sampling rates fs. Each collected
sample is converted to a 16-bit two’s complement integer (a short data type in C). The codec actually samples
the audio input in stereo, that is, it collects two samples for the left and right channels. At each sampling instant,
the codec combines the two 16-bit left/right samples into a single 32-bit unsigned integer word (an unsigned int,
or Uint32 data type in C), and ships it over to a 32-bit receive register of the multichannel buffered serial port
(McBSP) of the C6713 processor.

The ADC part of the codec is implemented as a multi-bit third-order noise-shaping delta-sigma converter that
allows a variety of oversampling ratios that can realize the above choices of fs. The corresponding oversampling
decimation filters act as anti-aliasing prefilters that limit the spectrum of the input analog signals effectively to
the Nyquist interval [−fs/2,fs/2].

Clearly, all processing operations during the execution of any signal processing must be completed in the time
interval between samples read and write time, that is, T = 1/fs. For example, if fs = 44.1 kHz, then, T = 1/fs =
22.68 µsec. With an instruction cycle time of Tc = 4.44 nsec, this allows T/Tc = 5108 cycles to be executed
during each sampling instant, or, up to 8×5108 = 40864 instructions, or half of that per channel.

Lab Task
You will hear what aliasing effects sound like (i.e., distortions arising from using the wrong sampling rate). You
will hear what quantization effects sound like (i.e., when you use too few bits for your audio samples). You will
find out how the stereo A/D converter packs the two 16-bit samples from the left and right audio channels into
a 32-bit word and sends it over to the processor, and how it gets unpacked into the two individual 16-bit left/right
words by the processor.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 66


Lab Experiment | 9

You will begin with a basic talk-through program, listed below, that simply reads input samples from the codec
and immediately writes them back out. This will serve as a template on which to build more complicated sample
processing algorithms by modifying

C Code Template Program


#include<dsk6713.h>
#include<dsk6713_aic23.h>
#include<dsk6713_led.h>
#include<dsk6713_dip.h>
#include<math.h> // to configure codec

DSK6713_AIC23_Config config = {
0x0017, /* 0 - DSK6713_AIC23_LEFTINVOL Left line input channel volume */
0x0017, /* 1 - DSK6713_AIC23_RIGHTINVOL Right line input channel volume */
0x01f9, /* 2 - DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */
0x01f9, /* 3 - DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */
};

void main(){
DSK6713_AIC23_CodecHandle hCodec;
Uint32 IN,OUT;
Uint16 OUT_L,OUT_R;

DSK6713_init(); // Initialize the DSK6713 board


DSK6713_LED_init();// Initialize the DSK6713 board leds
hCodec = DSK6713_AIC23_openCodec(0, &config); // Start the codec
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ); // Set codec frequency to 8KHz
while(1) {

/* Read 32 bit sample from the audio channel */


while (!DSK6713_AIC23_read(hCodec, &IN));

/*Typecasting */
OUT_L = IN;
OUT_R = IN;

/* Read 16-bit samples to right and left audio channel */


while (!DSK6713_AIC23_write(hCodec, OUT_L));
while (!DSK6713_AIC23_write(hCodec, OUT_R));
if(DSK6713_DIP_get(1)==0)
break;

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 67


Lab Experiment | 9

}
/* Close the codec */
DSK6713_LED_on(1);
DSK6713_AIC23_closeCodec(hCodec);
}

Lab Task 1
Follow the steps discussed in Lab # 5 to build a project. Copy template C program and build your project. Plug-
in aux cable from the speaker-out of your system to line-in of DSK6713. Plug-in head phones at DSK6713
headphone out. Play the audio signal 20Hz to 20KHz from the link:
https://www.youtube.com/watch?v=qNf9nzvnd1k.

Write your analysis based on what you hear. Now attach the plug-in aux cable from DSK6713 headphone out
to Audio scope. Write your observations

Lab Task 2
Modify the template program so that the output pans between the left and right speakers every 2seconds, i.e.,
the left speaker plays for 2 secs, and then switches to the right speaker for another 2 secs, and so on.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 68


Lab Experiment | 9

Lab Task 3: Aliasing


Modify the template program to output every other sample, with zero values in-between. This can be
accomplished in different ways, but a simple one is to define a “sampling pulse” periodic signal whose values
alternate between 1 and 0, i.e., the sequence [1,0,1,0,1,0,... ] and multiply the input samples by that sequence.
Write your code:

Lab Task 4: Quantization


The DSK’s codec is a 16-bit ADC/DAC with each sample represented by a two’s complement integer. Given
the 16-bit representation of a sample, [b1b2 ··· b16], the corresponding 16-bit integer is given by:

x = −b121 + b222 + b323 +···+ b16216


The MSB bit b1 is the sign bit. The range of representable integers is: −32768 ≤ x ≤ 32767. The 16-bit samples
can be requantized to fewer bits by a right/left bit-shifting operation. For example, right shifting by 3 bits will
knock out the last 3 bits, then left shifting by 3 bits will result in a 16-bit number whose last three bits are zero,
that is, a 13-bit integer. These operations are illustrated below:

[b1,b2, ..., b13,b14,b15,b16] ⇒ [0,0,0,b1,b2, ..., b13] ⇒ [b1,b2, ..., b13,0,0,0]

Modify the basic template program so that the output samples are requantized to B bits, where 1 ≤ B ≤ 16. This
requires right/left shifting by L= 16 − B bits.

Solution

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 69


Lab Report

Topic: - To assemble the experiment of Sampling and Quantization of real time Audio
Signals on DSP Kit TMS320C6713; analyze the effect of Aliasing and Quantization Noise

Objectives:-
 To assemble the experiment of sampling theorem using real time audio signal on DSK 6713
 To measure the effect of quantization using real time audio signal on DSK 6713

Required equipment:
Software: MATLAB.
Methodology:

 First of all, look at the block diagram given below which depicts the overall operations involved
in all of the hardware experiments in the DSP lab. Processing is interrupt-driven at the sampling
rate fs,
 The AIC23 codec is configured (through CCS) to operate at one of the above sampling rates fs.
Each collected sample is converted to a 16-bit two’s complement integer (a short data type in C).
 The codec actually samples the audio input in stereo, that is, it collects two samples for the left
and right channels. At each sampling instant, the codec combines the two 16-bit left/right samples
into a single 32-bit unsigned integer word (an unsigned int, or Uint32 data type in C), and ships it
over to a 32-bit receive register of the multichannel buffered serial port (McBSP) of the C6713
processor.
 The ADC part of the codec is implemented as a multi-bit third-order noise-shaping delta-sigma
converter that allows a variety of oversampling ratios that can realize the above choices of fs.
 The corresponding oversampling decimation filters act as anti-aliasing prefilters that limit the
spectrum of the input analog signals effectively to the Nyquist interval [−fs/2,fs/2].
 Clearly, all processing operations during the execution of any signal processing must be
completed in the time interval between samples read and write time, that is, T = 1/fs. For
example, if fs = 44.1 kHz, then, T = 1/fs = 22.68 sec. With an instruction cycle time of Tc = 4.44
nsec, this allows T/Tc = 5108 cycles to be executed during each sampling instant, or, up to
8×5108 = 40864 instructions, or half of that per channel.

Results and conclusion:


 In This lab we were able to use TMS320C6713 DSP Starter Kit (DSK). The TMS320C6713 DSP
Starter Kit (DSK) developed jointly with Spectrum Digital is a low-cost development platform
designed to speed the development of high precision applications based on TI´s TMS320C6000
floating point DSP generation.
 The kit uses USB communications for true plug-and-play functionality.
 Both experienced and novice designers can get started immediately with innovative product
designs with the DSK´s full featured Code Composer Studio™ IDE and eXpressD SP™ Software
which includes DSP/BIOS and Reference Frameworks.

Lab task 1
% FA17-BEE-147
% Write your analysis based on what you hear from DSK6713. Attach the plug-
% in aux cable from DSK6713 headphone out to Audio scope. Write you
% observations.
Analysis: The DSK TMS320C6713 is used for the design process. The result shows that designing using the DSP
board, can be develop into a real-time application for audio effects in electronic devices and acoustic.
Observations: We just listen to signals generated by the on-board codec after plug- in aux cable from DSK6713
headphone out to Audio scope.
Lab Task 2:
%FA17-BEE-147
% Modify the template program so that the output pans between the left and
% right speakers every 2 seconds, i.e. the left speaker plays for 2 secs, and then
% switches to the right speaker for another 2 secs, and so on.
#include <dsk6713.h> #include <dsk6713_aic23.h> #include <dsk6713_Led.h>
#include <math.h> #Define D 16000 // represent 2 sec at fs=8kHz
short d=0; DSK6713_AIC23_config config = DEFAULT_CONFIG;
void main()
{ DSK6713_AIC23_Codec_Handle hCodec; Unit32 IN, OUT; Unit16 OUT_L, OUT_R;
DSK6713_init(); DSK6713_LED_init(); hCodec = DSK6713_AIC23_openCodec;
DSK6713_AIC23_setFreq(hCodec,DSK6713_AIC23_FREQ_8KHz);
while (1) { OUT_L = (d<D)*IN; OUT_R = (d>=D)*IN; if (++d >= 2*D) {d = 0;}
OUT_L = IN; OUT_R = IN; while (!DSK6713_AIC23_write(hCodec,OUT_L)) {
while (!DSK6713_AIC23_write(hCodec,OUT_R)) {if (DSK6713_DIP_get(1) == 0) {break;} } } }
/* close the codec */ DSK6713_LED_on(1); DSK6713_AIC23_closeCodec(hCodec); }
Lab task 3
%FA17-BEE-147
% Modify the template program to output every other sample, with zero values
% in between. This can be accomplished in different ways, but a simple one is
% to define a “sampling pulse” periodic signal whose values alternate between
% 1 and 0 i.e. the sequence [1, 0, 1, 0, 1, 0,] and multiply the input samples by
% that sequence.
OUT_L = pulse+IN;
OUT_R = pulse+IN;
pulse = (pulse == 0);
Lab Task 4:
%FA17-BEE-147
% Modify the basic template program so that the output samples are
% requantized to B bits, where 1<=B<=16. This requires right/left shifting by
% L=16-B bits.
OUT_L = (IN >> L) << L;
OUT_R = (IN >> L) << L;

Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
Good 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 10

LAB # 10
To assemble the FFT Algorithm with Radix-2 on DSP Kit TMS320C6713.

Objective
1. To construct C Code for FFT Radix-2 Algorithm.
2. To measure and sketch real time signal in frequency domain

Pre-Lab Task
A DFT decomposes a sequence of values into components of different frequencies. This operation is useful in
many fields (see discrete Fourier transform for properties and applications of the transform) but computing it
directly from the definition is often too slow to be practical. An FFT is a way to compute the same result more
quickly: computing a DFT of N points in the naive way, using the definition, takes (N2) arithmetical operations,
while an FFT can compute the same result in only (N log N) operations. The difference in speed can be
substantial, especially for long data sets where N may be in the thousands or million in practice, the computation
time can be reduced by several orders of magnitude in such cases, and the improvement is roughly proportional
to N / log(N).

Lab Task
Lab Task 1
Follow the steps discussed in Lab # 5 to build a project. C program is given to implement 16-point DFT using
DIT FFT Algorithm. Properly show graphs of sine signal and its frequency response

Template Program: C Code for FFT Algorithm


#include<stdio.h>
#include<math.h>
#define N 16 #define pI 3.14159
typedef struct {
float real,imag;
} complex;
float iobuffer[N];
float y[N];
void main() {
int i;
complex w[N], x[N];
complex temp1, temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++) {
iobuffer[i]=sin((2*pI*2*i)/32.0);
}
for(i=0;i<N;i++) {
x[i].real=iobuffer[i];
x[i].imag=0.0;
}

for(i=0;i<N;i++) {

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 71


Lab Experiment | 10

w[i].real=cos((2*pI*i)/(N*2.0));
w[i].imag=sin((2*pI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<5;i++) {
index=0;
for(j=0;j<leg_diff;j++){
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff)) {
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++) {
k=N/2;
while(k<=j) {
j=j-k;
k=k/2;
}
j=j+k;
if(i<j){
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++) {
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++) {
printf("%f\t",y[i]);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 72


Lab Experiment | 10

}
return(0);
}

Lab Task 1
Change the above code for frequency analysis real time audio signal.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 73


Lab Report
Topic: - This lab has been designed for student to familiarize with the FFT Algorithm with
Radix-2 on DSP Kit TMS320C6713

Objectives:-

 Familiarization with DSP Starter Kits TMS320C6713.

 To construct C Code for FFT Radix-2 Algorithm.

 To measure and sketch real time signal in frequency domain.

 Familiarization with decimation in time (DIT) and decimation in frequency (DIF).

Required equipment:
Software: MATLAB.
Methodology:
1. This operation is useful in many fields (see discrete Fourier transform for properties and
applications of the transform) but computing it directly from the definition is often too slow to be
practical.
2. An FFT is a way to compute the same result more quickly: computing a DFT of N points in the
naive way, using the definition, takes (N2) arithmetical operations, while an FFT can compute the
same result in only (N log N) operations.
3. The difference in speed can be substantial, especially for long data sets where N may be in the
thousands or millions in practice, the computation time can be reduced by several orders of magnitude
in such cases, and the improvement is roughly proportional to N / log(N).

Results and conclusion:


 In This lab we learnt some unique features of DSP Starter Kits TMS320C6713.
 It helped us with familiarize with FFT Radix-2 Algorithm, its decimation in time and
decimation in frequency techniques.
 This Lab helped to compute FFT (both decimation in time and frequency) of function using
Radix-2 algorithm.

Lab Task 01:


% Change the above code for frequency analysis real time audio signal.
#include <dsk6713.h>
#include <dsk6713_aic23.h>
#include <dsk6713_Led.h>
#include <math.h>
typedef struct
{
float, real, imag;
}
float isbuffer[N];
float y[N];
DSK6713_AIC23_CONFIG config = Default config;
void main()
{
int i;
complex w[N], x[N];
complex temp1, temp2;
int j, k, upper_leg, lower_leg, leg_diff, index, step;
DSK6713_AIC23_CODEC_Handle hCodec;
Unit32 IN, OUT;
Unit16 OUT_L, OUT_R;
DSK6713_init();
DSK6713_LED_init();
hCodec = DSK6713_AIC23_openCodec(0,&Config);
DSK6713_AIC23_setFreq(hCodec,DSK6713_AIC23_FREQ);
while (1)
{
for (i=0; i<=15; i++)
{
while (!DSK6713_AIC23_read(hCodec,&IN));
iobuffer[i] = N;
}
}
}
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 11

LAB # 11
To compute and sketch the realization of Discrete Time Systems, Structures for
FIR and Structure for IIR, using MATLAB
Objectives
• To compute and the filter coefficients related to different types of IIR filter structures to sketch the
structures of IIR filters
• To compute and the filter coefficients related to different types of FIR filter structures to sketch the
structures of FIR filters
Pre Lab
We have studied the theory of discrete systems in both the time and frequency domains. We will now use this
theory for the processing of digital signals. To process signals, we have to design and implement systems called
filters (or spectrum analysers in some contexts). The filter design issue is influenced by such factors as the type
of the filter (i.e., IIR or FIR) or the form of its implementation (structures). Hence before we discuss the design
issue, we first concern ourselves with how these filters can be implemented in practice.

As we discussed earlier, IIR filters are characterized by infinite duration impulse responses. Some of these
impulse responses can be modelled by rational system functions or, equivalently, by difference equations. Such
filters are termed as auto-regressive moving average (ARMA) or, more generally, as recursive filters.
Furthermore, ARMA filters include moving average filters that are FIR filters.

Part 1

IIR Filter Structures


The system function of an IIR filter is given by

Where b, and a, are the coefficients of the filter. We have assumed without loss of generality that ao=1. The order
of such an IIR filter is called N if aN 0. The difference equation representation of an IIR filter is expressed as

Three different structures can be used to implement an IIR filter:

Direct Form: In this form the difference equation is implemented directly as given. There are two parts to this
filter, namely the moving average part and the recursive part (or equivalently, the numerator and denominator
parts). Therefore this implementation leads to two versions: direct form I and direct form II structures.

Cascade Form: In this form the system function H(z) is factored into smaller second order sections, called
biquads. The system function is then represented as a product of these biquads. Each biquad is implemented in
a direct form, and the entire system function is implemented as a cascade of biquad sections.

Parallel Form: This is similar to the cascade form, but after factorization, a partial &action expansion is used to
represent H(z) as a sum of smaller second-order sections. Each section is again implemented in a direct form,
and the entire system function is implemented as a parallel network of sections.

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 75


Lab Experiment | 11

Direct Form
As the name suggests, the difference equation (6.2) is implemented as given using delays, multipliers, and adders.
For the purpose of illustration, let M = N = 4. Then the difference equation is

Which can be implemented as shown below.

(a) (b)
Figure: (a) Direct Form I Structure (b) Direct Form II Structure

Now the two delay lines are close to each other, connected by a unity gain branch. Therefore one delay line can
be removed, and this reduction leads to a canonical structure called direct form II structure, shown in Figure 6.3.
It should be noted that both direct forms are equivalent form the input output point of view. Internally, however,
they have different signals.

In MATLAB the direct form structure is described by two row vectors; b containing the {b n} coefficients and a
containing the {an} coefficients.

Cascade Form
In this form the system function H(z) is written as a product of second-order sections with real coefficients. This
is done by factoring the numerator and denominator polynomials into their respective roots and then combining
either a complex conjugate root pair or any two red roots into Second order polynomials. In the remainder of
this chapter we assume that N is an even integer. Then

where K is equal to N/2, and BK,1, Bk,2,, Ak,1, and Ak,2 are real numbers representing the coefficients of second
order sections. The second-order section

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 76


Lab Experiment | 11

is called the kth biquad section. Now each biquad section Hk(Z) can be implemented in direct form II as shown
in Figure

Figure: Cascade Form Structure for N=4

Given the coefficients {bn} and {an} of the direct form filter, we have to obtain the coefficients b o, {Bk,i}, and
{Ak,i}.

Part 2

FIR Filter Structures


A causal discrete-time FIR filter of order N, each value of the output sequence is a weighted sum of the most
recent input values:

The order of the filter is M-1, and the length of the filter (which is equal to the number of coefficients) is M. The
FIR filter structures are always stable, and they are relatively simple compared to IIR structures. Furthermore,
FIR filters can be designed to have a linear phase response, which is desirable in some applications.
Direct Form
An FIR filter of order N is characterized by N+1 coefficients and, in general, require N+1 multipliers and N
twoinput adders. Structures in which the multiplier coefficients are precisely the coefficients of the transfer
function are called direct form structures.

Cascade Form
A higher-order FIR transfer function can also be realized as a cascade of second-order FIR sections. Each section
is implemented in direct form and the entire filter as cascaded of 2nd-order sections. To this end, the FIR transfer
function H(z) is expressed in a factored form as,

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 77


Lab Experiment | 11

where:

• M is the number of sections; and


• ak1, ak2 are the multiplication coefficients of section k.

Block diagram describing the hardware cascade realization of a FIR filter is as under,

Pre Lab Tasks


(Attach extra A4 White page if needed)

A filter is described by the following difference equation:

16y(n) + 12y(n - 1) + 2y(n - 2) - 4y(n - 3) - y(n - 4) = x(n) – 3x(n - 1) + l1x(n - 2) – 27x(n - 3) + 18x(n - 4)

Determine its cascade form structure. To verify the direct form filter and cascade form filter give an input the
both and verify the answer.

Lab Task
Lab Task 1
For the following IIR filter functions described by the system functions determine and draw the Direct Form I,
Direct Form II and Cascade Form containing the second order direct form II structure.

a)

b)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 78


Lab Experiment | 11

lab Report

Topic: - This lab has been designed for student to familiarize with the structures for FIR and
structure for IIR
Objectives:-
 Familiarization with structures for FIR and IIR.
 To compute and the filter coefficients related to different types of IIR filter structures to sketch the
structures of IIR filters.
 To compute and the filter coefficients related to different types of FIR filter structures to sketch
the structures of FIR filters.

Required equipment:
Software: MATLAB.
Methodology:
1. To process signals, we have to design and implement systems called filters (or spectrum analyzers in
some contexts).
2. The filter design issue is influenced by such factors as the type of the filter (i.e., IIR or FIR) or the form of
its implementation (structures).
3. IIR filters are characterized by infinite duration impulse responses. Some of these impulse responses can
be modeled by rational system functions or, equivalently, by difference equations.
4. Such filters are termed as auto-regressive moving average (ARMA) or, more generally, as recursive
filters. Furthermore, ARMA filters include moving average filters that are FIR filters. Three different
structures can be used to implement an IIR filters Direct Form, Cascade Form, Parallel Form.
5. The other type is FIR Filter Structures. A causal discrete-time FIR filter of order N, each value of the
output sequence is a weighted sum of the most recent input values:

6. The order of the filter is M-1, and the length of the filter (which is equal to the number of coefficients) is
M. The FIR filter structures are always stable, and they are relatively simple compared to IIR structures.
Furthermore, FIR filters can be designed to have a linear phase response, which is desirable in some
applications. Two different structures can be used to implement an FIR filters are Direct Form. Cascade
Form.

Results and conclusion:


 This lab helped to familiarize Familiarization with structures for FIR and IIR.
 In this I computed the filter coefficients related to different types of IIR filter structures to sketch the
structures of IIR filters and FIR filters.

Pre lab task:


clc
clear allose all
%cofficent of X will be cofficent of mtix B,while cofficent of matix A
b=[1 -3 11 -27 18]
a= [16 12 2 -4 -1]
S_Direct1=dfilt.df1(b,a)%filter command
S_Direct2=dfilt.df2(b,a)
fvtool(S_Direct1)
fvtool(S_Direct2)
gain=dfilt.scalar(1)
S_Cas1=dfilt.cascade(gain,S_Direct1,S_Direct2)
fvtool(S_Cas1)
Muhammad Usman Iqbal 79
Lab Experiment | 11

Lab task1 (a)


% FA17-BEE-147
%%
clc
clear all
close all
H1n=[1 0 1]
H1d=[1 -0.8 0.64]
H2n= [2 -1]
H2d=[1 -0.75]
H3n=[1 2 1]
H3d=[1 0 0.81]
%%
H1=dfilt.df1(H1n,H1d)
H2=dfilt.df1(H2n,H2d)
H3=dfilt.df1(H3n,H3d)
%%
fvtool(H1)
fvtool(H2)
fvtool(H3)
gain=dfilt.scalar(2)
%%
H_Cas1=dfilt.cascade(gain,H1,H2,H3)
fvtool(H_Cas1)
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 12

LAB # 12
To construct Digital IIR filters using Analog Prototype

Objectives
 To construct IIR filter via reference analog prototype filter.

Pre Lab
IIR filters have infinite duration impulse responses; hence they can be matched to analog filters, all of which
generally have infinitely long impulse responses. Therefore the basic technique of IIR filter design transforms
well-known analog filters into digital filters using complex valued mappings. The advantage of this technique
lies in the fact that both analog filter design (AFD) tables and the mappings are available extensively in the
literature. This basic technique is called the A/D (analog- to-digital) filter transformation. However, the AFD
tables are available only for low pass filters. We also want to design other frequency-selective filters (highpass,
bandpass, bandstop, etc.). To do this, we need to apply frequency-band transformations to low pass filters. These
transformations are also complex-valued mappings, and they are also available in the literature. There are two
approaches to this basic technique of IIR filter design:

IIR filter design technique we will follow the following steps:

• Design analog low pass filters.


• Study and apply filter transformations to obtain digital low pass
• Study and apply frequency-band transformations to obtain other filters digital filters from digital low
pass filters.

The main problem with these approaches is that we have no control over the phase characteristics of the IIR
filter. Hence IIR filter designs will be treated as magnitude-only designs. We begin with a discussion on the
analog filter specifications and the properties of the magnitude squared response used in specifying analog filters.
This will lead us into the characteristics of three widely used analog filters, namely, Butterworth, Chebyshev,
and Elliptic filters.

Pre Lab Tasks


(Attach extra A4 White page if needed)

Design a lowpass Butterworth filter to satisfy

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 81


Lab Experiment | 12

Passband cutoff: 𝑇e, = 0.2𝑇 ; Stopband cutoff: 𝑇s, = 0.3𝑇 ;

Passband ripple: RP= 7dB ; Stopband ripple: As = 16dB

Lab Tasks
Lab Task 1
Design a band pass Chebyshev Type II filter using analog prototyping. The order of filter is 20 with a value of
60 dB stop band attenuation and 0.75dB pass band ripple where,

Pass band edge = 800Hz

Stop band edge=2000Hz

Sampling frequency = 6000

Solution

Lab Task 2
Design a Digital Bandpass IIR filter using Analog filter prototype and Frequency Transformation. The filter
should have following specifications:

Minimum order of the filter

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 82


Lab Experiment | 12

Maximum passband = 0.5dB


Minimum stopband attenuation= 30 dB
Pass band edge frequencies = (N-5) – (N+5) MHz
Stop band edge frequencies = (N-5.5) – (N+5.5) MHz
Sampling rate of 8N MHz

Where

10𝑇, if𝑇 < 15


N= { , MHz 𝑇 = Your 𝑇eg. No.
𝑇, otℎerwiswe

i) Give reason which filter type you would prefer based on the specification
ii) Compute the normalized passband and stopband frequencies
iii) Compute the order and transfer function of desired filter
iv) Properly present your results to show that your designed filter meet the specification

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 83


Lab Experiment | 12

Solution

Lab Report #12


To construct Digital IIR filters using Analog Prototype
Objective:
 To construct IIR filter via reference analog prototype filter.
Required Equipment:
Software:
 MATLAB

Procedure/ Methodology
 First of all I launched the MATLAB software on my laptop.
 I then initiated a new script from the tool strip in MATLAB.
 Before starting work on this current lab I made sure to revise the concepts of my previous lab regarding
the computation and sketching the realization of discrete time systems, structures for FIR and structure
for IIR, using MATLAB.
 In applications that use filters to shape the frequency spectrum of a signal such as in communications or
control systems, the shape or width of the roll-off also called the “transition band”, for a simple first-
order filter may be too long or wide and so active filters designed with more than one “order” are
required.
 These types of filters are commonly known as “High-order” or “nth-order” filters.
 For the prelab task of this lab, I have to design a low-pass Butterworth filter to satisfy certain set of
conditions.
 For my first lab task, I have to design a band pass Chebyshev Type II filter using analog prototyping.
 Also known as inverse Chebyshev filters, the Type II Chebyshev filter type is less common because it
does not roll off as fast as Type I, and requires more components. It has no ripple in the passband, but
does have equiripple in the stopband. The gain is:

 In the stopband, the Chebyshev polynomial oscillates between -1 and 1 so that the gain will oscillate
between zero and the smallest frequency at which this maximum is attained is the cutoff frequency ω.
 For my second lab task, I have to design a band pass Chebyshev Type II using Analog filter prototype
and Frequency Transformation.
 The bandpass IIR response has more rejection than that of the analog prototype as you approach fs/2.This
is due to the bilinear transform, which compresses the entire bandwidth into 0 to f s/2. Thus, the analog
zeros at infinity occur at fs/2 for the discrete-time filter.

Results and Conclusion:


In conclusion to this lab, I can satisfactorily state that both the assigned tasks of this lab have been
completed. Furthermore, I have learned how to construct IIR filter via reference analog prototype filter. Low-
pass Butterworth, band pass Chebyshev Type II and band pass Chebyshev Type II were all successfully
designed using my acquired knowledge of analog prototype.

Lab Tasks
Pre-Lab Task:
Design a lowpass Butterworth filter to satisfy:

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

Solution:
High Pass Response:
Code:
function prelab_lab12
%Name: Zeeshan Ashraf
%Roll No: FA17-BEE-147
%main function body
clc;clear all;close all
Wp = 0.2*pi; Ws = 0.3*pi; Rp = 7; As = 16;
% Analog filter design:
[b,a] = afd_butt(Wp,Ws,Rp,As)
[C,B,A] = sdir2cas(b,a)
j=impulse(b,a)
fvtool(b,a)
%definitions of called/used functions
function [C,B,A] = sdir2cas(b,a);

% DIRECT-form to CASCADE-form conversion in s-plane

% -------------------------------------------------

% [C,B,A] = sdir2cas(b,a)

% C = gain coefficient

% B = K by 3 matrix of real coefficients containing bk's

% A = K by 3 matrix of real coefficients containing ak's

% b = numerator polynomial coefficients of DIRECT form

% a = denominator polynomial coefficients of DIRECT form

Na = length(a)-1; Nb = length(b)-1;
% compute gain coefficient C

b0 = b(1); b = b/b0;

a0 = a(1); a = a/a0;

C = b0/a0;
% Denominator second-order sections:

p= cplxpair(roots(a)); K = floor(Na/2);

if K*2 == Na % Computation when Na is even

A = zeros(K,3);

for n=1:2:Na

Arow = p(n:1:n+1,:);

Arow = poly(Arow);

A(fix((n+1)/2),:) = real(Arow);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

end
elseif Na == 1 % Computation when Na = 1

A = [0 real(poly(p))];
else % Computation when Na is odd and > 1

A = zeros(K+1,3);

for n=1:2:2*K

Arow = p(n:1:n+1,:);

Arow = poly(Arow);

A(fix((n+1)/2),:) = real(Arow);

end

A(K+1,:) = [0 real(poly(p(Na)))];

end

% Numerator second-order sections:

z = cplxpair(roots(b)); K = floor(Nb/2);

if Nb == 0 % Computation when Nb = 0

B = [0 0 poly(z)];

elseif K*2 == Nb % Computation when Nb is even

B = zeros(K,3);

for n=1:2:Nb

Brow = z(n:1:n+1,:);

Brow = poly(Brow);

B(fix((n+1)/2),:) = real(Brow);

end
elseif Nb == 1 % Computation when Nb = 1

B = [0 real(poly(z))];

else % Computation when Nb is odd and > 1

B = zeros(K+1,3);

for n=1:2:2*K

Brow = z(n:1:n+1,:);

Brow = poly(Brow);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

B(fix((n+1)/2),:) = real(Brow);

end

B(K+1,:) = [0 real(poly(z(Nb)))];

end
function [b,a] = afd_butt(Wp,Ws,Rp,As);

% Analog Lowpass Filter Design: Butterworth

% -----------------------------------------

% [b,a] = afd_butt(Wp,Ws,Rp,As);

% b = Numerator coefficients of Ha(s)

% a = Denominator coefficients of Ha(s)

% Wp = Passband edge frequency in rad/sec; Wp > 0

% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0

% Rp = Passband ripple in +dB; (Rp > 0)

% As = Stopband attenuation in +dB; (As > 0)

if Wp <= 0

error('Passband edge must be larger than 0')

end

if Ws <= Wp

error('Stopband edge must be larger than Passband edge')

end

if (Rp <= 0) | (As < 0)

error('PB ripple and/or SB attenuation ust be larger than 0')

end
N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)));

fprintf('\n*** Butterworth Filter Order = %2.0f \n',N)

OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));

[b,a]=u_buttap(N,OmegaC);
function [b,a] = u_buttap(N,Omegac);

% Unnormalized Butterworth Analog Lowpass Filter Prototype

% --------------------------------------------------------

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

% [b,a] = u_buttap(N,Omegac);

% b = numerator polynomial coefficients of Ha(s)

% a = denominator polynomial coefficients of Ha(s)

% N = Order of the Butterworth Filter

% Omegac = Cutoff frequency in radians/sec


[z,p,k] = buttap(N);

p = p*Omegac;

k = k*Omegac^N;

B = real(poly(z));

b0 = k;

b = k*B;

a = real(poly(p));

Output:

Low pass Response:


Code:
function prelab_lab12
%main function body
%Name: Zeeshan Ashraf
%Roll No: FA17-BEE-147
clc
clear all
close all
Wp = 0.2*pi;
Ws = 0.3*pi;
Rp = 7;
As = 16;
% Analog filter design:
[b,a] = afd_butt(Wp,Ws,Rp,As)
[C,B,A] = sdir2cas(b,a)
j=impulse(b,a)
fvtool(b,a)

%definitions of called/used functions


Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84
Lab Experiment | 12

function [C,B,A] = sdir2cas(b,a);

% DIRECT-form to CASCADE-form conversion in s-plane

% -------------------------------------------------

% [C,B,A] = sdir2cas(b,a)

% C = gain coefficient

% B = K by 3 matrix of real coefficients containing bk's

% A = K by 3 matrix of real coefficients containing ak's

% b = numerator polynomial coefficients of DIRECT form

% a = denominator polynomial coefficients of DIRECT form

Na = length(a)-1; Nb = length(b)-1;

% compute gain coefficient C

b0 = b(1); b = b/b0;

a0 = a(1); a = a/a0;

C = b0/a0;
% Denominator second-order sections:

p= cplxpair(roots(a)); K = floor(Na/2);

if K*2 == Na % Computation when Na is even

A = zeros(K,3);

for n=1:2:Na

Arow = p(n:1:n+1,:);

Arow = poly(Arow);

A(fix((n+1)/2),:) = real(Arow);

end
elseif Na = 1 % Computation when Na = 1

A = [0 real(poly(p))];
else % Computation when Na is odd and > 1

A = zeros(K+1,3);

for n=1:2:2*K

Arow = p(n:1:n+1,:);

Arow = poly(Arow);

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

A(fix((n+1)/2),:) = real(Arow);

end

A(K+1,:) = [0 real(poly(p(Na)))];

end
% Numerator second-order sections:

z = cplxpair(roots(b)); K = floor(Nb/2);

if Nb == 0 % Computation when Nb = 0

B = [0 0 poly(z)];
elseif K*2 == Nb % Computation when Nb is even

B = zeros(K,3);

for n=1:2:Nb

Brow = z(n:1:n+1,:);

Brow = poly(Brow);

B(fix((n+1)/2),:) = real(Brow);

end
elseif Nb == 1 % Computation when Nb = 1

B = [0 real(poly(z))];
else % Computation when Nb is odd and > 1

B = zeros(K+1,3);

for n=1:2:2*K

Brow = z(n:1:n+1,:);

Brow = poly(Brow);

B(fix((n+1)/2),:) = real(Brow);

end

B(K+1,:) = [0 real(poly(z(Nb)))];

end
function [b,a] = afd_butt(Wp,Ws,Rp,As);

% Analog Lowpass Filter Design: Butterworth

% -----------------------------------------

% [b,a] = afd_butt(Wp,Ws,Rp,As);

% b = Numerator coefficients of Ha(s)

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

% a = Denominator coefficients of Ha(s)

% Wp = Passband edge frequency in rad/sec; Wp > 0

% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0

% Rp = Passband ripple in +dB; (Rp > 0)

% As = Stopband attenuation in +dB; (As > 0)


if Wp <= 0

error('Passband edge must be larger than 0')

end

if Ws <= Wp

error('Stopband edge must be larger than Passband edge')

end

if (Rp <= 0) | (As < 0)

error('PB ripple and/or SB attenuation ust be larger than 0')

end
N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)))

fprintf('\n*** Butterworth Filter Order = %2.0f \n',N)

OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));

[b,a]=butter(N,OmegaC);
function [b,a] = u_buttap(N,Omegac);

% Unnormalized Butterworth Analog Lowpass Filter Prototype

% --------------------------------------------------------

% [b,a] = u_buttap(N,Omegac);

% b = numerator polynomial coefficients of Ha(s)

% a = denominator polynomial coefficients of Ha(s)

% N = Order of the Butterworth Filter

% Omegac = Cutoff frequency in radians/sec


[z,p,k] = buttap(N);

p = p*Omegac;

k = k*Omegac^N;

B = real(poly(z));

b0 = k;
Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84
Lab Experiment | 12

b = k*B;

a = real(poly(p));

Output:

Lab Task 1
Design a band pass Chebyshev Type II filter using analog prototyping. The order of filter is 20 with a
value of 60 dB stop band attenuation and 0.75dB pass band ripple where,
Pass band edge = 800Hz
Stop band edge=2000Hz
Sampling frequency = 6000

Solution:
Code:
%Name: Zeeshan Ashraf
%Roll No: FA17-BEE-147
%Chebyshev
clc
clear all
close all

Rp=0.75
Rs=60
fp=800
fst=2000
fs=6000
ft=fs/2

wp=fp/ft
wst=fst/ft

%chebbyshev
[n1,wn]=cheb1ord(wp,wst,Rp,Rs)
[num,den]=cheby1(n1,Rp,wn)
[H,w]=freqz(num,den,512,fs)
plot(w,20*log10(abs(H)))
title('Chebbyshev mag in dB')

Output:

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Lab Experiment | 12

Lab Task 2
Design a Digital Bandpass IIR filter using Analog filter prototype and Frequency Transformation. The
filter should have following specifications:
Minimum order of the filter
Maximum passband = 0.5dB
Minimum stopband attenuation= 30 dB
Pass band edge frequencies = (N-5) – (N+5) MHz
Stop band edge frequencies = (N-5.5) – (N+5.5) MHz
Sampling rate of 8N MHz
Where,

i) Give reason which filter type you would prefer based on the specification
ii) Compute the normalized passband and stopband frequencies
iii) Compute the order and transfer function of desired filter
iv) Properly present your results to show that your designed filter meet the specification

Solution:
Code:
%Name: Zeeshan Ashraf
%Roll No: FA17-BEE-147
clc;
close all;
clear all;
N = 147;
Rp = 0.5;
Rs = 30;
fp = [(N-5) (N+5)].*(10^6)
fs = [(N-5.5) (N+5.5)].*(10^6)
Fs = 8*N*(10^6);
ft = Fs;
wp = 2*fp/ft; % normalized Pass band corner frequency
ws = 2*fs/ft; % normalized Stop band corner frequency
[n,Wn] = ellipord(wp,ws,Rp,Rs);
[n1,wn1]=cheb1ord(wp,ws,Rp,Rs)
[n2,wn2]=cheb2ord(wp,ws,Rp,Rs)
[nb,wnb]=buttord(wp,ws,Rp,Rs)
[num,den] = ellip(n,Rp,Rs,Wn);
[H,w] = freqz(num,den,512,Fs);
Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84
Lab Experiment | 12

mag = mag2db(abs((H)))
phase = rad2deg(angle(H))
subplot(2,1,1)
plot(w,mag,'C','LineWidth',2)
grid on;
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
legend('mag')
title('Magnitude Plot')
subplot(2,1,2)
plot(w,phase,'M','LineWidth',2)
grid on;
xlabel('Frequency (Hz)')
ylabel('Phase (degrees)')
legend('phase')
title('Phase Plot')

Output:

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 84


Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 13

LAB # 13
To construct Linear Phase FIR filters based on Windows

Objectives
 To construct FIR filters based on Windows

Pre Lab
The basic idea behind the window design is to choose a proper ideal frequency selective filter (which always
has a no causal, infinite duration impulse response) and then truncate (or window) its impulse response to obtain
a linear-phase and causal FIR filter. Therefore, the emphasis in this method is on selecting an appropriate
windowing function and appropriate ideal filter. We will denote an ideal frequency-selectiveHd(ejw), which has
a unity magnitude gain and linear-phase characteristics over its pass band, and zero response over its stop band.
An ideal LPF of bandwidth wc < 𝛼 is given by

where wc, is also called the cut-off frequency, and 𝛼 is called the sample delay (note that from the DTFT
properties, ej𝛼w implies shift in the positive n direction or delay). The impulse response of this filter is of infinite
duration and is given by

Note that hd(n) is symmetric with respect to a, a fact useful for linear phase FIR filters.

To obtain an FIR filter from hd(n), one has to truncate hd(n) on both sides. To obtain a causal and linear-phase
FIR filter h(n) of length M, we must have

This operation is called "windowing." In general, h(n) can be thought of as being formed by the product of hd(n)
and a window function w(n) as follows:

Depending on how we define w(n) above, we obtain different window designs.

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 86
Lab Experiment | 13

WINDOW DESIGN TECHNIQUES

Table 13.1: Summary of commonly used window function characteristics.


Window Transition Width Δw Exact Min. Stopband
Name Approximate Values Attenuation
4π 1.8π
Rectangular 21 dB
M M
8π 6.1π
Bartlett 25 dB
M M
8π 6.2π
Hanning 44 dB
M M
8π 6.6π
Hamming 53 dB
M M
12π 11π
Blackman 74 dB
M M

Design Equations
Given w,, w., Rp, and As

MATLAB Implementation
MATLAB provides several routines to implement window functions discussed in this section. A brief
description of these routines is given below.

• w=rectwin(M) returns the M-point rectangular window function in array w.


• w=triang(M) returns the M-point Bartlett (triangular) window function in array w.
• w=hann(M) returns the K-point Hanning window function in array w.
• w=hamming(M) returns the M-point Hamming window function in array w.
• w=blackman(M) returns the M-point Blackman window function in array w.
• w=kaiser(M, beta) returns the beta-valued Kpoint rectangular window function in array w.
Using these routines, we can use MATLAB to design FIR filters based on the window technique, which also
requires an ideal low pass impulse response hd(n). Therefore it is convenient to have a simple routine that creates
hd(n).

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 87
Lab Experiment | 13

Pre-Lab Tasks
(Attach extra A4 White page if needed)

Design a high pass FIR filter using window method. Select an appropriate window function and justify your
choice by comparing it with any of other window function for same high pass filter.

Lab Tasks
Lab task 1
Design a digital FIR lowpass filter with the following specifications:

Choose an appropriate window function from Table 11.1. Determine the impulse response and provide a plot of
the frequency response of the designed filter.

Solution

Lab task 2
Design a filter for digital signal processing with following specifications: At the receiver side of radar a bandpass
filter is used to extract the information from transmitted signal. Furthermore the wave shape of a returned radar
signal contain important information about the target's properties it is required that the phase response of filter
should be linear in passband. While other parameters are given by

Pass band attenuation of ripples RP = 1dB

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 88
Lab Experiment | 13

Stop band attenuation AS = A dB


Pass band edge frequencies = (5-0.5) – (5+0.5) MHz
Stop band edge frequencies = (5-0.7) – (5+0.7) MHz
Sampling rate of 10N MHz
Where,
 70 R  15
 16  R  25
 50
A  
 40 26  R  35
 21 R  35
i) Explain with reason which filter type you would prefer based on the specification
ii) Compute the normalized passband and stopband frequencies for filter
iii) Compute the order and impulse response of the desired filter
iv) Show the results that designed filter meet the specification

Solution

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 89
Lab Report

Topic: - This lab has been designed for student to familiarize with the construct Linear
Phase FIR filters based on Windows.

Objectives:-

 Familiarization with FIR filters.

 To construct FIR filters based on windows.

 In - Lab task 2 is an open ended task

Required equipment:
Software: MATLAB.
Methodology:
1. The basic idea behind the window design is to choose a proper ideal frequency selective filter
(which always has a no causal, infinite duration impulse response) and then truncate (or window) its
impulse response to obtain a linear-phase and causal FIR filter.
2. Therefore, the emphasis in this method is on selecting an appropriate windowing function and
appropriate ideal filter.
3. We will denote an ideal frequency-selective ( ), which has a unity magnitude gain and linear-phase
characteristics over its pass band, and zero response over its stop band.
4. An ideal LPF of bandwidth wc < is given by where wc, is also called the cut-off frequency, and is
called the sample delay (note that from the DTFT properties, implies shift in the positive n direction
or delay).
5. The impulse response of this filter is of infinite duration and is given by To obtain an FIR filter
from hd (n), one has to truncate hd(n) on both sides.
6. To obtain a causal and linear-phase FIR filter h (n) of length M, we must have

7. This operation is called "windowing." In general, h (n) can be thought of as being formed by the
product of hd (n).

Results and conclusion:


 This lab helped to familiarize with FIR filters.
 Lab helped me to construct FIR filters based on windows.
 Different types of FIR windows like Kaisar, Rectangular, Hanning was designed and their
responses on different frequencies were observed.
 Pre- Lab task 1
 % FA17-BEE-147
 %%
 %Lab 13 pre lab
 clc
 clear all
 close all
 ord = 22;
 band = [0.6];
 bw1 = fir1(ord,[band],'high');
 bw2=fir1(ord,[band],'high',hann(ord+1));
 fvtool(bw1,1,bw2,1);

 legend('bartlet','rectangular')

Lab task 1
% FA17-BEE-147
%%
clc;
clear all;
close all;
wp = 0.2*pi; ws = 0.3*pi;
tr_width = ws - wp
M = ceil(6.6*pi/tr_width) +1
n=[0:1:M-1];
wc = (ws+wp)/2
hd = ideal_lp(wc,M);
w_ham = (hamming(M))';
h = hd .* w_ham;
delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1))) % Passband Ripple
As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation
% plots
stem(n,h);title('Impulse Response')
figure; freqz(h,[1]) ;
title('Magnitude Response in dB');
grid
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _


Lab Experiment | 14

LAB # 14
To assemble FIR and IIR filters on DSP Kit TMS320C6713 for real time
processing

Objectives
 To Assemble IIR filter (LPF & HPF) on DSP Starter Kit DSK6713
 To assemble FIR filter on DSP Starter Kit DSK6713

Pre-Lab Task
IIR Filters
The IIR filter can realize both the poles and zeroes of a system because it has a rational transfer function,
described by polynomials in z in both the numerator and the denominator

m and n are order of the two polynomials b and a are the filter coefficients. These filter
coefficients are generated using FDS (Filter Design software or Digital Filter design package. IIR filters can be
expanded as infinite impulse response filters. In designing IIR filters, cutoff frequencies of the filters should be
mentioned. The order of the filter can be estimated using Butterworth polynomial. That’s why the filters are
named as Butterworth filters. Filter coefficients can be found and the response can be plotted.

FIR Filters
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose output is based on the
weighted summation of a finite number of past inputs. An FIR transversal filter structure can be obtained directly
from the equation for discrete-time convolution. FIR – filter is a finite impulse response filter. Order of the filter
should be specified. Infinite response is truncated to get finite impulse response. Placing a window of finite
length does this. Types of windows available are Rectangular, Bartlett, Hamming, Hanning, Blackmann window
etc., This FIR filter is an all zero filter.

Lab Tasks
Lab Task 1: Implement IIR filter
Follow the steps discussed in Lab # 5 to build a project. C program is given for real time processing of audio
signal. Signal from audio-in will be filtered and send to audio-out.

C PROGRAM IIR_BUTERWORTH_LP FILTER


#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"

//const signed int filter_coeff[] = {2366,2366,2366,32767,-18179,13046};//IIR_BUTTERWORTH_LP


FILTER pass band range 0-2.5kHZ
//const signed int filter_coeff[] = {312,312,312,32767,-27943,24367};//IIR_BUTTERWORTH_LP
FILTER pass band range 0-800Hz
const signed int filter_coeff[] = {15241,15241,15241,32761,10161,7877};//IIR_BUTERWORTH_LP
FILTER pass band range 0-8kHz

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 91
Lab Experiment | 14

DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main() {
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

while(1) {
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
if(DSK6713_DIP_get(1)==0)
break;
} // end while
DSK6713_AIC23_closeCodec(hCodec);
} // end main

signed int IIR_FILTER(const signed int * h, signed int x1) {


static signed int x[6] = {0,0,0,0,0,0};
static signed int y[6] = {0,0,0,0,0,0};
int temp=0;
temp = (short int)x1;
x[0] = (signed int) temp;
temp = ( (int)h[0] * x[0]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[2] * x[2]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[5] * y[2]);
temp >>=15;
if ( temp > 32767 ) {
temp = 32767;
}
else if ( temp < -32767) {
temp = -32767;
}
y[0] = temp;
y[2] = y[1];
y[1] = y[0];
x[2] = x[1];
x[1] = x[0];

Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 92


Lab Experiment | 14

return (temp<<2);
}

Lab Task 2
C PROGRAM IIR_BUTERWORTH_HP FILTER
Change the above code for following specification
IIR_BUTTERWORTH_HP FILTER pass band range 2.5kHz-8KHz
IIR_BUTTERWORTH_HP FILTER pass band range 4kHz-8KHz
IIR_BUTTERWORTH_HP FILTER pass band range 7kHz-8Khz
(Write C Code Here)

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 93
Lab Experiment | 14

Lab Task 3: Implement FIR filter


Follow the steps discussed in Lab # 5 to build a project. C program is given for real time processing of audio
signal. Signal from audio-in will be filtered and send to audio-out.

C PROGRAM FIR_LP FILTER


#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
/* float filter_coeff[]={-0.000019,-0.000170,-0.000609,-0.001451,-0.002593,-0.003511,
-0.003150,0.000000,0.007551,0.020655,0.039383,0.062306,0.086494,0.108031,0.122944,
0.128279,0.122944,0.108031,0.086494,0.062306, 0.039383,0.020655,0.007551,0.000000,
-0.003150,-0.003511,-0.002593,-0.001451,-0.000609,-0.000710, -0.000019};
// kaiser low pass fir filter pass band range 0-500Hz */

/*float filter_coeff[]={-0.000035,-0.000234,-0.000454,0.000000,0.001933,0.004838,0.005671,-0.000000,
-0.013596,-0.028462,0.029370,0.000000,0.064504,0.148863,0.221349,0.249983,0.221349,0.148863,
0.064504,0.000000,-0.029370,-0.028462,-0.013596,-0.000000,0.005671,0.004838,0.001933,0.000000,
-0.000454,-0.000234,-0.000035};
// kaiser low pass fir filter pass band range 0-1000Hz */

float filter_coeff[]={-0.000046,-0.000166,0.000246,0.001414,0.001046,-0.003421,-0.007410,0.000000,
0.017764,0.020126,-0.015895,-0.060710,-0.034909,0.105263,0.289209,0.374978,0.289209,0.105263,
-0.034909,-0.060710,-0.015895,0.020126,0.017764,0.000000,-0.007410,-0.000046};
//Kaiser low pass fir filter pass band range 0-1500Hz */

DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main() {
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

while(1) {
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
if(DSK6713_DIP_get(1)==0)
break;
} // end while
DSK6713_AIC23_closeCodec(hCodec);
} // end main

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 94
Lab Experiment | 14

signed int FIR_FILTER(float * h, signed int x) {


int i=0;
signed long output=0;
static short int in_buffer[100];
in_buffer[0] = x;

for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];
for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
//output = x;
return(output);
}

Lab Task 4
C PROGRAM IIR_BUTERWORTH_HP FILTER
Change the above code for following specification
IIR_BUTTERWORTH_HP FILTER pass band range 2.5kHz-8KHz
IIR_BUTTERWORTH_HP FILTER pass band range 4kHz-8KHz
IIR_BUTTERWORTH_HP FILTER pass band range 7kHz-8Khz
(Write C Code Here)

Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 95
Rubric for Lab Assessment

The student performance for the assigned task during the lab session w as:
The student completed assigned taskswithout any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
G ood 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
W orst The student did not complete assigned tasks. 1

Instructor Signature: __ Date: _

You might also like