### 2.22.2 Discrete Fourier Transform

Let N be an integer. The Discrete Fourier Transform (DFT) is a transformation FN defined on the set of periodic sequences of period N, it depends on a choice of a primitive N-th root of unity ωN. If the DFT is defined on sequences with complex coefficients, we take:

ωN=e

2 i π
N

If x is a periodic sequence of period N, defined by the vector x=[x0,x1,...xN−1] then FN(x)=y is a periodic sequence of period N, defined by:

(FN,ωN(x))k=yk=

N−1
∑
j=0

xjωN−k· j, k=0..N−1

where ωN is a primitive N-th root of unity. The discrete Fourier transform may be computed faster than by computing each yk individually, by the Fast Fourier Transform (FFT). `Xcas` implements the FFT algorithm to compute the discrete Fourier transform only if N is a power of 2.

#### The properties of the Discrete Fourier Transform

The Discrete Fourier Transform FN is a bijective transformation on periodic sequences such that

FN,ωN−1

=

1
N

FN,ωN−1

=

1
N

FN

on ℂ

i.e. :

(FN−1(x))k=

1
N

N−1
∑
j=0

xjωNk· j

Inside `Xcas` the discrete Fourier transform and it’s inverse are denote by `fft` and `ifft`:

`fft(x)`= FN(x), `ifft(x)`= FN−1(x)

Definitions
Let x and y be two periodic sequences of period N.

- The Hadamard product (notation ·) is defined by:

  (x · y)k = xk yk

- the convolution product (notation *) is defined by:

  (x * y)k=

  N−1
  ∑
  j=0

  xjyk−j

Properties :

N*FN(x · y) | = | FN(x) * FN(y)
FN(x * y) | = | FN(x) · FN(y)

#### Applications

1. Value of a polynomial
   Define a polynomial P(x)=∑j=0N−1cjxj by the vector of its coefficients c:=[c0,c1,..cN−1], where zeroes may be added so that N is a power of 2.
   - Compute the values of P(x) at

     x=ak=ωN−k=exp(

     −2ikπ
     N

     ), k=0..N−1

     This is just the discrete Fourier transform of c since

     P(ak)=

     N−1
     ∑
     j=0

     cj(ωN−k)j=FN(c)k

     Input, for example :
     `P(x):=x+x```^```2; w:=i`
     Here the coefficients of P are [0,1,1,0], N=4 and ω=exp(2iπ/4)=i.
     Input :
     `fft([0,1,1,0])`
     Output :
     `[2,-1-i,0,-1+i]`
     hence
     - `P(0)=2`,
     - `P(-i)=P(w```^```-1)=-1-i`,
     - `P(-1)=P(w```^```-2)=0`,
     - `P(i)=P(w```^```-3)=-1+i`.
   - Compute the values of P(x) at

     x=bk=ωNk=exp(

     2ikπ
     N

     ), k=0..N−1

     This is N times the inverse fourier transform of c since

     P(ak)=

     N−1
     ∑
     j=0

     cj(ωNk)j=NFN−1(c)k

     Input, for example :
     `P(x):=x+x```^```2` and `w:=i`
     Hence, the coefficients of P are [0,1,1,0], N=4 and ω=exp(2iπ/4)=i.
     Input :
     `4*ifft([0,1,1,0])`
     Output :
     `[2,-1+i,0,-1-i]`
     hence :
     - `P(0)=2`,
     - `P(i)=P(w```^```1)=-1+i`,
     - `P(-1)=P(w```^```2)=0`,
     - `P(-i)=P(w```^```3)=-1-i`.
     We find of course the same values as above...
2. Trigonometric interpolation
   Let f be periodic function of period 2π, assume that f(2kπ/N)=fk for k=0..(N−1). Find a trigonometric polynomial p that interpolates f at xk=2kπ/N, that is find pj, j=0..N−1 such that

   p(x)=

   N−1
   ∑
   j=0

   pj exp(ijx), p(xk)=fk

   Replacing xk by it’s value in p(x) we get:

   N−1
   ∑
   j=0

   pj exp(i

   j2kπ
   N

   ) = fk

   In other words, (fk) is the inverse DFT of (pk), hence

   (pk)=

   1
   N

   FN( (fk) )

   If the function f is real, p−k=pk, hence depending whether N is even or odd:

   p(x)

   =

   p0+ 2 ℜ(

   N
   2

   −1

   ∑
   k=0

   pkexp(ikx))+ℜ(p

   N
   2

   exp(i

   Nx
   2

   ))

   p(x)

   =

   p0+ 2 ℜ(

   N−1
   2

   ∑
   k=0

   pkexp(ikx))

