You are on page 1of 6

University of Toronto Edward S.

Rogers Department of Electrical and Computer Engineering ECE216: SIGNALS AND SYSTEMS Project 1: Convolution and Fourier Series
Topic This project will give you practice using the Matlab program to explore the concepts of convolution, Fourier series, and their applications. Write-up The report will consist of the standardized answer booklet (available on the class webpage) and the attached plots. Collaboration You are encouraged to work with one other partner on this project. Each group of two should turn in a single report, with both of their names on it. Note that for the quizzes/midterm/nal we expect both partners to understand all parts of the project. Equipment Needed You will need to have access to a computer with MATLAB installed. The ECF Labs can be used for this course. There are no formal lab sessions. The project TA will be available at posted hours to answer questions and to provide help. You will also need a printer. Part of the project involves listening to and ltering sound signals. The lab computers have built-in speakers, but you might be able to hear more clearly if you bring headphones and use them instead. No Plagiarism! The following policy is quoted from the department website: Cheating: What Happens When a Student is Caught. Whenever a student is caught cheating, the incident is reported to the Undergraduate Oce. The penalty is zero on the assignment/test. In addition, double the value of the assignment/test is removed from the nal grade. Therefore, a student caught cheating on a test worth 25% will get no more than 25% on their nal grade (0 on the test, and 50% removed from the nal grade). The incident is also noted on their transcript for 5 years, which means that getting their rst job will be a challenge. A second oence will result in forced leave for one year. Ocially, all penalties are determined by the Dean, but he accepts the departments decisions in all cases where the assignment is worth 10% or less of a total course mark. Hand-in Procedure Hand in your report in the wooden boxes on the fourth oor hallway of the Bahen center between rooms BA 4110 and BA 4010. Late Report Penalties will be applied for late submission. Each project is worth 10% of the term mark. The late penalty is 2% of the term mark per 24 hours. (If you are handing in the report late, indicate on your booklet the actual time at which the report is handed in and email the project TA at the same time.) Returns Marked reports will be returned to you during the tutorial. Please indicate the tutorial section in which you wish to get your report back.

Convolution
+

In class, youve learned that the convolution of two signals x[n] and h[n] is dened as x[n] h[n] =
k=

x[k]h[n k]

(1)

The purpose of this part of the project is to learn how to use Matlab to convolve signals, and to explore an application to echo cancellation.

1.1

Implementing Convolution using the Matlab function conv

In Matlab the function conv(h,x) convolves the two nite-length sequences represented by the vectors h and x. The function call y = conv(h,x) returns the output y[n] = h[n] x[n] in the correct order, but does not keep track of the time-indices of y[n]. Part 1: (6 points) 1a. We start with an example. Let x[n] = u[n] u[n 6]. Analytically derive x[n] x[n]. Sketch both x[n] and x[n] x[n]. 1b. What happens if one repeatedly convolves x[n] with itself? Use conv to nd: (i) y[n] = x[n] x[n]; (ii) z[n] = y[n] y[n]; and (iii) w[n] = z[n] z[n]. Use stem to plot x[n], y[n], z[n] and w[n]. After dening x, y, z, w appropriately, your plotting commands may look something like >> >> >> >> >> figure; subplot(411); subplot(412); subplot(413); subplot(414); stem(x); stem(y); stem(z); stem(w);

The command subplot(mnk) puts m n plots on the same page. Attach the plot to the answer booklet. You may recognize that the repeated convolution converges to a bell shape (also known as the Gaussian shape in probability theory). You may also look at the implementation of the conv function in Matlab by typing type conv. 1c. When a length-k1 vector is convolved with a length-k2 vector, what is the length of the resulting vector? Explain. What is the length of w[n]? Briey explain. In Matlab, the time index for vectors starts with 1. However, signals in real applications do not always start at time 1. So, it is important to keep track of the indices manually. In addition, we often need to calculate the response of a causal LTI system with an innite-length impulse response h[n] to an innite-length input x[n]. Naturally, Matlab can only keep track of nite-length vectors. Part 2: (8 points) 2a. If h[n] and x[n] are non-zero on the nite intervals a n b and c n d, respectively, for what interval will y[n] be non-zero? Explain. 2b. Consider the following signal and impulse response: x[n] = h[n] = 1 u[n 2], 2 [n + 1] + 2[n 2]. 2
n2

