Sheet 6 Create the directory sheet06 and make it your working directory. Example 1. This example is warm-up to learn to use Matlab’s DFT algorithm and generate plots. a) Plot the absolute value of the DFT yb = {b yk } of f (x) = x + x2 , x ∈ [0, 2π] as follows: n = 2∧5; x = linspace(0,2*pi,n); w = 1:length(x); y = x + x.∧2; yt = fft(y); plot(w,abs(yt),’o’) xlabel(’k’);ylabel(’Modulus of DFT’) Try using n = 26 and 27 . Repeat this for : b) f (x) = x sin(10x)e−x , x ∈ [0, 2π] c) f (x) = cos(10x) sin(10x)e−x , x ∈ [0, 2π] d) f (x) = sin(30x) cos(10x), x ∈ [0, 2π] 0≤x≤π −1 if e) f (x) = 1 if π < x ≤ 2π Example 2. In this example, you are going to plot the modulus of the Discrete Fourier Transform of f (x) = (x−π)2 , x ∈ [0, 2π] along with the n times the modulus of the complex Fourier coefficients to see how they relate to one another. Proceed as follows. First enter the function and give the desired n clear f = @ (x) (x-pi).∧2; n = 2∧3; Find the complex Fourier coefficients βk : syms x k; b k = int(f(x)*exp(-i*k.*x),x,0,2*pi)/(2*pi) Remember to execute these lines, then copy and paste the output from the command window in the following line: kth coef = @ (k) paste here Now compute the coefficients: for m = 1:n-1 b(m) = int(f(x),x,0,2*pi)/(2*pi); end b 0 = kth coef(0); List all the coefficients (the double converts to decimal form) coeffs = double([b 0,b(1:n-1)]); Find the DFT x = linspace(0,2*pi,n); y = f(x); yt = fft(y); Finally, plot the coefficients and the DFT on the same graph: w = 1:length(x); plot(w,abs(yt),’o’,w,n*abs(coeffs),’r’,’linewidth’,2) xlabel(’k’); ylabel(’Modulus of DFT and n times Complex Fourier Coefficient’) legend(’n|DFT|’,’|Fourier Coefficient|’) Sometimes it is useful to zoom in on what is going on near the x−axis. Remember you do this with an axis statement, for example in this case, axis([0 n 0 10]) would be suitable. Try different values of n, say 24 and 25 . Aside: Recall if βk is the complex Fourier coefficient and yb = {b yk } is the DFT, then we have the approximation ybk ≈ nβk for k small compared to n. You should see how this is working as you change the value of n. Example 3. Repeat for the following (I suggest you save each separately: ex3a.m, ex3b.m, etc.). Again, vary n to see how the approximation changes and make appropriate axis statements to zoom in on the action near the x−axis, if necessary. a) f (x) = x + x2 , x ∈ [0, 2π] b) f (x) = xe−x sin(10x), x ∈ [0, 2π] Note that when we are plotting |βk | as a function of k = 1, . . . , n, any peak in the plot at some value k = k0 corresponds to a large frequency component for the frequency ω = k0 . Because of the sine that appears in f (x), wiggles in the plot of f will occur with an approximate frequency of ω = 10. So you should see a large frequency component in the DFT plot at k = 10. Do you? c) f (x) = cos(10x) sin(10.2x), x ∈ [0, 2π] In this example there should be two peaks corresponding to ω = 0, 20 in the first half of the plot of the DFT. d) f (x) = e−3x sin(30x) cos(10x), x ∈ [0, 2π] There should be two peaks in the first half of the DFT. What are the corresponding values of the frequency ω ? e) f (x) = −1 1 if 0≤x≤π if π < x ≤ 2π Hint: On this one, you will need to modify the method a bit. In the lines defining b k and b 0, enter the integral in two pieces corresponding to [0, π] and [π, 2π] and enter the corresponding value of f in place of f (x). Sheet 6: Further Exercises f) f (x) = π 2 − x2 if 0≤x≤π −π 2 + (x − π)2 if π < x ≤ 2π