# The DFT

Whereas the CTFT takes a continuous signal and outputs a continuous frequency spectrum and the DTFT takes a discrete signal and outputs a continuous, periodic frequecy spectrum, the Discrete Fourier Transform takes a discrete finite signal and outputs a discrete frequency spectrum. This is useful for signal processing because we cannot store infinite signals in a computer’s memory.

#### Definition 1

For a length
$N$
finite sequence
$\{x[n]\}^{n-1}_{0}$
, the Discrete Fourier Transform of the signal is a length N finite sequence
$\{X[k]\}^{n-1}_{0}$
where
$X[k] = \sum_{n=0}^{N-1}{x[n]e^{-j\frac{2\pi}{N}kn}}$
One way to interpret the DFT is in terms of the Fourier series for a disrete periodic signal
$\tilde{x}[n]=x[((n))_N]$
where the
$((n))_N = n \mod N$
. Recall that the coefficient of the kth term of the Fourier Series is
$a_k = \frac{1}{N}\sum_{n=0}^{N-1}{x[n]e^{-j\frac{2\pi}{N}kn}}$
Notice that the
$a_k$
of the Fourier Series are the DFT values except scaled by a factor of
$N$
. In other words, if we extend a finite signal periodically, then the DFT and the DTFS are the same up to a constant scale factor. This gives an intuitive inverse DFT.

#### Definition 2

For a length N finite sequence
$\{X[k]\}^{N-1}_{0}$
representing the DFT of a finite perioidc signal
$\{x[n]\}^{N-1}_{0}$
, the inverse DFT is given by
$x[n] = \frac{1}{N}\sum_{k=0}^{N-1}{X[k]e^{j\frac{2\pi}{N}kn}}$
Notice that the DFT and the IDFT are very similar in form. It turns out that the IDFT can be expressed as a DFT of
$X^*[k]$
. Namely
$IDFT\{X[k]\} = \frac{1}{N}DFT\{X^\star[k]\}^\star$
Further intuition for the DFT comes by relating it to the DTFT. Suppose we have a finite signal
$x[n]$
which is
$0$
for
$n < 0$
and
$n > N-1$
. The DTFT of this signal is
$X(\omega) = \sum_{n=-\infty}^{\infty}{x[n]e^{-j\omega n}} = \sum_{n=0}^{N-1}{x[n]e^{-j\omega n}}$
Suppose we sample the DTFT at intervals of
$\frac{2\pi}{N}k$
, then the kth sample is given by
$X[k] = X\left(\frac{2\pi}{N}k\right) = \sum_{n=0}^{N-1}{x[n]e^{-j\frac{2\pi}{N}k n}}$
Thus we can think of the DFT as a
$N$
evenly spaced samples of the DTFT. One important point to notice is that while the DTFT is often centered around 0 (meaning it is plotted over a range from
$-\pi$
to
$\pi$
), because we are summing from 0 to N-1 in the DFT, the DFT coefficients are centered around
$\pi$
, and thus they are plotted on a range fo
$[0, 2\pi - \frac{2\pi}{N}]$

## Convolution and the DFT

### Circular Convolution

When the DFT coefficients of two signals are multiplied, the resulting coefficients describe a circular convolution of the original two signals.
$x[n]\circledast y[n] \leftrightarrow X[k]Y[k]$

#### Definition 3

A circular convolution between two finite sequences is given by
$x[n]\circledast y[n] = \sum_{m=0}^{N-1}x[m]y[((n-m))_N]$
The mechanics of the circular convolution are the same as that of the regular convolution, except the signal is circularly shifted as shown in Figure 1.
Figure 1: A circular shift
A circular convolution is equivalent to a periodic convolution over a single period.

### Linear Convolution with the DFT

Because multiplying DFT coefficients performs a specific case of convolution, we can compute a linear convolution using the circular convolution. Suppose we have two finite signals
$\{x[n]\}_0^{L-1}$
and
$\{h[n]\}_0^{P-1}$
The linear convolution of these two signals will be length
$L+P-1$
, so in order to take an IDFT and get
$L+P-1$
samples, we need to take at least
$N\le L+P-1$
points.
1. 1.
$L+P-1$
2. 2.
Compute
$X[k]H[k]$
3. 3.
Take the Inverse DFT
If
$N$
is smaller than
$L-P+1$
, the result is akin to aliasing in the time domain. To see why, consider that the DFT coefficients are essentially the DTFS coefficients of the periodic extension of
$x[n]$
(denote
$\tilde{x}[n]$
).
$\tilde{x}[n]=\sum_{r=-\infty}^{\infty}x[n-rN]$
If we compute the DTFT of each periodic extension, then
$Y(e^{j\omega})=X(e^{j\omega})H(e^{j\omega})$
and the IDTFT of this will be
$\tilde{y}[n] = \sum_{r=-\infty}^{\infty}y[n-rN].$
Notice that if
$N$
is not large enough, then these copies will be overlapping (a.k.a aliasing). Since the DFT is just sampling the DTFT, the circular convolution will represent the true convolution so long as the copies don’t overlap.

### Block Convolutions

