Gibbs phenomenon is the oscillatory behavior observed when a square wave is reconstructed from a finite number of harmonics.
The unit cell of the square wave is given by

Its Fourier series representation is

A Matlab function for summing a finite number (-M to M) of terms is
function y = gibbs(x,M,duty) % GIBBS % % Finite Fourier Series evaluation of square wave % % y = Gibbs(x,M,duty) % % where x are the values to evaluate (0<x<0.5) % M is the number of terms to use % duty is the duty cycle (0-1) % if (nargin<3) duty = 0.5; end p = (-M:M); for (j=1:length(x)) y(j) = sum(duty*sinc(duty*p).*exp(-i*2*pi*p*abs(x(j)))); end
The reconstruction covers the full range of the unit cell
s = linspace(-0.5,0.5,200); plot(s,gibbs(s,M));


The reconstruction is expanded over the domain -3/M to 3/M about the edge
s = linspace(-3,3,200); plot(s,gibbs(s/M+0.25,M));



As M increases, the amplitude of the oscillations does not go to zero. Instead, the oscillations compress in location toward the edge.
Maintained by John Loomis, last updated 30 Aug 2003