Interactive course · about 2 hours 40

The Frequency Domain

A microphone hands a computer a list of numbers and nothing else. No note names, no instruments, no separate voices. Somewhere in that list is the fact that a smoke alarm is sounding. Or that somebody said a particular word, or that an aeroplane thirty miles away is announcing its height. Getting a fact like that out of a list of numbers starts by working out which sine waves the list is made of. This course does that by hand, on eight samples, with eight multiplications you can check on paper, before any machine does it for you. By the end you will be able to read a spectrum and say what its bars can and cannot tell you. You will also be able to say why the fast way of computing one changed what computers are used for.

How this works

One transform sits underneath every step, and it is the slow obvious one. For each frequency it might be looking for, it multiplies your samples by a cosine and adds the products up, then does the same against a sine. Two sums, one hypotenuse. That is a bar of the answer. Nothing on any page is looked up. Where a step says that a tone landing between two bins smears into every bar, something on that page builds that tone, transforms it, and reads the bars off. Where a step says the fast method needs a hundred times fewer multiplications, a counter has counted them both.

What you need to know first

Two courses in this stream come before this one. Sound and Signals gives you a wave, a sample, a sample rate, and the reason a frequency above half the sample rate comes back as something it is not. Filters gives you the habit of pushing one sine through a thing and measuring what comes out. Neither is strictly compulsory and the words are all reintroduced here as they arrive.

Beyond that: arithmetic with negative numbers, and one fact of geometry, that the long side of a right-angled triangle is found from the two short ones. There is no calculus here and no summation signs. Every sum in this course is written out in full, because the whole promise is that you can do one with a pencil.

The steps

Step 0

Hear one sound as a recipe of pure wiggles

Press three piano keys at once and you get a chord: several notes sounding together. Your ear does not receive three tidy notes. It receives one messy wiggle of air, all three notes added into a single motion. Yet you can hear that there are three. Something in your ear takes the mixture apart again. A prism does the same job with light. Sunlight looks white, but send it through a wedge of glass and it spreads into a band of pure colours. The prism invents nothing. The colours were in the mixture all along, and it sorts them.

This course does that trick with arithmetic. The claim underneath it is worth stating early: any wiggle is a recipe of pure wiggles. A pure wiggle is a smooth rise and fall that repeats at one steady rate. A recipe is a short list: how much of this ingredient, how much of that. The messy wave is the finished cake, and the whole subject is learning to read the recipe back off the cake.

You have seen the recipe drawn on a screen already. An equaliser in a music app is a row of sliders, one per ingredient, slow rumbles at the left and fast hisses at the right. Push a slider up and there is more of that pure wiggle in what you hear. That row of sliders is the sound seen from the frequency domain: not the wave against time, but the recipe. The wave against time is the time domain. Same sound, two honest pictures of it, and this course is about walking between the two.

Is that claim really true for any shape at all?

For any shape that repeats, yes. The proof is one of the famous results of mathematics: Joseph Fourier's claim of 1822, doubted loudly at the time. A recipe of smooth ingredients making a cornered shape sounds impossible. It is not, and the lab below lets you watch corners being built from smoothness.

This course does not ask you to take the claim on trust. It works on short lists of numbers, and for those the recipe can be computed exactly and then run backwards. The samples come back to the last decimal place, and a later step measures exactly that.

What exactly counts as a pure wiggle?

A wave that rises and falls the way a point on a spinning wheel rises and falls: smoothly, evenly, for ever, at one steady rate. Its proper name is a sine wave, and Step 1 pins it down with three numbers. For now the picture is enough: one ingredient, one steady rate of wiggling.

What makes it pure is what it lacks. Play it and you hear one flat, featureless tone, like a tuning fork or a test tone. Everything with character, a voice, a violin, a doorbell, is a mixture, and the character lives in the recipe.

Does my ear really take sound apart, or is that a metaphor?

It really does, physically. Inside the ear is a coiled ramp called the cochlea, stiff at one end and floppy at the other. Each spot along the ramp shakes hardest at one particular rate of wiggling. So a mixture of rates lights up a pattern of spots: fast ingredients near the entrance, slow ones deep inside.

The nerve to your brain reports which spots are shaking. So what you hear is closer to the row of equaliser sliders than to the wave itself. Your ear has been computing the frequency domain your whole life. This course is about doing the same thing with multiplication, where you can check the working.

Lab 1 · The recipe on one side, the wave on the other
Try this firstPress Play the build-up and watch the ingredients arrive one at a time. The wave starts as one smooth wiggle and grows corners as the recipe fills in. Then drag any slider, or drag a bar in the recipe picture itself, and watch the wave change shape at once.
The sliders are the frequency domain, and the wave is the time domain. Neither picture is more true than the other: the wave is what a microphone measures, and the recipe is what your ear hears. The buzz preset uses a famous recipe, each ingredient's height being one over its number, and the wave it builds has corners that no single smooth ingredient possesses.
You slide the leftmost equaliser slider all the way down. The singer's voice stays clear while the drum thump goes thin and papery. What did that slider actually change?
It removed the slow ingredients. An equaliser slider reaches into the recipe, not into the timeline. The drum thump leans on slow pure wiggles and the voice leans on faster ones, so pulling the slow end down changes the two by different amounts. That one observation, that a sound can be edited ingredient by ingredient, is the frequency domain earning its keep before a single sum has been done.
Step 1

One sine, kept as eight numbers

A sine wave is a smooth rise and fall that does the same thing over and over, and three numbers set one completely. How far it swings from the middle is its amplitude. How many complete rises and falls it gets through is its frequency. Where in its own cycle it was when you started watching is its shift, measured in degrees, a whole cycle being 360 of them.

A computer never has the wave. It has samples: the height of the wave measured at evenly spaced instants and written down as a list of numbers. This course keeps eight of them and no more, and eight turns out to be enough to show every idea in the subject. So frequency gets measured in a slightly different unit here. Not cycles per second, but cycles per block: how many complete rises and falls the wave fits into the eight samples you are holding.

Why measure frequency in cycles per block instead of hertz?

Because cycles per block is the only thing the eight numbers actually know. Hand somebody a list of eight numbers with no other information and they can tell you that the pattern repeats twice across the list. They cannot tell you whether the list took a second to record or a millionth of one, so they cannot tell you the frequency in cycles per second.

The two are joined by the sample rate, the number of samples taken each second. Eight samples taken at eight samples a second cover one second, so two cycles per block is two cycles per second, or 2 hertz, written 2 Hz. The labs use eight samples a second for exactly that reason: the two units read the same and there is nothing to convert. Step 7 pulls them apart again on purpose.

Sound and Signals drew waves as sines. Why is this one a cosine?

A cosine is a sine shifted forwards by a quarter of a cycle, which is 90 degrees. Nothing else about it differs: same shape, same amplitude, same frequency. Written as a cosine, a shift of zero puts a peak exactly on the first sample. That one convenience is worth a lot in Step 4, where it makes the first sum you work out by hand come to a tidy number.

If you prefer the sine picture, add 90 degrees to every shift on this page and you have it. The arithmetic is untouched either way.

Why eight samples, and not ten?

Two reasons, and both are real. Eight is a power of two, meaning it can be halved down to 1, and Step 12 is entirely about what that buys. Real systems pick 256, 1,024 or 4,096 samples for the same reason, and almost never a round decimal number.

The other reason is arithmetic you can do. At eight samples the cosine values Step 4 needs are 1, 0.707, 0 and their negatives, and the frequency worked out by hand uses only 1, 0 and minus 1. At ten samples the values are 0.809 and 0.309 and the promise of doing one by hand would be a cruelty.

Lab 2 · Three controls, and the eight numbers they produce
Try this firstLeave everything alone and read the row of eight numbers under the chart. Then drag height and watch every one of the eight change together, while the smooth line behind them keeps its shape. Then drag shift, degrees and watch the numbers change while the height of the line does not.
The eight numbers are the whole signal, and the smooth line behind them is a drawing for your benefit. A machine holding this wave holds the eight numbers and nothing else. The pill that reports the tallest sample is measured from that list, not read off the height control. That is why it disagrees with the height whenever no sample lands on a peak.

One thing about eight samples is worth meeting immediately, because the rest of the course leans on it. Count upwards through the whole numbers of cycles per block and the waves stop being new. Four cycles per block is the fastest wave eight samples can hold. Five gives the same eight numbers as three, six the same as two, seven the same as one, and eight the same as standing still.

Lab 3 · Count upwards and watch the waves run out
Try this firstPress +1 to step cycles per block up from 0, one at a time, all the way to 8. Watch the row of eight numbers. From 5 onwards the pill underneath names an earlier setting that gives the same eight numbers, and it found that match by comparing the lists.
Above four cycles per block, nothing new appears. Five and three produce the same eight numbers, and so do six and two, and seven and one. This is aliasing, from Sound and Signals, arriving in its other costume: a wave too fast for the sample rate is indistinguishable from a slower one. It is why the answer in Step 6 has only five useful bars in it and not eight. A shift is the one thing that separates the pair, and it separates them backwards. Five cycles shifted by 60 degrees is three cycles shifted by minus 60, which Step 6 measures.
You take eight samples of a steady tone and get eight numbers that go up and down twice across the list. A colleague says the tone must be 2 Hz. What is missing from that?
The sample rate is missing. Cycles per block is what a list of numbers knows; cycles per second needs someone to say how long the block lasted. Lab 2 uses eight samples a second so that the two numbers read the same. That is convenient, and it is also the reason to be careful. The same eight numbers taken at 44,100 samples a second are a tone of about 11,000 Hz.
Step 2

Two sines added, and a sum that resembles neither

Two waves in the same air add up. At every instant the air moves by the sum of what each one is asking for, and a machine sampling that air writes down the sum. So take two sines with different frequencies and add them sample by sample. The eight numbers you end up with are the eight numbers of the first plus those of the second.

What comes out can look nothing like either part. That is the honest difficulty of this whole subject. The sum is a single list of eight numbers, and nothing in it is labelled. There is no column that says which part contributed what.

Is adding really all that happens when two sounds mix?

For sound in air, yes, to a very good approximation, and it has a name: superposition. Two waves pass through the same place, add up while they are there, and carry on afterwards exactly as if the other had never happened. A shout is not damaged by crossing a violin note.

It matters here because it is what makes the whole course possible. If mixing two tones produced something other than their sum, taking a mixture apart again would be a different and much harder problem, and probably not a solvable one.

How can a sum be shorter than the taller part on its own?

