Salta al contenuto
Note per Studenti DFT and Roots of Unity Report

DFT and Roots of Unity

In questa pagina 4

Polynomials - Representations and ConvolutionA polynomial with degree bound n is represented by n coefficients or by n values at n distinct points (interpolation theorem, Vandermonde matrix). By coefficients the sum costs n and the product, the linear convolution, n^2 products and (n-1)^2 sums; by values the product costs only componentwise multiplication but needs at least 2n-1 points. General conversions cost too much: evaluation n times with Horner 2n(n-1), interpolation with Gauss-Jordan n^3 or Lagrange n^2. A special base is needed: the DFT.Polynomials - Representations and Convolution → showed that multiplying polynomials in o(n2)o(n^2) requires a base of evaluation points where conversions are cheap. Here the base is chosen: the nn-th roots of unity. We define the DFT, prove the properties that make it fast, and the theorem linking it to linear convolution. The fast algorithm is in Fast Fourier TransformThe FFT computes the DFT_n (n a power of two) by divide and conquer: split the coefficients by index parity, p(x) = p0(x^2) + x p1(x^2), and by the halving lemma two DFTs of order n/2 suffice; y_i = y0_i + w^i y1_i and y_{i+n/2} = y0_i - w^i y1_i. The recurrence T(n) = 2T(n/2) + 2n with T(1) = 0 has exact solution 2 n log2 n. The inverse has matrix F^{-1}_{ij} = w^{-ij}/n and is obtained with the FFT on negative powers (then dividing by n outside the recursion) or with a reversed DFT_n(y). LIN_CONV multiplies two polynomials with n coefficients in 12 n log2(2n) + 4n operations.Fast Fourier Transform →.

The signal-processing view differs: there the DFT is the Fourier series of a periodic signal with a minus sign in the exponent. Here it is the evaluation of a polynomial at special points, with the plus sign: ωn=e+2πi/n\omega_n=e^{+2\pi i/n}. The two conventions differ by an index permutation (below); numpy.fft.fft uses the minus sign.

Complex numbers in polar form

z=a+ib≠0z=a+ib\ne0 has modulus ρ=a2+b2\rho=\sqrt{a^2+b^2} and argument θ\theta: z=ρeiθz=\rho e^{i\theta} (Euler), so zn=ρneinθz^n=\rho^ne^{in\theta}. nn-th roots: if zkn=ρeiθz_k^n=\rho e^{i\theta} then ρk=ρ1/n\rho_k=\rho^{1/n} and nθk=θ+2πkn\theta_k=\theta+2\pi k; the nn distinct roots are zk=ρ1/ne i(θn+2πkn),0≤k≤n−1.z_k=\rho^{1/n}e^{\,i\left(\frac\theta n+\frac{2\pi k}n\right)},\quad0\le k\le n-1. For z=1z=1: the roots of unity e2πik/ne^{2\pi ik/n}.

Definition. The principal nn-th root of unity is ωn=e2πi/n\omega_n=e^{2\pi i/n}. The nn-th roots of unity are ωn0,…,ωnn−1\omega_n^0,\dots,\omega_n^{n-1}, forming Ωn=(ωn0,…,ωnn−1)\Omega_n=(\omega_n^0,\dots,\omega_n^{n-1}). Since ωnn=1\omega_n^n=1, ωnk=ωnk mod n\omega_n^k=\omega_n^{k\bmod n} for all k∈Zk\in\mathbb Z.

Example (n=8n=8). ω8=eiπ/4=1+i2\omega_8=e^{i\pi/4}=\frac{1+i}{\sqrt2}; the powers are the vertices of a regular octagon on the unit circle:

kk 0 1 2 3 4 5 6 7
ω8k\omega_8^k 11 1+i2\frac{1+i}{\sqrt2} ii −1+i2\frac{-1+i}{\sqrt2} −1-1 −1−i2\frac{-1-i}{\sqrt2} −i-i 1−i2\frac{1-i}{\sqrt2}

n=4n=4: ω4=i\omega_4=i, Ω4=(1,i,−1,−i)\Omega_4=(1,i,-1,-i). n=2n=2: Ω2=(1,−1)\Omega_2=(1,-1).

The DFT and the Fourier matrix

Definition (DFT). DFTn:Cn→Cn\mathrm{DFT}_n:\mathbb C^n\to\mathbb C^n maps the coefficients a\mathbf a of pp to its values at the nn-th roots of unity: yi=p(ωni)=∑j=0n−1aj ωnij,0≤i≤n−1.y_i=p(\omega_n^i)=\sum_{j=0}^{n-1}a_j\,\omega_n^{ij},\qquad0\le i\le n-1. (Ωn,y)(\Omega_n,\mathbf y) is a representation by values (distinct points, interpolation theorem applies).

