\chapter{Discrete Transforms (\module{cvxopt.fftw})} \label{c-fftw}

The \module{cvxopt.fftw} module is an interface to the FFTW library
and contains routines for discrete Fourier, cosine, and sine 
transforms.  This module is optional, and only installed when 
the FFTW library is made available during the CVXOPT installation.

\textbf{See also:}
\seelink{http://www.fftw.org}{FFTW3 code, documentation, copyright and
license.}{}

\section{Discrete Fourier Transform} 
\begin{funcdesc}{dft}{X}
Replaces the columns of a dense complex matrix with their discrete 
Fourier transforms:  if \var{X} has {\it n} rows,
\[
  X[k,:] := \sum_{j=0}^{n-1} e^{-2\pi j k \sqrt{-1}/n} X[j,:],
 \qquad k=0,\ldots,n-1.
\]
\end{funcdesc}

\begin{funcdesc}{idft}{X}
Replaces the columns of a dense complex matrix with their inverse 
discrete Fourier transforms: if \var{X} has {\it n} rows,
\[
  X[k,:] := 
 \frac{1}{n} \sum_{j=0}^{n-1} e^{2\pi j k \sqrt{-1}/n} X[j,:],
  \qquad k=0,\ldots,n-1.
\]
\end{funcdesc}

\section{Discrete Cosine Transform} 
\begin{funcdesc}{dct}{X\optional{, type=2}}
Replaces the columns of a dense real matrix with their discrete
cosine transforms.  The second argument, an integer between 1 and 4,
denotes the type of transform (DCT-I, DCT-II, DCT-III, DCT-IV).
The DCT-I transform requires that the row dimension of \var{X} is at 
least 2.
These transforms are defined as follows 
(for a matrix with {\it n} rows).
\BEAS
\mbox{DCT-I:} \qquad
 X[k,:]  & := & X[0,:] + (-1)^k X[n-1,:] + 
 2 \sum_{j=1}^{n-2} X[j,:] \cos(\pi j k /(n-1)), 
 \qquad k=0,\ldots,n-1.\\
\mbox{DCT-II:} \qquad
 X[k,:]  & := & 2 \sum_{j=0}^{n-1} X[j,:] \cos(\pi(j+1/2)k/n), 
 \qquad k=0,\ldots,n-1.\\
\mbox{DCT-III:} \qquad
 X[k,:]  & := & X[0,:] + 2 \sum_{j=1}^{n-1} X[j,:] \cos(\pi j(k+1/2)/n),
 \qquad k=0,\ldots,n-1.\\
\mbox{DCT-IV:} \qquad
 X[k,:]  & := & 2 \sum_{j=0}^{n-1} X[j,:] \cos(\pi (j+1/2)(k+1/2)/n), 
 \qquad k=0,\ldots,n-1.
\EEAS
\end{funcdesc}

\begin{funcdesc}{idct}{X\optional{, type=2}}
Replaces the columns of a dense real matrix with the inverses
of the discrete cosine transforms defined above.  
\end{funcdesc}

\section{Discrete Sine Transform} 
\begin{funcdesc}{dst}{X\optional{, type=1}}
Replaces the columns of a dense real matrix with their discrete
sine transforms.  The second argument, an integer between 1 and 4,
denotes the type of transform (DST-I, DST-II, DST-III, DST-IV).
These transforms are defined as follows 
(for a matrix with {\it n} rows).
\BEAS
\mbox{DST-I:} \qquad
 X[k,:] & := & 
 2 \sum_{j=0}^{n-1} X[j,:] \sin(\pi(j+1)(k+1)/(n+1)), 
 \qquad k=0,\ldots,n-1.\\
\mbox{DST-II:} \qquad
 X[k,:]  & := & 2 \sum_{j=0}^{n-1} X[j,:] \sin(\pi(j+1/2)(k+1)/n), 
 \qquad k=0,\ldots,n-1.\\
\mbox{DST-III:} \qquad
 X[k,:]  & := & (-1)^k X[n-1,:] + 2 \sum_{j=0}^{n-2} 
 X[j,:] \sin(\pi(j+1)(k+1/2)/n), 
 \qquad k=0,\ldots,n-1. \\
\mbox{DST-IV:} \qquad
 X[k,:]  & := & 2 \sum_{j=0}^{n-1} X[j,:] \sin(\pi (j+1/2)(k+1/2)/n), 
 \qquad k=0,\ldots,n-1.
\EEAS
\end{funcdesc}

\begin{funcdesc}{idst}{X\optional{, type=1}}
Replaces the columns of a dense real matrix with the inverses
of the discrete sine transforms defined above.  
\end{funcdesc}
