A tone, removed in software
An analog-electronics assignment asked us to build a band-stop circuit to strip a constant tone out of a music recording. I solved it in software, first with a spectrogram-based band-stop, then with phase cancellation, and compared the two side by side. Phase cancellation won; the writeup is in Norwegian and lives in the repo as a PDF.
The problem
A music file had been corrupted by a single, constant-frequency tone, the kind of thing that shows up as a bright horizontal line near the bottom of a spectrogram. The brief: remove that tone with minimal damage to the music underneath.
Method 1: spectrogram band-stop
- Take the spectrogram of the input.
- Find the frequency bin with the most energy in the offending band, which is the tone's centre.
- Zero out (or attenuate) the centre bin and a small ring around it to absorb spectrogram quantisation slop.
- Inverse-transform back to time domain.
It works, and the audio sounds clean, but the spectrogram shows a clearly empty slot where the tone used to be: a thin black stripe in the middle of the music. Some original signal was thrown away with the noise.
Method 2: phase cancellation
Because the offending tone is just an added sinusoid, you can cancel it by adding back another sinusoid of the same frequency and amplitude, phase-shifted 180°. Estimate amplitude, frequency, and phase from the recording; generate the inverse; sum them. In theory, the tone vanishes and the original music is left completely intact.
In practice, that is roughly what happened. The output spectrogram looks identical to the original everywhere except where the tone used to be, and even there, the surrounding music spectrum is preserved. The audio sounds natural; no traces of the processing leaked through.
What I learned
That a band-stop filter is the right answer to the question "remove a narrow band of frequencies", and the wrong answer to the question "remove a constant sinusoid". The latter has more structure than the former and a cancellation approach exploits all of it. Whenever the problem hands you that much structure, spend a moment looking before you reach for the generic filter.
Writeup
The full Norwegian course report (figures, derivations, before/after spectrograms) is in the repo: