Electronic – Vanishing of Gibbs Phenomenon in MatLab

digital-communicationsfourierMATLABsignalsignal processing

I was trying to represent a square wave with its Fourier series in Matlab.enter image description here But as I increased the number of terms in Fourier series expression, the Gibbs phenomenon vanished and the edges of the resultant square wave appeared to be curved a little.enter image description here Why does this happen in Matlab when it is impossible in theory?

This is my code:

clc;
close all;

f = 50;      %setting frequency as 50 Hz
t = 0:0.0001:3/f;

fourier = zeros(1,length(t));

for n = 1:1:50
   temp = ((2/(n*pi))*(1-cos(n*pi)))*sin(2*pi*n*f*t); %phase shifted by 'pi/2'
   fourier = temp + fourier;
end

%subplot(3,1,2);
plot(t,fourier);
title('When the number of terms is 200');
grid on;

Best Answer