AnyLearn
All lessons
Mathintermediate

The Frequency Domain: Why Everything Is Sinusoids

The same signal can be written as a function of time or as a recipe of frequencies. This lesson explains why sinusoids in particular get that job, builds the discrete Fourier transform, and shows how the FFT turned a quadratic computation into one you can run on a million samples in a fraction of a second.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 10

Two descriptions of the same thing

A recording is a list of numbers, one per instant. That is the time domain, and it is the natural way to store a signal and almost the worst way to reason about one. Nothing in a waveform tells you there is a 440 Hz note under a 60 Hz hum.

The frequency domain rewrites the identical signal as a recipe: how much of each frequency it contains, and with what phase. No information is added or lost. It is a change of coordinates, exactly like describing a point by latitude and longitude instead of by distance and bearing.

Key idea: Every question in this course, filtering, sampling, compression, noise removal, is easy in one of the two domains and awkward in the other. The skill being taught is knowing which one you are in and how to move.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. Two descriptions of the same thing

A recording is a list of numbers, one per instant. That is the time domain, and it is the natural way to store a signal and almost the worst way to reason about one. Nothing in a waveform tells you there is a 440 Hz note under a 60 Hz hum.

The frequency domain rewrites the identical signal as a recipe: how much of each frequency it contains, and with what phase. No information is added or lost. It is a change of coordinates, exactly like describing a point by latitude and longitude instead of by distance and bearing.

Key idea: Every question in this course, filtering, sampling, compression, noise removal, is easy in one of the two domains and awkward in the other. The skill being taught is knowing which one you are in and how to move.

2. Fourier's claim

Joseph Fourier made the claim in 1822, in his treatise on the propagation of heat: any reasonable periodic function can be written as a sum of sines and cosines at integer multiples of its fundamental frequency.

f(t)=a02+n=1(ancos(nωt)+bnsin(nωt))f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \left( a_n \cos(n\omega t) + b_n \sin(n\omega t) \right)

Contemporaries including Lagrange objected, and they were not being obtuse: the claim is that a sum of perfectly smooth curves can reproduce a square wave with a vertical edge in it. It can, in the limit, though the way it fails on the way there matters and shows up again in the filters lesson.

Definition: The coefficients ana_n and bnb_n are the spectrum. Finding them is analysis; adding the terms back up is synthesis. A synthesiser and a spectrum analyser are the same machine run in opposite directions.

3. Why sinusoids and not something else

You could decompose a signal onto square waves, wavelets, or any other basis, and people do. Sinusoids get special treatment for a structural reason, not an aesthetic one.

Feed a sinusoid into any linear, time-invariant system, an amplifier, a room, a cable, a filter, and what comes out is a sinusoid at the same frequency. Only the amplitude and the phase change. No other family of signals survives an arbitrary LTI system so cleanly; feed in a square wave and you generally get something that is no longer square.

Key idea: Sinusoids are the eigenfunctions of linear time-invariant systems. That is why the frequency domain turns the hard operation, convolution, into the easy one, multiplication. Every result in the rest of this course is downstream of that single fact.

4. The discrete Fourier transform

Real signals are finite lists of samples, so the practical tool is the discrete Fourier transform. For NN samples x0xN1x_0 \dots x_{N-1}:

Xk=n=0N1xne2πikn/NX_k = \sum_{n=0}^{N-1} x_n \, e^{-2\pi i k n / N}

Each XkX_k is a complex number obtained by multiplying the signal against a complex sinusoid at bin frequency kk and summing. Large magnitude means the signal has a lot of that frequency in it.

The complex exponential is doing the work of the sine and cosine at once, via Euler's identity eiθ=cosθ+isinθe^{i\theta} = \cos\theta + i\sin\theta. The real part correlates against the cosine, the imaginary part against the sine, and the pair carries both how much and when.

  • Xk|X_k| is the magnitude: how much of that frequency is present
  • arg(Xk)\arg(X_k) is the phase: where in its cycle that component starts.

5. Reading a spectrum in ten lines

import numpy as np

fs = 8000                      # sample rate, Hz
N = 8000                       # one second of audio
t = np.arange(N) / fs
x = np.sin(2*np.pi*440*t) + 0.5*np.sin(2*np.pi*1000*t)

X = np.fft.rfft(x)             # real input -> half spectrum
freqs = np.fft.rfftfreq(N, 1/fs)
mag = np.abs(X) / (N/2)        # scale to amplitude

peaks = np.argsort(mag)[-2:]
print(freqs[peaks], mag[peaks])  # [1000. 440.] [0.5 1.0]

Two tones go in, two peaks come out at the right frequencies with the right amplitudes. rfft is used rather than fft because a real-valued signal has a symmetric spectrum, so the upper half is redundant and computing it wastes half the work.

