function [a0,A,B] = fourier(fun,n)
%fun je 2pi periodicna funkcija

A=zeros(1,n);
B=zeros(1,n);

a0 = 1/(2*pi)*quad(fun,-pi,pi);
% ili
% a0=quad(fun,-pi,pi)/quad(@(x)x.^0,-pi,pi);

for i=1:n
    A(i) = 1/pi*quad(@Af,-pi,pi,[],[],fun,i);
    B(i) = 1/pi*quad(@Bf,-pi,pi,[],[],fun,i);
    
    %ili
    % A(i) = quad(@Af,-pi,pi,[],[],fun,i)/quad(@(x)cos(i*x).*cos(i*x),-pi,pi)
    % B(i) = quad(@Bf,-pi,pi,[],[],fun,i)/quad(@(x)sin(i*x).*sin(i*x),-pi,pi)
end

function y = Af(x,f,i)
y=feval(f,x).*cos(i*x);

function y = Bf(x,f,i)
y=feval(f,x).*sin(i*x);