Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 38 ยท Multirate and Adaptive Filters

Adaptive Noise Cancellation

Remove interference from a signal using a reference noise input and an adaptive filter. Build an NLMS canceller, compare it to RLS and see why the signal survives.

Suppose you record a voice with a microphone placed near a noisy fan. The fan noise is mixed into your recording, and an ordinary filter cannot remove it because it overlaps the voice in frequency. If you have a second sensor that picks up mostly the fan noise, an adaptive filter can learn how the noise gets from the second sensor into the first and subtract it. This is adaptive noise cancellation (ANC), the principle behind echo cancellers and the noise-cancelling headset.

The configuration

  • Primary input d[n] = s[n] + v1[n]: the wanted signal s plus noise v1.
  • Reference input x[n] = v0[n]: noise correlated with v1 but (ideally) uncorrelated with s.
  • The adaptive filter processes x to produce y[n], an estimate of v1.
  • The error e[n] = d[n] - y[n] is the output of the whole system, and it is also the training signal.

Here is the surprising part: the filter minimizes the power of e. Since it can only reproduce what correlates with x, it can cancel v1 but not s. Minimizing the total error power therefore leaves s intact. The error is the cleaned signal.

Noise canceller layout

Primary Signal plus noise
Reference Noise only
Adaptive filter Learns the noise path
Error output The cleaned signal

The reference must not contain the wanted signal.

1 / 2

An NLMS canceller

Let the wanted signal be a 440 Hz sinusoid, and let the noise reach the primary sensor through an unknown short filter.

Python Cancelling a filtered noise source

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The signal-to-noise ratio improves by about 19 dB (from -3.5 to 15.4 dB), and the first six weights are close to the unknown path. The sinusoid remains because it is uncorrelated with the reference. The sinusoid also acts as noise for the adaptation, so a smaller mu gives a cleaner result than a large one.

What can go wrong

  • Signal leakage into the reference. If x contains some of s, the filter cancels part of the wanted signal too. Place the reference sensor well, or add a short decorrelation delay.
  • Too short a filter. The filter must be at least as long as the noise path's impulse response, plus the delay.
  • Non-stationary paths. If the path changes, the filter must track it, so mu should not be too small.
  • Delay. If the reference arrives later than the noise at the primary sensor, the filter would need a non-causal response. Add a delay to the primary signal to give the filter room.
Python Reference contaminated by the signal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

As the leak grows, the filter learns to subtract some of the sinusoid, and the output amplitude falls below 1. This is why the reference sensor must be isolated from the signal.

RLS: faster convergence

Recursive least squares (RLS) minimizes a weighted sum of past squared errors exactly, updating an inverse correlation matrix each step. It converges in about 2L samples regardless of the eigenvalue spread, at a cost of O(L^2) operations per sample compared with O(L) for LMS. A forgetting factor lambda (typically 0.98 to 0.9999) controls how fast old data is discounted.

Python RLS versus NLMS convergence speed

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

On a colored input RLS has a weight error below 0.002 after 20 steps, while NLMS is still near 0.9 and needs hundreds of steps to get below 0.05. In exchange it costs more per sample and needs care with numerical stability.

Other uses of the same structure

  • Acoustic echo cancellation: reference = loudspeaker signal, primary = microphone; the filter models the room (hundreds to thousands of taps).
  • ECG interference removal: reference = power-line sensor.
  • Active noise control: the output is played through a speaker and the error microphone closes the loop; the filter also models the secondary acoustic path (filtered-x LMS).

Compare this with the fixed filters of earlier lessons, such as a notch filter for hum, which works when the interference has a fixed frequency but fails for broadband noise.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In an adaptive noise canceller, what is the system output?

    The adaptive filter estimates the noise in the primary input; subtracting it leaves the cleaned signal, which is the error.
  2. 2. Why does the wanted signal survive the cancellation?

    Minimizing the error power can only remove components correlated with the reference.
  3. 3. What happens if the reference sensor picks up part of the wanted signal?

    The filter then finds a correlation between the reference and the signal, and subtracts that part.
  4. 4. What is the main advantage of RLS over LMS?

    RLS solves the least-squares problem recursively, converging in about 2L steps, at O(L^2) cost per sample.

Summary

  • ANC subtracts an adaptive estimate of the noise, driven by a reference sensor, from the primary input; the error is the output.
  • NLMS works well in practice; the filter needs to be long enough and the reference free of the wanted signal.
  • RLS converges faster on colored input at higher cost.
  • The same structure powers echo cancellation and active noise control.

Next: An Audio Equalizer from Biquads