Because at that instant the two parts are pulling opposite ways. A part 2 tall sitting at plus 2, added to a part 1 tall sitting at minus 1, gives 1. Nothing was destroyed: a moment later the second part is somewhere else in its cycle and the sum is different again.

This is why the tallest sample of a sum is not something you can predict from the two heights. It depends on where each part is in its own cycle at the instant the sample was taken, which is exactly what the shift controls set.

Do the two parts have to be at different frequencies?

No, and what happens when they are not is worth seeing. Two cosines at the same frequency add up to a single cosine at that frequency, taller or shorter depending on how well their shifts agree. Two waves became one. Nothing about there having been two survives.

That is not a flaw in the arithmetic, it is the world. Two violins playing the same note reach a microphone as one wave, and no analysis of that wave can count the violins. A bar in a spectrum says how much of a frequency arrived, never how many things sent it.

Lab 4 · Two parts, and their sum, all three as numbers
Try this firstRead down the three rows of eight numbers and check one column with your own arithmetic. Column 0 should be the first part's 0 plus the second part's 0. Then drag the second part's shift, degrees and watch the bottom row change while the two rows above it keep their heights.
Sliding one part along changes every number in the sum without changing either part's height. The pill reporting the tallest sample of the sum is measured from the sum's own eight numbers. It equals the two heights added only when both parts happen to peak on the same sample, which is a coincidence and not the rule.
Lab 5 · Commit to an answer before the machine gives you one
Try this firstPress one of the three answers before you press anything else. A part 2 tall and a part 1 tall are about to be added. Then press Add them up at four shifts and read the four measured results.
Two heights of 2 and 1 produce a tallest sample anywhere from 2.0 to exactly 3.0. Three happens when both parts peak on sample 0 together, which is 2 of the 24 shifts the control offers. Everything below that is the two parts partly getting in each other's way, and no amount of staring at the two heights tells you which you will get. Only the shifts decide, and the sum is the only place they show up.
You are handed eight numbers and told they are two sines added together. Which of these can you work out just by looking at the list, with no arithmetic?
A total forgets its parts. That is what makes going backwards a real problem rather than a reading exercise. Sometimes you get lucky, and a slow shape with fast ripples on it is plainly two things. As soon as the two frequencies are close, or the heights are similar, the sum stops looking like anything in particular. Step 4 is the method that never needs luck.
Step 3

Going the other way, and finding out how hard guessing is

Here is the question the rest of this course answers. Somebody hands you eight numbers. You are told they were made by adding sine waves together. Which ones, and how tall was each, and how far along was each when the recording started.

Everything a machine does with sound sits on top of that question. Recognising a spoken word means finding which frequencies are present in the last fortieth of a second. Tuning an instrument means finding one frequency accurately. Decoding a radio signal means finding which of two frequencies just arrived. All of them are the same going-backwards problem on a list of numbers.

Is there always exactly one right answer?

For a fixed number of samples, and frequencies limited to whole numbers of cycles per block, yes. Eight numbers can be built from whole-cycle sines in exactly one way, and Step 5 finds it. That is a real and slightly surprising result: the answer is not a good fit, it is the fit.

Allow any frequency at all, not just whole numbers of cycles per block, and the tidiness goes. Step 8 is about what happens then. It is the single most common way a spectrum gets misread.

Could I not just count where the wave crosses zero?

For a single sine, yes, and it is a decent trick: count the crossings, halve the count. You have the number of cycles. For a sum of two it collapses at once. The crossings of the sum are nowhere near the crossings of either part, and how many there are depends on the shifts.

On eight samples it is worse, because a crossing almost never lands on a sample. You know the wave went from plus to minus somewhere between two samples and the list does not say where. Counting crossings is a method for one clean tone and for nothing else.

Where does this going-backwards problem turn up outside sound?

A prism does it with light, mechanically. White light goes in and the colours it was made of come out spread in order. That band is a spectrum in the original sense of the word, and it answers the same question about a different kind of wave. X-rays pointed at a crystal answer it about the spacing of atoms.

A hospital scanner is the most striking case. An MRI machine does not photograph anything. It measures a signal and works out which frequencies are in it, and the frequencies map onto positions in the body. The picture is the answer to a going-backwards problem and nothing else.

Lab 6 · Guess the two parts, and be marked on the numbers
Try this firstSet both parts however you like and press Check my guess. The verdict compares your eight numbers with the target's eight numbers, so it never looks at your settings. Then press Try 40 random guesses and see how close pure luck gets.
Hunting works, and it is slow, and it does not scale. With two parts and a target you can compare against, patience gets you there. A real signal has dozens of parts and no target to compare against, and forty random guesses barely dent it. What is wanted is a method that computes the answer once rather than searching for it.

It is worth knowing how big the haystack is, because the number is what makes the method in the next step feel like a gift rather than a formality.

Lab 7 · Count the combinations you would have to try
Try this firstDrag the shift steps control from coarse to fine and watch the total. Each control says how finely you are prepared to chop up one of the three numbers that describe a part. The total is the product of all of them, for two parts, and it is multiplied out rather than quoted.
Two parts is cheap and the exponent is what does the damage. At the default settings a computer could try every combination in about a quarter of a second, so brute force is not hopeless here. Every extra part multiplies the total by 1,560, and a real signal has dozens: drag parts in the signal up to 4 and the quarter of a second becomes days. The method in Step 4 does not search at all. It asks one direct question per candidate frequency, costs 128 multiplications whatever the signal is, and its answer is exact rather than the closest thing on a grid.
Your guess in Lab 6 gets the two frequencies exactly right and both heights slightly wrong. The verdict still says not yet. What does that tell you about how it is marking?
It compares lists, not settings. That is the only fair way to mark this, because two different sets of settings can produce the same eight numbers, and both deserve to pass. It is also why the verdict prints the average gap. A gap of 0.30 with the frequencies right means the heights are close but not close enough. You can watch the number fall as you fix them.
Step 4

Multiply eight samples by one cosine, and add up

The method is one idea, and it is not obvious until you have done it once, so this step does it once, slowly, with your own arithmetic. Pick a frequency you want to test for. Write down the value of a cosine at that frequency at each of the eight sample instants. Multiply each sample by the cosine value beside it. Add up the eight products. That single total says how much of that frequency is in the signal.

Why it works is worth a sentence. Suppose the signal really does contain a wave at the frequency you are testing, lined up with your cosine. Then the products come out positive wherever both are positive, and positive again wherever both are negative, so they pile up. Now suppose the signal contains something at a different frequency. The products come out positive about as often as negative and cancel to nothing. The total is large when your guess is present and about zero when it is not.

Where do the cosine values in the table come from?

From the frequency being tested. For 2 cycles per block on 8 samples, the cosine gets through two complete cycles in eight steps. So it advances a quarter of a cycle each sample: 1, then 0, then minus 1, then 0, and round again. Those four values are the whole table, which is exactly why this step tests two cycles per block first. Multiplying by 1, 0 or minus 1 is arithmetic anybody can do in their head.

For 1 cycle per block the wave advances an eighth of a cycle each sample, and the values include 0.707, which is the cosine of 45 degrees. Nothing changes about the method, only the tidiness. A real program keeps these numbers in a table too, for the same reason you would: working them out again for every sample is wasted effort.

Why does multiplying by a cosine pick out one frequency?

Try it with numbers rather than words. Take the sequence 1, 0, minus 1, 0 repeating, which is the 2-cycle cosine. Multiply it by itself and you get 1, 0, 1, 0 repeating, which are all positive, so the total grows. Now multiply it by the 4-cycle cosine, which is 1, minus 1, 1, minus 1: the products are 1, 0, minus 1, 0, which cancel in pairs and total zero.

That is the property the whole subject rests on. Any two different whole-cycle waves across the same block multiply out to a total of zero, so testing for one of them cannot accidentally report another. The name for it is orthogonality, and you have just checked a case of it by hand.

Lab 8 · Work out one bar of the answer yourself
Try this firstFill in the eight products in the last column and press Check my column. Every cosine value in this table is 1, 0 or minus 1, so each product is the sample, or nothing, or the sample with its sign flipped. Then press The sine column and do the second one.
Two totals, and then a hypotenuse. The cosine total is 8 and the sine total is 0, and the two are the short sides of a right-angled triangle. The long side, 8, is how much of this frequency the signal holds. Divide by four, which is half of eight samples, and you have 2.0: exactly the height of the part that was put in.

Two sums, then, not one. The reason for the second is the shift. A wave that has slid along is still there, but it no longer lines up with your cosine, and the cosine total alone would report it as absent. So test twice, once against a cosine and once against a sine at the same frequency. A sine is a cosine shifted by a quarter of a cycle, so whatever the first test misses the second one catches.

Then the two totals combine. Draw them as the two short sides of a right-angled triangle, the cosine total across and the sine total up. The long side is the magnitude, how much of that frequency is present regardless of where it starts, and the angle at the corner is the shift. Two ordinary sums have become a height and a shift.

I have not met the hypotenuse, or I have forgotten it

In any triangle with a square corner, the long side sitting opposite that corner is the hypotenuse, and there is a rule for its length. Square each short side, add the two squares, and take the square root. Sides of 3 and 4 give 9 plus 16, which is 25, whose square root is 5.

Here the two short sides are the cosine total and the sine total, and the hypotenuse is the answer you want. A cosine total of 8 with a sine total of 0 gives a magnitude of 8. A cosine total of 0 with a sine total of 8 gives a magnitude of 8 as well. That is the point: the same amount of wave, sitting in a different place.

Everyone else writes this with complex numbers. Am I being sheltered from something?

You are being shown it in the order that makes it learnable, and here is the translation so nothing is a surprise later. The two totals you have just worked out are usually written as one item, a complex number. Its real part is the cosine total. Its imaginary part is the sine total with a minus sign in front of it, and that minus is only a bookkeeping convention. Magnitude is the hypotenuse of the same triangle either way, so every bar in this course is the number a textbook would print. Step 14 turns the pair into a picture you can hold.

What the complex notation buys is compactness, and the ability to multiply two of these things together in one step. That matters a great deal once you are designing filters, and not at all while you are reading a spectrum. It buys nothing you need today, and paid for in advance it would have cost you this step.

