Session 26 · Unit 3

Complex Matrices; Fast Fourier Transform


Complex numbers have slipped into the course through eigenvalues, so once and for all this lecture makes the change to complex vectors and matrices. One rule governs everything, whenever you transpose, you also conjugate. That gives the right length, the right inner product, Hermitian matrices, and unitary matrices. Then the most important complex matrix of all, the Fourier matrix, and the factorization behind the FFT that cuts n squared multiplications down to n log n.

Why complex numbers, and the one rule to remember

Complex numbers have slipped into this course already: even a real matrix can have complex eigenvalues, and with them complex eigenvectors. Most of what remains about eigenvalues will be real, but at some point we have to face the question squarely — what changes when the vectors are complex, when the matrices are complex? What is the dot product of two complex vectors?

The answer to every one of those questions is the same small change, and it’s the message of the first half of this lecture: whenever we transpose, we also take complex conjugates.

The second half is the payoff — the most important complex matrix there is, the Fourier matrix, and the idea everyone calls the FFT. The fast Fourier transform is running “in a thousand places” as we speak; it transformed whole industries. And it turns out to be nothing more than a simple matrix factorization — one that cuts the cost of multiplying by an n×nn \times n matrix from n2n^2 down to nlog2nn \log_2 n.

Length and inner product in complex space

Take a vector z\mathbf{z} with components z1,z2,,znz_1, z_2, \ldots, z_n — complex numbers now, so z\mathbf{z} lives in Cn\mathbb{C}^n, complex nn-dimensional space, instead of Rn\mathbb{R}^n.

What’s its length? The old recipe, zTz\mathbf{z}^T\mathbf{z}, is no good. Length squared should be positive, and Strang’s two-component example shows the old recipe failing: take z=(1,i)\mathbf{z} = (1, i) in C2\mathbb{C}^2. Then

zTz=11+ii=11=0,\mathbf{z}^T\mathbf{z} = 1 \cdot 1 + i \cdot i = 1 - 1 = 0,

but that vector certainly doesn’t have length zero. What we really want in each slot is zˉ1z1\bar{z}_1 z_1 — conjugate times the number — because zˉ1z1=z12\bar{z}_1 z_1 = |z_1|^2, the modulus squared, which is what a length ought to be built from. If z1=iz_1 = i, then (i)(i)=+1(-i)(i) = +1: exactly right. So the correct length squared is

z2=zˉTz=z12+z22++zn2.\|\mathbf{z}\|^2 = \bar{\mathbf{z}}^T\mathbf{z} = |z_1|^2 + |z_2|^2 + \cdots + |z_n|^2 .

For (1,i)(1, i): conjugate to get (1,i)(1, -i), multiply, and get 1+1=21 + 1 = 2. Length 2\sqrt{2} — not the zero the unconjugated formula gave.

The inner product definition is forced on us: once the length is zHz\mathbf{z}^{\mathrm{H}}\mathbf{z}, the inner product has to match it.

Hermitian and unitary: the complex dictionary

Two more words need updating — the book gives a little dictionary translating between the real case, Rn\mathbb{R}^n, and the complex case, Cn\mathbb{C}^n.

Symmetric becomes Hermitian. For real matrices, symmetry means AT=AA^T = A. That’s no good if AA is complex; the right complex version is: flip across the diagonal and take conjugates. A matrix with AH=AA^{\mathrm{H}} = A is called a Hermitian matrix. On the diagonal, the entries had better be real — flipping leaves them in place, so conjugating must leave them alone. Off the diagonal, entries pair up as conjugates:

A=[23+i3i5]A = \begin{bmatrix} 2 & 3+i \\ 3-i & 5 \end{bmatrix}

is Hermitian: the 3+i3+i above the diagonal must meet a 3i3 - i below it. These matrices are the complex heirs of symmetric matrices, and they inherit the good properties: real eigenvalues and perpendicular eigenvectors.

