Convolution and Fourier Series

September 24, 2017 | Author: Virn Maneqk | Category: Electronic Filter, Fast Fourier Transform, Fourier Transform, Applied Mathematics, Algorithms
Share Embed Donate


Short Description

Download Convolution and Fourier Series...

Description

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/final 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 filtering 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 Office. The penalty is zero on the assignment/test. In addition, double the value of the assignment/test is removed from the final grade. Therefore, a student caught cheating on a test worth 25% will get no more than 25% on their final grade (0 on the test, and 50% removed from the final grade). The incident is also noted on their transcript for 5 years, which means that getting their first job will be a challenge. A second offence will result in forced leave for one year. Officially, all penalties are determined by the Dean, but he accepts the department’s 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 floor 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.

1

1

Convolution

In class, you’ve learned that the convolution of two signals x[n] and h[n] is defined as x[n] ∗ h[n] =

+∞ X

x[k]h[n − k]

(1)

k=−∞

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 finite-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 find: (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 defining 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]? Briefly 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 infinite-length impulse response h[n] to an infinite-length input x[n]. Naturally, Matlab can only keep track of finite-length vectors. Part 2: (8 points) 2a. If h[n] and x[n] are non-zero on the finite 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: µ ¶n−2 1 x[n] = u[n − 2], 2 h[n] = −δ[n + 1] + 2δ[n − 2]. 2

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.b(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, reflections off walls in conference rooms that are picked up by speaker phones or off mismatched switching equipment in telephone lines. The effect 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 reflection. 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 difference 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 file 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 defined 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 0’s. 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 differ, as a result of the echo removal.

3

2

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

x(t) =

ak ejkω0 t

(4)

x(t)e−jkω0 t dt,

(5)

k=−∞

where ω0 = 2π/T and ak =

1 T

Z

T

0

i.e., a continuous-time periodic function x(t) is decomposed into a sum of complex exponentials with a discrete set of frequencies {· · · , −2ω0 , −ω0 , 0, ω0 , 2ω0 , · · · }. The computation of the continous-time Fourier series coefficients 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 1 ak = T

Z

T

x(t)e−jkω0 t dt ≈

0

N −1 1 X x[n]e−jkω0 nTs Ts T n=0

(6)

(Note that dt ≈ Ts .) This approximation is valid as long as the integrant x(t)e−jkω0 t does not change too much within each sampling period Ts . This holds whenever Ts is sufficiently small and k is not too large (typically the approximation is valid only for k ¿ N ).

2.1

Using fft to Compute Fourier Series Coefficients

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: X[k] =

N −1 X

x[n]e−j2πkn/N ,

k = 0, 1, · · · , N − 1.

(7)

n=0

fft stands for “Fast Fourier Transform” — an extremely efficient 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 coefficients ak in (6) from X[k]? Explain. 4b. Define one period of three periodic square pulses as follows: ½ ½ 1, 0 ≤ t < T2 1, 0 ≤ t < T4 x1 (t) = x2 (t) = T 0, 2 ≤ t < T 0, T4 ≤ t < T 4

½ x3 (t) =

1, 0 ≤ t < T8 0, T8 ≤ t < T

(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 find Matlab functions ones and zeroes useful. For example x=[ones(1,20), zeros(1,10)] produces a vector of 20 1’s followed by 10 0’s. Use fft to compute the approximate Fourier series coefficients 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 coefficients 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 defined 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)).b2); ...

4c. The Fourier Series of a rectangular pulse should look like sampled version of a sinc() function. The first 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 first zero crossing of the Fourier Series coefficients 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 a−1 , a−2 etc., for xi (t) defined above? Explain. R 4e. Verify Parseval’s theorem for x2 (t) by computing T1 T |x2 (t)|2 dt analytically, and approximately comP∞ puting k=−∞ |ak |2 by including only {a−19 , a−18 , · · · , a−1 , a0 , a1 , · · · , a19 } terms. What is the percentage error? 4f. To visualize the Fourier series reconstruction of the rectangular pulse x2 (t), define y

(K)

(t) =

K X

ak ejω0 kt

(9)

k=−K

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 different 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 define y (K) (t). Also, in Matlab, functions can operate on a vector directly. For example, for the vector t defined 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 coefficients when a periodic signal is passed through a filter. An FIR filter of unknown characteristics is specified in the file filter spec.mat. We use x3 (t) over five periods as the input signal. The goal is to find out what type of filter it is. Part 5: (10 points)

5

5a. Use the following commands to load the filter (named h), construct the input signal, and produce the output due to the filtering 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 coefficients. On the same page, produce the following two labelled plots (using subplot(211), etc). The first plot is the overlay of x input and y output (over five periods). The second plot is the overlay of the square magnitudes of the Fourier series coefficients of one period of x input and y output (for k = 0, 1, ..., 19). Attach the plot to your report. 5b. What kind of filter is h (high-pass, low-pass or band-pass)? Filters are often defined 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 coefficients computed in the previous part, find the approximate 3-dB bandwidth of h. Please explain with brief calculations.

6

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF