Problem Set 8 - Solution

Similar documents
18.085: Summer 2016 Due: 3 August 2016 (in class) Problem Set 8

1. Calculation of the DFT

18.085, PROBLEM SET 8 SOLUTIONS

LAB 2: DTFT, DFT, and DFT Spectral Analysis Summer 2011

Computer Problems for Fourier Series and Transforms

The Discrete Fourier Transform

Introduction to the FFT

Fourier analysis of discrete-time signals. (Lathi Chapt. 10 and these slides)

5.6 Convolution and FFT

MAT 343 Laboratory 6 The SVD decomposition and Image Compression

Ch 7 Summary - POLYNOMIAL FUNCTIONS

Fourier Series. (Com S 477/577 Notes) Yan-Bin Jia. Nov 29, 2016

Algorithm Design and Analysis

(Refer Slide Time: 01:30)

Discrete Fourier Transform (DFT) & Fast Fourier Transform (FFT) Lab 9

What is Image Deblurring?

23. The Finite Fourier Transform and the Fast Fourier Transform Algorithm

Linear Algebra, Summer 2011, pt. 2

Transforms and Orthogonal Bases

Numerical Analysis. Carmen Arévalo Lund University Arévalo FMN011

Neural Networks 2. 2 Receptive fields and dealing with image inputs

Lecture 6: Discrete Fourier Transform

Section 3.1 Quadratic Functions

Design and Analysis of Algorithms

CS168: The Modern Algorithmic Toolbox Lecture #11: The Fourier Transform and Convolution

Horizontal and Vertical Asymptotes from section 2.6

Learning goals: students learn to use the SVD to find good approximations to matrices and to compute the pseudoinverse.

8/19/16. Fourier Analysis. Fourier analysis: the dial tone phone. Fourier analysis: the dial tone phone

L6: Short-time Fourier analysis and synthesis

Definition. A signal is a sequence of numbers. sequence is also referred to as being in l 1 (Z), or just in l 1. A sequence {x(n)} satisfying

Math 56 Homework 5 Michael Downs

Contents. Signals as functions (1D, 2D)

Wavelets. Lecture 28

Math 365 Homework 5 Due April 6, 2018 Grady Wright

Fast Fourier Transform

12.1 Fourier Transform of Discretely Sampled Data

Contents. Signals as functions (1D, 2D)

Power Series Solutions We use power series to solve second order differential equations

MA3232 Summary 5. d y1 dy1. MATLAB has a number of built-in functions for solving stiff systems of ODEs. There are ode15s, ode23s, ode23t, ode23tb.

! Circular Convolution. " Linear convolution with circular convolution. ! Discrete Fourier Transform. " Linear convolution through circular

Lecture 3: Linear Filters

L. Vandenberghe EE133A (Spring 2017) 3. Matrices. notation and terminology. matrix operations. linear and affine functions.

56 CHAPTER 3. POLYNOMIAL FUNCTIONS

E2.5 Signals & Linear Systems. Tutorial Sheet 1 Introduction to Signals & Systems (Lectures 1 & 2)

VU Signal and Image Processing. Torsten Möller + Hrvoje Bogunović + Raphael Sahann

Robert Collins CSE586, PSU Intro to Sampling Methods

Lecture 3: Linear Filters

1. Use the properties of exponents to simplify the following expression, writing your answer with only positive exponents.

2D Discrete Fourier Transform (DFT)

Multiplying huge integers using Fourier transforms

Fast Polynomial Multiplication

Dividing Polynomials: Remainder and Factor Theorems

CS711008Z Algorithm Design and Analysis

Modified Fourier Spectral Method for Non-periodic CFD

d 1 µ 2 Θ = 0. (4.1) consider first the case of m = 0 where there is no azimuthal dependence on the angle φ.

Contents. Signals as functions (1D, 2D)

MARN 5898 Fourier Analysis.

Polynomial Degree Leading Coefficient. Sign of Leading Coefficient

Digital Image Processing. Filtering in the Frequency Domain

1.4 Techniques of Integration

Simplifying Rational Expressions and Functions

Scientific Computing: An Introductory Survey

Chapter 6: Fast Fourier Transform and Applications

Numerical Methods I Orthogonal Polynomials

Name: INSERT YOUR NAME HERE. Due to dropbox by 6pm PDT, Wednesday, December 14, 2011

LECTURE NOTES IN AUDIO ANALYSIS: PITCH ESTIMATION FOR DUMMIES

1. Use the properties of exponents to simplify the following expression, writing your answer with only positive exponents.

2 Two-Point Boundary Value Problems

Information and Communications Security: Encryption and Information Hiding

Signal Processing COS 323

EDISP (NWL2) (English) Digital Signal Processing Transform, FT, DFT. March 11, 2015

PHYS 391 Fourier Transform Primer Eric Torrence with modifications by Dean Livelybrooks, March 2014

Fourier Transform Chapter 10 Sampling and Series

MTH301 Calculus II Glossary For Final Term Exam Preparation

AP Calculus Chapter 9: Infinite Series

18.310A Final exam practice questions

EE482: Digital Signal Processing Applications

Centre for Mathematical Sciences HT 2017 Mathematical Statistics

MITOCW MITRES_6-007S11lec09_300k.mp4

Projections and Least Square Solutions. Recall that given an inner product space V with subspace W and orthogonal basis for

Ross Program 2017 Application Problems

Technische Universität Kaiserslautern WS 2016/17 Fachbereich Mathematik Prof. Dr. J. Franke 19. January 2017

MATH 167: APPLIED LINEAR ALGEBRA Chapter 3

The Growth of Functions. A Practical Introduction with as Little Theory as possible

Linear Cyclic Codes. Polynomial Word 1 + x + x x 4 + x 5 + x x + x

Rational Functions. Elementary Functions. Algebra with mixed fractions. Algebra with mixed fractions

CMU CS 462/662 (INTRO TO COMPUTER GRAPHICS) HOMEWORK 0.0 MATH REVIEW/PREVIEW LINEAR ALGEBRA

1 1.27z z 2. 1 z H 2

MATH 220 solution to homework 4

Fourier Transform 4: z-transform (part 2) & Introduction to 2D Fourier Analysis

MITOCW watch?v=rf5sefhttwo

MTH5112 Linear Algebra I MTH5212 Applied Linear Algebra (2017/2018)

EE123 Digital Signal Processing

FFT: Fast Polynomial Multiplications

COMS 4721: Machine Learning for Data Science Lecture 19, 4/6/2017

256 Summary. D n f(x j ) = f j+n f j n 2n x. j n=1. α m n = 2( 1) n (m!) 2 (m n)!(m + n)!. PPW = 2π k x 2 N + 1. i=0?d i,j. N/2} N + 1-dim.

Compression. Reality Check 11 on page 527 explores implementation of the MDCT into a simple, working algorithm to compress audio.

Singular Value Decompsition

Lab 4: Introduction to Signal Processing: Fourier Transform

Introduction to Fourier Analysis Part 2. CS 510 Lecture #7 January 31, 2018

Transcription:

Problem Set 8 - Solution Jonasz Słomka Unless otherwise specified, you may use MATLAB to assist with computations. provide a print-out of the code used and its output with your assignment. Please 1. More on relation between Fourier series and Discrete Fourier Transform (DFT). Let f(x) be a periodic function of period 2π. We can express it as a Fourier series f(x) = k= c k e ikx. (1) Suppose we want to approximate f(x) by keeping only the first n lowest frequency amplitudes f(x) n k= n c k e ikx. (2) The number of terms on the rhs is N = 2n + 1. Let s sample f(x) at points x j = 2π j j = n,..., 0,... n, (3) N that are uniformly distributed over the interval ( π, π), and include the origin. If we denote the corresponding vector of samples by f j = f(x j ), then, at point x j, the approximation (2) gives f j = n k= n c k ω kj, (4) where ω = e i 2π N. Similarly, we can approximate the exact expression for the Fourier coefficient c k by the finite sum c k = 1 π f(x)e ikx dx 1 2π π 2π Since x = 2π, this is N n f j ω kj x, k = n,..., 0,... n. (5) j= n c k = 1 N n f j ω kj. (6) j= n We can see that Eq. (6) looks almost like the DFT and Eq. (4) is almost the inverse DFT. What is different is that the zero frequency mode is in the middle, rather than on the left. We need two steps to exactly recover the usual DFT. 18.085 PSET8 - Solution Page 1 of 12

