Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let x(t)have complex Fourier series representation x(t) = sigma^infinity_k=-infi

ID: 2080656 • Letter: L

Question

Let x(t)have complex Fourier series representation x(t) = sigma^infinity_k=-infinity c_k e^. Then the truncated exponential Fourier series for x(t)is given by x_N(t) = sigma^N_k=-N c_k e^. Using MATLAB, plot the truncated Fourier Series for waveform number 1 (the square wave) of Table 4.3 in your textbook, for N=3, 10, and 30. To make your plots, assume that amplitude X_0 = 1, and period T_0 = 1 seconds, and plot the waveforms for 0 lessthanorequalto t lessthanorequalto 2 seconds. Using t = (0:0.01:2) as the plot variable should give sufficient resolution, but you can also try a step size of 0.001. Comment on how well your plots approximate the actual square wave x(t). Where are the significant approximation errors? Are there any unusual "phenomena"? Repeat part 1 for the triangular wave (waveform number 3) in Table 4.3. Assume the same values for X_0, T_0, and the plotting range as in part 1. Is this waveform better or worse approximated than the square wave, for a given value of N? Turn in your plots, and your MATLAB code. (If you prefer not to use MATLAB "m" command files, you can use the MATLAB "diary" command to save a record of your MATLAB commands, and then turn in the diary file.)

Explanation / Answer

clear all; close all; % maximum depth of Fourier coefficients Nmax = 100; xn = 201; % this is the exact function xex = [0 0 1.5 1 2 2.5 3 3.5 4]; fex = [0 0.5 0.5 2 1 1.5 0.5 1 0]; c = zeros(Nmax,1); a = zeros(Nmax,1); b = zeros(Nmax,1); fapp = zeros(xn,Nmax+1); xapp = linspace(0,4,xn)'; fapp(:,1) = 7/8*ones(xn,1); for n=1:Nmax % compute the real and imaginary Fourier coefficents c(n) = -i*(3*(-i)^n+(-1)^n+i^n+1)/(4*pi*n) - (1-(-i)^n)/(pi^2*n^2); a(n) = real(2*c(n)); b(n) = -imag(2*c(n)); % compute the according approximation fapp(:,n+1) = fapp(:,n) + c(n)*exp(i*pi/2*n*xapp) + conj(c(n))*exp(-i*pi/2*n*xapp); %fapp(:,n+1) = fapp(:,n) + a(n)*cos(pi/2*n*xapp) + b(n)*sin(pi/2*n*xapp); end % which approximations should be displayed? nvec = [1 2 3 4 5 7 10 20 50 100]; leg = cell(1,3); leg{1} = 'exact'; % Plot for n=1:length(nvec) hold off; % Plot the exact solution plot(xex,fex,'k-','LineWidth',2); hold on; set(gca,'FontSize',20); xlim([0 4]); ylim([0 2]); % Plot the approximate solution plot(xapp,fapp(:,nvec(n)),'r-','LineWidth',3); ss = strcat('n=',int2str(nvec(n))); leg{2} = ss; if n>1 %plot the former solution also plot(xapp,fapp(:,nvec(n-1)),'r:','LineWidth',2); ss = strcat('n=',int2str(nvec(n-1))); leg{3} = ss; legend(leg); else legend(leg(1:2)); end pause; % uncomment these lines if the pictures should be printed %ss = strcat('print -depsc2 baum',int2str(n),'.eps'); %eval(ss); %ss = strcat('print -djpeg95 baum',int2str(n),'.jpg'); %eval(ss); end