Lab 9 · The same eight numbers against a frequency that is not there
Try this firstPress Next sample repeatedly and watch the running total. This is 1 cycle per block against the same eight samples. The total wanders up and down and the pill tracks it. Watch where it finishes.
Both totals finish at zero, and that is an answer rather than a failure. The signal contains nothing at 1 cycle per block, so the products cancel: each positive one is matched by a negative one somewhere else in the block. A test that reports a confident zero for an absent frequency is exactly as useful as one that reports 8 for a present one.
A signal contains one wave at 3 cycles per block, and it happens to be shifted so that it is a pure sine rather than a cosine. You test it against the 3-cycle cosine only, and get a total of about zero. What should you conclude?
The sine test catches what the cosine test misses. That is the whole reason for the second sum. A wave shifted by a quarter of a cycle is invisible to the cosine test and completely visible to the sine test. Any shift in between splits itself between the two. The hypotenuse comes out the same for every shift, which is what makes magnitude a property of the wave rather than of when you happened to start recording.
Step 5

Do it for every frequency the block can hold

Step 4 tested one frequency. There is nothing special about that one, so test them all. For eight samples the whole numbers of cycles per block run from 0 to 7, so there are eight tests, each with a cosine sum and a sine sum. Those eight answers are the complete description of the signal.

That is the discrete Fourier transform, usually shortened to DFT. Discrete because it works on a list of samples rather than on a continuous wave. It is named after Joseph Fourier, who worked out in 1822 that any repeating shape can be built from sines. There is nothing else to it. Two sums per frequency, and one frequency per sample you are holding.

Why exactly eight frequencies for eight samples, and not more or fewer?

Because eight numbers going in should give eight numbers coming out, or something has been lost or invented. Eight samples hold eight numbers' worth of information, and the transform is a rearrangement of it rather than a summary. Step 6 shows the strongest evidence for that. Run the answer backwards, adding the eight frequencies up again with the sums as their weights, and the original eight samples come back exactly.

The eight are not all separately useful, because Lab 3 showed that 5 behaves like 3 and 6 like 2. So there are eight answers and five distinct frequencies, and the other three are mirrors carrying the same information the other way up. Step 6 measures that.

Fourier was working in 1822. Did he do this to lists of numbers?

No. He was working with continuous curves and infinite sums, on the question of how heat spreads through metal. His claim was that any repeating shape can be written as a sum of sines. The version in this course, on a finite list of samples, came later and belongs to the age of machines.

The name stayed because the idea is his. What is different here is that a finite list gives a finite answer: eight samples, eight frequencies, no infinite sum and nothing that has to converge. In that sense the discrete version is the easier one, which is why it can be taught first.

What if the signal is not made of whole-cycle sines in the first place?

The transform still gives an exact answer, and the answer is still eight numbers that rebuild the samples perfectly. What changes is how it reads: instead of one or two bins holding everything, the content is spread across many of them.

That is not a failure and it is not noise. It is the transform saying that the only way to build your samples out of whole-cycle waves is with a little of a great many of them. Step 8 takes one tone that does not fit and looks hard at what comes out.

Lab 10 · Step through all eight frequencies
Try this firstPress Test the next frequency eight times and watch the bars fill in. Each press does exactly what you did by hand in Step 4, at one more frequency. Read the two totals as they appear: most of them are zero.
Six of the eight answers are zero, and two are not. The signal was two cosines added, so exactly two frequencies are present, and the transform found them without being told how many to look for. That is the difference between this and the guessing in Step 3. Nothing here searched.

Each of those eight answers has a name. A bin is one frequency's worth of answer: its cosine sum, its sine sum, and the magnitude and shift that come out of them. The word comes from the idea of sorting something into containers. It is a good word, because a bin holds everything that lands near its frequency rather than only what lands exactly on it. Step 8 is what happens when something lands between two bins.

Lab 11 · Put something in and watch the transform find it
Try this firstSet the first part to 1 cycle per block and 3 tall, and the second part to 4 cycles and 1 tall. The bars should be 3 and 1 in exactly those two places. Then slide either part's shift and watch the bars stay completely still.
The bars report the heights you set, and ignore the shifts entirely. The verdict line compares each bar with the part you asked for and prints the worst disagreement, which stays at zero to several decimal places. The shifts have not been lost, they have moved into the shift column, which Step 10 is about.
You transform eight samples of a signal you know is a single cosine at 2 cycles per block, 3 tall. Bin 2 comes back with a magnitude of 12. Where does 12 come from, given the height was 3?
A sum over more samples is a bigger sum. Eight samples each contribute a product, so the total carries the block length in it. Dividing the magnitude by half the sample count turns it back into a height in the same units as the samples. That is what the amplitude column in these labs shows. Two frequencies are exceptions: nothing at all, and the fastest wave the block can hold. They divide by the full sample count instead, because they have no mirror partner to share with.
Step 6

Reading a spectrum, bar by bar

A row of magnitudes, one per bin, is a spectrum. It is the single most common picture in engineering and it is easy to half-read, so this step goes along it slowly. Each bar answers one question: how much of this frequency is in the block. Four things are worth reading off every bar, and the labs print all four.

Its bin number, counting from 0, which is how many cycles per block it stands for. Its frequency in hertz, which is the bin number times the sample rate divided by the number of samples. Its magnitude, the hypotenuse from Step 4. And its amplitude, the magnitude turned back into a height in the same units as the samples.

Why do the bars above the middle repeat the ones below it?

Because of Lab 3 in Step 1. On eight samples, 6 cycles per block draws the same eight numbers as 2 cycles per block. So a test at 6 cannot help reporting whatever a test at 2 reports. Bin 6 is bin 2's mirror, bin 5 is bin 3's, and bin 7 is bin 1's. Bin 4, the fastest wave eight samples can hold, has no partner and stands alone.

The mirror is not quite an exact copy: the magnitudes match and the shifts come out as one full turn minus the other, which the lab measures. Real programs simply throw the top half away, and every spectrum you meet in the wild has already had that done to it.

What is bin 0 measuring, if zero cycles is not a wave at all?

The average of the samples. A wave at zero cycles per block never rises or falls, so it is a flat line at some height. Testing for it means multiplying every sample by 1 and adding up. Divide by the number of samples and you have the mean.

Engineers call it the DC component, from direct current, meaning the part that is not going up and down at all. A microphone with a slightly wrong zero point puts a large bar there and nothing anywhere else, and taking it off is usually the first thing done to a recording.

Why draw a spectrum as separate bars rather than a smooth curve?

Because there are only as many answers as there are samples, and a curve drawn through them implies readings at frequencies nobody tested. Between bin 2 and bin 3 the transform has said nothing at all and a line drawn there is an invention.

Most software draws the curve anyway, and on a long block with narrow bins it does no harm. On a short block it actively misleads, which is why every spectrum in this course is drawn as bars with their own numbers printed beside them.

Lab 12 · Take one bar apart
Try this firstPress the bar labelled bin 3 and read the four numbers that appear. The chart underneath draws that bin's own cosine, at the height and shift the bin reports, against the eight samples. Then press bin 1 and see what an empty bin draws.
Every bar is a claim about one wave, and the claim can be drawn. A bin is not an abstract quantity: it names a specific cosine, with a specific height and a specific shift. Adding the ones that are not zero back together reproduces the samples. The line under the chart says how much of the signal the selected bin accounts for on its own.

Two bars carrying the same information is wasteful, so almost nobody keeps both. The convention is to keep bins 0 up to half the sample count, which for eight samples means bins 0 to 4, five bars, and to discard the rest. Half the sample rate is the highest frequency the samples can describe, which is the Nyquist limit from Sound and Signals arriving from the other direction.

Lab 13 · Check that the top half really is a mirror
Try this firstDrag the shift of the 2-cycle part and watch the two right-hand columns. The magnitudes of bin 2 and bin 6 stay equal to the last decimal place shown, and the two shifts always add up to 360 degrees. Neither is asserted: both are subtracted in the widget.
The pairing holds at every shift, and the worst disagreement is a rounding error. That is why a spectrum of 1,024 samples is drawn with 513 bars and not 1,024. The information is all in the lower half, and the upper half is the same information written backwards.
A program takes 1,024 samples at 8,000 samples a second and prints a spectrum. How many bars should it print, and what is the highest frequency any of them stands for?
Exactly 513 bars, up to 4,000 Hz. Bins 0 to 512 inclusive is 513 of them, and the top one sits at half the sample rate. The two easy mistakes are both worth having made once: forgetting that bin 0 counts, and forgetting that the upper half is a mirror. A spectrum whose highest bar claims to be at the full sample rate is a spectrum somebody has printed without thinking about it.
Step 7

Bin width, and the two things that set it

Eight samples gave five useful bars, which is not many. The obvious question is how to get more, and the answer is the one number that governs every practical use of a transform. The gap in frequency between one bin and the next is the bin width. It is the sample rate divided by the number of samples in the block. Nothing else affects it.

Written the other way round it says something more useful. The number of samples divided by the sample rate is how long the block lasted, so bin width is one divided by the block length in seconds. A block of one second gives bins 1 Hz apart. A block of a tenth of a second gives bins 10 Hz apart, whatever the sample rate is. To tell two nearby frequencies apart you need a long enough recording, and no amount of sampling faster will do instead.

Sampling faster does not help? That seems wrong.

Sampling faster does help with something else. It raises the highest frequency you can describe at all, because that is half the sample rate. What it does not do is put the bins closer together. The arithmetic says why. Doubling the rate doubles the number of samples you collect in the same time, and bin width is the rate divided by the sample count. Both halves of the fraction double, so nothing moves.

You can check this in Lab 14. Set the rate to 32 and the block to 32 samples, note the bin width, then set the rate to 64 and the block to 64 samples. Same one second, same bin width, twice as many bars, and the extra bars are all above the old top frequency.

What exactly is a block?

The stretch of samples handed to one transform. Eight of them in these labs, 1,024 in a typical audio program. It is a choice made by whoever wrote the program rather than a property of the recording, and Steps 7 to 11 are all about what that choice decides.

A recording is usually far longer than one block, so it gets cut into many, and each is transformed on its own. Step 11 makes a picture out of the results, which is where the choice of block length becomes visible at a glance.

Can I get finer bins by padding the block out with zeros?

You can make more bars appear, and it is worth knowing exactly what they are, because this is the most misunderstood trick in the subject. Adding zeros to the end of a block does lengthen it, so the bin width does fall and the extra bars are real calculations.

What they are not is new information. The zeros told the transform nothing, so the extra bars are a smooth interpolation between the ones you already had. Two tones that merged into one hump before padding still merge after it. Zero padding buys a better estimate of where a peak sits and never buys resolution. Only a longer recording does that.

