A signal is usually stored as a long list of samples, but that list is rarely its most economical description. Choose the right basis — the right set of axes to measure it against — and nearly all of those numbers collapse to zero, leaving a sparse handful that describes the signal with almost no loss.

This post builds that idea from first principles, on a small signal.

1. A signal is a high-dimensional vector

Start with a real-world signal: a sound wave, a temperature trace, a row of pixel intensities. Almost any measurement unfolds over time or space.

A smooth periodic waveform plotted against time, oscillating a few times across one second.

When we measure the signal, we sample its values at evenly spaced intervals — here of them.

The same waveform drawn as 64 discrete stems, one per sample index.

Stack those samples into a column and the signal becomes a single vector:

The entire signal is a single point in an -dimensional space. Each sample is its extent along one dimension. Our signal is one point in .

2. Changing coordinates

What happens if we change the coordinates — the basis vectors — we measure against?

Here is a two-dimensional vector measured against two sets of axes: the standard basis in blue, and a rotated basis in red. Drag the slider. The arrow never moves. Only the numbers we measure it with do.

A vector measured against a standard basis in blue and a basis rotated 30 degrees in red, with dashed lines dropping to each basis to show the two sets of coordinates.

A vector is a geometric object — an arrow that exists before any axes are chosen. Selecting a basis only fixes the rulers we measure it against. Collect two orthonormal basis vectors as the columns of a matrix,

and that matrix is the transformation — here a rotation of the axes. The same vector acquires new coordinates :

Because the basis is orthonormal, : the change of basis is a reversible rotation that discards nothing.

The same move in dimensions

Nothing about this is special to two dimensions. Choose any orthonormal basis of — unit vectors meeting at right angles — and collect them as the columns of a matrix . Just as turned a vector’s standard coordinates into rotated ones, gives the same vector new coordinates :

Reading the product column by column, the signal is just a weighted sum of the basis vectors , each scaled by its coordinate . Orthonormality () keeps this a pure rotation: nothing is lost, and it reverses exactly through .

Parseval's theorem

An orthonormal rotation preserves length, — the signal carries the same energy in every such basis.

3. Bases of waves: Fourier and the DCT

For natural signals the most useful rotations use waves of increasing frequency as their axes. This is just another orthonormal basis, so its coordinates describe the same signal vector as faithfully as the raw samples do. We have only rotated into a more revealing frame.

Fourier

The Fourier basis writes a signal as a sum of complex exponentials of increasing frequency,

where Euler’s formula unpacks each exponential into a cosine and a sine. Paired with the fast Fourier transform, this single decomposition became the backbone of modern signal processing — audio and image coding, communications, filtering, and spectral analysis all live in it.

The DCT

Splitting each complex exponential into its cosine and sine parts gives a real Fourier basis: a constant DC term, then a normalized cosine/sine pair at each frequency ,

The discrete cosine transform (DCT), introduced by Nasir Ahmed in 1974, goes one step further and keeps only the cosines. An even reflection of the signal at its edges avoids the artificial jump a periodic basis imposes at the boundary, and its energy-compacting cosines made it the workhorse behind JPEG, MPEG, and MP3 — among the most widely used transforms in computing. Each column is a single cosine of rising frequency,

with the column normalized by and the rest by .

A coordinate asks how much of wave is present in the signal. Each column of — Fourier or DCT — is one wave; the first six of each are plotted below.

Two rows of six small plots. The top row shows the first six Fourier basis vectors, the bottom row the first six DCT basis vectors, each a cosine or sine of increasing frequency.

4. Building the signal one wave at a time

A change of basis is a recipe for rebuilding the signal: stack the basis waves as the columns of , weight each by its coordinate , and sum.

The signal drawn vertically, equal to the sum of its three largest weighted Fourier basis vectors, plus an ellipsis for the rest.

The same statement as matrices: a tall column , the square basis , and the coordinate column .

The matrix equation as three colour-mapped strips: the signal x, the 64 by 64 basis matrix Psi, and the coordinate vector s.

5. The payoff: the right basis is sparse

Below is the same -dimensional signal expressed in three bases. In the standard basis all coordinates matter. Rotated into the DCT, the energy concentrates in a few low-frequency coordinates. Rotated into the Fourier basis — exactly matched to this periodic signal — all but a handful of coordinates are zero:

Same vector, same information, now described by numbers. That is sparsity. Beneath each panel is the number of coordinates needed to hold of the signal’s energy.

Three stem plots side by side showing the signal's coordinates in the standard, DCT and Fourier bases. The standard basis needs many coordinates, the DCT far fewer, and the Fourier basis only a handful.

Those few nonzero coordinates are all it takes. Adding the Fourier waves back in order of importance — and because this signal is only a few Fourier cosines — a handful of terms does not merely approximate it. It reproduces it exactly:

Four panels showing the reconstruction with r equal to one, two, three and four terms. The error falls to zero percent by four terms.

6. Keep the top

When most coordinates are near zero, discard them. Keep the largest, set the rest to zero to form , and rotate back:

In the Fourier basis the error collapses to zero at ; in the DCT it fades more gradually. The basis that matches the signal wins.

The reconstruction from the top four Fourier coordinates overlaid on the original signal, beside a stem plot of the coordinates with the four kept ones highlighted.

That is the whole idea behind transform coding. JPEG does exactly this to blocks of pixels in the DCT basis; MP3 does it to short windows of audio. The work is in choosing a basis where natural signals are sparse — and in the next post, in what happens when you don’t get to choose which coordinates you measure.


The figures and numerics here are generated from notebooks/01_signal_is_a_vector.py; the transforms are ported to TypeScript and parity-tested against scipy.