Construct a vector x for x[n] up to n = 24. Construct a vector h for h[n] over 1 n 2. Let y = conv(h,x). On the same page, use the Matlab command stem (with subplot) to plot x, h and y with the correct time indices. Write down the matlab commands for creating x, h, y, and the plot. Attach the plot to the answer booklet. You can overload Matlab operators to operate on a vector component-wise. For example, 0.5. (1:3) creates a vector [0.5, 0.52 , 0.53 ]. To align the time index, you need to create a vector of time axis when calling stem (e.g. stem(-1:2,h) aligns the 4-element h to start at time index 1).

1.2

Echo Cancellation

A basic signal processing task in many voice applications is echo cancellation. Echos can result from, for example, reections o walls in conference rooms that are picked up by speaker phones or o mismatched switching equipment in telephone lines. The eect of a single echo can be modelled as: y[n] = x[n] + x[n N ], (2)

where x[n] is the voice signal, N is the delay resulting from the greater distance the echo must travel, and is a constant modelling the attenuation of signal energy resulting from non-perfect reection. The example in this part has N = 1000 and = 0.5. Part 3: (12 points) 3a. In your answer booklet, sketch the impulse response h[n] for the system of (2) for 0 n 1500. 3b. An echo removal system must take y[n] as input and produce x[n] as output. Thus, an echo removal system must be described by the dierence equation (2) with input x[n] replaced by y[n], and output y[n] replaced by x[n], i.e., x[n] = y[n] + y[n N ], which is equivalent to: y[n] = x[n] y[n N ]. (3)

In your answer booklet, analytically derive the impulse response of the above inverse system g[n], and sketch g[n] for 0 n 4N . 3c. Verify analytically that h[n] g[n] = [n]. 3d. Load the le lineup.mat into Matlab using load lineup.mat. Type who in Matlab to see the variables loaded in. (Typing clear prior to load will erase all prior variables from your workspace.) Listen to the signal y (with echo) by typing soundsc(y). Process the signal y with your echo removal system using the command x = filter(1,a,y). Type help filter to understand how a should be dened for this function call. Listen to the output of the inverse system by typing soundsc(x). In your answer booklet, use Matlab notation to write down the appropriate a. (Hint, you may use zeros(1,n) to create a vector of n 0s. Be careful that in Matlab, the time index for vectors always starts with 1.) Attach plots of y and x. Use the commands subplot(211) and subplot(212) to put both plots on the same page. Use the command axis([0 7000 -7 7]) after each plot so that both plots are on the same scale. Point out on the plots where the signals dier, as a result of the echo removal.

Fourier Series

Fourier series is a representation of periodic signals as a linear combination of harmonically related complex exponentials. A continuous-time periodic function x(t) with period T can be expressed as
+

x(t) =
k=

ak ejk0 t

(4)

where 0 = 2/T and ak = 1 T


0

x(t)ejk0 t dt,

(5)

i.e., a continuous-time periodic function x(t) is decomposed into a sum of complex exponentials with a discrete set of frequencies { , 20 , 0 , 0, 0 , 20 , }. The computation of the continous-time Fourier series coecients involves integration. On a computer, one has to resort to numerical integration to compute ak approximately. This part of the project illustrates how this is done in Matlab. The main idea is to discretize x(t), i.e. sampling x(t) with sampling period Ts T . Let x[n] = x(t)|t=nTs , n = 0, 1, , N 1, where N = T /Ts . Then, the discrete-time signal x[n] represents samples of x(t) over one period T . One way to approximate (5) is to recognize that ak = 1 T
T 0

x(t)ejk0 t dt

1 T

N 1

x[n]ejk0 nTs Ts
n=0

(6)

(Note that dt Ts .) This approximation is valid as long as the integrant x(t)ejk0 t does not change too much within each sampling period Ts . This holds whenever Ts is suciently small and k is not too large (typically the approximation is valid only for k N ).

2.1

Using fft to Compute Fourier Series Coecients

Matlab has a powerful build-in function fft to compute the type of summation in (6). Type help fft. You will see that it computes the following:
N 1

X[k] =
n=0

x[n]ej2kn/N ,

k = 0, 1, , N 1.

(7)