Lab 14 · The two controls that set the bin width
Try this firstDouble the samples in the block and watch the bin width halve. Then put it back and double the sample rate instead, and watch the bin width double. The block length in seconds is printed beside them, worked out from both.
Bin width is the sample rate over the sample count, and equally one over the block length. Both forms are printed and they agree, because they are the same division. The one that matters in practice is the second. To tell 1,000 Hz from 1,010 Hz you need a tenth of a second of recording at least, and that holds whether you sampled at 8,000 or at 8 million.

Knowing the bin width is not the same as knowing when two tones will look like two tones. That takes a little more than one bin of separation, and it is worth finding the boundary yourself rather than being told where it is.

Lab 15 · Find the shortest block that separates two tones
Try this firstStart at 16 samples and press Transform this block. Two tones 1 Hz apart are in there and you will see one hump. Then step the block length up and keep pressing, until the count of separate humps reads 2.
One bin of separation is not enough: you need an empty bin between them. At a one second block the two tones land in neighbouring bins and the two bars touch, which reads as one wide hump and is counted as one. At two seconds there is a bin between them holding almost nothing, and the two bars are unmistakably two. The hump count is not a judgement, it is a walk along the bars looking for runs above half the tallest.
A receiver has to tell a 1,000 Hz beep from a 1,020 Hz beep. It samples at 48,000 samples a second. What decides whether it can do the job?
The block length decides it. Bins 20 Hz apart need a block lasting a twentieth of a second. Lab 15 shows that landing in neighbouring bins is not quite enough to look like two things, so about a tenth of a second is the honest requirement. At 48,000 samples a second that is roughly 4,800 samples. The sample rate is not the constraint here and never was: what costs you is waiting.
Step 8

A frequency between two bins lands in every bar

Everything so far has quietly assumed that the frequencies in the signal are whole numbers of cycles per block. Real signals have no such manners. A tone at 5.5 Hz, with bins 1 Hz apart, does not fit any bin. What the transform does about it is the single most misread thing in the subject.

So commit to a prediction first. Bins at every whole hertz, a tone at 5.5 Hz, amplitude 1.0. Write down what you expect the bars to look like before pressing anything, and then find out.

Lab 16 · Predict, then transform
Try this firstPress whichever of the three predictions you believe, before pressing Transform it. Then press Transform it and read all seventeen bars, including the ones far away from 5.5 Hz.
Two large bars, and not one bar in the whole spectrum reads zero. The tallest bar reports 0.654 for a tone that is 1.000 tall, which is 35 per cent low, and the total magnitude across the spectrum has nearly tripled. The energy did not go anywhere: it was never in one place to begin with. Every bin is answering the question it was asked, honestly, about a wave that does not fit the block.

The name for this is leakage, or spectral leakage. It happens because a bin's test compares your samples against a wave that fits the block a whole number of times. A 5.5 Hz tone in a one second block ends halfway through a cycle. The block, repeated, would have a step in it and a step contains every frequency.

Why does an unfinished cycle produce a step?

Because the transform only ever sees the block, and everything it can express repeats with the block. Ask it to describe a tone that ends halfway up. The only thing it can build out of whole-cycle waves is a pattern that jumps back down when the block restarts.

A jump is a sudden change, and sudden changes need fast waves to build. So the transform includes a little of every frequency it has, right up to the top, in order to manufacture a corner it never wanted. That is why the far bars in Lab 16 are not zero.

Does this mean a spectrum of real audio is mostly wrong?

Mostly imprecise rather than wrong, and knowing by how much is the useful part. A tone landing between two bins reads up to about 36 per cent short, and the worst case is exactly halfway. Its true frequency lies somewhere between the two tallest bars. Both errors are bounded and both are correctable if you care: the two tallest bars can be compared to estimate where the tone really sits.

What is not correctable by arithmetic afterwards is a quiet tone buried under leakage from a loud one. That one has to be prevented, which is Step 9.

Can the true frequency be recovered from the two tallest bars?

Yes, to a useful accuracy, and instrument makers rely on it. The relative heights of the two tallest neighbours say where between them the tone sits: equal heights mean the middle, and four to one means much nearer the taller one. The arithmetic is a few lines and the name for it is interpolation.

It is how a guitar tuner reads to a tenth of a hertz off a block whose bins are a hertz apart. What it cannot do is separate two tones that have merged, because it assumes there is exactly one tone in the neighbourhood and reports nonsense, quietly, when there are two.

Lab 17 · Slide a tone across a bin boundary
Try this firstDrag the tone's frequency slowly from 5.0 up to 6.0. Watch the tallest bar's reported height sag towards the middle and recover, and watch the share of the spectrum sitting in the tallest bar collapse and come back.
Exactly on a bin the answer is perfect, and it degrades smoothly from there. The worst case is precisely halfway between two bins, where the peak reads about 0.65 instead of 1.00 and the tallest bar holds less than a quarter of the total. The DFT bars measure energy at fixed bin frequencies; an off-bin tone spreads across several bars, so the tallest bar alone underestimates it.
You transform one second of a recording, bins 1 Hz apart. A bar at 440 Hz reads 0.71, a bar at 441 Hz reads 0.69, and small bars sit everywhere else. What is the most likely explanation?
One tone between the two bins. Two nearly equal neighbours with small bars everywhere else is what a badly fitting frequency looks like. The small bars are the part that gives it away. Two genuine tones sitting on their own bins would leave the rest of the spectrum at zero. As a bonus, the two heights can be compared to work out where the tone really is. That is how a tuner reads to a fraction of a hertz off a one second block.
Step 9

Taper the ends of the block, and pay for it

Leakage came from the block having a step in it when repeated. The fix follows from that: make the block end where it begins. Multiply the samples by a set of weights that are nothing at both ends and full in the middle. Whatever the signal was doing at the edges then fades out before the transform sees it. That set of weights is a window.

Three windows have been in use since the 1960s and all three are the same shape, a constant with a cosine taken off it. Hann is the plain one, Hamming is the same idea that does not quite reach zero at the ends, and Blackman adds a second cosine and tapers harder. Nothing about them is deep. They are eight or a thousand numbers you multiply by.

Does multiplying my samples by something not damage them?

It changes them, deliberately, and the damage is the price being paid. A windowed block is quieter overall, so the labs divide by the average weight to keep the bars comparable with the unwindowed ones. More importantly, the samples near the edges of the block have been thrown away. A signal that only happened at the very start of a block will be nearly invisible.

That is why real analysis overlaps its blocks. Run them half a block apart, and whatever the window faded out at one block's edge sits in the middle of the next. The spectrogram in Step 11 does exactly this.

Why are the windows named after people?

Because somebody worked out each shape and the name stuck. Julius von Hann was an Austrian meteorologist smoothing weather data in the nineteenth century, well before any of this was digital. Richard Hamming and Ralph Blackman were both at Bell Labs in the middle of the twentieth.

The names carry no meaning and there is nothing to remember about them. They are three particular sets of weights, and the full catalogue runs to dozens with names like Kaiser, Bartlett and flat top. Every one of them is a list of numbers you multiply your samples by.

So which one should I actually use?

Hann, unless there is a reason, and the reason is usually one of two. If a quiet thing near a loud thing matters more than anything else, go to Blackman and accept a wider main bar. If separating two similar things at nearly the same frequency matters more, use none and accept the leakage.

The honest summary is that there is no best window, because the two things a window trades cannot both be won. What somebody experienced actually does is work out which of the two the job needs, and that is a question about the signal rather than about the window.

Lab 18 · Four windows on the same badly fitting tone
Try this firstPress each of the four window buttons in turn and watch the far bars collapse. The two numbers under the spectrum are the two halves of the trade. One is the tallest bar four or more bins from the peak. The other counts bars at least half as tall as the peak.
Leakage falls by a factor of about a hundred, and the main bar gets wider. With no window the worst far bar is 0.141 of the peak. With Blackman it is 0.0014, a hundredth of that. What it costs shows in the on-bin reading. With no window, a tone that fits exactly gives one bar and its neighbours read zero. With Blackman the neighbours read 0.595 of the peak, so two nearby tones are harder to separate than they were.

The trade is worth stating plainly, because it is the reason there is no best window. A window buys freedom from leakage and pays in resolution. If you need to see a quiet thing next to a loud thing, window hard. If you need to separate two things at similar heights and nearly the same frequency, window lightly or not at all.

Lab 19 · Find a quiet tone hiding under a loud one
Try this firstLeave the window at none and read what the bar at 11 Hz says. There is a real tone there, 0.020 tall, and the bar is reporting several times that. Then press Hann and read the same bar again.
With no window the quiet tone is invisible, and it is not a question of it being small. The leakage from the loud tone alone puts 0.080 in that bar, four times the quiet tone's own height. So the reading of about 0.097 says almost nothing about the tone really there. With a Hann window the same bar reads 0.020, which is the truth to two decimal places. This is what windows are actually for.
You are looking for two tones of about the same height, 2 bins apart, and you know there is nothing else at all in the signal. Which window should you use?
No window, in this one case. A window is bought to stop a loud thing hiding a quiet one, and there is no quiet one here. What it charges is a wider main bar, which is the only thing standing between you and separating two tones 2 bins apart. This is why "always use Hann" is a useful habit and still wrong sometimes, and why knowing the trade beats knowing a default.
Step 10

The shifts you discarded, and what they were holding

Every spectrum so far has been a row of magnitudes, and the shift column has sat there unused. Almost every spectrum you will ever meet does the same: it prints heights and throws the shifts away. That is usually the right decision and it is never a free one. This step measures what it costs.

Take the eight samples this course started with. Slide each of its two parts along by some amount, leaving both heights alone. The magnitudes come out identical, to fifteen decimal places, because magnitude is the hypotenuse and sliding a wave only moves the answer around the triangle. The eight numbers, meanwhile, are completely different.

If magnitude ignores the shift, what is the shift column for?

For putting the signal back together. The transform is reversible, and running it backwards needs both sums, which is the same as needing both the magnitude and the shift. Keep magnitudes only and the original samples are gone for good: you can build something with the same spectrum, but not the same wave.

Where that matters most is anything with a sharp edge in it. A drum hit, a consonant at the start of a word, a radar echo: all of those are a moment in time. A moment in time is stored entirely in the relationships between the shifts. Lose them and you keep the ingredients and lose the timing.

Shifted relative to what?