In a discrete time system, the input signal might have a very long length, making it impractical to be stored in a computer’s memory or to compute the DFT of it all at once (especially if we have a real-time system). Thus to compute the output of a digital filter (with impulse response of length
$P$
), we need to compute the DFT in blocks shorter than the signal.
The first method of block convolution is the overlap-add method.
1. 1.
Decompose
$x[n]$
into nonoverlapping segments of length
$L$
$x[n] = \sum_{r}x_r[n] \qquad x_r[n] = \begin{cases} x[n] & rL \le n \le (r+1)L\\ 0 & \text{else}. \end{cases}$
2. 2.
Since convolution is linear,
$y[n] = x[n]*h[n]=\sum_r{x_r[n]*h[n]}.$
3. 3.
$x_r[n]$
and
$h[n]$
to length
$N\ge L+P-1$
to prevent time-domain aliasing
4. 4.
Compute the DFTs, multiply them, and take the inverse DFT.
5. 5.
The neighboring outputs overlap in the last
$P-1$
points, so add the overlapping sections together to get the final output
The other method of block convolution is the overlap-save method.
1. 1.
Divide
$x[n]$
into sections of length
$L$
such that each section overlaps the previous by
$P-1$
points
$x_r[n]=x[n+r(L-P+1)-P+1] \qquad 0 \le n \le L-1$
2. 2.
$x_r[n]$
and
$h[n]$
to length
$N\ge L+P-1$
to prevent time domain aliasing.
3. 3.
Compute the DFTs, multiply the coefficients, and compute the inverse DFT.
4. 4.
The first
$P-1$
samples of the output will be incorrect, so we can discard them.
$y[n]=\sum_{r=0}^{\infty}y_r[n-r(L-P+1)+P-1] \qquad y_r[n]= \begin{cases} x_r[n]*h[n] & P-1\le n \le L-1\\ 0 & \text{ else} \end{cases}$

## FFT

The DFT gives us an easy way to do convolutions. Unfortunately naiively, computing it is an
$O(N^2)$
operation because we must sum together
$N$
elements to compute
$N$
different coefficients. Thankfully, there is a fast algorithm which can compute the DFT in
$O(N\log N)$
time so we can compute convolutions quickly.

#### Definition 4

The fast fourier transform is an algorithm which computes the DFT efficiently in
$O(N\log N)$
time.
It works by exploiting properties of the Nth roots of unity.

#### Definition 5

The Nth roots of unity are the complex roots of
$W_N^N=1$
.
$W_N^k=e^{-j\frac{2\pi k}{N}}$
The roots of unity have the following properties.

#### Theorem 1

The Nth roots of unity are conjugate symmetric.
$W_N^{N-kn} = W_N^{-kn} = (W_N^{kn})^\star$

#### Theorem 2

The Nth roots of unity are periodic in N.
$W_{kn} = W_N^{k(n+N)} = W_N^{(k+N)n}$

#### Theorem 3

When squared, the Nth roots of unity become the
$\frac{N}{2}$
th roots of unity.
$W_N^2 = W_\frac{N}{2}$
Using Theorem 1, Theorem 2, Theorem 3, we can take two approaches to the FFT: decimation in time, which splits
$x[n]$
into smaller subsequences, and decimation in frequency which splits
$X[n]$
into smaller subsequences.

### Decimation in Time

The idea here is too break
$x[n]$
into smaller subsequences. We assume that
$N$
is a power of 2 for simplicity.
$X[k]=\sum_{n=0}^{N-1}x[n]W_N^{kn} = \sum_{\text{n even}}x[n]W_N^{kn}+\sum_{\text{n odd}}x[n]W_N^{kn}$
We let
$n=2r$
and
$n=2r+1$
.
\begin{aligned} X[k] &= \sum_{r=0}^{\frac{N}{2}-1}x[2r]W_N^{2rk}+\sum_{r=0}^{\frac{N}{2}-1}x[2r+1]W_N^{k(2r+1)}\\ &= \sum_{r=0}^{\frac{N}{2}-1}x[2r]W_{\frac{N}{2}}^{rk}+W_N^k\sum_{r=0}^{\frac{N}{2}-1}x[2r+1]W_{\frac{N}{2}}^{kr}\\\end{aligned}
These are just the DFTs of the even and odd elements of the signal!
\begin{aligned} \therefore X[k] = G[k] + W_N^kH[k]\end{aligned}
Both
$G$
and
$H$
are
$\frac{N}{2}$
periodic, and notice that
$W_N^{k+\frac{N}{2}}=e^{-j\frac{2\pi}{N}(k+\frac{N}{2})}= -W_N^k.$
This means once we compute
$G[k]$
and
$H[k]$
we can compute
$X[k]$
easily because
$X[k] = G[k]+W_N^kH[k]\qquad X\left[k+\frac{N}{2}\right]=G[k]-W_N^kH[k] \qquad \text{for }k\in\left[0, \frac{N}{2}\right)$
We can continue this relationship recursively downwards. Once we get too
$N=2$
, we can represet this as a simple butterfly operation:
$X[0] = x[0]+x[1] \qquad X[1] = x[0]-x[1].$

### Decimation in Frequency

The decimation in frequency approach is very similar to the decimation in time approach except instead we split the frequency components
\begin{aligned} X[2r] &= \sum_{n=0}^{\frac{N}{2}-1}x[n]W_N^{2rn}+\sum_{n=0}^{\frac{N}{2}-1}x\left[n+\frac{N}{2}\right]W_N^{2r\left(n+\frac{N}{2}\right)}=W_{\frac{N}{2}}^{rn}\sum_{n=0}^{\frac{N}{2}-1}\left(x[n]+x\left[n+\frac{N}{2}\right]\right)\\ X[2r+1] &= W_{\frac{N}{2}}^{rn}\sum_{n=0}^{\frac{N}{2}-1}\left(x[n]-x\left[n+\frac{N}{2}\right]\right)\end{aligned}