Hum removal plug-in

Share your Audacity/Nyquist plug-ins here, or test drive the latest plug-ins submitted by Audacity users.

After testing a plug-in from this forum, please post feedback for the plug-in author.
steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Hum removal plug-in

Post by steve » Sun Mar 28, 2010 10:50 pm

It was mentioned in this thread http://forum.audacityteam.org/posting.p ... 16&t=27627 that "mains hum", while usually having a fundamental frequency of 50 or 60Hz (depending on which part of the world) usually has many "overtones". These overtones are predominantly "odd harmonics", though there may also be some amount of even harmonics.
kozikowski wrote:Hum and buzz does not go 60, 120. It goes 60, 180. Odd harmonics -- and then, of course, only in 60 Hz power countries.
Unfortunately there is no hard and fast rule about how much of each harmonic will be present, though the higher harmonics generally get weaker.

Here's a plug-in that allows odd and even harmonics to be controlled separately. The default settings should work pretty well with moderate amounts of hum.

One of the main drawbacks of using notch filters is that they cause damage. In this "Hum Remover" effect, the amount of damage is limited by only applying the notch filters to audio that is below the set threshold. During loud sections, the hum will usually be "masked" by the music so it is less damaging to leave the hum than to remove it.

To apply the notch filters to all of the sound and not just low level sound, push the Threshold setting up to 100%.
hum remover.zip
(1.02 KiB) Downloaded 1383 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Trebor
Posts: 9883
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: Hum removal plug-in

Post by Trebor » Mon Mar 29, 2010 12:21 am

I’ve strained my brain over this mains hum removal before.
It really is necessary to remove all the harmonics, odd and even , right up to half the nyquist frequency.

Here’s an example with limey 50Hz hum, then dehummed using my plugin, then the hummy original again, then your dehummer applied with all the settings at maximum*
I can still clearly hear a buzz on the final version due to not notching all the harmonics.

[* Odd harmonics max is 119 on your plugin for this 24000Hz sample rate recording].

To be fair my dehummer plugin causes Gibbs ringing, which isn't too noticable on the echoey example I've used.

Trebor
Posts: 9883
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: Hum removal plug-in

Post by Trebor » Mon Mar 29, 2010 1:52 am

Hold on a mo' I think you’re onto something.

By attenuating the notching when a spike occurs there is no Gibbs ringing after the spike.

Attached is an example which uses a modified version of your de-hum plug-in ...

1st. A hummy recording of my neighbour slamming their rubbish bin lid (and their door squeaking).
2nd. my dehummed version of 1 using my plug-in with he lowest possible amount of dehum, Gibbs ringing immediately follows the loud bin lid slam.
3rd. Same as 1.
4th. Modified version of your dehummer applied , No hum and no Gibbs ringing !