To the first sample of the block. A shift of 0 means the wave was at a peak when sample 0 was taken, and 90 degrees means it was a quarter of a cycle past that. It is a statement about the recording having started when it did, which is arbitrary.

What is not arbitrary is the shifts relative to each other. Move the whole recording along by one sample and every shift changes while the sound does not. Slide one part and leave the others where they are, and the shape changes completely, which is what Lab 21 does.

Where is the shift the thing you actually want?

Anything that measures distance by timing. A radar or a sonar gets range from how late the echo comes back, and late is a shift. Two microphones a few centimetres apart give the direction a sound came from, from the shift between them, which is how a phone keeps your voice and drops the room.

Radio goes further and uses the shift as the message. Several of the schemes in Modulation carry data by jumping a carrier between four or eight shifts. The column this step has been treating as a nuisance becomes the only one that matters.

Lab 20 · Two shift controls, and a spectrum that will not move
Try this firstDrag either shift control and watch the two magnitudes stay where they are. The row of eight numbers underneath changes completely as you drag, and the pill reporting how far the wave has moved from the original is measured between the two lists.
The same spectrum, and a different signal. At 90 and 180 degrees the eight numbers sit a long way from the ones this course started with. The average gap is about one and a half times the size of the signal itself, and the magnitudes have not budged. The last line rebuilds the wave from the magnitudes with every shift forced back to zero, which is what discarding the shifts and then trying again would give you.

The clearest case of all is a single spike. Its magnitudes are the same height at every frequency. So the magnitude spectrum of a click at the start of a block matches that of a click in the middle of it. Everything that says when the click happened is in the shifts.

Lab 21 · Line up the shifts, scramble them, and listen
Try this firstPress Line them all up, then press Scramble the shifts, and read the three measured numbers each time. Eight equally loud harmonics, same heights throughout. Then press Play both, one after the other if you have sound.
Same spectrum, same loudness, different shape and a different sound. Lined up, the eight harmonics all peak together. The wave is a narrow spike 8.0 tall on a typical size of 2.0, and it sounds like a buzz made of clicks. Scrambled, the peak drops to about 6.5 while the typical size is unchanged at 2.0, and it sounds smoother. Every bar of the spectrum is identical in both.
You store only the magnitudes of a recording, then rebuild it later with every shift set to zero. What comes back?
The right ingredients, assembled wrongly. Forcing every shift to zero puts every part's peak on the first sample, so the result is as spiky as those frequencies can possibly be. Lab 20 does this and measures the difference. It is also why an image or an audio codec that stores only magnitudes sounds wrong in a very particular way: the notes are right and the attacks are smeared.
Step 11

Frequency against time, so a changing sound becomes a picture

One transform of a whole recording answers what frequencies are in it, and refuses to answer when. Two notes played one after the other and the same two notes played together give the same spectrum. For most real signals that is useless, because when is the entire content: speech is nothing but a sequence of changing frequencies.

The fix is what you would do anyway. Chop the recording into short blocks, transform each one on its own, and put the answers side by side. Time runs across, frequency runs up, and the height of each bar becomes the darkness of a cell. That picture is a spectrogram. It is how anybody who works with sound actually looks at it.

Why overlap the blocks instead of laying them end to end?

Because of the window from Step 9. A window fades out the samples at each end of its block. A short event landing on a boundary would be faded out of both blocks it touches and appear nowhere. Running the blocks half a block apart means every sample sits in the middle of some block.

Overlapping costs work, and it is the usual arrangement anyway: a half-block hop doubles the number of transforms and is the standard choice. Step 12 is about why doubling the number of transforms stopped being a serious objection.

Why does a steadily rising tone look like a staircase?

Because both directions are chopped up. The tone rises smoothly, and the picture has one column per block and one row per bin, so a smooth rise gets rounded onto whichever cell is nearest. A finer staircase needs more rows or more columns, and Lab 23 shows that you cannot have both.

It is the same effect as a photograph having pixels. Nothing is wrong with the analysis, and the tone really is somewhere inside each cell it lights up. What the picture will not tell you is where inside.

Is this the same picture a music program shows me?

Yes, and two things about the usual presentation are worth knowing. The vertical axis is normally spaced by doubling rather than by adding, so each octave gets the same amount of room, because that is how pitch is heard. And the darkness is normally in decibels, so a detail one thousandth the height of the loudest thing is still visible.

The grids in these labs do neither, on purpose. The rows are evenly spaced in hertz, and the digits are plain fractions of the loudest cell. What you see is what the transform said, with nothing applied on top.

Lab 22 · The same four sounds, as one spectrum and as a picture
Try this firstPress Two notes in a row, then press Both notes together. Compare the single spectrum, which is identical for the two, with the grid below it, which is not. Then press A rising tone.
One spectrum cannot tell a sequence from a chord, and the grid can. The two notes in a row and the two notes together produce the same two bars in the whole-block spectrum. The widget prints the largest disagreement between them to prove it. In the grid the first is one row dark early and another dark late, and the second is both rows dark at once and then nothing.

Chopping into shorter blocks buys time detail and sells frequency detail, because bin width is one over the block length. That is the same trade as Step 7, arriving in a place where you can see both halves of it at once.

Lab 23 · Short blocks or narrow bins, and never both
Try this firstPress 8, then 16, then 32 samples per block. A tone rising steadily from 2 Hz to 14 Hz is being analysed each time. Watch the number of columns and the number of rows swap places as you go.
At 8 samples a block you get 15 columns and bins 4 Hz apart; at 32 you get 3 columns and bins 1 Hz apart. The rising tone is a diagonal line in both, drawn coarsely one way and coarsely the other. There is no setting that gives fine detail in both directions, and choosing between them for the job in hand is most of the skill in using a spectrogram.
You need to spot a click that lasts about a thousandth of a second, in audio sampled at 48,000 samples a second. What block length should you analyse in?
Match the block to the event, and accept coarse bins. A thousandth of a second is about 48 samples at that rate, giving bins 1,000 Hz apart. That sounds terrible until you remember what you were asked for: the time of a click, not its pitch. The opposite job, telling two hums 5 Hz apart from each other, needs blocks of half a second and cannot say when anything happened. Lab 23 is that trade with numbers on it.
Step 12

Count the multiplications, then halve the problem

The transform as built in Step 5 does two multiplications per sample per frequency. Eight samples means eight frequencies to test and eight products in each of two sums, which is 128 multiplications for one transform of eight numbers. Double the block and it does not double: 16 samples take 512, because both the number of frequencies and the length of each sum went up.

That is the pattern worth having a name for. When the work goes up with the square of the block length, a block ten times longer costs a hundred times as much. A thousand samples costs two million multiplications, and a spectrogram wants one of those every few milliseconds.

Lab 24 · Count them, both ways, for real
Try this firstPress 8, then 16, then 32, and watch the slow column quadruple each time while the fast column roughly doubles. Both numbers are counted by a counter inside the transforms as they run. Then press 1024.
At 1,024 samples the slow way needs 2,097,152 multiplications and the fast way 20,480. The last column divides the slow count by the block length squared and gets 2.000 every single time. That is "goes up with the square" as a measurement rather than a claim. The fast column divided by the block length times the number of halvings gives 2.000 every time too.

The saving comes from one observation. Split the eight samples into the four at even positions and the four at odd positions. Transform each four on its own, which costs 32 multiplications each rather than 128. Then combine the two answers, which takes one round-the-circle multiplication per output pair, and each of those is four ordinary multiplications. Two smaller transforms plus a combining step beats one big one. The trick works again on each half, and again, until the pieces are one sample long and nothing is left to do.

What does "the number of halvings" mean, and is it a logarithm?

It is how many times you can halve the block before you get down to one sample. Halving 1,024 gives 512, then 256, and so on down to 1, which is ten halvings. Eight takes three. It is a small number and it grows very slowly: doubling the block adds one to it.

And yes, that is exactly what a logarithm to base two is. The fast transform's cost is usually written as the block length times the logarithm of the block length. The word is doing no work that counting halvings does not do, which is why this step counts instead.

Who worked this out, and why is it treated as such a big deal?

James Cooley and John Tukey published it in 1965, and it turned out that Gauss had the same idea in about 1805 and left it in an unpublished notebook. Their version is called the fast Fourier transform, or FFT. It computes exactly the same answer as the slow one. It is not an approximation.

It gets called one of the most important algorithms of the century because it moved a whole class of work from impossible to routine. Analysing a second of audio in one second stopped being a research problem. Everything downstream, from digital telephony to medical scanners to the wireless standards a phone uses, assumes it is cheap.

Does the fast one give a slightly different answer?

No, and that is the remarkable part. It is a rearrangement of the same multiplications and additions rather than an approximation to them, so no accuracy is being traded for the speed.

The two transforms behind this course are checked against each other on the same signals, and the largest disagreement between them is about one part in a thousand million million. That is the ordinary rounding of the arithmetic and not a difference of method.

Lab 25 · Split eight into two fours, and count what you saved
Try this firstPress Split once and read the running total. Each press splits every piece in half again and recounts. Watch the total fall, then stop falling when the pieces are one sample long.
128, then 80, then 64, then 48, and no further. One split saves 48 multiplications on its own, and each further split saves no more than the one before it. That is why the cost lands at the block length times the halvings rather than at nothing. The count is taken from the same counter that runs in Lab 24, so the two labs cannot disagree.
Your spectrogram uses 1,024 sample blocks and runs at the limit of what a processor can do. You are asked to double the block length to get narrower bins. Using the fast transform, roughly what happens to the work per second of audio?
Up by roughly a tenth. This is the part that surprises people about the fast transform: per second of audio, the block length almost stops mattering. Each block costs a little more than twice as much and there are half as many of them, so all that survives is one extra halving. Lab 24 has both numbers. With the slow transform the same change would double the work per second, which is why block lengths used to be chosen by what the machine could afford.
Step 13

Pick the right Fourier tool for the data you hold

Everything so far has been one tool, the DFT, which eats a finite list of samples. The word Fourier actually names a small family of tools, one for each kind of data. All of them answer the recipe question from Step 0. They differ only in what they assume the signal to be.

A smooth curve that repeats for ever has a Fourier series: a recipe with numbered ingredients, its harmonics. A smooth curve that never repeats has the continuous Fourier transform, whose recipe holds an amount at every frequency, not just at whole numbers. An endless list of samples has the DTFT, short for discrete-time Fourier transform. A finite list of samples has the DFT you have been using, and the FFT from Step 12 is not a fifth tool. It is a fast way of computing the fourth one.

