# DFT&IDFT学习笔记

DFT:

$多项式定义:\sum_{i=0}^n a_i x^i\\ 系数表示法:f(x)=\sum_{i=0}^n a_i x^i\\ 点值表示法:\{(x_0,f(x_0)),(x_1,f(x_1)),\dots,(x_n,f(x_n))\}$

$i^2=-1,i=\sqrt{-1}\\ 解方程x^n=1,n个根\\ 欧拉公式e^{\pi i}=-1\\ e^{2\pi i}=1=x^n\\ e^{\frac{2\pi i}{n}}=x\\ \because x_i^n=1\\ \therefore 模长为1,均匀分布在以原点为圆心的一个单位圆上\\ 则设\omega_n^x为方程x^n=1的第x个根(x_0=1,x_1=e^{\frac{2\pi i}{n}},\dots,x_k=e^{\frac{2\pi ik}{n}},\dots,x_{n-1}=e^{\frac{2\pi i(n-1)}{n}})\\ 称\omega_n^1(即\omega_n)为单位根\\ \omega_n^k=e^{\frac{2\pi ik}{n}}\\$

### 引理1:

$\forall\omega_{nk}^{tk}=e^{\frac{2\pi itk}{nk}}=e^{\frac{2\pi it}{n}}=\omega_{n}^{t}\\ 即上下同时乘一个数依然成立\\$

### 引理2:

$\omega_n^{\frac n 2+k}=e^{\frac{2\pi i(\frac n 2+k)}{n}}=e^{\frac{\pi in+2\pi ik}{n}}\\ =e^{\frac{\pi in}{n}}\times e^{\frac{2\pi ik}{n}}=e^{\pi i}\times e^{\frac{2\pi ik}{n}}\\ =e^{\pi i}\times e^{\frac{2\pi ik}{n}}=-e^{\frac{2\pi ik}{n}}=-\omega_n^k\\ 即\omega_n^{\frac n 2+k}=-\omega_n^k$

$由玄学内容可知\\ 将\omega_n^k代入f(x)并将其转为点值表示法很快\\$

$则f(\omega_n^k)=\sum_{i=0}^n a_i\omega_n^{ki}\\ 在这令n为2^m(m为使n\leq2^m的最小值),之后的a_i补零便于二分\\ f(\omega_n^k)=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_n^{2ki}+\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_n^{k(2i+1)}\\ f(\omega_n^k)=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_n^{2ki}+\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_n^{2ki}\\ f(\omega_n^k)=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{ki}+\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{ki}\\$

$令0\leq k<\frac n 2\\ f(\omega_n^k)=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{ki}+\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{ki}\\ f(\omega_n^{k+\frac n 2})=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{(k+\frac n 2)i}+\omega_n^{k+\frac n 2}\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{(k+\frac n 2)i}\\ =\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{(k+\frac n 2)i}-\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{(k+\frac n 2)i}\\$

$\omega_{\frac n 2}^{(k+\frac n 2)i}=\omega_{\frac n 2}^{ki+\frac n 2i}=\omega_{\frac n 2}^{ki}(\omega_{\frac n 2}^{\frac n 2})^i\\ \because \omega_n^n=1\\ \therefore \omega_{\frac n 2}^{(k+\frac n 2)i}=\omega_{\frac n 2}^{ki}$

$f(\omega_n^{k+\frac n 2})=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{(k+\frac n 2)i}-\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{(k+\frac n 2)i}\\ f(\omega_n^{k+\frac n 2})=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{ki}-\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{ki}$

$令A'=\sum_{i=0}^{\frac n 2-1} a_{2i}\omega_{\frac n 2}^{ki}\\ A''=\omega_n^k\sum_{i=0}^{\frac n 2-1} a_{2i+1}\omega_{\frac n 2}^{ki}\\ 观察得f(\omega_n^k)=A'+A''\\ f(\omega_n^{k+\frac n 2})=A'-A''\\ 即算出\omega_n^k的A'和A''即可O(1)算出f(\omega_n^{k+\frac n 2})=A'-A''\\ 不断二分，感性理解复杂度为O(n\log_2n)(类似于线段树)$

