DEV Community

Cover image for ANC: How Computers Learn to Cancel Noise
Ganesh Kumar
Ganesh Kumar

Posted on

ANC: How Computers Learn to Cancel Noise

Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a single platform for all development tools, cheat codes, and TL; DRs — a free, open-source hub where developers can quickly find and use tools without the hassle of searching the internet.

Have you ever used a regular audio filter? Maybe a notch filter to cut out that annoying 60 Hz hum from your speakers. It's set once and does one job. But what happens when the problem is more complex? What if the noise isn't a steady hum but something that changes, like a car engine, or a signal you're trying to listen to is buried under a much louder one?

This is where a normal, "fixed" filter fails. We need a "smart" filter—one that can listen, learn, and adjust its settings in real-time. This is the core idea behind an adaptive filter.

Let's explore the powerful concept of Adaptive Noise Cancellation (ANC) and how it's used in a classic (and life-saving) example.

Two Inputs are Better Than One

The magic of an adaptive filter, when used for noise cancellation, is that it uses two "ears" or inputs.

The Primary Input: This is your main signal, but it's corrupted. It contains the signal you want mixed with the noise you hate. (Desired Signal + Noise)

The Reference Input: This is the special ingredient. It's a second microphone or sensor that picks up only the noise. The key assumption is that this noise is related to, or correlated with, the noise in the primary input. (Noise Only)

Having just the noise reference is the trick. You can't just subtract the reference from the primary—they might be slightly out of phase or at different amplitudes. The filter's job is to "learn" how to modify the reference noise so it perfectly matches the noise in the primary signal.

A Classic Example: Finding a Baby's Heartbeat

This is the text-book case for ANC.

The Goal: To monitor a faint fetal heartbeat (the desired signal).

The Problem: The mother's heartbeat is 2 to 10 times stronger and completely masks the baby's signal on any sensor. The mother's ECG is, in this case, the "noise" we need to remove.

Here's the adaptive filter setup:

Primary Input: An electrode is placed on the mother's abdomen. It picks up both signals: the (Strong) Maternal ECG + the (Weak) Fetal ECG.

Reference Input: Electrodes are placed on the mother's chest. They pick up only the (Strong) Maternal ECG.

Now the adaptive filter has everything it needs. It has a "corrupted" signal and a "clean" reference of the noise it needs to cancel.

The Learning

This is the most clever part. The filter's one and only goal is to minimize its own output. It works in a constant loop:

The filter takes the Reference Input (Maternal ECG from the chest).

It processes and adjusts this signal, creating its best "guess" of what the noise component looks like in the Primary Input. Let's call this the Estimated Noise.

It subtracts this Estimated Noise from the Primary Input.

The result of this subtraction is a new signal, called the Error Signal, $e(n)$.

This error signal, $e(n)$, is everything. Think about what it represents:

$e(n) = \text{(Primary Input)} - \text{(Estimated Noise)}$

$e(n) = \text{(Maternal ECG + Fetal ECG)} - \text{(Filter's Guess of Maternal ECG)}$

The filter's "Adaptive Algorithm" looks at this $e(n)$ output. If the output is loud, it means the filter did a bad job—its guess was wrong, and a lot of the strong Maternal ECG is "leaking" through. The algorithm then adjusts the filter's settings.

It keeps asking, "How can I change my settings to make that $e(n)$ signal as quiet as possible?"

As the filter gets better and better, its "guess" gets closer and closer to the actual Maternal ECG component. When it finally creates a perfect match, the two "Maternal ECG" signals cancel each other out completely.

What's left in the $e(n)$ output? The only thing that wasn't in the reference signal: the weak Fetal ECG.

By relentlessly trying to create silence, the filter automatically reveals the hidden signal.

The Feedback Loop

This e(n) signal is the key. It serves two purposes at once:

It is the final output: This is the "cleaned" signal (the Fetal ECG) that we send to the monitor.

It is the feedback: This is the "report card" that the adaptive algorithm uses to "learn" and update the filter for the next signal sample.

This creates a beautiful, continuous loop: The filter subtracts the noise $\rightarrow$ the algorithm looks at the leftover error $\rightarrow$ the algorithm adjusts the filter to do a better subtraction next time. This process repeats hundreds or thousands of times a second, allowing the filter to "track" and cancel noise even as it changes.

So, the next time you hear about adaptive filtering, you'll know it's not magic. It's just a clever system that learns to cancel noise by trying to make its own output as quiet as possible, revealing the important signal that was hidden underneath all along.

I’ve been building for FreeDevTools.

A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction in searching tools/materials.

Any feedback or contributions are welcome!

It’s online, open-source, and ready for anyone to use.

👉 Check it out: FreeDevTools
⭐ Star it on GitHub: freedevtools

Top comments (0)