Here is a matlab function i wrote to plot a Fourier series of different orders that I wrote for homework a while ago. It does not find the Fourier series but once you know the series representation you can enter it into the 6th and 8th lines and it plots the 3,6, and 20th orders. The 6th line is for the first term in the series.
x=[-pi:2*pi/100:pi];
y=zeros(20,101);
for i=1:20
for j =1:101
if i ==1
y(i,j) = pi/4 - 2/pi * cos (x(j)) + sin (x(j));
else
y(i,j)= y(i-1,j)-2/pi*cos((2*i-1)*x(j))/(2*i-1)^2
+(-1)^(i+1)/i * sin (i*x(j));
end
end
end
plot(x,y(20,:),x,y(3,:),x,y(6,:))
set(gca, 'XTick', -pi:pi/2:pi);
set(gca, 'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'});
xlabel('-\pi \leq \Theta \leq \pi');
If you have any questions feel free to email me.