% This script animates the Gibbs Phenomenon for a square wave % using the first 31 nonzero terms of the Fourier series. The cosine terms % are zero due to the function being an odd function. The even trrms are % zero because of the halfwave symmetry. The delay between % frames can be reset by adjusting the arguement of the pause in line 38. % This m-file was written at the University of Wyoming in the Electrical % and Computer Engineering Department and is to be distributed without % cost. clc disp(' ') disp(' ') disp('This script displays the pariial sum of the Fourier') disp('series associated with a square wave. It is easy to observe') disp('the Gibbs Phenomenon on either side of the discontinuities') disp('and that the height of the "ears" is independent of the number') disp('of terms in the partial sum while the width decreases with the') disp('number of terms.') disp(' ') disp(' Press Enter to Continue') pause clear all set(0,'DefaultAxesFontSize',12); set(0,'DefaultTextFontSize',12); f=[];b=[]; x=linspace(0,3*pi,901); sum=zeros(1,901); for i=1:2:61 b=4/(i*pi); sum=sum+b*sin(i*x); f=[f;sum]; end text1='Press Enter to Continue'; figure(1);clf; y=[0 ones(1,299) 0 -ones(1,299) 0 ones(1,299) 0]; axis([0 3*pi -1.5 2]); hold on plot(x,y,'r') hold on P=plot(x,f(1,:),'EraseMode','xor'); box on T2=text(5,1.8,['n = ' num2str(1)]); T=text(.5,1.8,text1); xlabel('Dimensionless Time, \omega_0t'); ylabel('Signal, f(t)') pause set(T,'String',' '); for i=2:31 set(P,'Ydata',f(i,:)); set(T2,'String',['n = ' num2str(2*i-1)]); pause(.5) end