First, note that f j and c k are labelled from n to n while in the definition of DFT we have labels from 0 to N. Let s relabel: fk = f k n and c k = c k n. If we also change the summation to run from 0 to N, we get f j = N 1 k=0 c k ω (k n)(j n), c k = 1 N N 1 j=0 f j ω (k n)(j n). (7) We shift the above expressions by n f j+n = N 1 k=0 c k ω (k n)j, c k+n = 1 N N 1 j=0 f j ω k(j n). (8) A small rearrangement gives ω nj fj+n = N 1 k=0 c k ω kj, ω kn c k+n = 1 N N 1 j=0 f j ω kj. (9) If you remember that, for DFT and its inverse, factor like ω kn in front of c k+n comes from the shift of f j by n, f j f j n, then you realize that the above formulae are exactly inverse DFT and DFT, respectively, just with input and output shifted. MATLAB has built in commands to perform these shifts for you. All you need is fftshift() and ifftshift() on top of the usual fft() (DFT) and ifft() (inverse DFT). The transforms are f = fftshift(ifft(ifftshift(n c))), (10) c = fftshift(fft(ifftshift(f/n))). (a) In Problem set 6 you showed that the periodic function f(x) defined by f(x) = x on ( π, π) has Fourier series given by f(x) = 2 k=1 ( 1) k sin(kt). (11) k Convert f(x) into the complex form f = k= c ke ikx (find c k ). Since sin(kt) = eikt e ikt, we get 2i c 0 = 0, (12) c k = i ( 1)k, k > 0, k c k = c k, k < 0. (b) Sample f(x) at the grid points defined by Eq. (3). Do so for N = 2n+1 equal to 3 3, 3 5 and 3 7. Convert the samples to the coefficients using c = fftshift(fft(ifftshift(f/n))). Plot the difference between these coefficients and the coefficients of the Fourier 18.085 PSET8 - Solution Page 2 of 12

series from (a). Use log-log scale. Comment on the behaviour of the difference for the three values of N. Answer Evaluating c = fftshift(fft(ifftshift(f/n))) is like approximating the integrals c k = 1 π 2π π f(x)e inx dx. The higher the discretization size, the better the approximation. (c) In Problem set 7 you showed that the periodic function g(x) defined by g(x) = x on ( π, π) has Fourier series given by Repeat (a) and (b) for g(x). g(x) = π 2 4 π n=1,3,5, Since cos(kt) = eikt +e ikt 2, we get 1 cos(nx). (13) n2 c 0 = π 2, (14) c k = 2 1 π k, k > 0, k odd, 2 c k = c k, k < 0, k odd. 18.085 PSET8 - Solution Page 3 of 12

18.085 PSET8 - Solution Page 4 of 12

2. (Simplified) JPEG compression. Download the following two pictures of the MIT dome (MITdome.jpg and MITdome2.jpg) from the course webpage. You will perform image compression using the two-dimensional variants of the Discrete Cosine Transform (DCT) and the Discrete Sine Transform (DST). (a) In MATLAB, load the first file MITdome.jpg, convert it to the grayscale and display it, using RGB = imread( MITdome.jpg ); (15) I = double(rgb2gray(rgb)); figure, imshow(i, [0255]) (b) Apply the DCT to compute the frequency spectrum of the grayscale image. Display, on the log scale, the normalized magnitude of the coefficients. Use J = dct2(i); (16) figure, imshow(log10(abs(j)/max(abs(j(:)))), []), colormap(jet), colorbar 18.085 PSET8 - Solution Page 5 of 12

