You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.3 KiB

  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{amsfonts}
  4. \usepackage{amsthm}
  5. \usepackage{amsmath}
  6. \usepackage{amssymb}
  7. \usepackage{enumerate}
  8. \usepackage{hyperref}
  9. \hypersetup{
  10. colorlinks,
  11. citecolor=black,
  12. filecolor=black,
  13. linkcolor=black,
  14. urlcolor=blue
  15. }
  16. \theoremstyle{definition}
  17. \newtheorem{definition}{Def}[section]
  18. \newtheorem{theorem}[definition]{Thm}
  19. \newtheorem{innersolution}{}
  20. \newenvironment{solution}[1]
  21. {\renewcommand\theinnersolution{#1}\innersolution}
  22. {\endinnersolution}
  23. \title{FFT: Fast Fourier Transform}
  24. \author{arnaucube}
  25. \date{August 2022}
  26. \begin{document}
  27. \maketitle
  28. \begin{abstract}
  29. Usually while reading papers and books I take handwritten notes, this document contains some of them re-written to $LaTeX$.
  30. The notes are not complete, don't include all the steps neither all the proofs. I use these notes to revisit the concepts after some time of reading the topic.
  31. This document are notes done while reading about the topic from \cite{gstrang}, \cite{tpornin}, \cite{rfateman}.
  32. \end{abstract}
  33. \tableofcontents
  34. \section{Discrete \& Fast Fourier Transform}
  35. \subsection{Discrete Fourier Transform (DFT)}
  36. Continuous:
  37. $$
  38. x(f) = \int_{-\infty}^{\infty} x(t) e^{-2 \pi f t} dt
  39. $$
  40. Discrete:
  41. The $k^{th}$ frequency, evaluating at $n$ of $N$ samples.
  42. $$
  43. \hat{f_k} = \sum_{n=0}^{n-1} f_n e^{\frac{-j \pi kn}{N}}
  44. $$
  45. where we can group under $b_n = \frac{\pi kn}{N}$. The previous expression can be expanded into:
  46. $$
  47. x_k = x_0 e^{-b_0 j} + x_1 e^{-b_1 j} + ... + x_n e^{-b_n j}
  48. $$
  49. By the \emph{Euler's formula} we have $e^{jx} = cos(x) + j\cdot sin(x)$, and using it in the previous $x_k$, we obtain
  50. $$
  51. x_k = x_0 [cos(-b_0) + j \cdot sin(-b_0)] + \ldots
  52. $$
  53. Using $\hat{f_k}$ we obtained
  54. $$
  55. \{f_0, f_1, \ldots, f_N\} \xrightarrow{DFT} \{ \hat{f_0}, \hat{f_1}, \ldots, \hat{f_N} \}
  56. $$
  57. To reverse the $\hat{f_k}$ back to $f_k$:
  58. $$
  59. f_k = \left( \sum_{n=0}^{n-1} \hat{f_n} e^{\frac{-j \pi kn}{N}} \right) \cdot \frac{1}{N}
  60. $$
  61. $$
  62. DFT =
  63. \begin{pmatrix}
  64. \hat{f_0}\\
  65. \hat{f_1}\\
  66. \hat{f_2}\\
  67. \vdots\\
  68. \hat{f_n}\\
  69. \end{pmatrix}=
  70. \begin{pmatrix}
  71. 1 & 1 & 1 & \ldots & 1 \\
  72. 1 & w_n & w_n^2 & \ldots & w_n^{N-1} \\
  73. 1 & w_n^2 & w_n^4 & \ldots & w_n^{2(N-1)} \\
  74. \vdots & \vdots & \vdots & & \vdots\\
  75. 1 & w_n^{n-1} & w_n^{2(n-1)} & \ldots & w_n^{(N-1)^2} \\
  76. \end{pmatrix}
  77. \begin{pmatrix}
  78. f_0 \\ f_1 \\ f_2 \\ \vdots \\ f_n
  79. \end{pmatrix}
  80. $$
  81. \subsection{Fast Fourier Transform (FFT)}
  82. While DFT is $O(n)$, FFT is $O(n \space log(n))$
  83. Here you can find a simple implementation of the these concepts in Rust: \href{https://github.com/arnaucube/fft-rs}{arnaucube/fft-rs} \cite{fftrs}
  84. \section{FFT over finite fields, roots of unity, and polynomial multiplication}
  85. FFT is very useful when working with polynomials. [TODO poly multiplication]
  86. An implementation of the FFT over finite fields using the Vandermonde matrix approach can be found at \cite{fftsage}.
  87. \subsection{Intro}
  88. Let $A(x)$ be a polynomial of degree $n-1$,
  89. $$
  90. A(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + \cdots + a_{n-1} \cdot x^{n-1} = \sum_{i=0}^{n-1} a_i \cdot x^i
  91. $$
  92. We can represent $A(x)$ in its evaluation form,
  93. $$
  94. (x_0, A(x_0)), (x_1, A(x_1)), \cdots, (x_{n-1}, A(x_{n-1})) = (x_i, A(x_i))
  95. $$
  96. We can evaluate A(x) at n given points $(x_0, x_1, ..., x_{n-1}$):
  97. $$
  98. \begin{pmatrix}
  99. A(x_0)\\ A(x_1)\\ A(x_2)\\ \vdots\\ A(x_{n-1})
  100. \end{pmatrix}=
  101. \begin{pmatrix}
  102. x_0^0 & x_0^1 & x_0^2 & \ldots & x_0^{n-1} \\
  103. x_1^0 & x_1^1 & x_1^2 & \ldots & x_1^{n-1} \\
  104. x_2^0 & x_2^1 & x_2^2 & \ldots & x_2^{n-1} \\
  105. \vdots & \vdots & \vdots & & \vdots\\
  106. x_{n-1}^0 & x_{n-1}^1 & x_{n-1}^2 & \ldots & x_{n-1}^{n-1} \\
  107. \end{pmatrix}
  108. \begin{pmatrix}
  109. a_0 \\ a_1 \\ a_2 \\ \vdots \\ a_{n-1}
  110. \end{pmatrix}
  111. $$
  112. This is known by the Vandermonde matrix.
  113. But this will not be too efficient. Instead of random $x_i$ values, we use \emph{roots of unity}, where $\omega_n^n = 1$. We denote $\omega$ as a primitive $n^{th}$ root of unity:
  114. $$
  115. \begin{pmatrix}
  116. A(1)\\ A(\omega)\\ A(\omega^2)\\ \vdots\\ A(\omega^{n-1})
  117. \end{pmatrix}=
  118. \begin{pmatrix}
  119. 1 & 1 & 1 & \ldots & 1 \\
  120. 1 & \omega & \omega^2 & \ldots & \omega^{n-1} \\
  121. 1 & \omega^2 & \omega^4 & \ldots & \omega^{2(n-1)} \\
  122. \vdots & \vdots & \vdots & & \vdots\\
  123. 1 & \omega^{n-1} & \omega^{2(n-1)} & \ldots & \omega^{(n-1)^2} \\
  124. \end{pmatrix}
  125. \begin{pmatrix}
  126. a_0 \\ a_1 \\ a_2 \\ \vdots \\ a_{n-1}
  127. \end{pmatrix}
  128. $$
  129. Which we can see as
  130. $$
  131. \hat{A} = F_n \cdot A
  132. $$
  133. This matches our system of equations:
  134. \begin{itemize}
  135. \item at $x=0$, $a_0 + a_1 + \cdots + a_{n-1} = A_0 = A(1)$
  136. \item at $x=1$, $a_0 \cdot 1 + a_1 \cdot \omega + a_2 \cdot \omega^2 + \cdots + a_{n-1} \cdot \omega^{n-1} = A_1 = A(\omega)$
  137. \item at $x=2$, $a_0 \cdot 1 + a_1 \cdot \omega^2 + a_2 \cdot \omega^4 + \cdots + a_{n-1} \cdot \omega^{2(n-1)} = A_2 = A(\omega^2)$
  138. \item $\cdots$
  139. \item at $x=n-1$, $a_0 \cdot 1 + a_1 \cdot \omega^{n-1} + a_2 \cdot \omega^{2(n-1)} + \cdots + a_{n-1} \cdot \omega^{(n-1)(n-1)} = A_2 = A(\omega^{n-1})$
  140. \end{itemize}
  141. We denote the $F_n$ as the Fourier matrix, with $j$ rows and $k$ columns, where each entry can be expressed as $F_{jk} = \omega^{jk}$.
  142. To find the $a_i$ values, we use the inverted $F_n = F_n^{-1}$
  143. \subsection{Roots of unity}
  144. todo
  145. \subsection{FFT over finite fields}
  146. todo
  147. \subsection{Polynomial multiplication with FFT}
  148. todo
  149. \bibliography{fft-notes.bib}
  150. \bibliographystyle{unsrt}
  151. \end{document}