One fact holds across the whole family. It is worth meeting as a picture before any lab uses it. A short event needs a wide recipe, and a long steady event can make do with a narrow one. Squeeze a pulse in time and its frequency content spreads out. Stretch it and the content gathers in. The two widths trade against each other, always.

Lab 26 · Squeeze a pulse and widen its recipe
Try this firstPress 0.25 s, the shortest pulse width, and read the two bars. The time bar shrinks and the frequency bar grows. Then press 2 s and watch them swap roles.
Concentration trades across the two domains. The width product pill stays at 1.00 whichever pulse you pick: halving one width doubles the other. This is why a click in Step 11 lit every row of the spectrogram, and why a steady hum lights only one.

The family matters because using any of them is a claim about your data. Transform a finite block and you have silently claimed that the block repeats for ever. The leakage in Step 8 was the bill for that claim arriving. Naming the assumption is what lets you predict the bill.

Lab 27 · Name the right tool from the data
Try this firstPress continuous and then repeating, and read the tool the diagram lands on. Then work back to sampled and finite, which is every lab in this course.
Start from the data you actually have. The DFT is exact for its finite list. The assumptions only enter when that list is treated as a piece of something longer, and the diagram makes you say which piece.
Why does squeezing a pulse widen its recipe?

Because telling frequencies apart takes time. Two tones that differ by one cycle per second only drift apart by a whole cycle after a full second. A pulse a quarter of a second long ends before the drift shows, so waves across a wide band all fit it about equally well. The transform reports that honestly: a wide band of ingredients.

This is Step 7's rule wearing different clothes. Bin width was one over the block length, and a short pulse is its own short block. Nothing about the arithmetic changed, only the name on the picture.

Where do the Laplace and z-transforms fit?

The Fourier family asks one question: how much steady wiggling at each rate. The Laplace transform asks a wider one. It allows ingredients that grow or die away as they wiggle, so it can describe a system settling down, or running away, not just one holding steady. Control Systems leans on it for exactly that reason.

The z-transform is the same widening for sampled signals, and the DTFT sits inside it as the special case where nothing grows or dies. You do not need either one to read a spectrum. You will meet both the moment you ask whether a filter is stable.

The family map also settles the most tempting shortcut in the subject: padding a block with zeros to get more bars. The zeros do lengthen the list, so the bars land closer together. What they cannot do is add information, because the zeros were not measured. The extra bars are a smooth curve drawn through the answers you already had.

Lab 28 · Zero padding against a longer recording
Try this firstPress 2048 under DFT length after padding, and watch the dots crowd together on the same wide hump. Then press 2 s under measured time instead, and watch the hump itself narrow.
Padding interpolates the display, and measuring longer sharpens the truth. Two tones sharing one hump before padding still share it after. Only more measured seconds, which means waiting, can split them. The plot spacing pill and the true resolution pill move independently, and only one of them is evidence.
You append a second of zeros to a one-second recording before transforming it. What improves?
Only the plotted spacing improves. Padding buys a smoother drawing of the same evidence, which is real help when reading off where a peak sits. It never buys the power to separate tones, because that is fixed by how long you actually listened. Lab 28 shows the two numbers moving independently.
Step 14

Turn the two sums into one turning arrow

Every bin so far has been a pair of numbers: a cosine total and a sine total, drawn as the two short sides of a right-angled triangle. There is a second picture of the same pair, and the rest of engineering is written in it. Draw an arrow out from the centre of a clock face. Give it the magnitude as its length and the shift as its angle. The cosine total is that arrow's shadow on the floor. The sine total is its shadow on the wall.

A pair of numbers handled as one arrow has a name: a complex number. The horizontal shadow is called its real part and the vertical shadow its imaginary part. Both names are historical accidents and neither is a comment on reality. Nothing imaginary happens anywhere: the arrow is two ordinary sums stapled together so that they travel as one thing.

The arrow earns its keep when things move. Slide the wave along, as Step 10 did, and the two sums change in a complicated see-saw while the arrow simply rotates, keeping its length. The magnitude spectrum that would not move in Lab 20 is the picture you get by recording only the arrow lengths and letting the angles go.

Where does the famous e to the j theta come in?

Textbooks write the arrow at angle theta as e^(jθ), and the statement that this equals cos θ + j sin θ is Euler's relation. You can read that whole expression as pure notation: "the unit arrow at angle theta", floor shadow cosine, wall shadow sine. Nothing in this course needs more than that reading.

What the notation buys is compact bookkeeping. One symbol carries both sums, and the rules for combining arrows come out of the ordinary rules for combining symbols. It is shorthand that turns out to do arithmetic for you, which is why every textbook adopts it on page one.

Step 4 said the imaginary part carries a minus sign. Why?

Convention, and only convention. The standard DFT tests each frequency with an arrow turning clockwise, so the sine shadow it records is the negative of the plain sine total this course computes. The magnitude is a length either way, and lengths do not care about the direction of turning.

It matters exactly once: when you hand-check a course number against a library such as NumPy, expect the sine part to come back with its sign flipped. The cosine part and the magnitude will agree to rounding error.

What happens when two arrows are multiplied?

The lengths multiply and the angles add. That single rule is why the arrow picture took over the subject. A filter scales each ingredient and slides it, which is exactly a length multiplied and an angle added. So passing a signal through a filter becomes one arrow multiplication per bin.

Step 15 uses that rule to move a whole filtering job into the frequency domain and back. Doing the same with separate cosine and sine sums is possible and miserable: four multiplications and two additions per bin, arranged in a pattern nobody remembers.

Lab 29 · Turn one arrow and watch its two shadows
Try this firstPress 90° and watch the floor shadow vanish while the wall shadow takes everything. Then press 180° and 270°, reading the cosine and sine pills at each stop.
One arrow, two shadows, and the length never changes. The cosine and sine readings trade against each other as the angle turns, exactly the way the two sums traded in Step 4's quiz. A DFT bin stores this arrow: two coordinates, or equally a length and an angle.
A DFT bin comes back with real part 0 and imaginary part 4. What is that pair telling you?
An arrow of length 4, pointing straight up. The two parts are the shadows of one arrow, so a zero real part with a full-size imaginary part means the arrow stands vertical: a shift of 90 degrees. This is the same wave the cosine test alone would have missed entirely, back in Step 4, now read off in one glance.
Step 15

Keep an honest account of the energy

Square each of your samples and add the squares up. That total is the signal's energy, and squaring is what makes it honest. A swing to minus 2 works the air as hard as a swing to plus 2, and squaring counts both as 4. Loud signals have big energy, silence has none, and no clever shifting of parts can change the total.

Now do the same on the other side of the transform. Square each bin's magnitude, add them up, and divide by the number of samples. You get exactly the same total. That is Parseval's theorem, and it says the transform neither creates nor destroys anything. It only re-sorts the signal into ingredients, the way pouring flour into labelled jars changes no flour.

This sounds like a curiosity and is actually a working tool. Transform code is riddled with scaling choices: divide by the sample count, or by half of it, or not at all. Run the energy account on both sides and a wrong scale announces itself as a mismatch, before it quietly corrupts every number downstream.

Lab 30 · Balance the account on both sides
Try this firstPress impulse and read the two energy pills: both say 1. Then press sine and each block length in turn, and watch the two totals move together while the difference pill stays at rounding error.
The two totals agree for every signal and every block length, to rounding error. The agreement is computed here, not asserted, and it depends on dividing the squared magnitudes by the sample count. Change that convention and the account stops balancing, which is precisely how the check catches wrongly scaled code.

The arrow rule from Step 14 pays off here too. A filter, in frequency terms, multiplies each bin's arrow by its own arrow: length times length, angle plus angle. So a long, slow filtering job in the time domain can be done as transform, one multiplication per bin, and transform back. The sliding weighted average that a filter performs sample by sample has a name, convolution, and this route computes it wholesale. For long filters it is enormously cheaper, and the saving rides on Step 12's fast transform.

Why does filtering through the transform need padding with zeros?

Because the DFT treats its block as repeating, from Step 13. Multiply two unpadded transforms and the filtered output that should slide off the right-hand edge wraps round to the left. The start of the block gets corrupted with the end of it.

The fix is room: pad both lists with zeros until the block is at least as long as the two lengths added, less one. Then the wrap lands on zeros, harming nothing, and the answer matches the honest sample-by-sample version exactly.

Is energy here the same energy as in physics?

It is proportional to it, for the signals a sensor hands you. A loudspeaker driven by twice the voltage pushes with twice the force through twice the motion. The power goes up four times, which is the square showing up in the physics too. Engineers borrow the word with a clear conscience.

The proportion matters when the units do, which is Step 16's whole subject. Within one signal, though, the squared total is a fair loudness account whatever the units are, and that is all Parseval's theorem needs.

Does the energy account see the shifts that magnitude discards?

No, and that is worth noticing. Each bin contributes the square of its magnitude, and magnitude ignores shift, so the aligned and scrambled harmonics of Lab 21 carry identical energy. Your ear agreed: they were equally loud and differently shaped.

So the account can vouch for a transform's scaling and still say nothing about its phases. A code check built only on Parseval's theorem would pass a library that mangled every shift. That is why test suites also transform a known shifted wave and read the angle back.

You port transform code to a new library. A test signal's samples square-sum to 96, and the new library's bins square-sum, divided by the sample count, to 48. What is the most likely story?
A scaling convention, caught red-handed. The energy account balancing to exactly half is the signature of a factor placed differently, not of damage. This is the check working as designed: one comparison, run once, telling you to read the library's normalisation notes before trusting a single bar it draws.
Step 16

Put units on a spectrum, and error bars on your trust

Every bar in this course so far has been an amplitude in the same units as the samples: volts if the sensor speaks volts, pascals for a microphone. That is one honest choice among three. Square a bar and you have power per bin, in squared units, which is the energy account of Step 15 read bin by bin. Divide that by the bin width and you have power spectral density, shortened to PSD: squared units per hertz, the standard way measurement gear reports noise.

Density earns its place when block lengths differ. Halve the bin width and each bin catches half the noise power, so the per-bin bars all drop, while the density stays put. A bar without its unit is therefore unfinished: the same physical noise can be drawn three different heights, and only the label says which drawing you are looking at.

Lab 31 · The same signal under three labels
Try this firstPress amplitude, power and density in turn, and watch the unit box rewrite itself. Then change the block and watch the bin width pill move while the unit stays.
Three displays, one signal, and only the label tells them apart. A recorded spectrum should carry its unit, its scaling convention, its window and its bin width, because a later reader cannot reconstruct any of them from the picture. Writing them beside the data is a habit that costs one line.