(c) Perform the compression J Jcompressed by keeping only the largest amplitudes that contain 99.9% of the image energy. This should be very similar to the Speech Signal Compression Example we did in class, the difference is that now the signal is a matrix, rather than a vector. To convert a matrix into a vector by, stacking its columns on top of each other, simply put vecj = J(:). To reshape the vector vecj back into a matrix, use reshape(vecj, m, n), where m, n are the dimensions of the matrix [m, n] = size(j). The image energy is defined as a sum over the squares of the Fourier amplitudes. In MATLAB, this is EnergyJ = norm(j(:)) 2. Calculate the percentage of nonzero amplitudes left after the compression. After the compression, there is 34.0469% nonzero amplitudes left. (d) Once you compressed the image in the frequency domain, go back to the physical domain by inverting the DCT and display the image Icompressed = idct2(jcompressed); (17) figure, imshow(icompressed, [0255]) (18) 18.085 PSET8 - Solution Page 6 of 12

(e) Show the (10 times) magnified difference between the original and the compressed images figure, imshow(10 abs(i Icompressed), [0255]) (19) Where is the discrepancy the largest? In other words, which features of the original image are badly captured after the compression? Sharp edges suffer most from the compression. This is a direct manifestation of the Gibbs phenomenon in practice. (f) Repeat the above analysis for two other compression thresholds: keep 99% and 98% of the image energy. In each case, record the percentage of nonzero amplitudes left after the compression. Let s do the 99% threshold first. I needed only 5.5781% of the amplitudes. 18.085 PSET8 - Solution Page 7 of 12

Now comes the 98% threshold. I needed as little as 1.5432% of the amplitudes and the resolution is still not that bad. (g) Repeat the analysis by using DST rather than DCT, still for the same image, MITdome.jpg. There is no dst2() command in MATLAB. You will have to use the one-dimensional version dst() twice, first on columns, then on rows. This is done by Similarly, to apply the (2D) inverse of DST use J2 = dst(dst(i). ). ; (20) J2 = idst(idst(i). ). ; (21) Again, for the three thresholds, record the percentage of nonzero amplitudes left after the compression. How does it compare with the DCT case? Using DST I got for the three thresholds: 34.2086%, 5.7904% and 1.7463% nonzero amplitudes. This is only marginally worse than using DCT. 18.085 PSET8 - Solution Page 8 of 12

(h) Now repeat the analysis (for both DCT and DST) with the other image, MITdome2.jpg. Which of the two (DCT or DST) gives a more efficient compression? Can you explain why? For MITdome2.jpg, the amplitudes look like (DCT left, DST right): DCT DST 99.9% 22.3860% 23.2773% 99% 0.7434% 1.6629% 98% 0.0929% 0.4534% For the high resolution (99.9%) there is still little difference. As we decrease the desired resolution, we see that DCT beats DST by a factor of two in the 99% case, and by a factor of five in the 98% case. This is because DST is wasting energy on resolving the boundaries. Odd flipping inherent in the definition of DST creates sharp jumps if the four edges of the picture are significantly different (from zero). This is the case for MITdome2.jpg and not so much for MITdome.jpg where the two trees around the dome make the picture almost periodic in the horizontal direction. For the 99% case let s compare the DCT and DST. DCT: 18.085 PSET8 - Solution Page 9 of 12

DST: It is now clear that DST does badly not only at the contours of the tree and the dome (same as DCT), but also around the four edges of the picture itself. 3. Fast multiplication through convolution. (a) Given two vectors a and b with components a i and b i, respectively, the discrete convolution of a and b is a third vector a b with components (a b) n = a i b j. (22) i+j=n The sum on the rhs goes over all pairs of indices i and j such that i + j = n. If a has n a components, and b has n b components, show that a b has n a + n b 1 components. Think about sliding the vector b against a and the resulting overlap. Sliding the right end of (flipped) b against a gives n a overlaps. Sliding the left end 18.085 PSET8 - Solution Page 10 of 12

