File:Square wave summation animation.gif

Summary

Description
English: The animation shows the square wave being constructed. The blue curve is the summation of the previous frequencies while the red curve is the frequency that is currently added.

freq = 1/(2*pi); x = 0:0.01:2*pi; figure(1) filename = 'image.gif'; flag_first = 1 map = @(x) -2*x.^3+3*x.^2 % maps [0,1] to [0,1] for n = 1:8

   s = @(x,k) bsxfun(@rdivide,sin(bsxfun(@times,2*pi*(2*k-1)*freq,x)),(2*k-1));
   f = @(x,t) 4/pi * (sum(s(x,[1:n-1]'),1) + t*sin(2*pi*(2*n-1)*x*freq)/(2*n-1));
   for t = map(linspace(0,1,18-n))
       clf
       hold on
       plot(x,f(x,t))
       plot(x,t*4/pi*sin(2*pi*(2*n-1)*x*freq)/(2*n-1),'r-')
       axis([0,2*pi,-1.5,1.5]);
       text(-0.2,1.5,['f = ',num2str(2*n-1)])
       set(gcf,'color',[1 1 1]);
       axis off
       hold off
       drawnow
       frame = getframe(1);
       im = frame2im(frame);
       [imind,cm] = rgb2ind(im,256);
       if flag_first == 1;
           imwrite(imind,cm,filename,'gif', 'Loopcount',inf, 'DelayTime',0.1);
           flag_first = 0;
       else
           imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.1);
       end
   end
end
Date
Source Own work
Author Feudiable

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-3.0#Square%20wave%20summation%20animation.gif
Category:Self-published work Category:Fourier series animations Category:Gibbs phenomenon Category:Signal processing Category:Animated GIF files Category:Order 15
Category:Animated GIF files Category:CC-BY-SA-3.0 Category:Fourier series animations Category:Gibbs phenomenon Category:Order 15 Category:Self-published work Category:Signal processing