Suppose we have some sort of  function f(x)  in an interval     -L/2 < x < L/2  i.e.  the function has period L  then we can always express 

f(x) = (∑_(n=-∞)^(n=∞))   (Subscript[A, n ]) (e^(i  2π n (x/L)))

(Subscript[A, n ])=   (1/L)   (∫_(-L/2)^(L/2)) (e^(-i  2π n (x/L)))f(x) dx

(* Example 1: *) 

(* Let L = 2 π *)

Clear[x];
L=2Pi;
f1[x_]:=x

Plot[f1[x],{x,-L/2,L/2} ]

a[n_]:=1/L  NIntegrate[Exp[- I 2 π n x/L] f1[x],{x,-L/2,L/2}]

max=20;
atable=Table[Chop[a[n]],{n,-max,max}];

fouriersum[x_]:=Sum[atable[[i]] Exp[ 2I π (i-max-1) x/L],{i,1,2max+1}]

Plot[Chop[fouriersum[x]],{x,-L/2,L/2}]

power=Table[{n,Abs[atable[[n+max+1]]]^2},{n,-max,max}]

ListPlot[power,PlotStyle->{Red,PointSize[Large]},PlotRange->All]

Discrete Fourier Transform

In the examples given above we considered the function f(x) for any arbitrary value of x in the region
-L/2 < x < L/2. If we take L ⟶ ∞ then the sums become integral, the Fourier integral

f(t) =  (∫_(-∞)^∞)  h(ω)  (e^(-i  2π  ω t)) dω

h(ω) = (∫_(-∞)^∞)  f (t) (e^( i  2π  ω   t )) dt

h(ω) is called the Fourier transform of f(t). Suppose we sample the f(t) at a finite set of points
given by the relation  (Subscript[t, n]) = (n Δ)  so that f((Subscript[t, n])) ≡ (Subscript[f, n])  where n = 0,1,...N-1

Then the second integral can be written as a sum

h(ω)  ≈   (∑_(k=0)^(N-1)) Δ  f((Subscript[t, k]))  (e^(i  2π ω k Δ))    =   Δ (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[f, k])  (e^( i  2π  ω k Δ)) 

Now let ω be discretized as  (Subscript[ω, n]) =  (n/(N Δ))    n=  -N/2 ... -2, -1, 0, 1,2, ... N/2   or  

h((Subscript[ω, n]))  =   Δ (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[f, k])  (e^( i  2π  ((n  k )/N)))  

The quantity 

 (Subscript[h, n])   ≡ (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[f, k])  (e^( i  2π  ((n  k )/N)))    is called the discrete Fourier transform (DFT) of the list of numbers (Subscript[f, k])
 
 note that we also get that
 
 (Subscript[f, k]) = (1/N)  (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[h, n])  (e^( -i  2π  ((n  k )/N)))  which is called the discrete inverse Fourier transform of (Subscript[h, n])

If we re-scale (Subscript[f, k]) -> (Subscript[f, k])/(Sqrt[N])   we obtain a somewhat more symmetric form

(Subscript[h, n])   ≡    (1/(Sqrt[N])) (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[f, k])  (e^( i  2π  ((n  k )/N)))
 (Subscript[f, k]) = (1/(Sqrt[N]))  (Underoverscript[ ∑, (k=0), (k=N-1)])  (Subscript[h, n])  (e^( -i  2π  ((n  k )/N)))