DSP from Scratch · Lesson 4
How Much Coffee Is Still in You at Midnight? The Impulse Response
One measurement after one cup predicts any day of coffee. The same idea predicts what any system does.

Press play: it starts at
Chapters17 parts, tap one to jump there
In one sentence
One tap in, one answer out, and that answer predicts everything.
Watch first, then read. The video shows every idea moving. These notes write out each step so you can check the maths at your own pace. Press any ▶ time button to jump the video to that moment.
Here is a strange fact. If you drink a coffee at seven in the evening, about half of its caffeine is still in your body at midnight. That is like drinking half a coffee right before bed. And if you had two more coffees earlier that day, the total at midnight is almost a whole cup.
How can we possibly work that out? With one simple idea: measure what happens after one single cup, and you can predict any day of coffee. In signal processing this idea is called the impulse response. Engineers use it to test speakers, train wheels and bridges; here we learn it with your own body.
By the end you will be able to answer this: you drink a coffee at 9 am, 2 pm and 7 pm. How much caffeine is still in you at midnight?
Quick recap
In lesson 1 we saw that a digital signal is a list of measurements taken at regular moments, like a nurse writing down your temperature every hour. Today our list is the caffeine in your body, measured in cups: one cup means the caffeine from one ordinary cup of coffee.
One cup: watch the caffeine fade
Start with a single cup at 9 am. Its caffeine quickly soaks into your blood: one cup’s worth. Then your body starts clearing it out, slowly. For a typical adult, about half is gone after five hours, so let us check every five hours: at 2 pm, 7 pm and midnight.
- At 2 pm, half a cup is left.
- At 7 pm, half of that: a quarter.
- At midnight, half again: an eighth of a cup. Fifteen hours later, it still has not gone.
So one cup gives this curve: 1, ½, ¼, ⅛. Tall at first, then fading. Keep your eye on this shape: it is the only measurement we will ever need.
Real people differ: some clear caffeine in three hours, others take eight or more. But the idea works the same for everyone, so we will stick with five. (You can change it in the lab.)
Two simple rules
What if you drink two cups at once, or have your coffee later in the day? Do we need a new test for every possibility? No. Your body follows two simple rules, and they do all the work.
Rule 1: twice the coffee gives twice the caffeine, at every check. A double coffee gives 2, 1, ½, ¼: the same shape, just twice as tall. Half a cup gives the same shape, half as tall. And when coffees overlap, their caffeine simply adds up; your blood does not care which cup it came from.
Rule 2: the same coffee later gives the same curve, just later. A coffee at 2 pm gives 1, ½, ¼, ⅛, starting at 2 pm. The whole curve simply slides along the clock.
Rule 1: twice the coffee, twice the caffeine
A double coffee at 9 am: 2, 1, ½, ¼. Same shape, twice as tall.
Rule 2: a later coffee gives the same curve, later
One cup at 2 pm: 1, ½, ¼, starting at 2 pm.
Half a cup. From 2 pm to midnight is two checks, and after two checks one cup leaves a quarter. Twice a quarter is a half.
A whole day of coffee
Now the big question: coffees at 9 am, 2 pm and 7 pm. Here is the trick: deal with each cup on its own. Each one makes its own copy of the curve, starting at the moment you drink it.
- The 9 am cup: 1, ½, ¼, ⅛.
- The 2 pm cup: the same curve, starting one check later.
- The 7 pm cup: one check later again.
Now add them up at each check:
| Check | 9 am cup | 2 pm cup | 7 pm cup | Total |
|---|---|---|---|---|
| 9 am | 1 | 1 | ||
| 2 pm | ½ | 1 | 1½ | |
| 7 pm | ¼ | ½ | 1 | 1¾ |
| midnight | ⅛ | ¼ | ½ | ⅞ |
At midnight: of a cup. Almost a whole coffee, still in you as you go to bed. And look where most of it comes from: the 7 pm cup, which on its own leaves half a cup at midnight. That is why an evening coffee keeps you awake.
One measurement predicts them all
Here is the surprising part. We never tested three cups. We never looked inside your body. We measured one cup, once. Everything else came from copying that one curve:
- sized to the cup,
- slid to the moment you drank it,
- and added up.
And it works for any coffee day at all: a cup here, half a cup there, a double at lunch. One measurement predicts them all.
The real names
Engineers use these ideas every day, so let us give them their real names.
- Anything that takes a signal in and gives a signal out is called a system. Here, your body is the system. Its input is your coffee, a list of how many cups you drink at each moment; its output is the caffeine in your blood.
- A single, short input, like one cup at one moment, is called an impulse. Think of it as one quick tap.
- What comes out after that single tap is called the impulse response, often written . Your body’s impulse response, checked every five hours, is .
The two rules have names too:
- Twice the input gives twice the output, and overlapping inputs simply add: that is called linear.
- The same input later gives the same output later: that is called time-invariant.
When the rules break
The rules really must hold. Turn a small speaker up too far and it starts to crackle: it cannot move any further, so twice the input no longer gives twice the output. It is not linear, and the copies will not add up to the right answer.
And if someone keeps turning a volume knob while you test, a tap now and a tap later get different answers. That system is not time-invariant.
The same idea with sound
In a computer, a sound is a list of numbers, one for each moment. So the simplest tap is a list with a single 1 and zeros everywhere else:
It is called the unit impulse: “unit” because its size is one. Played as a sound, it is a single sharp click.
Here is a simple system: a tiny program that smooths out jumpy numbers. Each output is the average of the newest number and the one just before it. Writing for the input and for the output, as in lesson 1:
where means “the number one step before ”.
Tap it with the unit impulse. At the first step the newest number is 1, with nothing before it, so the average is ½. At the next step it is 0 and 1: ½ again. After that, only zeros. So its impulse response is
Your body’s response fades slowly; this one is over in two steps. Every system has its own impulse response, a bit like a fingerprint.
Now a real input: 2, then 4. Treat each number as a tap.
- The 2 makes a copy twice as tall: 1, 1.
- The 4 makes a copy four times as tall, one step later: 2, 2.
- Add them up: 1, then , then 2. The output is 1, 3, 2.
Check it the long way, by averaging: 2 and 0 give 1; 4 and 2 give 3; 0 and 4 give 2. Exactly the same.
3, 4, 1. The 6 makes 3, 3; the 2 makes 1, 1, one step later. Added: 3, then , then 1.
The one-tap test in real life
- Speakers. Engineers play a single click through a new speaker and record what comes out. That recording is the speaker’s impulse response, and it tells them how the speaker will sound with any song.
- Train wheels. Railway workers once tapped every train wheel with a hammer and listened. A healthy wheel rings clearly; a cracked wheel sounds dull. The crack changes the system, so it changes the impulse response. Engineers still tap aircraft panels and bridges for the same reason.
- Medicine. Scientists measure the level in the blood after a single dose, then add up copies of that curve to plan a schedule, like one tablet every eight hours, that keeps the level high enough to work but never too high. Exactly our coffee trick.
Three common mistakes
Recap
- A system turns an input signal into an output signal.
- Give it a single tap, and what comes out is its impulse response.
- If the system is linear and time-invariant, every input is a row of taps. Each tap brings a copy of the impulse response, sized to the tap and slid to its moment. Add the copies and you have the output.
Say the main idea aloud once: one tap in, one answer out, and that answer predicts everything.
Next, lesson 5 turns copy, slide and add into one quick recipe for any input. It is called convolution.
Interactive lab
Plan a day of coffee, then feed the smoother
Tap the hours you drink coffee and watch each cup bring its own copy of the one-cup curve. Then type any input into the two-point smoother and see the copies add up.
1. Plan a day of coffee
Each colour is one cup’s own copy of the curve. The bar at each hour is all the copies stacked.
2. Feed the smoother
Type any input. Each number brings its own copy of ½, ½; the copies are added, then checked by averaging.
Sign in to open the lab
It is free. Signing in with Google also keeps your progress and your scores.
Sign in with GoogleLesson 1 of every course is open without signing in.
Check yourself
Did it stick?
Work each one out on paper first. Every question has a full worked answer.
- 1
What is an impulse response?
Worked answer
An impulse is a single, short input: one tap. The impulse response is what comes out of the system after that one tap. For the body and one cup of coffee, checked every five hours, it is 1, ½, ¼, ⅛.
- 2
A system’s impulse response is 1, ½, ¼. You tap it with a size of 4. If the system is linear, what comes out?
Worked answer
Linear means a tap four times as big gives an output four times as big, at every step. So multiply every value of the impulse response by 4:
The same shape, four times as tall.
- 3
Half the caffeine is gone every five hours. You drink a double coffee (two cups’ worth) at 7 pm. How much caffeine from it is still in you at midnight?
Worked answer
From 7 pm to midnight is five hours: one check. After one check, one cup leaves ½ a cup.
A double coffee is twice the input, so its copy is twice as tall:
A whole cup’s worth of caffeine at bedtime.
- 4
A system gives three times the output when you double the input. Can you predict it by sizing, sliding and adding copies of its impulse response?
Worked answer
The trick needs a linear system: twice the input must give twice the output. Here twice the input gives three times the output, so the system is not linear, and copies of the impulse response will not add up to the true output. Being time-invariant is not enough on its own: both rules must hold.
- 5
The two-point smoother has impulse response ½, ½. The input is 4, then 6. What comes out?
Worked answer
Treat each input number as a tap and make its copy:
- the 4 makes , starting at step 0;
- the 6 makes , starting one step later, at step 1.
Add them at each step: step 0 gives 2; step 1 gives ; step 2 gives 3. The output is 2, 5, 3.
Check the long way, averaging each number with the one before: , , . The same.
Sign in to open the checks
It is free. Signing in with Google also keeps your progress and your scores.
Sign in with GoogleLesson 1 of every course is open without signing in.
Was this lesson clear?
Free weekly email
Get the next lesson by email.
The week's new lessons, the daily facts in one place, one thing to try in the lab and one puzzle. Free.
No spam. One click to leave.