Attenuating the depth of the notching with the absolute value of the rate of change of the amplitude would cure the ringing.
I think that would require "look ahead" (like in Chris's Compressor).
Attachments
Bin lid Slam, before-after Trebor dehummer, then before-after modified Steve dehum.mp3
(791.83 KiB) Downloaded 473 times
Last edited by Trebor on Mon Mar 29, 2010 2:05 am, edited 2 times in total.

kozikowski
Forum Staff
Posts: 69243
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Hum removal plug-in

Post by kozikowski » Mon Mar 29, 2010 2:00 am

<<<It really is necessary to remove all the harmonics, odd and even , right up to half the nyquist frequency.>>>

Right. This is one of those "you can't really do this" tools. Particularly with buzz, by the time you get rid of it all, there's a great many little frequency notches in the show and musical notes and overtones either damaged or missing.

You might go as far as possible with the notches and clean up the remaining trash with one of the new threshold keyers.

What's the possibility that a cheap sound card is going to produce a buzzy captured show off pitch? This is the down side of assuming all sound cards are perfect.

Koz

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Hum removal plug-in

Post by steve » Mon Mar 29, 2010 2:50 am

Thanks for the feedback Trebor - I really do appreciate it (much better than the deafening roar of silence as tumble-weed rolls across the forum page :D)

The example you have posted has much more severe damage than this plug-in is designed to deal with. In truth the only "effect" I would consider using on such a low quality sample would be the delete key (unless of course it was an irreplaceable once-in-a-lifetime recording with personal value). In my description I use the phrase "moderate amounts of hum".

Here is an example at the high end of what I would describe as a "moderate amount"
pianohum.mp3
(276.56 KiB) Downloaded 549 times
(apologies to Koz for butchering his lovely piano sample - I don't have a suitably buzzy recording so I had to record some buzz then mix some audio with it. The buzz is a recording of my finger on the end of a jack plug straight into the sound card).


Here's the results of the two hum removal effects:
piano-de-hum2.mp3
(554.06 KiB) Downloaded 662 times
The first section is using your de-hummer and the second section using my de-hummer (not intending to suggest one is "better" than the other - just a matter of differentiating between the two effect).

The first de-hummer certainly removed more noise than the second, but the damage done to the piano is clearly audible.

Of course there is no reason why these two effects could not be combined. The "new" part of this de-hummer is that it makes a smooth transition from filtered low level sound (where it is most needed) to unfiltered high level sound (where it is not needed). There is a degree of "distortion" that occurs during the transition due to difference in phase, but it is pretty negligible and a good trade-off.

Just looking at your effect again - it's pretty similar to the notch loop used in this one. The main difference is the algorithm for calculating Q.
I've deliberately left out any settings for this for the sake of a simple user interface and instead opted for optimised* settings for low to moderate amounts of hum.

(* only roughly optimised - a lot more real world samples would need to be analysed)

The other difference is that you have used a lot more iterations. The number of iterations for "even harmonics" in my plug-in are artificially limited by the slider range but can be overridden through text input right up to half the sample rate.

As well as the damage caused by removing significant amounts of frequencies (the dull sound), there is also the problem that you mention in your previous topic of steep notch filters causing ringing. This will be particularly noticeable with transients, but are virtually eliminated with this "new" plug-in because transients are not filtered.

The other difference is in separating out the odd and even harmonic into 2 loops as per Koz's comment http://forum.audacityteam.org/viewtopic ... 627#p79346 . Doing this makes a significant reduction to the amount of damage when dealing with lower levels of hum. My own interest is in looking for ways to reduce low level hum for cleaning up otherwise high quality recordings, so my priority is more concerned with minimising the damage and I'm looking for ways to reduce the damage further.

[Edit] I see there's been further discussion while I've been typing - I'd better post this quick :D
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Hum removal plug-in

Post by steve » Mon Mar 29, 2010 3:18 am

Trebor wrote:Attached is an example which uses a modified version of your de-hum plug-in ...
Nice one Trebor. Yes, different de-noise algorithms can be easily "dropped in" to replace the "dehum" function.
I've also left the "gate" parameters near the top so that they can be easily tweaked.
Trebor wrote:I think that would require "look ahead"
It already uses lookahead.

The envelope follower has a rise time and a fall time set by the "attack" variable (currently set at 250 milliseconds) and the lookahead ("look") is set equal to "attack". When there is rise in amplitude the envelope will "fade-in" before the higher amplitude level is reached. When the amplitude drops, the envelope will "fade-out" after the drop.

This is a trade-off. On the downside, there will be a short period of hum that is not removed immediately before and after a transient that occurs during a low level part of the audio. On the plus side, transients will pass through the effect unharmed. It is possible to artificially create audio samples that show up this weakness, but in practice it seems to work well.
Trebor wrote:Attenuating the depth of the notching...
Unfortunately this is not an easy thing to do - to do this properly I think we would need to get into FFTs but so far I've found that pretty impenetrable. Have you done anything with FFTs yet?
kozikowski wrote:What's the possibility that a cheap sound card is going to produce a buzzy captured show off pitch?
Quite high I'd guess, and almost a certainty if trying to clean up old cassette or VHS recordings.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

kozikowski
Forum Staff
Posts: 69243
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Hum removal plug-in

Post by kozikowski » Mon Mar 29, 2010 6:16 am

<<<(apologies to Koz for butchering his lovely piano sample - I don't have a suitably buzzy recording so I had to record some buzz then mix some audio with it. The buzz is a recording of my finger on the end of a jack plug straight into the sound card).>>>

That's a Twilight Zone Moment, isn't it? One of my chores over the weekend was to create an illustration page on the technique of rapidly generating a "test signal" by... say it with me... touching the end of a jack plug straight into the sound card.

So I'm in a perfect position to tell you that if you do that in the US, you do get all the harmonics, odd and even. And there are seemingly billions of them. I'll post the sound clip before I finish the web page. It's almost Monday in California.

Koz

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Hum removal plug-in

Post by steve » Mon Mar 29, 2010 6:58 am

UK mains hum (finger on jack plug test)
window-Frequency Analysis-000.png
50Hz hum
window-Frequency Analysis-000.png (29.28 KiB) Viewed 10096 times
In order of amplitude:

50 Hz - fundamental -44dB
250 Hz - 5th harmonic -61dB
-69dB - 150 Hz - 3rd harmonic
-69dB - 450 Hz - 9th harmonic
-71dB - 750 Hz - 15th harmonic
-77dB - 850 Hz - 17th harmonic
-79dB - 550 Hz 11th harmonic
-80dB - 650 Hz - 13th harmonic
-81dB - 1050 Hz - 21st harmonic
-82dB - 1150 Hz 23rd harmonic
-84dB - 350 Hz - 7th harmonic
-84dB - 1650 Hz - 33rd harmonic
-85dB - 220 Hz - half of 9th harmonic?
-85dB - 100 Hz - 2nd harmonic (even harmonic)
-85dB - 300Hz - 6th harmonic (even harmonic)
-87dB - 78 Hz - half of 3rd harmonic?
-90dB - 950 Hz - 19th harmonic

indistinct beyond -90dB though harmonics are visibly present up to 4000Hz (80th harmonic)
At 105dB and below, harmonics are visually indistinguishable from other noise.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

kozikowski
Forum Staff
Posts: 69243
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Hum removal plug-in

Post by kozikowski » Mon Mar 29, 2010 3:54 pm

Yes, but.

There's only 20dB difference between the third harmonic and the 19th. The one that I generated is much worse starting out; the fundamental is only a handful of dB down. I have a much better finger than you do (I live under high tension wires). There is serious trash out so far only dogs can hear it. 17KHz plus.

Koz

Trebor
Posts: 9883
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: Hum removal plug-in

Post by Trebor » Mon Mar 29, 2010 9:11 pm

Frequency Analysis of Wikipedia 50Hz mains hum.png
Frequency Analysis of Wikipedia 50Hz mains hum.png (23.94 KiB) Viewed 10078 times
Now I can see where Steve got the idea of only notching the odd harmonics up to 2kHz, as it would get rid of the worst offenders.

What about notching all the harmonics, odd and even, but applying a deeper notch the odd ones than the even.
Combine this with a general reduction in notch depth as frequency increases, (to both odd and even harmonics).
And the envelope follower thingy, (which I don’t yet understand), which cured the ringing artifacts from transients.

Then I think we’d have a mains dehummer that would suit most purposes.

Post Reply