function [a_vec,b_vec]=fourier_step(N)
	%% Fourier series for step function of t
	% N - how many member in the sum

	T=2*pi; % period
	t=linspace(-pi,pi, 1001);
	w0=2*pi/T; % fundamental frequency

	y=t.*0; % all zeros
	y(t>0)=1;

	function ret=a_n(n)
		if( n == 0)
			ret=1;
		else
			ret=0;
		end
	end

	function ret=b_n(n)
		if ( mod(n,2) == 0) 
			%n is even
			ret=0;
		else
			ret=2/pi/n;
		end
	end


	yf=a_n(0)/2;
	a_vec=zeros(1,N);
	b_vec=zeros(1,N);
	for n=1:N
		a_vec(n)=a_n(n);
		b_vec(n)=b_n(n);
		yf=yf+ a_n(n)*cos(n*w0*t)+b_n(n)*sin(n*w0*t);;
	end
	fh1=figure(1);
	plot( t, y ,  'r-', 'LineWidth',2); hold on;
	plot( t, yf,  'b-', 'LineWidth',2); hold off; 
	xlabel('t', 'FontSize',24);
	ylabel('y', 'FontSize',24);
	str=sprintf('Fourier series with %d terms', N);
	title(str, 'FontSize',24);
	legend('y(t)=|t|', 'Fourier series');
	
end



