Professional Documents
Culture Documents
Matlab Project I
Fall 2001
Issued: Monday, September 24, 2001 Due: Wednesday, October 17, 2001
The purpose of this project is to develop a thorough understanding of the Discrete Fourier Transform
(DFT) and how it is used to implement digital filters. Part 1 focuses on the circular convolution property
of the DFT. You will write and test Matlab functions that implement the circular flip, circular shift, and
circular convolution operations. In addition you will examine the relationship between linear convo-
lution and circular convolution. Part 2 considers the problem of using the DFT to implement linear,
time-invariant filtering operations on long signals. Specifically, you will write Matlab functions that
implement block convolution using the overlap-add and overlap-save strategies.
A list of guidelines for preparing the writeup of this project are given below. Failure to comply with
these guidelines will result in a grade of ZERO for the project.
• The report must be neatly handwritten or typed, and all pages must be numbered.
• All plots must be neatly annotated with x-axis and y-axis labels and a title.
• When referring to plots in the text, you should do at least one of the following:
– use figure numbers, e.g., “Figure 1 is a plot of the signal x[n].”
– cite the page number they are on, e.g., “The figure at the top of page 4 is a plot of x[n].”
• All Matlab code must be well-documented and should be included in an Appendix at the end of
the report.
1 CIRCULAR CONVOLUTION
The following exercises focus on the circular convolution property of the DFT. An N −point circular
convolution is defined as follows
N
X −1
y[n] = x[n]
N h[n] = x[m]h[(n − m)mod N ]. (1)
m=0
Combining N -point vectors according to the circular convolution rule (Equation 1) is easy to visualize
with some experience, and Matlab provides the means to do the visualization. Circular convolution
requires that all indexing be done in a circular (or periodic) fashion. Thus a shifting operation becomes
a rotation. In the exercises below you will develop functions for circular flipping, circular shifting, and
then use those functions to implement circular convolution.
(b) Define several test signals and use them to verify that your function is working. Include plots of a
few (two or three) test cases in your writeup, i.e., plots of both the original signal and the flipped
signal. You will probably want to use the subplot command to get these plots on the same
page.
x[(n − m) mod N ]
(a) Write a function Matlab called cshift to implement the circular shifting operation.
Hint:
First write a short function that computes n mod N . Matlab’s rem function will be useful for
this task, but is not sufficient by itself because it will not handle the case where n is negative.
However, a simple modification that uses two calls to rem will guarantee an answer in the range
[0, N − 1]. Take advantage of the fact that (n + N ) mod N = n mod N .
Once you have code to compute n mod N , writing the rest of the cshift function should be
easy.
(b) Define several test signals and use them to verify that your function is working. Include plots of
two or three of these test cases as documentation in your writeup. You should verify that your
function handles the case where m is negative and also the case where m is greater than N .
(c) We know that a circular shift corresponds to multiplying the DFT by complex exponential. Verify
the results of your test cases by
%% File : cconv
%% Author : The DSP Wizard/Wizardess
%% Date : September 26, 2001
(a) The frequency-domain implementation uses the fact that the circular convolution of x[n] and h[n]
is equivalent to the multiplication of their DFT’s, i.e., X[k] · H[k]. Use this idea to implement the
frequency-domain method in cconv. This should require three calls to Matlab’s fft function.
Try (and plot!) the following simple tests for N = 16 and N = 21.
(b) Implement the time-domain option for circular convolution in your cconv function, i.e., imple-
ment This can be done with for loops, but good Matlab programming style replaces for loops
with vector operations whenever possible. Since each output point in the circular convolution is
an inner product of x with a circularly-flipped and shifted version of h, only one for loop is
needed. Write a function called cconv2 based on this idea. Test your function using some of the
examples from part (a). Include several of the test cases in your writeup.
2 BLOCK CONVOLUTION
While short signals provide useful illustrations of convolution, they are not typical of practical filtering
problems. In many applications the input x[n] is very long with respect to the filter impulse response
h[n]. It is often impractical to process the entire input signal at once. An alternative solution is to
break the input into blocks, filter each block separately and then combine the blocks appropriately to
obtain the output. There are two basic strategies for block processing, which are known as overlap-
add and overlap-save, respectively. Matlab’s fftfilt program uses the overlap-add approach. In the
following exercises you will develop your own Matlab implementations of overlap-add and overlap-save
block convolution.
%% File : oladd
%% Author : The DSP Wizard/Wizardess
%% Date : September 26, 2001
(b) Test your code using the signal and filter defined in the file projIdata.mat, available on the
course website. You can verify the results by comparing them to the result of convolving x and
h using the built-in conv function. Make sure that your function works for any reasonable DFT
length (i.e., longer than the filter).
(a) Write a Matlab function called olsave to implement overlap-save block convolution. The inputs
to this function should be the input signal vector x, the filter vector h, and the DFT size. Use a
header for your function similar to the one for oladd.
(b) Test your code as you did the oladd function, i.e., using the data in projIdata.mat. Make
sure that your function works for any reasonable DFT-length (i.e., longer than the filter itself).