This is a signal.

A signal is a quantity that carries information over time. In the case of this visualization, it's audio: air pressure varying over time. In general, however, this can be anything from electrical signals from the heart to vibrations in buildings.

This is noise.

Noise is any unwanted signal that degrades the original signal. In the audio world, this might correspond to ambient noise leaking through headphones or actual signal noise from the transmission of the audio information.


Noisy Signal

This is what the signal looks like when it reaches your headphones. In the real world, the signal will always have some sort of noise. The result is a corrupted waveform where the original signal is hard to hear. The louder or more complex the noise, the harder it is to recover the desired signal.

Active Noise Cancelling (ANC)

Active noise cancelling (ANC) uses microphones and signal processing to reduce unwanted sounds like these in real time. Unlike passive noise cancelling, like earplugs, ANC generates a signal to cancel the noise instead of physically blocking it. In this visualization, we'll walk you through:

  1. Anti noise and how phase inversion works
  2. Generic filters and why they fall short
  3. Adaptive filters that adjust to changing noise
  4. The LMS algorithm, one used in headphones today!

In the end, this visualization (and project) is meant to be an entry into the world of adaptive filters and noise cancelling. If you're interested in learning more, there are many resource available online.

Anti Noise

The key idea behind noise cancelling is to use a digital signal processor(DSP) to convert the analog signal from the microphones into a digital signal. An analog-to-digital converter (ADC) samples the continuous wave at discrete time intervals and then quantizes each sample to the nearest digital level.

Once digital, the DSP inverts the signal's polarity, multiplying each sample by -1. This creates a wave that is equal in frequency and amplitude but opposite in phase. When played through speakers alongside the original wave, they will destructively interfere and cancel each other out.

The digital anti-noise signal is then converted back to an analog signal to drive a speaker. A digital-to-analog converter (DAC) reconstructs the continuous signal from the digital samples.

Generic Filters

At first glance, a static low-pass filter might seem like a good option to remove noise. A low-pass filter passes frequences below a chosen frequency and attenuates everything above it.

There are two key problems with this approach. The first is that real life noise is rarely band-limited as it spans a wide range of frequencies (that may or may not overlap with the signal you want to keep).
Second, any filter that attenuates frequencies also distort the signal passing through it. For high-fidelity audio or precise measurements, even small distortions like this will degrade output.
In the end, a filter that cannot adapt to the noise cannot reliably protect the signal.

Adaptive Filter

An adaptive filter solves the static filter problem by continuously updating its own coefficients (or weights) based on the input. Rather than using a fixed transfer function, it uses an optimization algorithm to minimize the cost. This could be any cost function (typically taught in a machine learning course), but a common one is the least mean squared (LMS) error.
In ANC, a reference microphone picks up the noise before it reaches the listener. The adaptive filter uses this to predict and generate an anti-noise estimate that gets added to the original signal.

Feed-forward Path

The filter weights are updated each sample such that the estimated anti-noise (in blue above) converges toward the actual noise from the input. Once the error is minimized enough, the combination leaves only the clean signal.

Error Feedback

This works well when the noise is periodic and stable. In practice, however, the noise is rarely that cooperative. Real headphone noise contains sustained background noise, and the adaptive filter must track these changes continuously.

LMS Noise Cancelling

The Least Mean Squares (LMS) algorithm is one of the more popular algorithms used in adaptive filtering. For each sample, it computes the error e[n]=d[n]-y[n] between the desired signal and the current estimate. Then it changes each filter wait in the direction that reduces that error: w[n+1]=w[n]+μ*e[n]*x[n]
The step size μ controls the trade-off between convergence speed and accuracy. A larger value will adapt faster but might result in more leftover noise. A smaller value will adapt slower but will cancel more of the noise.
The filter weight number, N, determines how many past samples the filter uses to handle more complex noises, at the cost of computation time.

Input / Estimated Noise / Output

Filter Weights vs. Target Acoustics



Here's one of the first demo's of this, way back in 1971!

ECSE316 Final Project

Trevor Piltch, 26117160

Motivation

At the beginning of the semester, I got a new pair of noise cancelling headphones. I kept wondering how they worked and figured this project was a good time to fall down that rabbit hole. I also figured what better way to teach myself this than to help others learn it too in an interactive and visual way. This project definitely helped my understanding of ANC and I hope it helps any future ECSE316 students (or others from the web!).
At the very least, I have a much better appreciation for all the engineers whose work let me work on this project in silence while the library was filled with noise.

Future Thoughts

Had there been more time for this project (or had I a better plan), here are some of the ideas I had:

  1. Noise selection: Users could see the difference between the types of noises we heard in class (pink, brown, etc.)
  2. Audio examples: Have the signals themselves as audio so users can hear the difference between signal vs. noise and analog vs. digital
  3. Other algorithms: I got deep in the LMS rabbit hole here so it'll be interesting to see how some of the other adaptive algorithms worked

Credits

  1. Adaptive Filtering of Broadband Signals as Applied to Noise Cancelling - Kaunitz, J. and Stanford University. Department of Electrical Engineering
  2. Rattlesnake - Loehnertz (for the idea for this project)
  3. ECSE316 - McGill University
  4. Demo idea of a LMS ANC
  5. Website Font