Signals and Images (AC51024) - Lab 3 Convolution: Exercise 1: Polynomials & Convolution in M
Signals and Images (AC51024) - Lab 3 Convolution: Exercise 1: Polynomials & Convolution in M
Exercise 1: Polynomials & Convolution in M ATLAB Search for Polynomials in the M ATLAB help to learn how to represent polynomials in M ATLAB . 1. Enter following polynomials P1 = 5x5 + 3x3 + 2x2 + 2x + 1 P2 = 4x3 2 2. Calculate following polynomials using M ATLAB functions (poly, roots, conv,...) P3 = P1 + P2 P4 = P1 P2
2 P5 = P1
3. Calculate the roots of P1 and P2 . 4. Create a polynomial P6 with roots 1,2,...,10. 5. Plot the polynomials P1 , . . . , P6 into one axis. Exercise 2: Signals & Convolution in M ATLAB 1. Create a discrete signal y (t) with (M ATLAB notation is used!): t=[1:1:80] y(10:1:70) are exactly 3 periods of a sine function with amplitude 1. y(1:1:9)=0 and y(71:1:80)=0 1 if t = 15 2. Create a discrete negative delta function (t) with 29 data points. I.e. (t) = 0 else 3. Calculate the convolution z (t) = y (t) ( (t)). Plot all three functions in one gure but separate axes. (subplot). Stem plots is often used to visualise discrete signals. Try it! (stem) 4. What is the convolution with ? (If you dont see it, create another function y (t) = y (t) + 0.05 t and do the convolution with and plot the results.) The results should look like this:
1 0.5 0
0 0.2 0.4
1 0.5 0
10 20 signal 2
30
20
40 60 80 Convolution of 1 and 2
100
5. You learned in the lecture that the function is the identity for convolution. Try it! Create a function and convolve with y (Create the vector as above, just with (15) = 1). Does it work? What goes wrong? How can we repair it? Remember this lesson for further work with convolution in M ATLAB ! 6. Convolution can change signals in a way to resemble mathematical operations like differentiation and integration. For discrete differentiation, the signal is g (t) = (t) (t 1), i.e. 1 if t = 0 g (t) = 1 if t = 1 . Since M ATLAB doesnt allow non-positive indices, create the signal as 0 else g=zeros(1,10);
1
g(3)=1; g(4)=-1; The signal should look like the graph on the right. Convolve y (t) g (t) and plot the result. Do you get the expected result? Remember part 5!
0 if t < 0 7. For discrete integration (running sum) the step function h(t) = is used. Cre1 if t 0 ate a M ATLAB vector of length 10 as above, with h(1:2)=0 and h(3:10)=1. Convolve y (t) h(t) and plot the result. Do you get the expected result?
8. Convolution can be used to lter data. A typical low-pass lter kernel is the windowed sinc - function. Download the le sinc.txt from the web page and import it into the M ATLAB vector v . Plot the kernel, v . It should look like the image on the right. When convolved with an input signal, this lter passes sinusoids that have fewer than 25 cycles in 500 samples, and blocks sinusoids with a higher frequency. Create the following signal x: t = 0:499;
0.1
0.08
0.06
0.04
0.02
0.02
10
20
30
40
50
60
70
80
90
100
x = sin(t/500*30*2*pi)+0.5*sin(t/500*11*2*pi); and convolve it with v . 9. The corresponding high-pass lter kernel u can be derived by subtracting v from the function. Convolve with x from the last part. Do you get the expected result? Can you see why you usually shouldnt use the rst M 1 data points if you convolve with a kernel of length M ? Exercise 3: Central limit theorem 1. The vector y=[1 1] represents the polynomial 1+ x in M ATLAB . What are the coefcients of (1 + x)2 , (1 + x)3 , . . . , (1 + x)10 ? What are the coefcients of (1 + x)100 ? Plot them (assuming the M ATLAB representation of polynomials)! What do you get? 2. Use the following outline to write a program in M ATLAB which convolves a random vector with itself 100 times and shows the result as an animation. Create a random vector y of length 10. Convolve y with y once plot the result pause 0.1 seconds Convolve y with y and then the result with y plot the result pause 0.1 seconds Convolve y with y and then the result with y and again the result with y plot the result pause 0.1 seconds ...... (Do this 100 times) (Hint(s): Use pause to start the animation after a key is pressed. If you keep the result from the previous iteration you just have to convolve this result with y !) 3. Do you get the expected result?