A Control Engineer’s Attempt at DIY Active Noise Cancellation with ESP32

I have always enjoyed modifying cars — not only for appearance and performance, but also for comfort.

Like many car enthusiasts, I experimented with various passive noise reduction methods:

  • sound deadening sheets
  • vibration damping
  • interior insulation
  • sealing gaps around panels

These methods certainly help, but they also come with trade-offs. Adding damping materials increases weight, installation effort, and cost. Eventually, the improvements start to diminish.

As a control engineer, that made me wonder:

Could some of these problems be solved actively instead of passively?

That was the moment I seriously started thinking about Active Noise Cancellation (ANC).

I had known the theory behind ANC for years, but I had never actually tried building one myself. Modern embedded hardware like the ESP32 made the idea feel surprisingly accessible, so I decided to experiment with a DIY implementation.

This article is not a “perfect ANC tutorial.”
Instead, it is a development log of my first experiments, including mistakes, unexpected hardware problems, and lessons learned along the way.


Initial Hardware Setup

For the first prototype, I chose inexpensive and widely available modules:

  • ESP32-WROOM-32
  • INMP441 I2S MEMS microphone
  • MAX98357A I2S DAC/amplifier
  • small speaker
  • breadboard and jumper wires

The initial goal was very simple:

Capture sound from the microphone and immediately output it from the speaker in real time.

Before attempting any ANC algorithm, I first wanted to confirm that the audio pipeline itself worked correctly.


First Step: Real-Time Audio Pass-Through

The ESP32 supports I2S audio, allowing both the digital microphone and amplifier to be connected directly.

The basic structure was:Microphone → ESP32 → Speaker

At first glance, this sounded simple.

In reality, it was surprisingly difficult to get stable audio output.

The first problems I encountered included:

  • loud buzzing noises
  • random crackling
  • distorted audio
  • situations where touching a wire changed the sound completely

Initially, I suspected software issues such as incorrect I2S configuration or bit depth conversion. However, many of the problems turned out to be hardware-related.


Grounding and Wiring Problems

One of the biggest surprises was how sensitive the system was to grounding.

At one point, simply changing the GND connection to another nearby pin dramatically changed the behavior of the entire system.

The difference between:

  • stable audio
  • loud buzzing
  • random noise

sometimes came down to a single ground connection.

This was an important reminder that in mixed-signal systems — especially when using MEMS microphones and class-D amplifiers — wiring quality matters just as much as software.

The MAX98357A amplifier in particular draws rapidly changing current, which can create noticeable voltage fluctuations on weak ground paths.

In retrospect, many of the “DSP problems” I thought I had were actually wiring problems.


First ANC Experiment

Once the basic audio pass-through worked, I implemented the simplest possible ANC structure:

$$ y[n] = -x[n] $$

This was simply an inverted version of the microphone input.

As expected, this alone did not work very well.

The cancellation effect was inconsistent and highly dependent on speaker position and frequency.


Adding Variable Delay

The next step was adding adjustable delay and gain:

$$
y[n] = -g x[n-d]
$$

Where:

  • \(g\) is gain
  • \(d\) is delay in samples

This made a major difference.

I started experimenting with pure sine waves generated from a smartphone speaker and observed how changing the delay affected cancellation.

At a 16 kHz sampling rate, one sample corresponds to:

$$
T_s = \frac{1}{16000} = 62.5\ \mu s
$$

Which translates to roughly:

$$
d = 343T_s \approx 2.1\ \mathrm{cm}
$$

of sound travel distance.

This means even a few samples of delay significantly affect phase alignment.


Low Frequencies Worked Better

One interesting observation was that the cancellation effect became much more noticeable around 300 Hz and below.

Higher frequencies mostly produced unpleasant effects such as:

  • buzzing
  • phasey sound
  • echo-like artifacts
  • unstable amplification

This makes physical sense because lower frequencies have much longer wavelengths and are therefore more tolerant of phase errors.

For example, at 300 Hz:

$$
\lambda = \frac{343}{300} \approx 1.14\ \mathrm{m}
$$

At 1 kHz:

$$
\lambda = \frac{343}{1000} \approx 34\ \mathrm{cm}
$$

Higher frequencies become extremely sensitive to even small delays or positional changes.

This was my first practical realization that real-world ANC is fundamentally a spatial and timing problem.


Trying It Inside a Car

Naturally, I wanted to test the prototype in an actual vehicle.

The results were… not very convincing.

The system clearly reacted to cabin noise, but instead of producing clean cancellation, it mostly generated strange low-frequency artifacts and unstable sound.

This made me realize how much more difficult real automotive ANC is compared to a simple single-tone experiment.

A car interior contains:

  • reflections from glass and panels
  • multiple noise sources
  • broadband road noise
  • continuously changing acoustic paths

The environment is far more complicated than a controlled desk experiment.


The Limitation of a Single Microphone

At this point, I also started to feel the limitations of using only one microphone.

The current setup is effectively a feedback ANC structure.

The microphone observes:

  • external noise
  • speaker output
  • reflections

all mixed together.

This makes stable adaptive control difficult.

In theory, adaptive filtering is the proper direction for handling continuously changing noise environments. However, implementing practical adaptive ANC likely requires at least:

  • a reference microphone
  • an error microphone

This separation is important because it allows the system to distinguish:

  • incoming noise
  • residual error after cancellation

With only one microphone, the system tends to react after the noise is already heard, while also feeding back its own output into the control loop.

This likely explains why low frequencies behaved somewhat reasonably while higher frequencies quickly became unstable.


Hardware Lessons Learned

Another major lesson from this project was that physical implementation matters enormously.

Simple things like:

  • ground routing
  • connector quality
  • cable placement
  • contact stability

had huge effects on system behavior.

The breadboard setup became increasingly unreliable as the project grew more complex.

As a result, my next step will probably involve:

  • migrating everything to a universal PCB
  • improving grounding
  • stabilizing connectors
  • reducing noise pickup

Before advancing the DSP side further, I want to make the hardware itself more reliable.


Next Steps

So far, I have implemented:

  • real-time audio pass-through
  • simple phase inversion
  • variable delay
  • low-frequency filtering experiments

And I was able to confirm some cancellation effects using pure sine waves.

However, practical ANC in a real car environment is clearly much more difficult.

The next stage will likely involve:

  • adding a second microphone
  • experimenting with adaptive FIR filters
  • LMS / FxLMS algorithms
  • better hardware integration

Even though the project is still in an early stage, it has already been extremely educational.

Most importantly, it reminded me that building real systems is very different from simply understanding the theory.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top