---
title: Unitary matrices and the DFT
heading: The Fourier matrix, a change to a basis of tones
eyebrow: A7 · Lesson 51 · The Fourier matrix
xp: 40
---

::: hook
A block of $N$ samples is a vector in $\mathbb{C}^N$, and so far its natural coordinates have been the samples themselves. A different basis is far more useful for signals: $N$ sampled complex tones, one for each frequency that fits a whole number of cycles in the block. Changing to that basis is the **discrete Fourier transform**, and its matrix is the most important complex matrix in engineering. Its columns are perpendicular, which makes it a scaled **unitary** matrix: its inverse is just its conjugate transpose, and it keeps energy the same in both bases.
:::

::: play
- The stems are column $k$ of the 8-point Fourier matrix: the real part (a sampled cosine) and the imaginary part (a sampled negative sine).
- Step $k$ from 0 to 7. Column 0 is constant, column 1 makes one cycle across the block, column 4 alternates sign every sample.
- Compare columns $k$ and $8 - k$: their real parts are the same, and their imaginary parts are opposite.
:::

```sim plot
view: graph
x: n = 0..7
y: value = -1.2..1.2
slider: k = 0..7 step 1 = 1
plot: cos(2*pi*k*n/8) | stems | label: real part
plot: -sin(2*pi*k*n/8) | stems | color: ch2 | label: imaginary part
readout: cycles across the block = k | digits: 1
```

::: predict
## How are columns $k$ and $8 - k$ of the 8-point Fourier matrix related?

- [x] Each is the complex conjugate of the other
- [ ] They're equal
- [ ] They're negatives of each other
- [ ] They're unrelated

::: reveal
Conjugates. $e^{-2\pi j(8 - k)n/8} = e^{-2\pi jn}e^{2\pi jkn/8} = e^{2\pi jkn/8}$, since $e^{-2\pi jn} = 1$ for whole $n$. Sampled, a tone at $8 - k$ cycles per block is indistinguishable from one at $-k$. That's why the DFT of a real signal has $X_{N-k} = \overline{X_k}$, and only half of it carries new information.
:::
:::

::: nameit
## Complex inner products

For complex vectors, length uses the conjugate: $|\mathbf{x}|^2 = \sum|x_i|^2 = \mathbf{x}^H\mathbf{x}$, where $\mathbf{x}^H$ is the **conjugate transpose**. The inner product is $\mathbf{x}^H\mathbf{y}$, and $\mathbf{x}$ and $\mathbf{y}$ are perpendicular when it's zero. Without the conjugate, $(1, j)$ would have length zero.

## Hermitian and unitary matrices

- **Hermitian:** $A^H = A$. The complex version of symmetric: real eigenvalues, perpendicular eigenvectors.
- **Unitary:** $U^HU = I$. The complex version of orthogonal: the columns are orthonormal, $U^{-1} = U^H$, and $|U\mathbf{x}| = |\mathbf{x}|$ for every $\mathbf{x}$. Every eigenvalue has magnitude 1.

## The Fourier matrix

With $w = e^{-2\pi j/N}$, the $N \times N$ **Fourier matrix** has entries $F_{kn} = w^{kn}$, for $k, n = 0, \ldots, N - 1$. The DFT of a sample vector $\mathbf{x}$ is $\mathbf{X} = F\mathbf{x}$:

$$X_k = \sum_{n=0}^{N-1}x_ne^{-2\pi jkn/N}$$

Its columns are perpendicular, each with length squared $N$, so $F^HF = NI$:
- the inverse DFT is $\mathbf{x} = \frac1NF^H\mathbf{X}$;
- **Parseval's theorem:** $\sum|x_n|^2 = \frac1N\sum|X_k|^2$;
- $\frac{1}{\sqrt N}F$ is unitary.

## Circulant matrices

A **circulant** matrix has each row equal to the one above shifted one place right, wrapping around. Multiplying by it is a circular convolution. Every circulant matrix has the Fourier columns as eigenvectors, and its eigenvalues are the DFT of its first column. That's the convolution theorem: in the Fourier basis, filtering is a diagonal matrix, one gain per frequency.
:::

