Latest - Updated Manual
Latest - Updated Manual
Semester 6
Revision History
Dr. Hafiz M
Asif Dr.
Khurram Ali
2 Lab Manual Review Feb-2015
3 Layout Modifications Feb-2015 Mr. M Usman Iqbal
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.
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
1. Digital Signal Processing: A Computer-based approach by Sanjit K. Mitra, McGraw-Hill Science (SKM)
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
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 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)
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.
iv
Preface ......................................................................................................................................................................... ii
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
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
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
LAB # 13 .................................................................................................................................................................... 86
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
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)}
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 + 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.
7. Sample Products
This operation also differs from signal multiplication operation. It multiplies all sample values of x(n) between
n1 and 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
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.
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.
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
wℎ ere t = 0 → 2sec
Use proper indicators, legends, title and label the axis. Use help command if require
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
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
Write MATLAB code to call all the functions and plot it on one figure with proper labelling
Solution
Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 14
Lab Experiment No. | 1
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
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
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
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.
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.
For a given sampling interval T, which is defined as the time span between two sample points, the sampling rate
is therefore given by
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.
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
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
Lab Task 2
Given the digital speech signal in the file guitatune.wav, Write a MATLAB program to
Solution
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
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:
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
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
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
L {.} Shift By
Shift By L {.}
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.
Lab Tasks
Lab Task 1
Given the following two sequences, determine the convolution y(n). Plot each step in the subplot.
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.
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
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)
% --------------------------------------------------
% [y,ny] = conv_m(x,nx,h,nh)
% y = convolution result
% ny = support of y
% nx = support of x
% nh = support of h
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];
y = conv(x,h);
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)
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
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)}.
[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);
Write a MATLAB program that take two vectors ‘n’ & ‘d’ that are the numerator and denominator coefficients.
Program should find the following.
Lab Tasks
Lab Task 1
Determine the rational Z-Transform from its poles and zero locations. The zeros 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.
Lab Task 2
Using MATLAB, determine the partial fraction expansion of the z transform G(z), given by
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)
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
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)
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
Generate pulses
Interrupt the CPU
Send synchronization events to the EDMA controller
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.
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.
Creating a Project
After verification of DSK6713 open Code Composer Studio v3.1. Following window will appear.
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
In menu Linker category Basic and set Library Search Path and Include Libraries.
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);
}
junk=0;
}
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.
Break Point
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.
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
Topic: - This lab has been designed for student to familiarize with 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
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.
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);
}
}
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
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].
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)
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
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
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=
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);
% 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
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 =
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 :
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
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)
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
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
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.
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
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
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.
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.
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')
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
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')
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
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
• 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.
Lab Tasks
Task 1 SIMULINK Model
Build a SIMULINK model for Sampling and Reconstruction of analog signal
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
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;
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
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.
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.
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
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;
/*Typecasting */
OUT_L = IN;
OUT_R = IN;
}
/* 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.
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
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.
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;
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
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
for(i=0;i<N;i++) {
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]);
}
return(0);
}
Lab Task 1
Change the above code for frequency analysis real time audio signal.
Objectives:-
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).
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
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
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
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.
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
(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
is called the kth biquad section. Now each biquad section Hk(Z) can be implemented in direct form II as shown
in Figure
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
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,
where:
Block diagram describing the hardware cascade realization of a FIR filter is as under,
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)
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.
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
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:
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.
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,
Solution
Lab Task 2
Design a Digital Bandpass IIR filter using Analog filter prototype and Frequency Transformation. The filter
should have following specifications:
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
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.
Lab Tasks
Pre-Lab Task:
Design a lowpass Butterworth filter to satisfy:
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);
% -------------------------------------------------
% [C,B,A] = sdir2cas(b,a)
% C = gain coefficient
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);
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);
A(fix((n+1)/2),:) = real(Arow);
end
A(K+1,:) = [0 real(poly(p(Na)))];
end
z = cplxpair(roots(b)); K = floor(Nb/2);
if Nb == 0 % Computation when Nb = 0
B = [0 0 poly(z)];
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))];
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);
% -----------------------------------------
% [b,a] = afd_butt(Wp,Ws,Rp,As);
if Wp <= 0
end
if Ws <= Wp
end
end
N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)));
OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));
[b,a]=u_buttap(N,OmegaC);
function [b,a] = u_buttap(N,Omegac);
% --------------------------------------------------------
% [b,a] = u_buttap(N,Omegac);
p = p*Omegac;
k = k*Omegac^N;
B = real(poly(z));
b0 = k;
b = k*B;
a = real(poly(p));
Output:
% -------------------------------------------------
% [C,B,A] = sdir2cas(b,a)
% C = gain coefficient
Na = length(a)-1; Nb = length(b)-1;
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);
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);
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);
% -----------------------------------------
% [b,a] = afd_butt(Wp,Ws,Rp,As);
end
if Ws <= Wp
end
end
N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)))
OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));
[b,a]=butter(N,OmegaC);
function [b,a] = u_buttap(N,Omegac);
% --------------------------------------------------------
% [b,a] = u_buttap(N,Omegac);
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:
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:
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
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:
Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 86
Lab Experiment | 13
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.
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
Muhammad Usman Iqbal |EEE 324 | Digital Signal Processing Lab Manual 88
Lab Experiment | 13
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:-
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).
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
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.
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
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
/*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
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