A filter that does not know the room can still learn it. One tiny rule, nudged by each new error, drives the error down about 30 dB in our toy room.
Learn how a filter tunes its own weights sample by sample, why that works, how fast, and where it settles.
Drag the step size, then press Change the room and watch the weights chase the new truth. Push the step size too high and watch it break. Then we build, piece by piece, the Wiener filter, the LMS rule, its convergence, and the jobs it does: cancelling noise, equalizing a channel, training a neuron.
You need a little linear algebra (a vector, a dot product, a matrix times a vector) and the idea of an average. We build the rest from zero.
Based on Lecture 14 (23 November 2020) of Stanford EE269: Signal Processing for Machine Learning, taught by Mert Pilanci. Lecture slides (PDF) and the course slide list. Every idea is re-taught here in our own words and devices. It builds on regression, linear systems and stationary signals.
Toy setup: white input noise of power 1, a six-tap unknown room with random weights, and measurement noise with standard deviation 0.03 (power about −30 dB). The filter runs the LMS rule of Chapter 4, two samples per frame. Error power is a running average of e squared.
Chapter 0
See why a fixed filter fails when the world changes, and meet the delay line, the error and the notation the whole lecture uses
You are on a speakerphone call. Your friend talks, her voice comes out of your speaker, bounces off the walls, and creeps back into your microphone. She hears her own voice a moment later. That is an echo. To remove it, your phone must know exactly how the room changes a sound on its way from speaker to microphone.
Nobody gives the phone that recipe. Worse, the room does not hold still. You turn your head, someone opens a door, a cup lands on the table. Any recipe measured in advance goes stale within seconds.
So the phone does something smarter. It makes a guess, listens to what is left over after the guess, and uses that leftover to improve the guess. It repeats this thousands of times a second. The guess learns the room, and it keeps learning when the room changes. This is an adaptive filter, and the hero at the top of this page is one at work.
A filter makes a new signal from an old one. The kind we use here is the simplest: each output sample is a weighted sum of the last few input samples. A weight says how much one past sample counts. A big weight means “listen closely to that moment”. A zero weight means “ignore it”.
The lecture draws this as a tapped delay line. The input u[n] enters a chain of delays, each holding the previous sample one step longer. At every tap, a weight multiplies the sample. A sum adds the products. The weights w0, w1, …, wM−1 are the filter’s impulse response, and M is its length.
Try one by hand. Take three weights, 0.5, 0.3 and 0.2, and the last three inputs, 1.0, 0.4 and −0.2. The output is 0.5 × 1.0 + 0.3 × 0.4 + 0.2 × (−0.2) = 0.50 + 0.12 − 0.04 = 0.58. That is all a filter ever does: one dot product per time step.
The blue curve is a noisy signal u. The green dashed curve is the clean signal d we wish we had. The warm curve is what the filter outputs. Drag the time slider to move the five taps along, then choose a set of weights.
Toy signals: a clean wave d[n] = sin(2πn/20) plus Gaussian noise of power 0.25 gives u[n], 120 samples, the same every visit. The best weights are fitted live by least squares over the whole signal, the idea of Chapter 1.
Move the slider and watch. The output is a smoothed copy of the noisy blue curve. With zero weights the filter does nothing and the error is as large as the signal. With the best weights the error is small, because the filter learned to average out the noise but keep the wave.
Now the lecture adds two more signals. The desired signal d[n] is what we want the output to be. The error e[n] is the miss: how far the output landed from the target.
The diagram on the lecture’s slide has a second box under the filter, labelled weight control. It takes the error and the input, and it adjusts the weights. That box is the whole subject. Every chapter after this one asks one question: how should the weight control turn an error into a better set of weights?
Writing every sum with an index gets heavy. The lecture packs the M weights into one column vector w and the M newest samples into another, un. Then the whole filter is one dot product.
w = [w0 w1 … wM−1]T un = [u[n] u[n−1] … u[n−M+1]]T y[n] = unT w
Two averages will matter. Take many time steps and average. The correlation matrix Ru = E[un unT] records how much each tap’s sample moves with every other tap’s. The cross-correlation vector rud = E[un d[n]] records how much each tap moves with the target. Here E means “the average over all the randomness”.
Their shapes are worth fixing in mind: Ru is M × M, rud is M × 1. For white noise of power σ2, each sample ignores the others, so Ru is σ2 times the identity. Whenever the signal has a rhythm, the off-diagonal entries become non-zero. That detail will control how fast learning goes in Chapter 5.
A last word on the logistics. This is Lecture 14 of EE269, given on 23 November 2020 by Mert Pilanci. Our chapters follow its slides in order, and the last one ends at a single neuron, the doorway to the neural network lessons that come next in this series.
Chapter 1
Stack the recent samples into a matrix, solve for the weights in one shot, and learn why one shot is not enough
Suppose you recorded 200 samples of the signal going into the speaker, and 200 samples of what the microphone heard. You want the three weights that turn the first recording into the second as closely as possible. How do you find them?
You could guess, check the miss, and guess again. A cleaner way is to treat the whole recording at once. Every time step is one small equation: “these three input samples, times these three weights, should give this microphone sample”. There are 200 such equations and only three unknowns. They cannot all be exactly true, because of noise. So we ask for the weights that make them nearly true, in total.
Pick a window of K time steps, from n0 to n0 + K − 1. The lecture requires K ≥ M, at least as many equations as weights. For each step, the filter output is the dot product from Chapter 0. Stack the K outputs into a column. Stack the K rows of input samples into a matrix A.
Each row of A is one window of the input: u[n], u[n−1], …, u[n−M+1]. The next row slides one step along, so the matrix repeats itself along its diagonals. Row 1 starts at u[n0]; row 2 starts at u[n0+1] and reuses most of row 1’s numbers, shifted by one place. The slide draws exactly this, K rows by M columns.
The cost is a bowl in the weights. Its lowest point is where the slope is zero. Write the cost as (Aw − d)T(Aw − d), differentiate with respect to w, and you get 2AT(Aw − d). Set that to zero.
ATA w = ATd so w = (ATA)−1 ATd
These are the normal equations, the same ones as in regression. The word “normal” means “at right angles”: at the best weights, the error column is at right angles to every column of A. Nothing in the error can still be explained by the input.
Look at what ATA holds. Entry (i, j) is the sum, over the window, of the product of tap i and tap j. Divide by K and it is an average of products: an estimate of the correlation matrix Ru from Chapter 0. In the same way, (1/K) ATd estimates rud. Hold on to that. Chapter 2 will find the best weights from the true averages, and the normal equations will reappear with R and r in place of the window sums.
Take M = 2 weights and K = 4 steps. The input is 1, −1, 2, 0, 1 for n = 0 to 4, and we use the steps n = 1 to 4. The target is d = [−0.2, 0.8, 0.5, 0.4]. The numbers are illustrative.
Each row of A is (u[n], u[n−1]): (−1, 1), (2, −1), (0, 2), (1, 0). Column 0 is [−1, 2, 0, 1] and column 1 is [1, −1, 2, 0]. Now take sums of products.
ATA = [[6, −3], [−3, 6]] ATd = [2.2, 0.0] w = (1/27) [[6, 3], [3, 6]] [2.2, 0.0] = [0.489, 0.244]
Check the right angle. The outputs are y = [−0.244, 0.733, 0.489, 0.489], so the errors are e = [−0.044, −0.067, −0.011, 0.089]. Column 0 times e: 0.044 − 0.133 + 0 + 0.089 = 0. Column 1 times e: −0.044 + 0.067 − 0.022 + 0 = 0. Both are zero. The squared error is 0.0144, and no other pair of weights does better.
This works well for a recording you have already made. It is awkward for a live phone call, for three reasons. Each new window needs a new solve, costing about K × M2 operations to form ATA plus about M3 to solve it. An echo canceller with 1,000 taps, repeated 8,000 times a second, cannot afford that. You must also store the window. And you must choose K.
That choice is a real trade. A short window has few equations, so noise sways the weights: the estimate is jumpy. A long window averages the noise away, but it also holds old data. If the room changed halfway through the window, the fit is a muddle of two rooms: the estimate is stale. Try it.
The room has four weights. At sample 300 it changed, and we are now at sample 400. Top: the true new weights (blue) and the least squares fit from the last K samples (warm). Bottom: the average error against K, with your K marked. Drag K, and flip the noise.
Toy setup: white input of power 1, four true weights that change at sample 300, measurement noise as chosen. The curve averages 14 seeded random trials per window length. The bars show the first trial. Error is the squared distance between fitted and new weights, in dB.
With the noise up, the curve falls steeply at first: more samples tame the noise. Then it climbs again once the window reaches back past sample 300. The best K sits at the bottom, and it moves left when the room changes more often. No fixed K is right for a world that keeps moving, and that is the opening for an update that works one sample at a time.
Chapter 2
Average the squared error over all the randomness, see a bowl, and find its bottom with one line of calculus
Chapter 1 fitted the weights to one recording. Another recording would give slightly different weights, because the noise differs. What we really want are the weights that are best on average, over every recording the process could ever produce. Those are the weights worth learning.
The lecture says it in a short phrase: minimise the error, but ask for the typical size of the error rather than the size at one instant. Define the cost J(w) = E[e[n]2], the mean squared error. Here E[·] is an average over all the randomness in the signals. The best weights are w* = arg min J(w): the argument w that makes J smallest.
The error at one step is e[n] = unTw − d[n]. Square it by multiplying out: (unTw − d)(unTw − d). That gives three kinds of term: the target squared, the filter output squared, and a cross term between them. Average each.
The target term is just E[d2], the power of the desired signal. The output term is wT E[ununT] w, and the average inside is exactly Ru. The cross term is −2 wT E[un d], and the average inside is exactly rud. Both names come from Chapter 0.
Read the shape. A quadratic term plus a tilt is a bowl. With M weights it is a bowl in M dimensions, and the cost is the height. The bowl has one lowest point, with no other dips to get stuck in. That single fact is what makes everything after this chapter work.
The rings are contours of the cost J over two weights, like a map of the bowl. The star is the best point. Drag the warm dot, or use the sliders, and watch the cost. The input correlation ρ stretches the bowl: push it towards 1 and it becomes a long trough.
Toy setup: the target comes from a room with weights (0.8, −0.4) plus noise of power 0.1, and the input has Ru = [[1, ρ], [ρ, 1]]. Then rud = Ru(0.8, −0.4) and J(w) = 0.1 + (w − w*)TRu(w − w*). The arrow is the negative gradient.
At the bottom of a bowl, the ground is flat: the slope is zero in every direction. Differentiate J with respect to w. The d-term drops out, the quadratic gives 2Ruw, and the tilt gives −2rud.
∂J/∂w = 2Ruw − 2rud = 0 so w* = Ru−1 rud
This is the Wiener filter, written as the Wiener-Hopf equations Ruw = rud. It needs Ru to be invertible, which the slide notes in a parenthesis. Compare it with Chapter 1: the normal equations ATA w = ATd, with window sums replaced by true averages. The window answer converges to the Wiener answer as K grows.
The gradient has a second meaning. Since 2Ruw − 2rud = 2E[un(unTw − d)] = 2E[une[n]], the optimum satisfies E[une[n]] = 0. This is the orthogonality principle: at the best weights, the error is uncorrelated with every tap. Nothing left in the error can be predicted from the input.
Let M = 2 and let the input have Ru = [[1, 0.5], [0.5, 1]]. Suppose the target comes from a hidden room, d = 0.8u[n] − 0.4u[n−1] plus noise of power 0.1. These numbers are illustrative. Then rud = Ru(0.8, −0.4) = (0.8 − 0.2, 0.4 − 0.4) = (0.6, 0).
Invert Ru. Its determinant is 1 − 0.25 = 0.75, and its inverse is (1/0.75)[[1, −0.5], [−0.5, 1]]. Multiply by rud: w0* = (0.6 − 0)/0.75 = 0.8 and w1* = (−0.3 + 0)/0.75 = −0.4. The Wiener filter finds the hidden room from statistics alone.
Now the floor. The target power is 0.8 × 0.6 + (−0.4) × 0 + 0.1 = 0.58, and rudTw* = 0.6 × 0.8 = 0.48, so Jmin = 0.58 − 0.48 = 0.10. That is the noise power. No filter on this input can do better, since the noise cannot be predicted.
Push ρ towards 1 in the device. The symptom: the rings stretch into a long thin ellipse, and one direction becomes almost flat. The measurement: Ru has eigenvalues 1 + ρ and 1 − ρ. At ρ = 0.97 they are 1.97 and 0.03, a ratio of about 66. At ρ = 1 the smaller one reaches zero and Ru cannot be inverted. Two taps that always carry the same number give the filter no way to tell their weights apart.
The fix is to give the input more variety, for example by adding a little white noise, or to add a small number to the diagonal of Ru before inverting. The ratio of the biggest to the smallest eigenvalue is the eigenvalue spread. It is the number to watch, because Chapter 6 will show it sets how slowly a simple learner crawls along the trough.
One more caution. This answer is great when you know Ru and rud. In practice you do not. You must estimate them from data, store them, and invert an M × M matrix, and the answer is only right while the statistics stay put. The next chapters keep the bowl and drop the inversion.
Chapter 3
Place a learning filter beside a black box, feed both the same input, and learn why the input vector can come from time or from space
A sealed grey box sits on your bench. It could be a concert hall, a guitar amplifier, a patient’s arm. You cannot open it. You can feed it a signal and measure what comes out. Can you build a copy of it from those measurements alone?
Yes, by running a copy in parallel. Send the same input to the mystery box and to your model. Compare the two outputs. Where they differ, adjust the model. When they stop differing, the model behaves like the box. Engineers call this system identification, and it is the plainest use of an adaptive filter.
The lecture draws the box as an unknown dynamic system. It is stimulated by an input vector made of M elements, x1(i), x2(i), …, xM(i). All M elements arrive together at time i, so they form one vector x(i). The box answers with one number, d(i), the desired response.
Beside the box sits the adaptive filter. It forms its own output y(i) = xT(i) w(i), a weighted sum of the same M inputs. The lecture then writes the miss as desired minus output. Note the sign: on slide 2 the error was output minus desired, and from slide 11 on it is the other way round. Squared, the two are the same.
Where do the M numbers in x(n) come from? The lecture names two situations, and they are very different.
In the first, the M elements originate at different points in space. Picture four microphones in a row. At one instant, each reads a different value, because a sound wave reaches them at slightly different moments. The vector x(n) is a snapshot of data taken across space. A filter that weights the four microphones can point a listening beam at one talker, and an adaptive one can move a blind spot onto a noisy machine.
In the second, the M elements are the present and the M − 1 past values of one signal, spaced evenly in time. This is the tapped delay line of Chapter 0: x(n) = [x(n), x(n−1), …, x(n−M+1)]. One sensor, M moments.
The mathematics does not care which one you have. The update rules in the next chapter use only the vector x(n) and the error. Whether the vector came from space or from time is a choice of hardware.
Top: the learning setup. Middle: where the four numbers come from. Bottom: the vector x(n). Choose time or space, press Play, and change the knob. Space mode sends a tone at an angle across four sensors half a wavelength apart.
Toy signals: a pure tone cos(2πf n) in time mode, with f in cycles per sample. In space mode each sensor k reads cos(2πf n − kφ), where the phase step is φ = π sin(angle) for sensors half a wavelength apart.
In time mode, slow the tone down and the four numbers become nearly equal: the signal barely changes over four steps. Speed it up and they swing from positive to negative. In space mode, a wave straight on (angle 0) reaches all four sensors together, so the four numbers are equal. Tilt the wave and each sensor sits at a different point on the cycle. The vector’s pattern carries the information.
After n snapshots, we can stack them. The lecture writes e(n) = d(n) − [x(1), x(2), …, x(n)]Tw(n) = d(n) − X(n)w(n). Here d(n) is an n × 1 column of desired responses and X(n) is the n × M data matrix, one snapshot per row.
It is Chapter 1’s matrix A again, with new letters: rows are snapshots, columns are the M input channels. All n errors are written in one line, e = d − Xw, and the least squares answer is the same normal equations, XTX w = XTd. What changes is the plan: instead of solving that at once, we will walk the weights along as snapshots arrive, one row at a time.
A tiny example fixes the shapes. With M = 2 and two snapshots, x(1) = [1, 0.5] and x(2) = [−0.5, 1], the data matrix is X(2) = [[1, 0.5], [−0.5, 1]], shape 2 × 2. With w = [0.4, 0.2] the outputs are y = [0.4 + 0.1, −0.2 + 0.2] = [0.5, 0.0]. If the box gave d = [0.6, 0.1], the errors are e = d − y = [0.1, 0.1]. These numbers are illustrative.
How long must the filter be? If the box echoes for 20 milliseconds and you sample at 8,000 times a second, its memory is 160 samples, so M should be at least 160. A filter shorter than the box misses the tail of the echo, and that missed part stays in the error forever. A filter much longer than needed costs more arithmetic and adds noise to the weights. Picking M is the first design choice, before any learning starts.
Chapter 4
Replace the average slope with the slope of one single error, and get a learner that needs no matrix, no statistics and no inversion
Picture a hiker in thick fog on the side of a smooth valley. She cannot see the map of the valley, so she cannot compute where the lowest point is. But she can feel the ground under her boots. She steps downhill, feels again, steps again. In a bowl, that always works.
The Wiener solution of Chapter 2 is the hiker with a perfect map: it needs Ru and rud, which are averages over all time. The fog is real. A live filter never has those averages. It has only the newest snapshot x(n) and the newest desired sample d(n). Can one sample tell us which way is downhill? Not exactly, but well enough.
Define the instantaneous cost as half the squared error at this one moment: E(w) = ½ e2(n). The half is only for tidiness, as you will see. The error is e(n) = d(n) − y(n) = d(n) − xT(n)w. Now find the slope of this cost with respect to the weights.
The cost depends on w only through e. By the chain rule, ∂E/∂w = e(n) · ∂e(n)/∂w. The error is d minus a dot product, so ∂e/∂w = −x(n): each weight’s effect on the error is the input sample it multiplies. The half cancelled the 2 from the square. We are left with a very clean slope.
Gradient descent steps against the slope. Step against −x e and you step along +x e. That is the least mean square (LMS) algorithm, found by Widrow and Hoff. Read it in words: add to each weight a bit of its own input sample, in proportion to the error. If the filter guessed too low (e is positive) and a tap saw a positive sample, raise that tap’s weight. If the sample was negative, lower it.
The slope of one sample is noisy. It reflects this sample’s noise as well as the true terrain. Yet it is right on average. Expand: x e = x(d − xTw) = xd − xxTw. Take the average over all the randomness. The first term averages to rud, the second to Ruw.
E[x(n) e(n)] = rud − Ru w
That is minus half the true gradient of Chapter 2. So on average, the LMS step is the true steepest descent step, w ← w + η(rud − Ruw). The single-sample version is a stochastic gradient: a random vector whose average is the true gradient. LMS is stochastic gradient descent, decades before that name became famous in deep learning.
The lecture states the whole recipe as a short box. You give it a training sample, input x(n) and desired response d(n), and you choose η. Set the first weights to zero, w(0) = 0. Then for n = 1, 2, …, compute e(n) = d(n) − wT(n)x(n) and update w(n+1) = w(n) + η x(n) e(n). That is the full algorithm.
The star is the Wiener answer (0.8, −0.4). The warm path is LMS, fed one noisy sample per step. The purple path is exact steepest descent, which knows the true averages. Press Step a few times, then Run 100. Then try a bigger step size.
Toy setup: input u white with power 1 (so Ru is the identity), x(n) = (u[n], u[n−1]), target d(n) = 0.8u[n] − 0.4u[n−1] plus noise of 0.3. Both learners start at w = (0, 0) and use the same η. The random samples are seeded and the same on every Reset.
Watch the two paths. Steepest descent glides in a smooth curve. LMS wobbles around it, because each noisy sample tugs the weights sideways. Yet the wobbly path heads to the same place. Once it arrives, it does not stop: it keeps jittering around the star, because the noise never goes away. Raise η and the jitter grows. Raise it too far and the path flies off the screen. Chapters 6 and 7 measure both effects.
Take M = 2 and η = 0.1, with w(0) = [0, 0]. A hidden room d = 0.8x1 − 0.4x2 makes the targets. The inputs below are illustrative.
Step 1: x = [1.0, 0.0], d = 0.8. The output is y = 0, so e = 0.8, and w = [0, 0] + 0.1 × 0.8 × [1.0, 0.0] = [0.080, 0].
Step 2: x = [0.5, 1.0], d = 0.4 − 0.4 = 0. Now y = 0.08 × 0.5 = 0.040, so e = −0.040, and w = [0.080 − 0.002, 0 − 0.004] = [0.078, −0.004].
Step 3: x = [−0.3, 0.5], d = −0.24 − 0.20 = −0.44. Now y = −0.0254, so e = −0.4146, and w = [0.078 + 0.0124, −0.004 − 0.0207] = [0.0904, −0.0247].
Step 4: x = [0.8, −0.3], d = 0.64 + 0.12 = 0.76. Now y = 0.0798, so e = 0.6802, and w = [0.0904 + 0.0544, −0.0247 − 0.0204] = [0.1449, −0.0451].
After four samples the weights have moved from (0, 0) towards (0.8, −0.4) but not far. Each step corrects only the part of the error that this one sample can see. A hundred more such corrections will get there.
The whole algorithm is a few lines. The shapes are the point: one input vector, one weight vector, two scalars per sample.
pythonimport numpy as np def lms(u, d, M, eta): # u: (N,) input signal d: (N,) desired signal M: taps eta: step size w = np.zeros(M) # (M,) w(0) = 0, as on the slide e = np.zeros(len(u)) for n in range(M - 1, len(u)): x = u[n - M + 1 : n + 1][::-1] # (M,) [u[n], u[n-1], ..., u[n-M+1]] y = w @ x # scalar: M multiply-adds e[n] = d[n] - y # scalar: the error, desired minus output w = w + eta * e[n] * x # (M,) M more multiply-adds return w, e
The cost per sample is about 2M multiplications, with no matrix and no stored statistics. An echo canceller with 1,000 taps at 8,000 samples a second needs about 16 million multiplications per second, which a small chip handles easily. The Wiener route would form and invert a 1,000 × 1,000 matrix, and do it again each time the room changed.
Chapter 5
Use a second sensor that hears only the noise, and see why the filter’s leftover error is the clean signal
A doctor wants to hear the heartbeat of an unborn baby. She places electrodes on the mother’s belly. The recording is dominated by the mother’s heartbeat, which is far stronger. The baby’s beat is a faint ripple underneath. A fixed filter cannot separate them, because both beats are heart signals with similar frequencies.
The slide titled “canceling of maternal electrocardiogram” shows a mother’s and a baby’s heart traces. The standard way to separate them, which we build here, is a second sensor. An electrocardiogram (ECG) is the electrical trace of a heart. Put a second electrode on the mother’s chest, far from the baby. It records the mother’s heart almost alone. That chest signal is the reference: it cannot say what the baby’s heart does, but it knows exactly what the mother’s heart does.
Name the pieces. The belly electrode records the primary signal, d(n) = s(n) + v(n), where s is the baby (the wanted part) and v is the mother’s beat as it arrives at the belly, changed by the body in between. The chest electrode gives the reference x(n), correlated with v and not with s. Feed x(n) to an adaptive filter. Its task is to learn the path from chest to belly, so that its output y(n) copies v(n).
Now look at the error. The filter output goes to a subtractor, and the lecture’s error is e(n) = d(n) − y(n) = s(n) + v(n) − y(n). If y matches v, then e is s. The error signal is the cleaned recording. This is the surprising twist: elsewhere we want the error small, and here we keep the error as the product.
The filter never sees s. It only minimises the mean squared error. Why does that remove the mother and not the baby? Square the error: e2 = s2 + (v − y)2 + 2s(v − y). Average it.
The cross term is the key. The output y is built only from the reference x. The baby s is uncorrelated with the reference, and with v. So the average of s × (v − y) is zero. What remains is the clean split below.
The first term is constant. So minimising the total is the same as minimising the leftover mother, E[(v − y)2]. The filter drives y to v, without ever being told what s looks like. And the lowest the cost can go is E[s2], the baby’s power. A learning curve that levels off at the wanted signal’s power is not a failure. It is the sign of success.
A quick check with numbers. Say the mother’s beat at the belly has power 1.0 and the baby’s has power 0.04, which is 14 dB below. Before cancelling, the baby is buried: signal to interference is −14 dB. If the filter cuts the mother’s power by a factor of 100, the leftover is 0.01, and the error power is 0.04 + 0.01 = 0.05. The baby is now 4 times stronger than the leftover, about +6 dB. These numbers are illustrative.
Top: the belly (or scalp) recording. Middle: the reference sensor. Bottom: the filter’s error, which is the output; the green dashed line is the true wanted signal. Choose a case, then try fewer taps, a bigger step size, and some leak of the wanted signal into the reference.
Synthetic signals, not patient data. Fetal case: mother’s beat plus light broadband noise, reaching the belly through a hidden four tap path; the baby’s beat is 14 dB weaker. EEG case: two slow waves for the EEG, blinks as large smooth bumps for the EOG. Power figures are running averages over the stream.
Give it a few seconds. The error trace starts out as tall as the belly recording, then the mother’s beats shrink and the baby’s small beats stand out. With M = 1 tap the filter cannot imitate a four tap path, and some of the mother stays. With the leak slider up, the filter starts to cancel some of the baby too, because the reference now contains a copy of her.
The next slide uses the very same plan for the head. Electroencephalography (EEG) records the brain’s electrical activity from electrodes on the scalp. Electrooculography (EOG) measures the voltage that exists between the front and the back of the eye. Every blink and eye movement changes that voltage, and the change leaks into scalp electrodes near the eyes, where it can be many times stronger than the brain signal.
So place an EOG electrode at the eye as the reference. The adaptive filter learns how a blink spreads to each scalp electrode. It subtracts that spread, and the error is a cleaner EEG. Switch the device to the second case and watch a blink vanish from the bottom trace while the slow brain waves stay.
Three conditions make this work. The reference must be correlated with the noise. It must not be correlated with the wanted signal. And the filter must be long enough to model the path from reference to recording. Break the second one and the symptom is a recording that looks clean but has lost part of what you wanted. The measurement is the gap between the error power and the wanted signal’s power in the read-out: with leak, the error falls below the wanted power, a sign that signal was subtracted. The fix is a better sensor position, away from the source of the wanted signal.
Chapter 6
Follow the weight error through one LMS step, split it into independent modes, and find the step size limit and the cost of a stretched bowl
You now have a rule that nudges the weights. Three questions follow at once. Does the walk reach the bottom? How many samples does it need? And what does the walk do once it arrives? This chapter answers the first two. Chapter 7 answers the third.
The lecture sets up the notation on slide 17. The correlation matrix is Rx = E[x(n)xT(n)]. The optimal Wiener filter is w* = Rx−1rdx. The quantity to track is the weight error ε(n) = w* − w(n): how far, and in which direction, the weights are from the best ones.
Start from the LMS update and subtract it from w*. We need the error e(n) in terms of ε. Write d(n) = xTw* + v(n), where v is the optimal error: what is left when the best weights are used. Then e = d − xT(w* − ε) = v + xTε.
Put that into ε(n+1) = ε(n) − η x e. You get ε(n+1) = (I − η xxT) ε(n) − η x v. Now take the average. Replace xxT by Rx. The last term vanishes, since E[x v] = 0: the orthogonality principle of Chapter 2. What remains is the lecture’s recursion, with the leftovers called zero mean noise.
The matrix I − ηRx mixes the components of ε. A change of coordinates untangles it. Rx is symmetric, so it has orthogonal eigenvectors: special directions where Rx only stretches. The stretch factors are the eigenvalues λi. Measure the error along each eigenvector, and each part evolves alone: the mean of mode i is multiplied by (1 − ηλi) every step.
E[modei(n)] = (1 − ηλi)n × modei(0)
A number raised to the n-th power dies away only if its size is below 1. So we need |1 − ηλi| < 1 for every mode. For a positive η, that means ηλi < 2 for all i, and the biggest eigenvalue decides.
0 < η < 2 / λmax(Rx)
This is the lecture’s convergence condition. A mode that shrinks by (1 − ηλ) each step needs about 1/(ηλ) steps to lose most of its error. That is the mode’s time constant. Small eigenvalue, long time constant: the input barely excites that direction, so the filter learns it slowly.
Take two taps with strongly correlated input, Rx = [[1, 0.9], [0.9, 1]]. Its eigenvalues are 1.9 and 0.1, along (1, 1) and (1, −1). The ratio 1.9 / 0.1 = 19 is the eigenvalue spread. The limit is η < 2/1.9 = 1.05. These numbers are illustrative.
Pick η = 0.5. The fast mode is multiplied by 1 − 0.5 × 1.9 = 0.05 each step. After two steps it is at 0.25 percent of where it began. The slow mode is multiplied by 1 − 0.5 × 0.1 = 0.95. To cut it to 1 percent you need ln(0.01)/ln(0.95) = 90 steps. The whole filter waits for its slowest mode.
Can we speed up the slow mode by raising η? Not much. At η = 1.0 the fast mode factor is 1 − 1.9 = −0.9: it flips sign each step and barely shrinks. The slow mode factor improves only to 0.90. At η = 1.1 the fast factor is −1.09 and it diverges. The big eigenvalue holds η back, and the small one needs it large. With a spread of 19, the best you can do is a few dozen times slower than a spread of 1.
Top: the weights walking from (0, 0) towards the star. Purple is the exact average path; warm is one real LMS run. Bottom: the error of each mode in dB, as straight lines, with the middle one of 30 real runs in warm. Raise the input correlation ρ to stretch the bowl, then try different step sizes.
Toy setup: two taps on an AR(1) input with correlation ρ, so Rx = [[1, ρ], [ρ, 1]] and its eigenvalues are 1 + ρ and 1 − ρ. The target is the noise free room (0.8, −0.4), so nothing but the spread limits the walk. The warm curve is the median of 30 seeded runs of 300 samples; the median hides the rare run where one burst of large input kicks the weights far away.
Set ρ = 0.9 and η = 0.2. The fast mode vanishes in a handful of steps while the slow mode sets the pace, and the weight path first slides fast across the bowl, then crawls along the long axis. Now push η up. Near 1.0 the path oscillates. Notice something the slide’s condition does not say: the real LMS run can blow up at a step size where the average still converges. The read-out names this case.
The reason is that the condition 0 < η < 2/λmax describes the averaged recursion. A real run also feels the noise term, and it adds its own wobble to every step. A standard refinement, not on the slides, asks that the sum of ηλi / (2 − ηλi) over all modes stay below 1. For small η that sum is about η times the trace of Rx, divided by 2, which gives the safe rule of thumb η < 2/tr(Rx). The trace is the sum of the eigenvalues, and it is easy to measure: it is M times the input power.
The failure story, in order. The symptom: the error curve falls fast, then flattens into a long shelf before it finishes. The measurement: the shelf’s slope is the slowest mode, 20 log10|1 − ηλmin| dB per step. The fix: whiten the input so the eigenvalues are closer, or normalise the step by the input power, or move to a method that uses more than one slope at a time, such as recursive least squares.
Chapter 7
Split the learning curve into a floor, a jitter and a transient, and see why a bigger step size always buys speed with accuracy
Chapter 6 asked how fast the weights reach the bottom of the bowl. Now ask what happens when they get there. The Wiener filter, once found, sits still. LMS never does. Every new sample brings its own noise, and every nudge is scaled by that noise. The weights circle the optimum like a moth around a lamp.
That circling costs accuracy. The lecture measures it with the learning curve: the mean squared error E(n) plotted against the sample number n. Slide 18 splits it into three pieces.
E(n) = Emin + Eex(∞) + Etrans(n)
Emin is the floor of Chapter 2: the lowest error any filter can reach, the power of the unpredictable part. Eex(∞) is the excess error that remains forever, caused by the jitter. Etrans(n) is the transient, the extra error that dies away while the walk is under way. After a long time only the first two are left.
Let us derive the lecture’s formula for the excess, one mode at a time. In Chapter 6 each mode of the weight error shrinks by (1 − ηλi) per step. The noise term adds a random kick to each mode. The kick is −ηxv, where v is the optimal error with power Emin. Seen along mode i, its power is about η2λiEmin.
Call the steady power of mode i, pi. At steady state, what gets added each step equals what gets removed: pi = (1 − ηλi)2 pi + η2λiEmin. Solve for pi. The bracket 1 − (1 − ηλi)2 equals ηλi(2 − ηλi). So pi = ηEmin / (2 − ηλi).
A weight error in mode i adds λi times its power to the mean squared error (that is what the bowl’s curvature means). Add all modes.
This is the slide’s formula, a small-step result that treats the weight error as independent of the current input. The ratio Eex(∞)/Emin has a name: misadjustment. For small η it is about (η/2) times the sum of the eigenvalues, which is (η/2) tr(Rx), or ηMσ2/2 for input power σ2.
Take M = 8 taps and white input of power 1, so every eigenvalue is 1. These numbers are illustrative. With η = 0.025, each mode’s share is 0.025/1.975 = 0.01266, and eight of them give a misadjustment of 0.101. The final error is about 10 percent above the floor, or 0.42 dB. With η = 0.05 the sum is 8 × 0.05/1.95 = 0.205: 20 percent, 0.81 dB.
Now the cost in time. The time constant of each mode is 1/(ηλ) = 40 samples at η = 0.025 and 20 samples at η = 0.05. Doubling the step size halved the waiting time and doubled the excess. The learning curve itself falls about twice as fast as one mode’s error, because an error power is a square, so its time constant is 20 samples at η = 0.025 and 10 at η = 0.05. That is the trade the lecture’s learning curve figure illustrates for two step sizes: the larger one falls faster but settles higher.
The yellow curve is the mean squared error against samples, averaged over 40 runs. The green dashed line is the floor Emin. The purple dashed line is the floor plus the predicted excess. Drag the step size. Press Pin to keep this curve in grey, then change the step size and compare.
Toy setup: white input of power 1, a hidden room with equal weights of total power 1, and measurement noise of power 0.09, so Emin = 0.09 (−10.5 dB). The curve is the mean of e squared over 40 seeded runs of 900 samples. The prediction uses Emin(1 + Mη/(2 − η)).
Slide the step size down and the curve gets smoother and flatter at the bottom, but it takes longer to arrive. Slide it up and it plunges quickly, then rides higher above the green line. The purple line, from the formula, tracks the measured level closely at small η. At larger η the real level climbs above it, because the formula drops terms that grow with η. That is the sign you are approaching the stability edge of Chapter 6.
The symptom: the learning curve flattens above the floor and will not come down. The measurement: the gap in dB between the flat part and Emin, which should be near 10 log10(1 + Mη/2). The fix is to shrink η, accepting a slower walk. Practitioners often start with a big step size to move fast, and then reduce it as the error stops falling. Or they use a normalised step, η divided by the input power plus a small number, so that loud inputs do not cause large kicks.
This trade also decides how an adaptive filter behaves when its world changes, as in the hero. A small η averages out the noise but reacts slowly when the room moves. A large η follows the room but never sits still. No setting is both quick and quiet.
Chapter 8
Train a filter on a known bit pattern so that it undoes the smearing of a channel, and read its learning curve
You send a message as a string of bits, each one a pulse of +1 or −1. The wire, the radio path or the room does not carry each pulse cleanly. Every pulse spreads a little into the pulses before and after it. At the receiver, each bit arrives mixed with its neighbours. This mixing is intersymbol interference, and it is the main thing that limits how fast data can travel through a channel.
The cure is a filter at the receiver that undoes the mixing. It is called an equalizer. The slide titled “channel equalization” shows the arrangement, and the problem is a perfect fit for an adaptive filter: nobody knows the channel in advance, and it can change.
A random sequence p(n) of +1 and −1 enters the channel, which has impulse response h(n). Noise is added. The lecture takes the noise power to be σ2 = 0.001. The result x(n) is what the receiver sees. Then x(n) feeds a filter of M + 1 taps, adapted by LMS.
What is the desired signal? It is the bit that was sent, p, delayed by Δ steps. In the diagram that is the box z−Δ. The receiver knows p during a short training period, because both ends agreed on the training pattern ahead of time. So d(n) = p(n − Δ), and the error e(n) = d(n) − y(n) tells the LMS rule how far the equalizer output is from the right bit.
Why the delay? The channel itself delays the signal. Also, a bit’s echo arrives after the bit, so the equalizer needs to see a few later samples before it can judge an earlier bit. A causal filter, one that sees only the past, can only look back. So we ask it for the bit as it was Δ steps ago. A common rule of thumb, not from the slides, is the channel’s own delay plus half the equalizer’s length.
Take a three tap channel with h = [0.4, 1.0, 0.4]. The numbers are illustrative; the slide does not state its channel. The receiver sees x(n) = 0.4 p(n) + 1.0 p(n−1) + 0.4 p(n−2), plus noise. The middle bit p(n−1) carries the weight 1, and its two neighbours each leak in 0.4.
Now trace the worst case. Say the bit of interest is −1 and both its neighbours are +1. Then x = 0.4 × (+1) + 1.0 × (−1) + 0.4 × (+1) = −0.2. The bit is still on the right side of zero, but only by 0.2. A bit of noise of 0.2 flips it. When both neighbours are −1, x = −1.8. So the received values land at four levels, ±0.2 and ±1.8, and the ±0.2 pair sits uncomfortably close to the decision line at zero. The gap between the two groups is the eye opening, and here it is 20 percent of a full bit before noise.
An equalizer with enough taps approximates the inverse of the channel. It makes the sum of all the leaks small, so each output lands near +1 or −1 again. LMS finds those taps from the training bits alone, without ever being told h.
Top: 120 received values x, smeared by the channel. Middle: the same symbols through the equalizer as trained so far. Bottom: the learning curve. Drag the training slider from 0 to the end, and choose a small or a large step size.
Illustrative setup: channel h = [0.4, 1.0, 0.4], noise power 0.001 as on the slide, a 9 tap equalizer, delay Δ = 5, training bits ±1. The test strip uses a fixed, fresh bit pattern. The curve is the mean over 20 seeded runs, smoothed over 20 symbols; the slide’s own figure averages 200 runs.
At zero training the equalizer outputs nothing, so the middle strip lies flat on the zero line. As you drag, the dots lift into two tight clouds near +1 and −1, and the eye between them opens wide. Try the large step. The curve falls much faster, but it floors higher and the clouds stay a little fuzzier.
Slide 20 shows learning curves for two step sizes. Its caption says the decay is related to λmin(Rx), and that a large η gives fast convergence but a large Eex(∞). That is Chapters 6 and 7 in a single plot. Here the eigenvalue spread is large: the channel boosts some frequencies and damps others, so Rx has big and small eigenvalues, and the slow modes set the pace.
Look for the shelf in the small-step curve. The symptom is a long tail where the error falls slowly. The measurement: the tail’s slope is set by the smallest eigenvalue. The fix: raise η at first and lower it later, or use a better optimiser.
Once the equalizer is trained, the receiver stops using the known bits. It rounds each output to the nearest of +1 and −1 and treats that as the bit. This decision directed mode is standard practice, though not part of the slides. Because the decisions are right nearly always, the filter keeps adapting with them as the desired signal, and it follows slow changes in the channel without any more training bits.
Chapter 9
Wrap the adaptive filter in a nonlinearity, train it with the same rule, and meet Adaline, the first adaptive neuron, along with its limit
Think about how you decide whether an email is spam. You weigh clues. A shouting subject line counts against it. A known sender counts for it. You add up the evidence, and if the total passes a line, you say “spam”. That is a weighted sum followed by a decision, and it is exactly the shape of the adaptive filter we have studied: inputs times weights, added up.
The last slides of the lecture make this step explicit. An adaptive filter that learns its weights from errors is already a neuron in the machine learning sense. Only one thing is missing: a nonlinear bend after the sum.
Slide 21 is titled “Adaptive filters to neural networks”, and its first line says: nonlinear models for function approximation. The linear filter computes u = wTx + b, where b is a bias, a constant offset that moves the decision line. The neuron passes u through a nonlinear function f.
The slide pairs this with a drawing of a biological nerve cell: a tree of dendrites gathers many inputs, the cell body adds them up, and a single axon carries the result onward. The model is a loose cartoon of that picture, and it is also exactly the adaptive filter with a bend added.
Slide 22 names the first such model, Adaline, the Adaptive Linear Neuron, by Bernard Widrow and Ted Hoff in 1960. Slide 23 carries only the title “Training Adaline”. The rule it points to is the one you already know, the recipe box of slide 13: Chapter 4’s LMS, with w(0) = 0, an error e(n) = d(n) − wTx(n), and the update w(n+1) = w(n) + η x(n) e(n). That is why the algorithm carries the names Widrow and Hoff.
One detail of the design, which comes from the original work rather than the slides: Adaline learns from its linear sum u, before any decision. The error is measured on u itself, against a target of +1 or −1. Only afterwards does it make a call: output +1 if u is positive, −1 if not. Learning on the smooth quantity is what lets gradient descent work, since a hard yes or no has no useful slope.
For the sigmoid neuron, differentiate again. The one-sample cost is E = ½ (d − y)2 with y = f(u). By the chain rule, ∂E/∂w = −(d − y) f′(u) x. The only new piece is f′(u), the slope of the bend. For the sigmoid, f′(u) = y(1 − y), which is easy to compute from the output.
w ← w + η (d − y) y (1 − y) x b ← b + η (d − y) y (1 − y)
Compare with LMS: the same η times error times input, with an extra factor y(1 − y). That factor is large when the neuron is unsure (y near 0.5) and tiny when it is already saturated near 0 or 1. The bias update is the same rule with an input of 1, so b can be seen as a weight on a constant input.
Let w = [0.2, −0.1], b = 0.1, the input x = [1, 2], and the target d = 1. The numbers are illustrative.
The sum is u = 0.2 − 0.2 + 0.1 = 0.1. Adaline takes y = u = 0.1, so e = 0.9. With η = 0.1 the updates are 0.1 × 0.9 × [1, 2] = [0.09, 0.18] for the weights and 0.09 for the bias. The new sum is 0.29 + 0.16 + 0.19 = 0.64, closer to 1.
The sigmoid neuron takes y = 1/(1 + e−0.1) = 0.525, so e = 0.475, and y(1 − y) = 0.249. Their product is 0.1185. With η = 1 the weights move by 0.1185 × [1, 2] = [0.118, 0.237] and the bias by 0.118. The new sum is 0.811 and the output rises from 0.525 to 0.692, closer to 1.
Filled dots are one class and rings are the other. The warm line is where the neuron’s sum is zero. Red outlines mark wrong calls. Choose a neuron and a data set, then Step through a few samples and press Train 200.
Toy data: 80 seeded points, 40 per class. Adaline learns the linear sum against targets ±1; the sigmoid neuron learns against 0 and 1. Both start at zero weights, as in the slide’s algorithm, and see the samples in a fixed shuffled order. Loss is the mean of ½(d − y)² over all 80 points.
On two blobs both neurons draw a line between the classes within a few dozen samples. Switch to the crossed data. No line can separate those four blobs, because each class lies on two opposite corners. Train as long as you like: the best any single line can do is 75 percent, and the neuron wanders. A single neuron can only draw one straight boundary.
This is the bridge to the next lesson. One neuron fails on the crossed data, so we stack neurons in layers, with a bend between layers. The training rule stays the same idea: slope of the error, nudge the weights. How to find the slope through many layers is the subject of backpropagation.
Chapter 10
Review the lecture in one page, with its numbers, a checklist, the core code and the paths that lead onward
You can now rebuild Lecture 14 of EE269 from memory. It began with a filter whose weights we want to learn, moved through the best weights in one shot and in the average, replaced the average by one sample at a time, studied how that walk converges and where it settles, put it to work on noise and on a smeared channel, and ended at a single neuron.
An adaptive filter is a weighted sum of recent input samples whose weights change to shrink an error against a desired signal. The best fixed weights are the Wiener solution w* = R−1r, the bottom of a bowl of mean squared error. The LMS rule, w(n+1) = w(n) + η x(n) e(n), walks down that bowl using one noisy slope per sample, which is right on average. It converges when η < 2/λmax, as fast as the slowest mode allows, and it settles above the floor by an excess that grows with η. Its uses are system identification, noise cancelling (where the error is the product), equalizers (trained on known bits), and, with a bend added, the neuron.
| What | Number or formula | Why it matters |
|---|---|---|
| Filter output (slides 2, 3) | y[n] = ∑ wm u[n−m] = unTw; Ru is M × M, rud is M × 1 | One dot product per sample, and two statistics |
| Least squares window (slide 4) | ATA w = ATd, A is K × M with K ≥ M; example w = (0.489, 0.244), squared error 0.0144 | One shot, but a new solve for each window |
| Wiener filter (slides 5, 6) | w* = R−1r; example R = [[1, 0.5], [0.5, 1]], r = (0.6, 0) gives (0.8, −0.4), Jmin = 0.10 | The floor no filter on this input can beat |
| LMS rule (slides 12, 13) | w(n+1) = w(n) + η x(n) e(n); about 2M multiplications per sample | No matrix, no statistics |
| LMS on average | E[x e] = r − R w | A noisy slope, right on average |
| Convergence (slide 18) | 0 < η < 2/λmax; mode factor (1 − ηλi); example λ = 1.9, 0.1 at η = 0.5 gives 0.05 and 0.95, about 90 steps for 99% | The slowest mode, not the step size, sets the speed |
| Learning curve (slide 18) | E(n) = Emin + Eex(∞) + Etrans(n); Eex = Emin∑ ηλi/(2 − ηλi); M = 8, λ = 1: 10.1% at η = 0.025, 20.5% at 0.05 | Speed is bought with accuracy |
| Noise cancelling (slides 14, 15) | E[e2] = E[s2] + E[(v − y)2]; example 0.04 + 0.01 = 0.05 | The error is the clean signal |
| Equalizer (slides 19, 20) | noise power 0.001; example h = [0.4, 1.0, 0.4] gives levels ±0.2 and ±1.8 | Train on known bits, then decide |
| Neuron (slides 21 to 23) | y = f(wTx + b); sigmoid factor y(1 − y); best line on crossed data 75% | LMS plus a slope factor; one neuron draws one line |
These five short functions are the lecture. The shapes are in the comments. This is a sketch: it leaves out buffering and real-time details.
pythonimport numpy as np def wiener(R, r): # R: (M, M) r: (M,) slides 5 and 6 return np.linalg.solve(R, r) # w* = R^-1 r, never form the inverse def lms_step(w, x, d, eta): # w, x: (M,) d: scalar slide 12 e = d - w @ x # error, desired minus output return w + eta * e * x, e # one noisy step down the bowl def nlms_step(w, x, d, eta, eps=1e-6): # normalised step: safe for loud inputs e = d - w @ x return w + (eta / (eps + x @ x)) * e * x, e def cancel_noise(primary, reference, M, eta): # (N,), (N,) slides 14 and 15 w, out = np.zeros(M), np.zeros(len(primary)) for n in range(M - 1, len(primary)): x = reference[n - M + 1 : n + 1][::-1] w, out[n] = lms_step(w, x, primary[n], eta) # the error IS the cleaned signal return out def sigmoid_step(w, b, x, d, eta): # slide 21: LMS with one more factor y = 1 / (1 + np.exp(-(w @ x + b))) g = (d - y) * y * (1 - y) # error times the slope of the bend return w + eta * g * x, b + eta * g
An equalizer is the same loop as cancel_noise with the received samples as the input, and the training bits delayed by Δ as the desired signal, so d[n] = p[n − Δ].
Chapters 1 and 2 are regression in signal clothing, and the correlation matrix and its estimates come from stationary signals. A filter’s impulse response and what it does to a signal live in linear systems. The step from the neuron to deep stacks is the next lesson, and the stochastic gradient idea reaches all the way to deep learning.
The lecture is part of Stanford EE269, Signal Processing for Machine Learning, taught by Mert Pilanci. The slides are at Lecture14.pdf, the course page is web.stanford.edu/class/ee269, and the list of all slide decks is here. Every explanation, derivation and device on this page is our own re-telling; the toy numbers are labelled illustrative.
Now press Present or Teach and explain the lecture out loud, from memory: why a fixed filter fails, what the Wiener solution is, how one sample gives a slope, why the step size has a speed and a floor, and why the error is the clean signal in a noise canceller. Then go back to the instrument at the top and break it again, on purpose.