::: example
## Find the 4-point DFT of $\mathbf{x} = (1, 2, 3, 4)$ and check Parseval's theorem.

::: solution
1. **The DFT matrix.** For $N = 4$, $w = e^{-j\pi/2} = -j$, and
   $$F = \begin{bmatrix}1 & 1 & 1 & 1\\1 & -j & -1 & j\\1 & -1 & 1 & -1\\1 & j & -1 & -j\end{bmatrix}$$
2. **Multiply.**
   $$F\mathbf{x} = \begin{bmatrix}10\\-2 + 2j\\-2\\-2 - 2j\end{bmatrix}$$
3. **Read the entries.** $X_0 = 10$ is the sum, $X_2 = 1 - 2 + 3 - 4 = -2$, and $X_3$ is the conjugate of $X_1$, as it must be for real samples.
4. **Parseval's theorem.** The energies match:
   $$\begin{aligned} \sum|x_n|^2 &= 1 + 4 + 9 + 16 \\ &= 30 \\ \tfrac14\sum|X_k|^2 &= \tfrac14(100 + 8 + 4 + 8) \\ &= 30 \end{aligned}$$

**Answer:** the DFT is $(10, -2 + 2j, -2, -2 - 2j)$, and both sides of Parseval's theorem give 30.
:::
:::

::: example
## Check that $U = \frac{1}{\sqrt2}\begin{bmatrix}1 & 1\\j & -j\end{bmatrix}$ is unitary.

::: solution
1. **Column lengths.** Each column has length squared
   $$\tfrac12(1 + |j|^2) = 1$$
2. **Inner product of the columns.** It uses the conjugate of the first:
   $$\begin{aligned} &\tfrac12\left(1 \cdot 1 + \overline{j} \cdot (-j)\right) \\ &= \tfrac12(1 + j^2) \\ &= 0 \end{aligned}$$
   So $U^HU = I$.
3. **Why the conjugate matters.** Without it, the second calculation would give $\frac12(1 - j^2) = 1$, and the perpendicular columns would look parallel.

**Answer:** $U^HU = I$, so $U$ is unitary.
:::
:::

::: example
## A 4-point circular two-sample average has first column $\left(\tfrac12, \tfrac12, 0, 0\right)$. What are its gains at the four DFT frequencies?

::: solution
1. **Eigenvalues of a circulant.** They are the DFT of its first column:
   $$H_k = \tfrac12(1 + w^k), \quad w = -j$$
2. **The four gains.**
   $$\begin{aligned} H_0 &= 1 \\ H_1 &= \tfrac12(1 - j) \\ H_2 &= 0 \\ H_3 &= \tfrac12(1 + j) \end{aligned}$$
   The magnitudes are 1, 0.707, 0 and 0.707.
3. **What the filter does.** A constant passes untouched, the alternating signal $(1, -1, 1, -1)$ is wiped out, and the in-between frequencies lose 3 dB: a two-sample average is a low-pass filter.

**Answer:** the gains are 1, 0.707, 0 and 0.707 in magnitude, a low-pass filter.
:::
:::

::: check
kind: parts
given: a = 1 | 3; b = 2 | 5; c = 4 | 6; d = 1 | 8

## Find the 4-point DFT of $(\given{a}, \given{b}, \given{c}, \given{d})$.

::: part
answer: a + b + c + d
tolerance: 0.5%

### What is $X_0$?

::: misses
- [any] Every entry of row 0 is 1.
:::
:::

::: part
answer: a - b + c - d
tolerance: 0.5%

### What is $X_2$?

::: misses
- [any] Row 2 is $(1, -1, 1, -1)$.
:::
:::
:::

::: check
given: N = 4 | 8 | 16; E = 64 | 128
answer: E/N
tolerance: 0.5%

## An $N$ = {N}-point DFT has $\sum|X_k|^2$ = {E}. What is $\sum|x_n|^2$?