DFTn(a)=Fna\mathrm{DFT}_n(\mathbf a)=F_n\mathbf a with the Fourier matrix Fn=V(Ωn)F_n=V(\Omega_n), [Fn]ij=ωnij[F_n]_{ij}=\omega_n^{ij}. First row and column are all ones; FnF_n is symmetric and invertible (Vandermonde on distinct points), so the inverse DFT is the interpolation from Ωn\Omega_n.

Example (n=4n=4). F4=(11111i−1−i1−11−11−i−1i)F_4=\begin{pmatrix}1&1&1&1\\1&i&-1&-i\\1&-1&1&-1\\1&-i&-1&i\end{pmatrix}. For p=3+4x+5x2+6x3≡(3,4,5,6)p=3+4x+5x^2+6x^3\equiv(3,4,5,6): y0=18y_0=18, y1=3+4i−5−6i=−2−2iy_1=3+4i-5-6i=-2-2i, y2=3−4+5−6=−2y_2=3-4+5-6=-2, y3=−2+2iy_3=-2+2i. So DFT4(3,4,5,6)=(18,−2−2i,−2,−2+2i)\mathrm{DFT}_4(3,4,5,6)=(18,-2-2i,-2,-2+2i).

Cost with general evaluation: nn Horner runs, 2n(n−1)=Θ(n2)2n(n-1)=\Theta(n^2).

Signal convention. With ωˉn=ωn−1\bar\omega_n=\omega_n^{-1} the "signal DFT" is Xk=∑jxjωˉnjkX_k=\sum_jx_j\bar\omega_n^{jk}; as ωn−k=ωn(n−k) mod n\omega_n^{-k}=\omega_n^{(n-k)\bmod n}, the two vectors differ by the permutation k↦(n−k) mod nk\mapsto(n-k)\bmod n (index 00 fixed, the others reversed). It reappears in the inverse transform.

Properties of the roots of unity

Group. Ωn\Omega_n is a multiplicative group: closure ωniωnj=ωn(i+j) mod n\omega_n^i\omega_n^j=\omega_n^{(i+j)\bmod n}; identity 1=ωn01=\omega_n^0; inverse of ωni\omega_n^i is ωn−i\omega_n^{-i}, i.e. ωnn−i\omega_n^{n-i} for 1≤i≤n−11\le i\le n-1.

Cancellation lemma. For positive integers n,dn,d and k∈Zk\in\mathbb Z: ωdndk=ωnk\omega_{dn}^{dk}=\omega_n^k.

Proof. (e2πi/(dn))dk=e2πik/n\bigl(e^{2\pi i/(dn)}\bigr)^{dk}=e^{2\pi ik/n}. □\square

Corollary. For even nn, ωnn/2=ω2=eiπ=−1\omega_n^{n/2}=\omega_2=e^{i\pi}=-1 (half a turn); hence ωnk+n/2=−ωnk\omega_n^{k+n/2}=-\omega_n^k.

Halving lemma. For even nn and 0≤i≤n2−10\le i\le\frac n2-1: (ωni)2=(ωni+n/2)2=ωn/2i(\omega_n^i)^2=(\omega_n^{i+n/2})^2=\omega_{n/2}^i. Squaring the nn roots of order nn yields the n/2n/2 roots of order n/2n/2, each twice.

Proof. (ωni)2=ωn2i=ωn/2i(\omega_n^i)^2=\omega_n^{2i}=\omega_{n/2}^i by cancellation; (ωni+n/2)2=ωn2iωnn=ωn/2i(\omega_n^{i+n/2})^2=\omega_n^{2i}\omega_n^n=\omega_{n/2}^i. □\square

Example (n=8n=8): the squares are 1,i,−1,−i,1,i,−1,−i1,i,-1,-i,1,i,-1,-i.

