# 离散余弦变换

## 形式化定义

### DCT-I

${\displaystyle f_{m}={\frac {1}{2}}(x_{0}+(-1)^{m}x_{n-1})+\sum _{k=1}^{n-2}x_{k}\cos \left[{\frac {\pi }{n-1}}mk\right]}$

### DCT-II

${\displaystyle f_{m}=\sum _{k=0}^{n-1}x_{k}\cos \left[{\frac {\pi }{n}}m\left(k+{\frac {1}{2}}\right)\right]}$

DCT-II大概是最常用的一种形式，通常直接被称为DCT。

### DCT-III

${\displaystyle f_{m}={\frac {1}{2}}x_{0}+\sum _{k=1}^{n-1}x_{k}\cos \left[{\frac {\pi }{n}}\left(m+{\frac {1}{2}}\right)k\right]}$

### DCT-IV

${\displaystyle f_{m}=\sum _{k=0}^{n-1}x_{k}\cos \left[{\frac {\pi }{n}}\left(m+{\frac {1}{2}}\right)\left(k+{\frac {1}{2}}\right)\right]}$

DCT-IV对应的矩阵是正交矩阵（再乘一个系数的话）。

DCT-IV暗示的边界条件是：${\displaystyle x_{k}}$相对于${\displaystyle k=-{\frac {1}{2}}}$点偶对称，并且相对于${\displaystyle k=n-{\frac {1}{2}}}$点奇对称；对${\displaystyle f_{m}}$类似。

## 反变换

DCT-I的反变换是把DCT-I乘以系数${\displaystyle {\frac {2}{n-1}}}$。 DCT-IV的反变换是把DCT-IV乘以系数${\displaystyle {\frac {2}{n}}}$。 DCT-II的反变换是把DCT-III乘以系数${\displaystyle {\frac {2}{n}}}$，反之亦然。

## 计算

### 方法一[1]

${\displaystyle y(n)=\left\{{\begin{matrix}x(n),&{\mbox{if }}n=0,1,...,N-1\\x(2N-n-1),&{\mbox{if }}n=N,N+1,...2N-1\end{matrix}}\right.}$

${\displaystyle y(n)}$之DFT為

${\displaystyle Y(m)=\Sigma _{n=0}^{2N-1}y(n)W_{2N}^{nm}}$

${\displaystyle Y(m)}$ 做以下化簡

{\displaystyle {\begin{aligned}Y(m)&=\sum _{n=0}^{N-1}y(n)W_{2N}^{nm}+\sum _{n=N}^{2N-1}y(n)W_{2N}^{nm}\\&=\sum _{n=0}^{N-1}y(n)W_{2N}^{nm}+\sum _{n=N}^{2N-1}x(2N-n-1)W_{2N}^{nm}\\&=\sum _{n=0}^{N-1}y(n)W_{2N}^{nm}+\sum _{n=0}^{N-1}x(n)W_{2N}^{(2N-n-1)m}\\&=\sum _{n=0}^{N-1}x(n)[W_{2N}^{nm}+W_{2N}^{-(n+1)m}],\,\,\,\,m=0,1,...,2N-1\end{aligned}}}

### 方法二 [2]

${\displaystyle y(n)=x(2n)}$ 並且 ${\displaystyle y(N-1-n)=x(2n+1),\,\,\,\,\,\,n=0,1,...,{\frac {N}{2}}-1}$

${\displaystyle X(m)=\sum _{n=0}^{N/2-1}y(n)\cos {[{\frac {(4n+1)m\pi }{2N}}]}+\sum _{n=0}^{N/2-1}y(N-n-1)\cos {[{\frac {(4n+3)m\pi }{2N}}]},\,\,\,\,\,\,\,m=0,1,...,N-1}$

${\displaystyle X(m)=\sum _{n=0}^{N-1}y(n)\cos {[{\frac {(4n+1)m\pi }{2N}}]},\,\,\,\,\,\,m=0,1,...,N-1}$

${\displaystyle Z(m)=W_{4N}^{m}Y(m)=W_{4N}^{m}\sum _{n=0}^{N-1}y(n)W_{N}^{nm},\,\,\,\,\,\,\,m=0,1,...,N-1}$

${\displaystyle Z(N-m)=-jZ(m)^{*}}$

## 参考

• K. R. Rao and P. Yip, 离散余弦变换：算法、优点和应用Discrete Cosine Transform: Algorithms, Advantages, Applications） (Academic Press, Boston, 1990).
• A. V. Oppenheim, R. W. Schafer, and J. R. Buck, 时间离散信号处理 (Discrete-Time Signal Processing), second edition (Prentice-Hall, New Jersey, 1999).
• S. A. Martucci, 对称卷积和离散正弦余弦变换 (Symmetric convolution and the discrete sine and cosine transforms), IEEE Trans. Sig. Processing SP-42, 1038-1051 (1994).
• Matteo Frigo and Steven G. Johnson: FFTW, http://www.fftw.org/页面存档备份，存于互联网档案馆）. 一个免费的C语言GPL，可以计算DCT-I~IV的1维到多维的任意大小的变换
• M. Frigo and S. G. Johnson, "FFTW3的设计和实现页面存档备份，存于互联网档案馆）," Proceedings of the IEEE 93 (2), 216–231 (2005).
• On the Computation of the Discrete Cosine Transform. (1978, June 1). IEEE Journals & Magazine | IEEE Xplore. https://ieeexplore.ieee.org/document/1094144页面存档备份，存于互联网档案馆

## 外部链接

1. ^ Rao, R. K., & Yip, P. (1990). Discrete Cosine Transform: Algorithms, Advantages, Applications (1st ed.). Academic Press.
2. ^ On the Computation of the Discrete Cosine Transform. (1978, June 1). IEEE Journals & Magazine | IEEE Xplore. https://ieeexplore.ieee.org/document/1094144页面存档备份，存于互联网档案馆