Noise brings a second problem: one block is not enough. Transform one block of a hissy signal and the spectrum of that single block, called a periodogram, comes out wild, each bar dancing far from the true level. The repair is honest averaging. Welch's method cuts the recording into overlapping windowed segments, transforms each, and averages the powers. More segments mean a steadier estimate. Shorter segments mean wider bins. You are trading resolution for confidence, the same currency as ever.

Lab 32 · Trade bin width for a steadier estimate
Try this firstPress 256 under segment length and watch the segment count rise and the scatter pill fall. Then press 75% overlap and see the count rise again while the scatter falls more slowly than the count suggests.
Overlap does not manufacture independent evidence. Overlapping segments share samples, so they partly agree by construction, and the effective number of independent looks grows more slowly than the raw count. The scatter model in the pill discounts for that, which is why 75 per cent overlap is not three times better than none.
Why does averaging steady the estimate at all?

Because noise disagrees with itself. Each segment's periodogram is the true level plus a random error, and the errors in different segments point in different directions. Averaging lets them cancel, so the average settles towards the true level as more segments join in.

The settling is slow: cutting the scatter in half takes four times the segments. That square root is the price of confidence throughout measurement, and it is why long noise measurements take minutes, not milliseconds.

Amplitude, power and energy signals: which applies when?

A finite event, a hand clap, has a finite energy total, and energy per hertz is the natural density for it. A signal that runs indefinitely, background hiss or the mains hum, has unbounded energy but a steady average power, so power per hertz is the honest measure. The two densities answer different questions and carry different units.

Calibration decides whether either number means anything physical. A vibration lab keeps a note of the sensor's volts-per-unit figure with every recording. A PSD in volts squared per hertz is only an acceleration statement if that link survives.

An accelerometer datasheet quotes the sensor's noise floor. Which unit should you expect the PSD figure to carry?
Acceleration squared per hertz. Density is content per slice of frequency, so summing it across a band gives the squared acceleration in that band, which is what a noise floor is for. If a quoted figure carries no per-hertz part, it silently depends on someone's bin width, and comparing it with yours is meaningless.
Step 17

Measure what a physical system does to each frequency

Filters taught the habit of pushing one sine into a thing and measuring what comes out. Spectra let you do every frequency at once. Record the input to a system and its output at the same time, transform both, and compare them bin by bin. Each bin answers two questions: how much did this frequency get scaled, and how far did it get delayed. That per-frequency answer sheet is the system's transfer function, written H(f): its gain and its shift at every frequency.

A pure delay has a tell worth memorising. It scales nothing, so the gain sits flat at 1, and it shifts every frequency by the same time, which is more cycles for faster waves. So its shift falls along a straight line as frequency rises. Instruments exploit that in reverse, reading a system's delay off the slope of its measured shift.

Lab 33 · Read gain and delay off the two waves
Try this firstPress gain and watch the output wave grow to twice the input's height. Then press 8 samples of delay and 200 Hz, and watch the displayed shift wrap past a full turn.
The shift wraps every full turn, and the wrap is a trap. A reading of minus 288 degrees displays as plus 72, because a circle cannot show more than one turn. Fitting a delay to measured shifts means unwrapping them first, following the line across the wraps rather than believing each reading alone.

Real measurements add noise, and dividing one noisy spectrum by another multiplies the mess. So practical instruments average many blocks, and they report one more number alongside the transfer function: coherence, a score from 0 to 1 per frequency. It asks how much of the output at that frequency moves in lockstep with the input. High coherence means the transfer estimate there stands on evidence. Low coherence means noise, an unmeasured second input, or a system that is not behaving linearly, and the estimate at that frequency should not be trusted.

Lab 34 · Decide whether the estimate deserves belief
Try this firstPress high shared signal and low output noise, and watch the coherence bar fill towards 1. Then raise the noise to high and watch the bar collapse. Finally press 32 averages and watch the whiskers tighten while the bar itself stays put.
Averaging narrows the uncertainty and cannot raise the truth. More averages shrink the whiskers around the coherence estimate, but only a stronger shared signal moves the bar. And a high bar is still not proof of cause: a third source driving both channels produces high coherence between two things that never touch.
What does a trustworthy measurement session look like?

Drive the system with an input that contains every frequency you care about, without pushing it so hard it stops behaving linearly. Record input and output on one shared clock, since a clock difference masquerades as delay. Average repeated runs, inspect the coherence before believing any bin, and write down the settings beside the data.

Then test the estimate against a different input than the one that built it. A model that only predicts the recording it was fitted to has memorised, not measured, and Step 20 meets the same rule again wearing machine-learning clothes.

Why would a system stop behaving linearly, and what does that do here?

Push most physical things hard enough and their response stops being proportional: an amplifier clips, a spring stiffens, a loudspeaker cone hits its limit. A clipped sine is no longer a sine, and the extra corners are new frequencies the input never contained.

The transfer function has no row to file those under, since it only maps input frequencies to themselves. The energy leaking into new frequencies drags coherence down, which is exactly the warning light behaving as designed: turn the drive level down and measure again.

At exactly 120 Hz your measured coherence drops to nearly zero while neighbouring frequencies read 0.98. What does that reading mean?
Distrust that one bin, then hunt the intruder. Coherence is a per-frequency warning light. A sharp dip at 120 Hz with healthy neighbours is the signature of interference, often mains hum harmonics, driving the output independently of your input. The transfer numbers there are not wrong so much as about somebody else's experiment.
Step 18

Survive samples that arrive unevenly, or not at all

The DFT's quietest assumption is the metronome: every sample exactly the same time after the last. Real data breaks it constantly. A telescope observes when the sky is clear. A wireless sensor drops packets. A logger writes a reading when something happens, not on the tick. Feed such data to a DFT as if it were even and the arithmetic runs happily, on a signal that was never measured.

The damage has a shape worth knowing. A sample taken late is a sample of the wave further along its cycle, so timing error becomes shift error, and the same lateness costs more cycles at higher frequency. A microsecond hardly moves a 10 Hz reading and mangles a megahertz one. Slow signals forgive sloppy clocks. Fast ones do not.

Lab 35 · Watch timing error become shift error
Try this firstPress 10 Hz and 500 µs, and read the worst shift error pill: small. Then press 400 Hz with the same jitter and watch the error grow forty-fold, with the drawing's dots sliding visibly off their ticks.
The same clock error matters more the faster the signal. The grey ticks are where a perfect metronome would sample and the dots are where the jittery clock actually did. The wave drawn behind them shows why the miss costs more at 400 Hz: the wave has moved further in the same mistaken interval.

The honest repairs all start the same way: keep the timestamps. Small jitter can be repaired by resampling onto an even grid, with the interpolation model written down. Bigger irregularity has purpose-built tools. The Lomb-Scargle method, named after its two inventors, asks Step 4's sine question at the times you actually measured, no even grid required. What no method can do is conjure the samples that were never taken.

Lab 36 · Judge a gap before filling it
Try this firstPress 1 missing sample against a period of 40 samples, and the verdict calls interpolation plausible. Then press 6 missing against a period of 4, and watch the unseen cycles pill explain the refusal.
Interpolation is a prediction, not a measurement. A gap much shorter than one cycle can be bridged because the wave had no room to surprise you. A gap hiding whole cycles can contain anything, and a smooth fill will contain none of it. Keep a mask saying which samples were observed, so nobody downstream mistakes the guesses for data.
Why is smoothly filling every gap actively dangerous?

Because a smooth interpolator is a promise that nothing interesting happened, inserted into the data as if it were evidence. A fault transient that struck inside the gap is replaced by a polite curve, and the filled record then looks cleaner than the machine it came from.

The defence is stated doubt: analyse with two different plausible fills, or with the gap simply cut out, and report which conclusions change. A conclusion that flips with the fill was resting on the guess, not on the measurement.

Who actually meets this problem?

Astronomers most famously: a star's brightness sampled only on clear nights, with the daytime a built-in gap, which is why the Lomb-Scargle method grew up in astronomy. Their gaps even manufacture fake frequencies, ghosts spaced at one cycle per day, that a naive spectrum reports as real.

Closer to this stream: battery sensors that report on change to save power, networks that drop packets, event logs stamped when software got round to writing them. Any spectrum computed from such records is only as honest as its treatment of the timestamps.

A sensor's packet went missing and you interpolate a replacement sample so the DFT can run. What must be kept alongside the filled record?
Timestamps and the mask. A predicted sample is a different kind of object from a measured one, and only the mask preserves the difference once both sit in the same list. Any later analysis can then choose its own treatment of the gap, including refusing to trust conclusions that lean on it.
Step 19

Read an image as frequencies across space

Nothing in the recipe idea mentions time. Take any line of pixels across a photograph and you have a list of brightness numbers, a wave in space rather than in time. Frequency becomes spatial frequency: how many times the brightness cycles per pixel travelled. Slow rolls of shading are low spatial frequencies. Fine textures and sharp edges are high ones.

An image runs in two directions at once, so its transform does too, comparing the picture against striped patterns at every spacing and every angle. One clean set of stripes in the image becomes a pair of bright points in the spectrum, mirrored through the centre, the same mirror pairing Step 6 measured. The pair sits along the direction the brightness changes, which is across the stripes, not along them. Closer stripes push the pair further out.

Lab 37 · Turn stripes into two points of spectrum
Try this firstPress 4 px spacing and watch the two points move far from the centre. Then press horizontal stripes and watch the pair swing onto the vertical axis, because that is the direction the brightness now changes in.
Closer stripes mean higher spatial frequency, further from the centre. The pair lies at right angles to the stripes themselves, which surprises everyone once. The spectrum records the direction of change, and brightness changes as you walk across stripes, not along them.

Editing the spectrum edits the picture. Keep only the points near the centre and fine detail vanishes: a blur. Remove the centre and keep the edges of the spectrum and only fine detail survives: an edge-finder. Delete one offending pair of points and a periodic nuisance, scanner stripes or sensor interference, lifts out of the photograph while everything else stays. That targeted deletion is called notching, and it has no counterpart as clean in the pixel domain.

Lab 38 · Filter a picture from inside its spectrum
Try this firstPress low-pass and then cutoff 0.15, and read how much detail survives. Then press notch and watch the mask bite one band while both ends pass.
The mask's shape comes back as texture in the image. A mask with a cliff edge makes ripples spread from every sharp feature, which is called ringing. It is Step 8's lesson in reverse: sharpness in one domain spreads in the other. A mask that fades gradually rings far less.
Do real imaging machines actually work in the spectrum?