fft stands for Fast Fourier Transform an extremely ecient numerical algorithm for computing the sum above for large N . (Note that the indices start with 0 in (7), but they start with 1 in Matlab.) Part 4: (14 points) 4a. Let X[k] be the fft of x[n], the sampled version of x(t) over one period T . How to obtain the approximate Fourier series coecients ak in (6) from X[k]? Explain. 4b. Dene one period of three periodic square pulses as follows: x1 (t) = 1, 0 t < T 2 0, T t < T 2 x2 (t) = 1, 0 t < T 4 0, T t < T 4 4 x3 (t) = 1, 0 t < T 8 0, T t < T 8 (8)

where the period T = 1ms. In Matlab, construct the corresponding discrete sampled versions x1 [n], x2 [n] and x3 [n] with N = 4096 samples over one period (i.e. Ts = 1ms/4096), and store them in vectors x1, x2, x3. You may nd Matlab functions ones and zeroes useful. For example x=[ones(1,20), zeros(1,10)] produces a vector of 20 1s followed by 10 0s. Use fft to compute the approximate Fourier series coecients ak s for x1 (t), x2 (t) and x3 (t), for k = 0, 1, , 19. Plot both the time-domain signals and the square magnitudes of the Fourier series coecients of x1 (t), x2 (t) and x3 (t) (stored in vectors a1, a2, and a3) on the same page using commands similar to that below. Note that ak is a complex number. The time-axis is dened over one period for xi (t). The frequency axis is re-aligned to start from 0. Attach the plot to your report. >> >> >> >> >> t = (0:1:N-1)*Ts; figure; subplot(321); plot(t,x1); axis([0, 1e-3, -0.2, 1.2]); subplot(322); stem(0:19, abs(a1(1:20)). 2); ...

4c. The Fourier Series of a rectangular pulse should look like sampled version of a sinc() function. The rst time the sinc() function crosses zero is a measure of its width. Let the width of the time-domain rectangular pulse in one period be T0 (in ms). Let the frequency corresponding to the rst zero crossing of the Fourier Series coecients be f0 (in kHz). Can you infer from the plot a relation between T0 and f0 ? 4d. fft only gives ak for k = 0, 1, 2, . How do we obtain a1 , a2 etc., for xi (t) dened above? Explain.
1 4e. Verify Parsevals theorem for x2 (t) by computing T T |x2 (t)|2 dt analytically, and approximately com 2 puting k= |ak | by including only {a19 , a18 , , a1 , a0 , a1 , , a19 } terms. What is the percentage error?

4f. To visualize the Fourier series reconstruction of the rectangular pulse x2 (t), dene
K

(K)

(t) =
k=K

ak ej0 kt

(9)

where 0 = 2/T . On the same page, produce three plots (using subplot(311), etc). Each plot consists of an overlay of x2 (t) and y (K) (t). Plot for K = 5, 20, 100. To overlay two plots (with dierent colors), use hold commend, e.g., >> subplot(311); plot(t,x2,b); hold; plot(t,y,r) You may use a for loop in Matlab to dene y (K) (t). Also, in Matlab, functions can operate on a vector directly. For example, for the vector t dened in 4b, one can use exp(j*k*2*pi/T*t) to apply the exponential function to each element of t. Attach the plot to your report. 4g. Attach the Matlab code for 4b, 4e, and 4f to your report.

2.2

Filtering of Fourier Series

In this part of the lab, we examine what happens to the Fourier series coecients when a periodic signal is passed through a lter. An FIR lter of unknown characteristics is specied in the le filter spec.mat. We use x3 (t) over ve periods as the input signal. The goal is to nd out what type of lter it is. Part 5: (10 points)

5a. Use the following commands to load the lter (named h), construct the input signal, and produce the output due to the ltering of the input signal. >> >> >> >> load filter spec.mat tt = (0:1:5*N-1)*Ts; x input = [x3, x3, x3, x3, x3]; y output = filter(h,1,x input);

Take the output over one period (e.g. y output(4*N:5*N-1)) and compute its Fourier Series coecients. On the same page, produce the following two labelled plots (using subplot(211), etc). The rst plot is the overlay of x input and y output (over ve periods). The second plot is the overlay of the square magnitudes of the Fourier series coecients of one period of x input and y output (for k = 0, 1, ..., 19). Attach the plot to your report. 5b. What kind of lter is h (high-pass, low-pass or band-pass)? Filters are often dened by its 3-dB bandwidth. This is the frequency at which the magnitude square of the output is half of the magnitude square of the input. Based on the Fourier Series coecients computed in the previous part, nd the approximate 3-dB bandwidth of h. Please explain with brief calculations.

You might also like