Summation lemma. For n>1n>1, k≥0k\ge0: ∑j=0n−1(ωnk)j={nk multiple of n0otherwise.\sum_{j=0}^{n-1}\bigl(\omega_n^k\bigr)^j=\begin{cases}n&k\text{ multiple of }n\\0&\text{otherwise.}\end{cases}

Proof. If n∣kn\mid k, ωnk=1\omega_n^k=1 and the sum is nn. Otherwise ωnk≠1\omega_n^k\ne1 and the geometric sum is (ωnk)n−1ωnk−1=(ωnn)k−1ωnk−1=0\frac{(\omega_n^k)^n-1}{\omega_n^k-1}=\frac{(\omega_n^n)^k-1}{\omega_n^k-1}=0. □\square

Example: n=4n=4: k=1k=1: 1+i−1−i=01+i-1-i=0; k=4k=4: 44; k=2k=2: 1−1+1−1=01-1+1-1=0.

All results hold with ωˉn=ωn−1\bar\omega_n=\omega_n^{-1} in place of ωn\omega_n (same roots, different order): needed for the inverse transform.

Example (ω16120\omega_{16}^{120}). 120 mod 16=8120\bmod16=8, so ω16120=ω168=ω2=−1\omega_{16}^{120}=\omega_{16}^8=\omega_2=-1; or by repeated cancellation ω860=ω430=ω215=(−1)15=−1\omega_8^{60}=\omega_4^{30}=\omega_2^{15}=(-1)^{15}=-1: Re=−1\mathrm{Re}=-1, Im=0\mathrm{Im}=0.

The linear convolution theorem

Theorem. For a,b∈Cn\mathbf a,\mathbf b\in\mathbb C^n and c=a⋆b∈C2n−1\mathbf c=\mathbf a\star\mathbf b\in\mathbb C^{2n-1}: (c ∣ 0)=DFT2n−1(DFT2n((a∣0n))⊙DFT2n((b∣0n))),(\mathbf c\,|\,0)=\mathrm{DFT}^{-1}_{2n}\Bigl(\mathrm{DFT}_{2n}\bigl((\mathbf a|\mathbf 0_n)\bigr)\odot\mathrm{DFT}_{2n}\bigl((\mathbf b|\mathbf 0_n)\bigr)\Bigr), with ∣| concatenation (zero padding) and ⊙\odot the componentwise product.

Proof. Let p≡ap\equiv\mathbf a, q≡bq\equiv\mathbf b, c=pqc=pq. Padding leaves the polynomials unchanged but raises the bound to 2n2n. The two DFTs of order 2n2n are the values p(ω2ni)p(\omega_{2n}^i), q(ω2ni)q(\omega_{2n}^i); their componentwise product is c(ω2ni)c(\omega_{2n}^i), the values of cc on Ω2n\Omega_{2n}. Since deg⁡c≤2n−2<2n\deg c\le2n-2<2n, 2n2n points determine it, its coefficient vector with bound 2n2n is (c∣0)(\mathbf c|0), and the inverse DFT returns it by uniqueness of interpolation. □\square

Order 2n2n (not 2n−12n-1) because the fast algorithm works on powers of two.

Example (n=2n=2). a=(1,2)\mathbf a=(1,2), b=(3,4)\mathbf b=(3,4), order 44: DFT(1,2,0,0)=(3,1+2i,−1,1−2i)(1,2,0,0)=(3,1+2i,-1,1-2i), DFT(3,4,0,0)=(7,3+4i,−1,3−4i)(3,4,0,0)=(7,3+4i,-1,3-4i), product (21,−5+10i,1,−5−10i)(21,-5+10i,1,-5-10i), which are the values of 3+10x+8x23+10x+8x^2 at 1,i,−1,−i1,i,-1,-i. So c=(3,10,8)\mathbf c=(3,10,8).

With general evaluations this costs Θ(n2)\Theta(n^2); with the FFT, Θ(nlog⁡n)\Theta(n\log n). The same link explains why circulant matrices are diagonalized by FnF_n (Supercirculant and Circulant MatricesSupercirculant matrices (alternating recursive quadrants) have only n distinct values: sum in n operations, product in 4n log2 n + n with the trick (A1+A2)(B1+B2) and (A1-A2)(B1-B2) instead of 4 calls (Theta(n^2)); their eigenvalues are the Hadamard transform of the first row (FHT, n log2 n). Circulant matrices are polynomials in the rotation matrix R, their product is the cyclic convolution of the first rows, and the Fourier matrix diagonalizes them: product in O(n log n) with the FFT.Supercirculant and Circulant Matrices →).

Versione ripasso

  • Roots: ωn=e2πi/n\omega_n=e^{2\pi i/n}; roots ωn0,…,ωnn−1\omega_n^0,\dots,\omega_n^{n-1} (vertices of a regular nn-gon on the unit circle), ωnk=ωnk mod n\omega_n^k=\omega_n^{k\bmod n}. nn-th roots of z=ρeiθz=\rho e^{i\theta}: ρ1/nei(θ/n+2πk/n)\rho^{1/n}e^{i(\theta/n+2\pi k/n)}. Ω4=(1,i,−1,−i)\Omega_4=(1,i,-1,-i), ω8=1+i2\omega_8=\frac{1+i}{\sqrt2}.
  • DFT: yi=p(ωni)=∑jajωnijy_i=p(\omega_n^i)=\sum_ja_j\omega_n^{ij}, DFTn(a)=Fna\mathrm{DFT}_n(\mathbf a)=F_n\mathbf a, [Fn]ij=ωnij[F_n]_{ij}=\omega_n^{ij} (symmetric invertible Vandermonde, first row and column of ones). General evaluation costs 2n(n−1)2n(n-1).
  • Example: DFT4(3,4,5,6)=(18,−2−2i,−2,−2+2i)\mathrm{DFT}_4(3,4,5,6)=(18,-2-2i,-2,-2+2i), F4F_4 with rows (1,1,1,1)(1,1,1,1), (1,i,−1,−i)(1,i,-1,-i), (1,−1,1,−1)(1,-1,1,-1), (1,−i,−1,i)(1,-i,-1,i).
  • Conventions: with the minus sign of signal courses (and numpy) the result differs by the permutation k↦(n−k) mod nk\mapsto(n-k)\bmod n.
  • Group: ωiωj=ω(i+j) mod n\omega^i\omega^j=\omega^{(i+j)\bmod n}, identity 11, inverse ωn−i=ωnn−i\omega_n^{-i}=\omega_n^{n-i}.
  • Cancellation: ωdndk=ωnk\omega_{dn}^{dk}=\omega_n^k. Corollary: ωnn/2=ω2=−1\omega_n^{n/2}=\omega_2=-1, so ωnk+n/2=−ωnk\omega_n^{k+n/2}=-\omega_n^k.
  • Halving (nn even): (ωni)2=(ωni+n/2)2=ωn/2i(\omega_n^i)^2=(\omega_n^{i+n/2})^2=\omega_{n/2}^i: the squares are the n/2n/2 roots of order n/2n/2, each twice. Proof: cancellation and ωnn=1\omega_n^n=1. n=8n=8: 1,i,−1,−i,1,i,−1,−i1,i,-1,-i,1,i,-1,-i.
  • Summation: ∑j=0n−1(ωnk)j=n\sum_{j=0}^{n-1}(\omega_n^k)^j=n if n∣kn\mid k, else 00 (ratio 11; otherwise geometric sum (ωnk)n−1ωnk−1=0\frac{(\omega_n^k)^n-1}{\omega_n^k-1}=0). Also with ωˉn=ωn−1\bar\omega_n=\omega_n^{-1}. n=4n=4, k=1k=1: 1+i−1−i=01+i-1-i=0.
  • Example: ω16120=ω168=ω2=−1\omega_{16}^{120}=\omega_{16}^{8}=\omega_2=-1 (or ω860=ω430=ω215=−1\omega_8^{60}=\omega_4^{30}=\omega_2^{15}=-1).
  • Linear convolution: (c∣0)=DFT2n−1(DFT2n(a∣0n)⊙DFT2n(b∣0n))(\mathbf c|0)=\mathrm{DFT}_{2n}^{-1}(\mathrm{DFT}_{2n}(\mathbf a|\mathbf 0_n)\odot\mathrm{DFT}_{2n}(\mathbf b|\mathbf 0_n)). Proof: the product of the values is the values of c=pqc=pq on Ω2n\Omega_{2n}; deg⁡c≤2n−2<2n\deg c\le2n-2<2n determines it; interpolation is unique. Order 2n2n (not 2n−12n-1) for a power of two.
  • Example: (1,2)⋆(3,4)(1,2)\star(3,4) at order 44: (3,1+2i,−1,1−2i)⊙(7,3+4i,−1,3−4i)=(21,−5+10i,1,−5−10i)(3,1+2i,-1,1-2i)\odot(7,3+4i,-1,3-4i)=(21,-5+10i,1,-5-10i), values of 3+10x+8x23+10x+8x^2 at 1,i,−1,−i1,i,-1,-i; result (3,10,8)(3,10,8). With the FFT it costs Θ(nlog⁡n)\Theta(n\log n); the same link diagonalizes circulant matrices (Supercirculant and Circulant MatricesSupercirculant matrices (alternating recursive quadrants) have only n distinct values: sum in n operations, product in 4n log2 n + n with the trick (A1+A2)(B1+B2) and (A1-A2)(B1-B2) instead of 4 calls (Theta(n^2)); their eigenvalues are the Hadamard transform of the first row (FHT, n log2 n). Circulant matrices are polynomials in the rotation matrix R, their product is the cyclic convolution of the first rows, and the Fourier matrix diagonalizes them: product in O(n log n) with the FFT.Supercirculant and Circulant Matrices →).
  • Quick checks: ∑j=07(ω83)j=0\sum_{j=0}^{7}(\omega_8^3)^j=0 (33 not a multiple of 88); ∑j=07(ω816)j=8\sum_{j=0}^{7}(\omega_8^{16})^j=8.
  • Common mistakes: order nn instead of 2n2n in the theorem; forgetting ωnn/2=−1\omega_n^{n/2}=-1; reducing the exponent modulo the wrong order (after a cancellation the order changes); using the summation lemma with k=0k=0 as if it gave 00.

Teoria collegata