Orthogonal becomes unitary. But what does perpendicular mean now? For an orthonormal basis q1,,qn\mathbf{q}_1, \ldots, \mathbf{q}_n, the test used to be qiTqj\mathbf{q}_i^T\mathbf{q}_j; now we must conjugate too:

qiHqj={0ij1i=j\mathbf{q}_i^{\mathrm{H}}\mathbf{q}_j = \begin{cases} 0 & i \neq j \\ 1 & i = j \end{cases}

— right angles measured in complex nn-dimensional space, unit lengths measured with the conjugate. Put those columns into a matrix QQ and the matrix statement, which used to be QTQ=IQ^TQ = I, becomes QHQ=IQ^{\mathrm{H}}Q = I. A square matrix with orthonormal columns in this complex sense gets a new name: a unitary matrix — just like an orthogonal matrix, with the word signaling that the entries may be complex.

The Fourier matrix

Now the substance: the most famous complex matrix, one of these unitary-type matrices with orthogonal columns, named after Fourier because it is the Fourier transform. For this half hour Strang moves “from the math department to EE” — electrical engineers start counting at zero, and for this matrix they’re probably right. So rows and columns are numbered 00 through n1n-1, and the entries could not be simpler:

(Fn)ij=Wij,i,j=0,1,,n1,(F_n)_{ij} = W^{ij}, \qquad i, j = 0, 1, \ldots, n-1,

the exponent is the row number times the column number. Column zero is all ones (W0W^0); column one holds the powers 1,W,W2,,Wn11, W, W^2, \ldots, W^{n-1}; column two holds the powers of W2W^2; and so on. Every entry is a power of one special number — none are zero, this is a full matrix, and it’s symmetric (in the old, not-quite-perfect AT=AA^T = A sense, since these entries are complex).

What is WW? It’s the number whose nn-th power is one:

W=e2πi/n=cos2πn+isin2πn.W = e^{2\pi i/n} = \cos\frac{2\pi}{n} + i\sin\frac{2\pi}{n}.

But forget the rectangular coordinates — “it’s never good to work with the real and imaginary parts when we’re taking powers.” In the exponential form, the tenth power is instantly e20πi/ne^{20\pi i/n}. Geometrically WW sits on the unit circle, one nn-th of the full way around. For n=6n = 6 it’s at 60°60°, and its powers march around the circle — W2W^2 at 120°120°, then W3W^3, W4W^4, W5W^5, and W6W^6 coming back to 11: the six sixth roots of one, with WW the primitive one.

Orthogonal columns make the inverse easy

Why is this matrix so remarkable? First: its columns are orthogonal — but only if you remember to conjugate. Try columns one and three of F4F_4 (in EE counting): (1,i,1,i)(1, i, -1, -i) and (1,i,1,i)(1, -i, -1, i). Without conjugating, the products are 1,i2,1,i21, -i^2, 1, -i^2 — four ones, not zero, and the columns look anything but perpendicular. Nevertheless they are orthogonal. Conjugate the first vector — the ii becomes i-i, the i-i becomes ii — and the inner product is 11+11=01 - 1 + 1 - 1 = 0. Right angles in the complex sense.

The columns aren’t quite orthonormal — each has length squared 1+1+1+1=41+1+1+1 = 4, so length 22 — but divide by 22 and 12F4\frac{1}{2}F_4 has genuinely orthonormal columns. Then, exactly like an orthogonal matrix, the inverse is immediate:

(12F4)H(12F4)=Ithe inverse is the conjugate transpose.\left(\tfrac{1}{2}F_4\right)^{\mathrm{H}}\left(\tfrac{1}{2}F_4\right) = I \quad\Longrightarrow\quad \text{the inverse is the conjugate transpose.}

So anything good we learn about F4F_4, we know a similar fact about its inverse. Fourier knew that. What Fourier didn’t notice — Gauss noticed it but didn’t make a point of it — is that this matrix is so special it can be broken into pieces with lots of zeros, so that multiplying by it, or by its inverse, becomes very, very fast.

The fast Fourier transform

Here is the idea. F64F_{64} has a neat connection to F32F_{32}, half as big (F6F_6 to F3F_3, F8F_8 to F4F_4 — same story). The link is in the WW‘s: the WW for F64F_{64} is e2πi/64e^{2\pi i/64}, one 64th of the way around the circle; square it — double the angle — and you get e2πi/32e^{2\pi i/32}, exactly the WW for F32F_{32}. That’s the hope, and here’s the factorization that realizes it:

F64  =  [IDID][F3200F32]PF_{64} \;=\; \begin{bmatrix} I & D \\ I & -D \end{bmatrix} \begin{bmatrix} F_{32} & 0 \\ 0 & F_{32} \end{bmatrix} P

Read it right to left. PP is a simple odd–even permutation matrix: it takes the even-numbered components of the vector first — x0,x2,x4,x_0, x_2, x_4, \ldots — and then the odds — x1,x3,x5,x_1, x_3, x_5, \ldots That’s hard-wired in the computer, essentially instantaneous. The middle matrix does a size-32 Fourier transform separately on the even part and the odd part; its two big zero blocks are the key, because half the matrix costs nothing. The left matrix puts the pieces back together, and its only real content is DD, the diagonal matrix

D=diag(1,W,W2,,W31),D = \mathrm{diag}\left(1,\, W,\, W^2,\, \ldots,\, W^{31}\right),

powers of WW. Multiplying by II costs nothing; multiplying by the diagonal DD costs just 32 multiplications. So the count drops from 64264^2 to

2×322+32(two half-size transforms, plus the fix-up).2 \times 32^2 + 32 \quad\text{(two half-size transforms, plus the fix-up)}.

But why stop? Recursion is the key word. Each F32F_{32} breaks into two copies of F16F_{16} with its own II-and-DD fix-up and its own size-32 odd–even permutation. The stacked permutations sort the vector into even-evens (x0,x4,x8,x_0, x_4, x_8, \ldots), even-odds (x2,x6,x10,x_2, x_6, x_{10}, \ldots), odd-evens, and odd-odds — four pieces that get multiplied separately by F16F_{16}. The 2×3222 \times 32^2 gives way to 2(2×162+16)2(2 \times 16^2 + 16), plus the original 32. Keep going: the transforms in the middle shrink to two-point, then one-point transforms — the count in the middle “goes down to zip” — while cheap factors pile up on both sides: permutations on the right, II‘s and DD‘s on the left. From 64 to 32 to 16 to 8 to 4 to 2 to 1 is six stepslog264\log_2 64 — and each fix-up level costs about 32 multiplications, so the final count is 6×326 \times 32: that is, log264\log_2 64 times 1264\tfrac{1}{2} \cdot 64.

Feel the difference at a typical size, n=210=1024n = 2^{10} = 1024. Then n2n^2 is over a million — 1024×10241024 \times 1024. The new count is 1024×102=5×10241024 \times \tfrac{10}{2} = 5 \times 1024. The calculation shrinks by a factor of about 200, just from factoring the matrix properly: 200 Fourier transforms where before we could do one — and in real scientific computing, Fourier transforms are happening all the time.

And notice what the whole thing hinged on: a special matrix with orthonormal columns. Next lecture it’s back to real numbers, and to the matrices you see most in applications — positive definite matrices.

Problems

Work these with the one rule in hand — transpose means conjugate-transpose.

Problem 26.1 Complex length and inner product

Let z=[21i]\mathbf{z} = \begin{bmatrix} 2 \\ 1 - i \end{bmatrix} and y=[i1+i]\mathbf{y} = \begin{bmatrix} i \\ 1 + i \end{bmatrix} in C2\mathbb{C}^2.

(a) Compute zTz\mathbf{z}^T\mathbf{z} and zHz\mathbf{z}^{\mathrm{H}}\mathbf{z}, and explain which one is the true length squared.

(b) Compute the inner product yHz\mathbf{y}^{\mathrm{H}}\mathbf{z}.

Show solution

(a) Without conjugating: zTz=22+(1i)2=4+(12i+i2)=42i\mathbf{z}^T\mathbf{z} = 2^2 + (1-i)^2 = 4 + (1 - 2i + i^2) = 4 - 2i — a complex number, which cannot be a length squared. With conjugating:

zHz=22+1i2=4+(12+(1)2)=6.\mathbf{z}^{\mathrm{H}}\mathbf{z} = |2|^2 + |1-i|^2 = 4 + (1^2 + (-1)^2) = 6.

The true length squared is 66, so z=6\|\mathbf{z}\| = \sqrt{6}. Length squared must be a positive real number, and only the Hermitian form guarantees that.

(b) Conjugate y\mathbf{y} first: yˉ=(i,  1i)\bar{\mathbf{y}} = (-i,\; 1 - i). Then

yHz=(i)(2)+(1i)(1i)=2i+(12i1)=4i.\mathbf{y}^{\mathrm{H}}\mathbf{z} = (-i)(2) + (1-i)(1-i) = -2i + (1 - 2i - 1) = -4i.

The inner product of two complex vectors is usually complex — that’s expected.

Problem 26.2 Building a Hermitian matrix

For which values of aa, bb, cc is

A=[a42ibc]A = \begin{bmatrix} a & 4 - 2i \\ b & c \end{bmatrix}

a Hermitian matrix? For your answer, verify that zHAz\mathbf{z}^{\mathrm{H}} A \mathbf{z} is real for z=[1i]\mathbf{z} = \begin{bmatrix} 1 \\ i \end{bmatrix} when a=1a = 1, c=3c = 3.

Show solution

Hermitian means AH=AA^{\mathrm{H}} = A: the diagonal entries must equal their own conjugates, so aa and cc must be real (any real numbers), and the off-diagonal entries must be conjugates of each other, so b=42i=4+2ib = \overline{4 - 2i} = 4 + 2i.

Check with a=1a = 1, c=3c = 3, z=(1,i)\mathbf{z} = (1, i): first

Az=[142i4+2i3][1i]=[1+(42i)i4+2i+3i]=[3+4i4+5i].A\mathbf{z} = \begin{bmatrix} 1 & 4-2i \\ 4+2i & 3 \end{bmatrix}\begin{bmatrix} 1 \\ i \end{bmatrix} = \begin{bmatrix} 1 + (4-2i)i \\ 4+2i + 3i \end{bmatrix} = \begin{bmatrix} 3 + 4i \\ 4 + 5i \end{bmatrix}.

Then zH(Az)=(1)(3+4i)+(i)(4+5i)=3+4i4i+5=8\mathbf{z}^{\mathrm{H}}(A\mathbf{z}) = (1)(3+4i) + (-i)(4+5i) = 3 + 4i - 4i + 5 = 8 — real, as it must be for a Hermitian matrix.

Problem 26.3 Fourier matrix by hand

Write down WW for n=4n = 4 and use it to build F4F_4. Then verify that columns 11 and 22 (EE counting: the columns (1,i,1,i)(1, i, -1, -i) and (1,1,1,1)(1, -1, 1, -1)) are orthogonal, and use orthogonality to write down F41F_4^{-1}.

Show solution

W=e2πi/4=iW = e^{2\pi i/4} = i, so (F4)jk=ijk(F_4)_{jk} = i^{jk} gives

F4=[11111i1i11111i1i].F_4 = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & i & -1 & -i \\ 1 & -1 & 1 & -1 \\ 1 & -i & -1 & i \end{bmatrix}.

Orthogonality of columns 1 and 2 — conjugate the first: (1,i,1,i)(1, -i, -1, i), then

(1)(1)+(i)(1)+(1)(1)+(i)(1)=1+i1i=0.(1)(1) + (-i)(-1) + (-1)(1) + (i)(-1) = 1 + i - 1 - i = 0. \checkmark

Each column has length squared 44, so (12F4)H(12F4)=I\left(\tfrac{1}{2}F_4\right)^{\mathrm{H}}\left(\tfrac{1}{2}F_4\right) = I, giving F4HF4=4IF_4^{\mathrm{H}} F_4 = 4I and

F41=14F4H=14[11111i1i11111i1i].F_4^{-1} = \tfrac{1}{4}F_4^{\mathrm{H}} = \tfrac{1}{4}\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -i & -1 & i \\ 1 & -1 & 1 & -1 \\ 1 & i & -1 & -i \end{bmatrix}.

The inverse transform is just the conjugate transform, scaled — replace ii by i-i and divide by 44.

Problem 26.4 Counting the FFT's savings

(a) Using the factorization of FnF_n into two copies of Fn/2F_{n/2} plus a diagonal fix-up of size n/2n/2, write the multiplication count for one level of the recursion when n=16n = 16.

(b) The full FFT costs 12nlog2n\tfrac{1}{2}n\log_2 n multiplications. For n=212=4096n = 2^{12} = 4096, compare this with n2n^2 and give the speedup factor.

Show solution

(a) One level replaces the 162=25616^2 = 256 multiplications by two transforms of size 8 plus a diagonal DD with 8 entries:

2×82+8=128+8=136.2 \times 8^2 + 8 = 128 + 8 = 136.

Already nearly a factor of 2, and the recursion keeps going on each F8F_8.

(b) Direct: n2=40962=16,777,216n^2 = 4096^2 = 16{,}777{,}216. FFT: 12(4096)(log24096)=12(4096)(12)=24,576\tfrac{1}{2}\, (4096)(\log_2 4096) = \tfrac{1}{2}(4096)(12) = 24{,}576. The speedup is

n212nlog2n=2nlog2n=2(4096)12683.\frac{n^2}{\tfrac{1}{2}n\log_2 n} = \frac{2n}{\log_2 n} = \frac{2(4096)}{12} \approx 683.

About 680 Fourier transforms for the price of one — the same effect as Strang’s factor of 200 at n=1024n = 1024, but larger because the gap widens as nn grows.

Problem 26.5 Roots of unity on the circle

Let W=e2πi/6W = e^{2\pi i/6}, the primitive sixth root of one. (a) Locate W,W2,,W6W, W^2, \ldots, W^6 on the unit circle by their angles. (b) Show that W2W^2 is the number that would serve as the "WW" for F3F_3. (c) Compute 1+W+W2+W3+W4+W51 + W + W^2 + W^3 + W^4 + W^5 and explain what this says about the columns of F6F_6.

Show solution

(a) WW is at 60°60°; the powers double, triple, … the angle: W2W^2 at 120°120°, W3W^3 at 180°180° (that’s 1-1), W4W^4 at 240°240°, W5W^5 at 300°300°, and W6W^6 back at 0°, equal to 11. Six equally spaced points — the six sixth roots of one.

(b) Squaring doubles the angle: W2=e2πi2/6=e2πi/3W^2 = e^{2\pi i \cdot 2/6} = e^{2\pi i/3}, which is one third of the way around — exactly the primitive cube root of one that builds F3F_3. This is the connection (Wn2=Wn/2W_n^2 = W_{n/2}, here in the 636 \to 3 form) that powers the FFT recursion.

(c) The sum is a geometric series: k=05Wk=W61W1=11W1=0\displaystyle\sum_{k=0}^{5} W^k = \frac{W^6 - 1}{W - 1} = \frac{1 - 1}{W - 1} = 0. (Geometrically, six equally spaced unit vectors balance out.) But this sum is precisely the inner product of column 0 of F6F_6 (all ones, its own conjugate) with column 1 (the powers of WW) — so it verifies that those two columns of the Fourier matrix are orthogonal.