IDFT:

$平面上有n个点，分别为\{(\omega_n^0,f(\omega_n^0)),(\omega_n^1,f(\omega_n^1)),\dots,(\omega_n^{n-1},f(\omega_n^{n-1}))\}(这是我们刚刚DFT转成的点值表示法)\\ 现想要得到这n个点组成的唯一能确定的n-1次的解析式\\ 设解析式为f(x)=\sum_{i=0}^{n-1}a_ix^i\\ 将点坐标代入\\ \begin{cases}\begin{array}{ccccccccccc} f(\omega_n^0)&=&a_0(\omega_n^0)^0&+&a_1(\omega_n^0)^1&+&a_2(\omega_n^0)^2&+&\dots&+&a_{n-1}(\omega_n^0)^{n-1}\\ f(\omega_n^1)&=&a_0(\omega_n^1)^0&+&a_1(\omega_n^1)^1&+&a_2(\omega_n^1)^2&+&\dots&+&a_{n-1}(\omega_n^1)^{n-1}\\ \vdots&&\vdots&&\vdots&&\vdots&&\vdots&&\vdots\\ f(\omega_n^{n-1})&=&a_0(\omega_n^{n-1})^0&+&a_1(\omega_n^{n-1})^1&+&a_2(\omega_n^{n-1})^2&+&\dots&+&a_{n-1}(\omega_n^{n-1})^{n-1}\\ \end{array}\end{cases}$

### 1.矩阵乘法

$A,B为两个矩阵\\ A为n\times p的矩阵，元素为a_{i,j}\\ B为p\times m的矩阵，元素为b_{i,j}\\ A\times B=C\\ C为n\times m的矩阵，元素为c_{i,j}\\ c_{i,j}=\sum_{k=1}^p a_{i,k}\times b_{k,j}\\$

### 2.单位元矩阵与逆矩阵

$单位元:类似乘法的单位元为1,异或运算的单位元为0等\\ 矩阵乘法的单位元为 I= \begin{bmatrix} 1&0&\cdots&0\\ 0&1&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\cdots&1\\ \end{bmatrix}\\ 即n\times n的从左上角到右下角都是1的矩阵，其余元素都是0\\ 称I_k为k\times k的单位元矩阵\\ 逆矩阵:如有A\times B=I\\ 则称B是A的逆矩阵\\ 记做B=A^{-1}$

### Tips:

$n\times D\to d_{i,j}\times n$

$解出以上方程组，即可知道所有a_i的值，也就成功将点值表示法转化为系数表示法\\ 将上述方程组转化为矩阵乘法形式\\ \begin{bmatrix} f(\omega_n^0)\\ f(\omega_n^1)\\ \vdots\\ f(\omega_n^{n-1}) \end{bmatrix} = \begin{bmatrix} (\omega_n^0)^0&(\omega_n^0)^1&(\omega_n^0)^2&\dots&(\omega_n^0)^{n-1}\\ (\omega_n^1)^0&(\omega_n^1)^1&(\omega_n^1)^2&\dots&(\omega_n^1)^{n-1}\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ (\omega_n^{n-1})^0&(\omega_n^{n-1})^1&(\omega_n^{n-1})^2&\dots&(\omega_n^{n-1})^{n-1}\\ \end{bmatrix} \begin{bmatrix} a_0\\ a_1\\ \vdots\\ a_{n-1}\\ \end{bmatrix}$

$设矩阵V= \begin{bmatrix} (\omega_n^0)^0&(\omega_n^0)^1&(\omega_n^0)^2&\dots&(\omega_n^0)^{n-1}\\ (\omega_n^1)^0&(\omega_n^1)^1&(\omega_n^1)^2&\dots&(\omega_n^1)^{n-1}\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ (\omega_n^{n-1})^0&(\omega_n^{n-1})^1&(\omega_n^{n-1})^2&\dots&(\omega_n^{n-1})^{n-1}\\ \end{bmatrix}\\ 另设矩阵D=\begin{bmatrix} (\omega_n^{-0})^0&(\omega_n^{-0})^1&(\omega_n^{-0})^2&\dots&(\omega_n^{-0})^{n-1}\\ (\omega_n^{-1})^0&(\omega_n^{-1})^1&(\omega_n^{-1})^2&\dots&(\omega_n^{-1})^{n-1}\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ (\omega_n^{-(n-1)})^0&(\omega_n^{-(n-1)})^1&(\omega_n^{-(n-1)})^2&\dots&(\omega_n^{-(n-1)})^{n-1}\\ \end{bmatrix}\\$