6. What sets your frequency resolution

The bins are evenly spaced, and the spacing follows from the two numbers you chose:

Δf=fsN\Delta f = \frac{f_s}{N}

Since N/fsN / f_s is just the duration TT of the recording, this is the same as Δf=1/T\Delta f = 1/T. Resolution is set by how long you listened, not by how fast you sampled.

Gotcha: To separate two tones 1 Hz apart you need at least one second of signal, whatever your sample rate. Recording at 192 kHz instead of 48 kHz raises the highest frequency you can see, four times higher, and does nothing at all for your ability to tell 440 Hz from 441 Hz. This is the single most common misconception about spectrum analysis, and it costs people money in hardware that cannot fix their problem.

7. The transform that was too slow to use

Look again at the DFT sum. Each of the NN outputs is a sum over all NN inputs, so the direct computation costs on the order of N2N^2 operations. For a one-second CD-quality clip, NN is about 44,100 and N2N^2 is around two billion multiply-accumulates for one spectrum.

Predict first

A direct DFT of a one-million-sample signal costs about 10^12 operations. The FFT computes the identical answer in N log2 N. By what factor is it faster?

The algorithm exploits redundancy: the same complex exponentials recur throughout the sum, so a transform of length NN splits into two of length N/2N/2, recursively.

8. How much the FFT actually buys

How many times faster the FFT is than a direct DFT
speedup factor01k2k3k4k5k321023411.17k4.1kN=256N=1024N=4096N=16384N=65536
Source: Computed: N^2 / (N log2 N) = N / log2 N

The advantage is not a constant, it grows with the transform size, which is why the FFT did not merely speed things up but changed what was worth attempting at all.

Cooley and Tukey published the algorithm in 1965. Gauss had worked out essentially the same decomposition in 1805 while interpolating the orbits of the asteroids Pallas and Juno, in a manuscript he never published and where he never analysed its cost. The 1965 paper landed when there were digital computers to run it on, and that timing is most of why the name attached there.

9. The half of the answer people throw away

Almost every spectrum you see plots magnitude only. Phase is discarded because the eye reads magnitude easily and phase plots look like noise. That discard is usually harmless and occasionally destroys everything.

MagnitudePhase
Answerswhich frequencies are presenthow they line up in time
Survives a time shiftunchangedrotates
Carries structure oftimbre, pitch, spectral shapeedges, transients, image content

The classic demonstration: take two images, swap their Fourier phases while keeping their magnitudes, and each result looks like the image that donated the phase. Where things are, in other words, lives in the part that gets thrown away.

In practice: If you reconstruct a signal from a modified spectrum, you must handle phase deliberately. Discarding it and guessing on the way back is what makes badly done audio processing sound smeared and metallic.

10. What a single spectrum cannot tell you

The DFT of a whole recording answers "which frequencies are in this signal" and refuses to answer "when". A five-minute track containing one brief 3 kHz beep produces a spectrum with a small 3 kHz component, indistinguishable from a faint 3 kHz tone running throughout.

That is not a defect to be fixed but a consequence of the transform: each basis sinusoid extends over the entire window, so it has no notion of location. Every real analysis tool works around it the same way, by chopping the signal into short overlapping windows and transforming each one, which is what a spectrogram is.

That workaround introduces its own arithmetic, a hard trade between time resolution and frequency resolution, and a set of artefacts that will make you misread a spectrum if you do not know they are there. Those are the subject of the last lesson in this course.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. You record for 0.5 seconds at 48 kHz. What is the frequency spacing between DFT bins?
    • 48 Hz
    • 2 Hz
    • 24000 Hz
    • 0.5 Hz
  2. Why are sinusoids the natural basis for analysing linear time-invariant systems?
    • They are the only functions that can be summed to make a square wave
    • They are the smoothest possible functions
    • A sinusoid passed through an LTI system comes out at the same frequency, with only amplitude and phase changed
    • They are the only functions the FFT can compute
  3. Your spectrum cannot separate two tones 1 Hz apart. Which change actually helps?
    • Record for longer
    • Increase the sample rate
    • Use 24-bit samples instead of 16-bit
    • Use a longer FFT on the same recording by zero-padding
  4. The FFT computes the DFT in N log N instead of N squared. What is the cost in accuracy?
    • It approximates the spectrum, with error decreasing as N grows
    • It is exact only for signals that are truly periodic
    • It discards phase information to save the operations
    • None: it computes the same answer, differing only by floating-point rounding
  5. Two images have their Fourier phase spectra swapped while keeping their own magnitudes. What does each result look like?
    • An unrecognisable blur, since phase alone carries no image content
    • The image that donated the phase
    • The image that donated the magnitude
    • An even blend of the two images

Related lessons