function [a,b]=dft(n,f)
% n értékének páratlannak kell lennie
close all
m=(n+1)/2;
a=zeros(1,m+1); b=zeros(1,m-1);
h = 2*pi/(n+1); x=[0:h:2*pi*(n/(n+1))]; fx=f(x); w=exp(-i*h);
Xhat=fft(fx);
X=Xhat/(n+1);
a(1)=X(1);
a(m+1)=X(m+1);
for j=2:m
    a(j)=2*real(X(j));
    b(j-1)=-2*imag(X(j));
end;

plot(x,fx,'o')
axis([0,2*pi,0,4])
pause
hold on
xx=[0:1/100:2*pi];

tm=a(1);
for l=1:m-1
   tm=tm+a(l+1)*cos(l*xx)+b(l)*sin(l*xx);
end
tm=tm+a(m+1)*cos(m*xx);

plot(xx,tm)