Destructive Interference: A Python Demonstration
Today I’ll be demonstrating destructive acoustic interference — the main principle behind Active Noise Control — with Python and a simple stereo speaker! The code I wrote and used lives on GitHub. Before we jump into how it works, take a look at the before and after:
Note
To embed a YouTube video in an HTML post (like this one), make sure to include /embed/ in your YouTube link.
It’s not perfect, but it’s still cool to see (hear) some effect!
My Approach
Destructive interference has been explained time and time again, but honestly I think this picture from Wikipedia explains it best:
I wanted to demonstrate the most basic case: a plain sine wave.
My code is available on GitHub. It essentially does what’s demonstrated in the graphic above. I output a 400 Hz sine wave from one channel of my laptop speakers and a 180° phase shifted 400 Hz sine wave from the other channel. When you stand in the right spot, the sound becomes muted!
Conclusion
This was a really simple experiment to put together. Maybe in the future I’ll try detecting real noise and inverting it real-time, like noise-cancelling headphones.