3. Fourier series
   Let f be a periodic function of period 2π, such that

   f(xk)=yk, xk=

   2kπ
   N

   , k=0..N−1

   Suppose that the Fourier serie of f converges to f (this will be the case if for example f is continuous). If N is large, a good approximation of f will be given by:

   ∑

   −

   N
   2

   ≤ n<

   N
   2

   cn exp(inx)

   Hence we want a numeric approximation of

   cn=

   1
   2π

   ∫

   2π
   0

   f(t)exp(−int)dt

   The numeric value of the integral ∫02πf(t)exp(−int)dt may be computed by the trapezoidal rule (note that the Romberg algorithm would not work here, because the Euler Mac Laurin developpement has it’s coefficients equal to zero, since the integrated function is periodic, hence all it’s derivatives have the same value at 0 and at 2π). If c_n is the numeric value of cn obtained by the trapezoidal rule, then

   c_n=

   1
   2π

   2π
   N

   N−1
   ∑
   k=0

   ykexp(−2i

   nkπ
   N

   ), −

   N
   2

   ≤ n<

   N
   2

   Indeed, since xk=2kπ/N and f(xk)=yk:

   f(xk)exp(−inxk)

   =

   ykexp(−2i

   nkπ
   N

   ),

   f(0)exp(0)=f(2π)exp(−2i

   nNπ
   N

   )

   =

   y0=yN

   Hence :

   [c0,..c

   N
   2

   −1

   ,c

   −N
   2

   ,..c−1]=

   1
   N

   FN([y0,y1...y(N−1)])

   since
   - if n≥0, cn=yn
   - if n<0 cn=yn+N
   - ωN=exp(2iπ/N), then ωNn=ωNn+N

   Properties

   - The coefficients of the trigonometric polynomial that interpolates f at x=2kπ/N are

     pn=cn, −

     N
     2

     ≤ n<

     N
     2

   - If f is a trigonometric polynomial P of degree m≤ N/2, then

     f(t)=P(t)=

     m−1
     ∑
     k=−m

     ckexp(2ikπ t)

     the trigonometric polynomial that interpolate f=P is P, the numeric approximation of the coefficients are in fact exact (cn=cn).
   - More generally, we can compute cn−cn.
     Suppose that f is equal to it’s Fourier serie, i.e. that :

     f(t)=

     +∞
     ∑
     m=−∞

     cmexp(2iπ mt),

     +∞
     ∑
     m=−∞

     |cm|<∞

     Then :

     f(xk)=f(

     2kπ
     N

     )=yk=

     +∞
     ∑
     m=−∞

     cmωNkm, c_n=

     1
     N

     N−1
     ∑
     k=0

     ykωN−kn

     Replace yk by it’s value in c_n:

     c_n=

     1
     N

     N−1
     ∑
     k=0

     +∞
     ∑
     m=−∞

     cmωNkmωN−kn

     If m≠ n (mod N ), ωNm−n is a N-th root of unity different from 1, hence:

     ωN(m−n)N=1,

     N−1
     ∑
     k=0

     ωN(m−n)k=0

     Therefore, if m−n is a multiple of N (m=n+l· N) then ∑k=0N−1ωNk(m−n)=N, otherwise ∑k=0N−1ωNk(m−n)=0. By reversing the two sums, we get

     c_n

     =

     1
     N

     +∞
     ∑
     m=−∞

     cm

     N−1
     ∑
     k=0

     ωNk(m−n)

     =

     +∞
     ∑
     l=−∞

     c(n+l· N)

     | = | ...cn−2· N+cn−N+cn+cn+N+cn+2· N+.....

     Conclusion: if |n|<N/2, c_n−cn is a sum of cj of large indices (at least N/2 in absolute value), hence is small (depending on the rate of convergence of the Fourier series).

   Example, input

   `f(t):=cos(t)+cos(2*t)`
   `x:=f(2*k*pi/8)$(k=0..7)`

   Output :

   `x={2,(√``2``)/2,-1,-((√``2``)/2),0,-((√``2``)/2),-1,(√``2``)/2}`
   `fft(x)=[0.0,4.0,4.0,0.0,0.0,0.0,4.0,4.0]`

   After a division by N=8, we get

   c0=0,c1=4.0/8,c2=4.0/2,c3=0.0,
   c−4=0,c−3=0,c−2=4.0/8,=c−1=4.0/8

   Hence bk=0 and ak=c−k+ck is equal to 1 if k=1,2 and 0 otherwise.

4. Convolution Product
   If P(x)=∑j=0n−1ajxj and Q(x)=∑j=0m−1bjxj are given by the vector of their coefficients a=[a0,a1,..an−1] and b=[b0,b1,..bm−1], we may compute the product of these two polynomials using the DFT. The product of polynomials is the convolution product of the periodic sequence of their coefficients if the period is greater or equal to (n+m). Therefore we complete a (resp b) with m+p (resp n+p) zeros, where p is choosen such that N=n+m+p is a power of 2. If a=[a0,a1,..an−1,0..0] and b=[b0,b1,..bm−1,0..0], then:

   P(x)Q(x)=

   n+m−1
   ∑
   j=0

   (a*b)jxj

   We compute FN(a), FN(b), then ab=FN−1(FN(a)· FN(b)) using the properties

   NFN(x · y)=FN(x) * FN(y), FN(x * y)=FN(x) · FN(y)