against a takes the length of b minus one step (after n b steps a and b are already stacked back-to-back so no overlap), so in total we have n a + n b 1 overlaps. (b) Consider two polynomials p(x) = a 0 + a 1 x + a 2 x 2, q(x) = b 0 + b 1 x + b 2 x 2 + b 3 x 3. (23) Find the polynomial r(x) = p(x)q(x). Show that the coefficients c n of r(x) are the discrete convolution of the coefficients a i and b i. Multiply out the two polynomials and collect terms of the same power p(x)q(x) = (a 0 + a 1 x + a 2 x 2 )(b 0 + b 1 x + b 2 x 2 + b 3 x 3 ) (24) = a 0 b 0 + (a 0 b 1 + a 1 b 0 )x + (a 0 b 2 + a 1 b 1 + a 2 b 0 )x 2 +(a 0 b 3 + a 1 b 2 + a 2 b 1 )x 3 + (a 1 b 3 + a 2 b 2 )x 4 + a 2 b 3 x 5. On the other hand, let s convolve a = [a 0, a 1, a 2 ] with b = [b 0, b 1, b 2, b 3 ]. From (a), we know that a b has 6 entries. From the definition of convolution, we get (a b) 0 = a i b j = a 0 b 0, (25) i+j=0 (a b) 1 = i+j=1 (a b) 2 = i+j=2 (a b) 3 = i+j=3 (a b) 4 = i+j=4 (a b) 5 = i+j=5 a i b j = a 0 b 1 + a 1 b 0, a i b j = a 0 b 2 + a 1 b 1 + a 2 b 0, a i b j = a 0 b 3 + a 1 b 2 + a 2 b 1, a i b j = a 1 b 3 + a 2 b 2, a i b j = a 2 b 3. (c) From part (b) it should be intuitively clear that, in the general case p(x) = P a i x i, q(x) = i=0 Q b j x i, (26) j=0 the coefficients of the polynomial r(x) = p(x)q(x) are given by a b. In other words, multiplying two polynomials means convolving their coefficients. We have seen in class that fft() can be used to cyclically convolve two vectors. Two avoid the cyclic property, we must add enough zeros at the end of a and b (zero-padding) so that their length is at least (P + 1) + (Q + 1) 1 = P + Q + 1. Denote the extended vectors by ã and b. Then the the following single line in MATLAB produces a b ifft(fft(~a). fft(~b)). (27) 18.085 PSET8 - Solution Page 11 of 12

Now suppose you want to multiply two really big numbers, one with 100 and the other with 400 digits. If you want to use Long Multiplication (as in elementary school), you would need about 100 400 = 40000 operations. Explain how you can use the above polynomial multiplication-convolution relation and fft() to reduce this number. With fft(), how many operations do you roughly need? Any number with a finite number of digits in the decimal representation can be thought of as an evaluation of the polynomial p(x) = a 0 +a 1 x +a 2 x 2 +..., where a i are the digits of the representation at x = 10. For example, to the number 5031, we associate the polynomial p(x) = 1 + 3x + 5x 3. (28) Then, of course, 5031 = p(10). Thus, to multiply two large numbers, with the number of digits, say n a and n b, we can form the two corresponding polynomials (of order n a 1 and n b 1, respectively). Instead of multiplying the polynomials directly, we can use the zero padding technique and the formula (27). In total, after zero padding, we have three FFTs (of size N = n a + n b 1) and one multiplication (of size N). The number of operations is roughly (FFT has complexity n log n) 3N log N + N 3N log N. (29) This is much slower growth than n a n b required when doing the Long Multiplication. For n a = 400 and n b = 100, the number of operations is around 9000. 18.085 PSET8 - Solution Page 12 of 12