\include{psfig}
\documentstyle[12pt,twoside]{article}
\setlength{\textwidth}{6in}
\setlength{\textheight}{8.5in}
\setlength{\topmargin}{-.5in} % top of page to top of running head minus 1in
% \setlength{\headsep}{.5in} % bottom of running head to top of text
\setlength{\oddsidemargin}{.5in} % left margin minus 1in on odd pages
\setlength{\evensidemargin}{0in} % left margin minus 1in on even pages
\setlength{\parskip}{2ex} % vertical space between paragraphs
% convolution symbol
\def\conv{\mathbin{\hbox{$\,*$\kern-1.5ex$\odot$}}}
%
% definite integrals and sums
\def\intinf{\int_{-\infty}^{+\infty}}
%
% matrix with rounded brackets
\def\rmatrix #1{\left\lgroup\matrix{ #1 }\right\rgroup}
\def\U{\hskip-.6em\relax&}
\def\ur{\cr\noalign{\vskip 1.5ex}}
\def\ud{\cdot}
% figure with caption and label
\def\fig #1 { % #1=psfig args
\begin{figure}[h]
\centerline{\psfig{figure=#1}}
\end{figure}
}
% NASTY STUFF: ==============================
\catcode`@=11 % make at signs act like letters, temporarily
% put back eqalign, which was removed by latex; it's better than eqnarray
%
\def\eqalign#1{\null\,\vcenter{\openup\jot\m@th
\ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
\crcr#1\crcr}}\,}
\catcode`@=12 % at signs are no longer letters
% END NASTY STUFF ==============================
\begin{document}
\noindent
Notes 7, Computer Graphics 2, 9 Feb. 1995
\vspace{.5in}
\begin{center}
{\noindent \bf \LARGE Discrete Fourier Transforms and the \\ \vskip 1ex
Fast Fourier Transform (FFT) Algorithm}
Paul Heckbert
\end{center}
We start in the continuous world; then we get discrete.
\section*{Definition of the Fourier Transform}
The Fourier transform (FT) of the function $f(x)$ is the function $F(\omega)$,
where:
$$
F(\omega) = \int_{-\infty}^{\infty} f(x) e^{-i \omega x} \,dx
$$
and the inverse Fourier transform is
$$
f(x) = {1 \over 2 \pi} \int_{-\infty}^{\infty}
F(\omega) e^{i \omega x} \,d\omega
$$
Recall that $i=\sqrt{-1}$ and
$e^{i\theta}=\cos\theta + i\sin\theta$.
Think of it as a transformation into a different set of basis functions.
The Fourier transform uses complex exponentials (sinusoids)
of various frequencies as its basis functions.
(Other transforms, such as Z, Laplace, Cosine, Wavelet, and Hartley,
use different basis functions).
A Fourier transform pair is often written $f(x) \leftrightarrow F(\omega)$,
or ${\cal F}(f(x)) = F(\omega)$ where $\cal F$ is the Fourier transform
operator.
If $f(x)$ is thought of as a signal (i.e. input data) then we call $F(\omega)$
the signal's {\it spectrum}.
If $f$ is thought of as the {\it impulse response}
of a filter (which operates on input data to
produce output data) then we call $F$ the filter's {\it frequency response}.
(Occasionally the line between what's signal and what's filter becomes blurry).
\section*{Example of a Fourier Transform}
In signal processing terms,
the ideal low pass filter with cutoff frequency $\omega_c$ has a
frequency response that is a box:
$$
F(\omega) = \cases{
1 & $|\omega| \le \omega_c$ \cr
0 & $|\omega| > \omega_c$ \cr
}
$$
What is its impulse response?
We know that the impulse response is the inverse Fourier transform of
the frequency response, so
taking off our signal processing hat and putting on our mathematics hat,
all we need to do is evaluate:
$$
f(x) = {1 \over 2 \pi} \int_{-\infty}^{\infty}
F(\omega) e^{i \omega x} \,d\omega
$$
for this particular $F(\omega)$:
$$
\eqalign{
f(x) &= {1 \over 2 \pi} \int_{-\omega_c}^{\omega_c} e^{i \omega x} \,d\omega \cr
&= {1 \over 2 \pi} {e^{i \omega x} \over i x}
\bigg|_{\omega=-\omega_c}^{\omega_c} \cr
&= {1 \over \pi x} {e^{i \omega_c x} - e^{- i \omega_c x} \over 2 i} \cr
&= {\sin \omega_c x \over \pi x}
\qquad \qquad \hbox{since }
\sin \theta = {e^{i \theta} - e^{-i \theta} \over 2 i} \cr
&= {\omega_c \over \pi} {\rm sinc}({ \omega_c \over \pi } x) \cr
}
$$
where $\rm sinc (x) = \sin (\pi x)/(\pi x)$.
For antialiasing with unit-spaced samples, you want the cutoff frequency to
equal the Nyquist frequency, so $\omega_c = \pi$.
\section*{Fourier Transform Properties}
Rather than write ``the Fourier transform of an $X$ function is a $Y$
function'', we write the shorthand: $X \leftrightarrow Y$.
If $z$ is a complex number and $z=x+iy$ where $x$ and $y$ are
its real and imaginary parts,
then the complex conjugate of $z$ is $z^*=x-iy$.
A function $f(u)$ is {\it even} if $f(u)=f(-u)$,
it is {\it odd} if $f(u)=-f(-u)$,
it is conjugate symmetric if $f(u)=f^*(-u)$,
and it is conjugate antisymmetric if $f(u)=-f^*(-u)$.
\begin{tabular}{l}
discrete $\leftrightarrow$ periodic \\
periodic $\leftrightarrow$ discrete \\
discrete, periodic $\leftrightarrow$ discrete, periodic \\
\hline
real $\leftrightarrow$ conjugate symmetric \\
imaginary $\leftrightarrow$ conjugate antisymmetric \\
\hline
box $\leftrightarrow$ sinc \\
sinc $\leftrightarrow$ box \\
Gaussian $\leftrightarrow$ Gaussian \\
impulse $\leftrightarrow$ constant \\
impulse train $\leftrightarrow$ impulse train \\
\end{tabular}
{\it (can you prove the above?)}
When a signal is scaled up spatially, its spectrum is scaled down in
frequency, and vice versa: $f(ax) \leftrightarrow F(\omega/a)$
for any real, nonzero $a$.
\section*{Convolution Theorem}
The Fourier transform of a convolution of two signals is
the product of their Fourier transforms: $f \conv g \leftrightarrow FG$.
Recall that the convolution of signals $f$ and $g$ is
$(f \conv g)(x) = \intinf f(t) g(x-t) \,dt$.
So $\intinf f(t) g(x-t) \,dt \leftrightarrow F(\omega)G(\omega)$.
The Fourier transform of a product of two signals is
the convolution of their Fourier transforms:
$fg \leftrightarrow F \conv G / 2 \pi$.
\section*{Delta Functions}
The (Dirac) delta function $\delta(x)$ is defined such that
$\delta(x)=0$ for all $x \ne 0$, $\intinf \delta(t)\,dt = 1$, and
$$
(f \conv \delta)(x) = \intinf f(t) \delta(x-t) \,dt = f(x)
$$
The latter is called the {\it sifting property} of delta functions.
\section*{Discrete Fourier Transform (DFT)}
When a signal is discrete and periodic, we don't need the continuous Fourier
transform.
Instead we use the discrete Fourier transform, or DFT.
Suppose our signal is $a_n$ for $n=0 \ldots N-1$,
and $a_n=a_{n+jN}$ for all $n$ and $j$.
The spectrum of $a$ is:
\begin{equation}
A_k = \sum_{n=0}^{N-1} W_N^{kn} a_n
\label{dft.eq}
\end{equation}
where
$$
W_N = e^{-i {2 \pi \over N}}
$$
and $W_N^k$ for $k=0 \ldots N-1$ are called the {\it Nth roots of unity}.
They're called this because, in complex arithmetic,
$(W_N^k)^N = 1$ for all $k$.
They're vertices of a regular polygon inscribed in the unit
circle of the complex plane, with one vertex at $(1,0)$.
The sequence $A_k$ is the discrete Fourier transform of the sequence $a_n$.
Each is a sequence of $N$ complex numbers.
\subsection*{Two-point DFT (N=2)}
$W_2 = e^{-i \pi} = -1$,
and
$$
A_k = \sum_{n=0}^1 (-1)^{kn} a_n
= (-1)^{k \cdot 0} a_0 + (-1)^{k \cdot 1} a_1
= a_0 + (-1)^k a_1
$$
so
$$
\eqalign{
A_0 &= a_0 + a_1 \cr
A_1 &= a_0 - a_1 \cr
}
$$
\subsection*{Four-point DFT (N=4)}
$W_4 = e^{-i \pi/2} = -i$,
and
$$
A_k = \sum_{n=0}^3 (-i)^{kn} a_n
= a_0 + (-i)^k a_1 + (-i)^{2k} a_2 + (-i)^{3k} a_3
= a_0 + (-i)^k a_1 + (-1)^k a_2 + i^k a_3
$$
so
$$
\eqalign{
A_0 &= a_0 + a_1 + a_2 + a_3 \cr
A_1 &= a_0 - i a_1 - a_2 + i a_3 \cr
A_2 &= a_0 - a_1 + a_2 - a_3 \cr
A_3 &= a_0 + i a_1 - a_2 - i a_3 \cr
}
$$
This can also be written as a matrix multiply:
$$
\rmatrix{ A_0 \ur A_1 \ur A_2 \ur A_3 }
=
\rmatrix{
1 & 1 & 1 & 1 \cr
1 & -i & -1 & i \cr
1 & -1 & 1 & -1 \cr
1 & i & -1 & -i \cr
}
\rmatrix{ a_0 \ur a_1 \ur a_2 \ur a_3 }
$$
More on this later.
To compute $A$ quickly, we can pre-compute common subexpressions:
$$
\eqalign{
A_0 &= (a_0 + a_2) + (a_1 + a_3) \cr
A_1 &= (a_0 - a_2) - i (a_1 - a_3) \cr
A_2 &= (a_0 + a_2) - (a_1 + a_3) \cr
A_3 &= (a_0 - a_2) + i (a_1 - a_3) \cr
}
$$
This saves a lot of adds.
(Note that each add and multiply here is a complex (not real)
operation.)
If we use the following diagram for a complex
multiply and add:
\fig{mulad.eps}
then we can diagram the 4-point DFT like so:
\fig{4pt.eps}
If we carry on to $N=8$, $N=16$, and other power-of-two
discrete Fourier transforms, we get...
\section*{The Fast Fourier Transform (FFT) Algorithm}
The FFT is a fast algorithm for computing the DFT.
If we take the 2-point DFT and 4-point DFT and generalize them
to 8-point, 16-point, ..., $2^r$-point, we get the FFT algorithm.
To compute the DFT of an $N$-point sequence using equation (\ref{dft.eq})
would take $O(N^2)$ multiplies and adds.
The FFT algorithm computes the DFT using $O(N \log N)$ multiplies and adds.
There are many variants of the FFT algorithm.
We'll discuss one of them, the ``decimation-in-time'' FFT
algorithm for sequences whose length is
a power of two ($N=2^r$ for some integer $r$).
Below is a diagram of an 8-point FFT,
where $W=W_8=e^{-i \pi / 4} = (1-i)/ \sqrt{2}$:
\fig{8pt.eps,width=3in}
\section*{Butterflies and Bit-Reversal}
The FFT algorithm decomposes the DFT into $\log_2 N$ stages,
each of which consists of $N/2$ {\it butterfly} computations.
Each butterfly takes two complex numbers $p$ and $q$ and
computes from them two other numbers, $p+\alpha q$ and $p-\alpha q$,
where $\alpha$ is a complex number.
Below is a diagram of a butterfly operation:
\fig{butterfly.eps}
In the diagram of the 8-point FFT above,
note that the inputs aren't in normal order:
$a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7$,
they're in the bizarre order:
$a_0, a_4, a_2, a_6, a_1, a_5, a_3, a_7$.
Why this sequence?
Below is a table of $j$ and the index of the $j$th input sample, $n_j$:
\begin{center}
\begin{tabular}{l|rrrrrrrr}
$j$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
\hline
$n_j$ & 0 & 4 & 2 & 6 & 1 & 5 & 3 & 7 \\
\hline
$j$ base 2 & 000 & 001 & 010 & 011 & 100 & 101 & 110 & 111 \\
$n_j$ base 2 & 000 & 100 & 010 & 110 & 001 & 101 & 011 & 111 \\
\end{tabular}
\end{center}
The pattern is obvious if $j$ and $n_j$ are written
in binary (last two rows of the table).
Observe that each $n_j$ is the {\it bit-reversal} of $j$.
The sequence is also related to breadth-first traversal of a binary tree.
It turns out that this FFT algorithm is simplest if the input array
is rearranged to be in bit-reversed order.
The re-ordering can be done in one pass through the array $a$:
\begin{verbatim}
for j = 0 to N-1
nj = bit_reverse(j)
if (j