### Tip:

$为方便后续计算，我们称第1行为第0行，第2行为第1行,第n行为第n-1行\\ 则v_{i,j}=(\omega_n^i)^j\\ 则d_{i,j}=(\omega_n^{-i})^j$

$等比求和公式:\\ 求\sum_{i=0}^{n-1}a^i\\ 令S=\sum_{i=0}^{n-1}a^i\\ 则S\times a=\sum_{i=0}^{n-1}a^{i+1}=\sum_{i=1}^na^i\\ S\times a-S=\sum_{i=1}^na^i-\sum_{i=0}^{n-1}a^i=a^n-1\\ S\times(a-1)=a^n-1\\ S=\frac{a^n-1}{a-1}$

$再设E=D\times V\\ 则e_{i,j}=\sum_{k=0}^{n-1} d_{i,k}\times v_{k,j}\\ =\sum_{k=0}^{n-1} (\omega_n^{-i})^k\times (\omega_n^k)^j\\ =\sum_{k=0}^{n-1} \omega_n^{-ik}\times\omega_n^{kj}\\ =\sum_{k=0}^{n-1} \omega_n^{k(j-i)}\\ 当[i=j]时\\ e_{i,j}=\sum_{k=0}^{n-1} 1=n\\ 当[i\not=j]时\\ e_{i,j}=\sum_{k=0}^{n-1} (\omega_n^{j-i})^k\\ =\frac{(\omega_n^{j-i})^n-1}{\omega_n^{j-i}-1}\\ =\frac{(\omega_n^n)^{j-i}-1}{\omega_n^{j-i}-1}\\ =\frac{1^{j-i}-1}{\omega_n^{j-i}-1}\\ =\frac{0}{\omega_n^{j-i}-1}\\ =0\\ \therefore e_{i,j}=[i=j]n\\ \therefore E=nI$

$\therefore DV=E=nI\\ \therefore \frac 1 nDV=I\\ \therefore \frac 1 nD=IV^{-1}\\ \because I为矩阵乘法的单位元\\ \therefore \frac 1 nD=V^{-1}\\ V^{-1}=\frac 1 nD$

$\begin{bmatrix} f(\omega_n^0)\\ f(\omega_n^1)\\ \vdots\\ f(\omega_n^{n-1}) \end{bmatrix} =V\begin{bmatrix} a_0\\ a_1\\ \vdots\\ a_{n-1}\\ \end{bmatrix}\\$

$\begin{bmatrix} f(\omega_n^0)\\ f(\omega_n^1)\\ \vdots\\ f(\omega_n^{n-1}) \end{bmatrix} V^{-1}=\begin{bmatrix} a_0\\ a_1\\ \vdots\\ a_{n-1}\\ \end{bmatrix}\\$

$\begin{bmatrix} a_0\\ a_1\\ \vdots\\ a_{n-1}\\ \end{bmatrix} =\begin{bmatrix} f(\omega_n^0)\\ f(\omega_n^1)\\ \vdots\\ f(\omega_n^{n-1}) \end{bmatrix} V^{-1}$

$\\\begin{bmatrix} a_0\\ a_1\\ \vdots\\ a_{n-1}\\ \end{bmatrix}=\begin{bmatrix} f(\omega_n^0)\\ f(\omega_n^1)\\ \vdots\\ f(\omega_n^{n-1}) \end{bmatrix} \frac 1 n D \\$

posted @ 2019-04-13 14:38  hzf29721  阅读(737)  评论(0编辑  收藏  举报