::: right
Right. Parseval: $\frac1N\sum|X_k|^2$ = {answer}.
:::

::: misses
- [E] The unscaled DFT multiplies energy by $N$.
- [E*N] Divide by $N$.
- [any] Not yet. $F^HF = NI$.
:::
:::

::: check
given: L = 2 | 5 | 13
answer: L
tolerance: 0.5%

## $U$ is unitary and $|\mathbf{x}|$ = {L}. What is $|U\mathbf{x}|$?

::: right
Right. Unitary matrices keep lengths: {answer}.
:::

::: misses
- [L^2] $|U\mathbf{x}|^2 = |\mathbf{x}|^2$, so the lengths themselves are equal.
- [any] Not yet. $|U\mathbf{x}|^2 = \mathbf{x}^HU^HU\mathbf{x} = \mathbf{x}^H\mathbf{x}$.
:::
:::

::: check
given: N = 8 | 16; k = 1 | 3
answer: abs(cos(pi*k/N))
tolerance: 0.5%

## An $N$ = {N}-point circular two-sample average has gains $H_k = \frac12(1 + w^k)$. What is $|H_k|$ for $k$ = {k}?

::: right
Right. $\left|\frac12(1 + e^{-2\pi jk/N})\right| = |\cos(\pi k/N)|$ = {answer}.
:::

::: misses
- [cos(2*pi*k/N)] Factor out $e^{-\pi jk/N}$: the half angle appears.
- [any] Not yet. $1 + e^{-j\theta} = e^{-j\theta/2} \cdot 2\cos(\theta/2)$.
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 3 | 5

## A real 4-point signal $(\given{a}, \given{b}, \given{a}, \given{b})$ repeats every two samples.

::: part
answer: 2*(a + b)
tolerance: 0.5%

### What is $X_0$?

::: misses
- [a + b] Add all four samples.
- [any] The sum of the samples.
:::
:::

::: part
answer: 2*(a - b)
tolerance: 0.5%

### What is $X_2$?

::: misses
- [any] $a - b + a - b$. ($X_1$ and $X_3$ are zero: the signal has no content at one cycle per block.)
:::
:::
:::

::: check
kind: derivation
vars: a = -2..2, d = -2..2, b = 0..2, c = 0..2

## Find the eigenvalues of the Hermitian matrix $\begin{bmatrix}a & b + jc\\b - jc & d\end{bmatrix}$.

::: step
answer: a*d - b^2 - c^2

### What is its determinant? (Note $(b + jc)(b - jc) = b^2 + c^2$.)
:::

::: step
answer: (a + d)/2 + sqrt(((a - d)/2)^2 + b^2 + c^2)

### What is the larger eigenvalue?
:::

::: right
Right. The square root is of a sum of squares, so both eigenvalues are real, as they are for every Hermitian matrix.
:::
:::

::: explain
## Why is it useful that the Fourier matrix's columns are perpendicular?

::: model
Perpendicular columns mean each coordinate in the new basis can be found on its own, by an inner product with one column, without solving a system: $X_k$ is just the correlation of the signal with tone $k$. The same property makes the inverse almost free ($F^{-1} = \frac1NF^H$), keeps energy accounted for exactly (Parseval), and means that changing one frequency's coefficient changes the signal only along that tone. A skewed basis would give coordinates that depend on every other coordinate and an inverse that amplifies rounding errors; the Fourier basis, like any orthogonal one, has condition number 1.
:::
:::

::: practice

::: check
given: N = 2..64 int; E = 1..1000
answer: E/N
tolerance: 0.5%

## Sample energy from $\sum|X_k|^2$ = {E} for an {N}-point DFT?

::: misses
- [any] Divide by $N$.
:::
:::

::: check
given: N = 4..64 int; k = 1..3 int
answer: abs(cos(pi*k/N))
tolerance: 0.5%

## Gain of the {N}-point two-sample average at bin {k}?

::: misses
- [any] $|\cos(\pi k/N)|$.
:::
:::
:::