Some are built there. An MRI scanner records its measurements directly as points of the image's spatial spectrum, and the photograph of your knee is one inverse transform later. The machine's operators talk about filling in the spectrum the way photographers talk about exposure.

A camera lens does it in glass: it cannot pass stripes finer than its aperture allows, so it is a physical low-pass filter. Its blur is the gentle kind a gradual mask predicts. Diffraction, telescope resolution and audio filtering are one mathematics wearing three costumes.

Does the idea stretch beyond flat pictures?

To three dimensions and beyond. Volume scans, simulated weather, and the pressure field around a wing all have spatial spectra. The transform's favourite trick still works there: taking a derivative, which is the slope of a field, becomes multiplying each ingredient by its own frequency.

Solvers for the equations of physics exploit that, doing calculus as multiplication in the spectrum at fast-transform prices. The method is superb while the field is smooth and repeats at the edges, and it inherits every assumption this course has priced, leakage included.

A scanned document has faint vertical stripes all over it from the scanner's lamp. Where should you look for them in the spatial spectrum?
On the horizontal axis, mirrored about the centre. Stripes are a spatial tone, and a tone is a pair of points along the direction of change. Notch those two points and the lamp's stripes lift cleanly out of the scan, which is a repair no amount of pixel-by-pixel retouching does as well.
Step 20

Feed spectra to learning machines without fooling yourself

Machine learning systems that listen, to speech, to machinery bearings, to heartbeats, rarely eat raw samples. Most eat some version of Step 11's picture. The spectrogram's formal name is the short-time Fourier transform, or STFT, and a complex STFT is one that keeps each bin's full arrow rather than just its length. Two further dressings are common. A log spectrum squashes the heights so quiet detail stays visible next to loud. Mel bands merge bins into wider bands going up in pitch steps matched to human hearing, named after a scale of melody.

Which dressing to use is an engineering decision, not a fashion. The rule that decides it is the one this course has been building: keep what the answer depends on. Discarding the arrows' angles, as every magnitude picture does, throws away timing within a cycle, which Step 10 showed is the shape of the wave. Fine for naming a vowel. Ruinous for a system that must rebuild or align the waveform it heard.

Lab 39 · Choose a representation for the job
Try this firstPress yes under phase required, and watch every budget and duration lead to the complex STFT. Then press no and walk the other two controls, reading how the candidate changes.
The choice is a starting candidate, not a verdict. The deciding questions are the course's own: how short are the events, does the answer depend on the shifts, and what can you afford to compute. The final word belongs to a measured comparison on data the model has not seen.

The transform has also moved inside the models. A Fourier neural operator is a learned simulator for fields: waves, heat, weather-like flows. It works by transforming the field to its spatial spectrum, mixing a limited number of ingredients with learned weights, and transforming back. Trained well, it answers in milliseconds where a classical solver takes hours. It remains a fit to its training data: outside what it saw, it can be confidently and smoothly wrong.

Lab 40 · Gate a learned solver like an instrument
Try this firstPress 32 retained modes, 95% coverage and residual 0.01, and watch all three gates go green. Then drop any one of them and watch the release verdict refuse.
A fast answer is only useful inside its measured limits. The three gates are the habits of this course applied to a model. Keep enough ingredients, test on enough of the territory, and check the answer against the physics it claims to obey. Keep a trusted slow solver, and route anything unfamiliar to it.
What are the standard tools for all this, as of 2026?

NumPy, SciPy and PyTorch all ship fast transforms, real-input variants, and explicit scaling options, and SciPy adds Welch averaging, coherence and Lomb-Scargle under those names. The conventions differ between libraries in exactly the ways Step 15's energy check catches, so run it once per library rather than assuming.

The Fourier neural operator paper is the readable origin of the learned-solver idea. Reproducing its comparisons on your own geometry, before trusting them, is the same habit as validating a transfer estimate on a fresh input.

Is a spectrogram front end old-fashioned now that models can eat raw audio?

No. End-to-end models that learn their own front end sometimes win, given oceans of data. Their first learned layer routinely turns out to resemble a bank of frequency filters anyway: the model reinvents the ear. With modest data, a fixed spectral front end is often the stronger and cheaper choice.

The honest comparison is measured, not argued: same task, same held-out data, both front ends. What this course adds is knowing what each representation discarded, so a mysterious failure can be traced to a missing ingredient rather than to bad luck.

A learned spectral solver scores excellent average test error, but on a new boundary shape its answers violate conservation of energy. What should ship?
Fall back, then validate. Task error, physical residuals and coverage all belong in the release decision, because each catches failures the others miss. A model that is excellent on its own territory and wrong beyond it is not a bad model. It is an instrument used outside its calibrated range, which is an operator error, not a mystery.
Step 21

Your own eight numbers, and nothing marked

Everything in this course is in one place here, with no goal and no verdict. Build a signal out of up to three parts, choose how long the block is and how fast it was sampled, pick a window, and read the spectrum it produces. The multiplication count for the transform being displayed is printed with it.

Four things are worth doing on purpose before you leave. Put a part at a frequency above half the sample rate and find where it comes back. Set two parts a fraction of a bin apart and watch them refuse to separate. Move a part off a bin and turn a window on. And set every part to the same frequency with different shifts, and see what one bar can be made of.

What comes after this course?

Advanced work derives transform pairs with calculus, studies distributions such as the impulse, and designs perfect-reconstruction filter banks. It uses wavelets and reassigned time-frequency methods, and solves inverse problems where the measured spectrum is incomplete or noisy.

The engineering habits here still apply: write the transform convention, preserve units and timestamps, state boundary assumptions, and measure uncertainty. Test a reconstructed or predicted result against data that was not used to produce it.

How do I know a spectrum I am looking at is telling me the truth?

Ask the four questions this course has put numbers on. How long was the block, which fixes the bin width and therefore what could possibly be separated. Was a window used, which decides whether a quiet bar is real or is leakage from a loud one. Is the interesting bar sitting on a bin or between two, which decides whether its height can be trusted to better than about a third. And is anything above half the sample rate, which will have folded down and be sitting on top of something innocent.

Four questions, and you can answer all of them from the settings rather than from the picture. Most misread spectra are misread because nobody asked the first one.

What does each control change?

The three parts each build one cosine, and they are added together to make the signal. Each part has a frequency in hertz, a height in the same units as the samples, and a shift in degrees. Setting a height to zero switches a part off. The samples in the block and the sample rate together fix the bin width and the block length in seconds.

The window multiplies the samples before the transform, and the readings are divided by the window average so that a windowed bar is comparable with an unwindowed one. Everything else on the panel is measured from the result, including the multiplication count, which comes from a counter inside the transform.

Lab 41 · Every control in the course, in one place
Try this firstSet part one to 5 Hz, then drag its frequency to 5.5 and watch the whole spectrum come alive. Then switch the window to Hann and watch the far bars collapse again. Nothing here is marked.
The most useful game is to predict before you press. Every number here is computed from the settings by the same two sums you did with a pencil in Step 4. If a bar surprises you, one of the four questions above will explain it, and working out which one is the skill this course was for.
A colleague shows you a spectrum of a motor's vibration, taken from a very short block, and points at a small bar near 300 Hz as evidence of a fault. What is the first thing to ask?
Ask about the window first. Lab 19 is this exact situation: a tone 0.020 tall reading 0.097 because a loud neighbour is leaking into its bin. On a short block with no window, small bars near a loud one carry almost no information. Everything else worth asking, the block length and whether the interesting bar sits on a bin, comes straight after. All of it is answered from the settings rather than from the picture.

What you can do now

  • Say what the frequency domain is: the recipe view of a signal, an amount and a shift for each pure wiggle, with the equaliser as its everyday picture.
  • Work out one bin of a transform by hand: multiply the samples by a cosine, add up, do the same against a sine, and take the hypotenuse.
  • Say why there are two sums per frequency and not one, and what the second one catches.
  • Turn a magnitude into an amplitude in the units of the samples. Say why the divisor is half the sample count for most bins and the full count for two of them.
  • Read a spectrum: bin number, frequency in hertz, magnitude and amplitude, and know which half of it to ignore.
  • Work out the bin width from the sample rate and the block length, in either direction. Say how long a recording has to be to separate two frequencies a known distance apart.
  • Recognise leakage from its fingerprint, two nearly equal neighbouring bars with a dusting everywhere else, and say how far the peak height can be trusted.
  • Choose a window on purpose, knowing that it buys freedom from leakage and pays in resolution, and name a case where the right choice is none.
  • Say what magnitude alone loses, and what a signal rebuilt from magnitudes only will sound like.
  • Choose a spectrogram's block length to match the event you are looking for, and say what that choice costs in frequency detail.
  • Explain, by counting rather than by quoting, why the slow transform costs the square of the block length and the fast one costs the block length times its halvings.
  • Distinguish Fourier series, continuous transform, DTFT, DFT and FFT, and explain why zero padding does not improve true resolution.
  • Use complex rotation to interpret DFT bins, check energy with Parseval, and explain why frequency-domain convolution needs padding.
  • Label amplitude, power and PSD with correct units, and choose Welch segment length and overlap with an explicit resolution-versus-variance trade.
  • Estimate a transfer function from paired input and output measurements, and use coherence to find frequencies where the estimate is not trustworthy.
  • Handle irregular or missing samples without discarding timestamps, and read spatial frequency in an image or field.
  • Choose a spectral representation for a learning task and gate a learned spectral solver with coverage, task error and physical residual checks.
  • Ask the four questions that decide whether a spectrum somebody hands you means what they say it does.

Where this goes

  • Modulation. Putting data on a carrier is done by changing its height, its frequency or its shift, and reading it back is a transform per symbol. The shift column that Step 10 kept becomes the data itself.
  • Software-Defined Radio. A radio that is mostly arithmetic runs transforms continuously. The count from Step 12 decides whether a given band can be watched at all on a given processor.
  • Filters. The frequency response measured one sine at a time in that course is a transform of the filter's impulse response, so everything measured there can now be computed instead.
  • Machine learning. Spectrograms, complex STFTs and learned waveform front ends are alternative representations whose value must be measured on the downstream task.
  • Computer Vision. Two-dimensional spectra explain spatial filtering, periodic interference and part of the geometry behind modern imaging systems.