Notch Filter (wiki)

Archive of Nyquist Plug-ins.
Many of the plug-ins here will be available on the Audacity Wiki.
Forum rules
This Forum is an archive of old topics concerning Nyquist plug-ins.

Feedback and questions relating to topics may be posted, but please
DO NOT POST NEW TOPICS HERE.

New plug-ins may be posted on the New Plug-Ins board.
Other posts relating to Nyquist should be posted to the main Nyquist board.

The main repository for Audacity/Nyquist Plug-ins is on the Audacity Wiki.
steve
Site Admin
Posts: 85699
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Notch Filter

Post by steve » Tue Sep 28, 2010 6:32 pm

Sorry if that last post appeared rather brusk, it was posted in a rush.

Having given it some consideration;

I think that for accuracy the name of the Q control should be "Q" or "Q factor" rather than "Width" but by including "(higher value reduces width)" the meaning is made clear for all.

I have reservations about the error message "Frequency must be at least 0 Hz." because although it is accurate in as far as 0Hz does not produce an error, I feel that it implies that 0Hz is a reasonable value, when in practice it does nothing. Currently the user has to wait for the sound to be written back (unaltered) to the track, which could be a significant wait for a long track. I think it would be better if the user was informed straight away that the effect is doing nothing.

So the situation is:
1) Negative frequencies are invalid and so should generate an error
2) 0 Hz should not produce an error, but it should be clear that it does nothing.

What I propose is:
1) For a negative frequency value the error message should be "ErrornNegative frequency is invalid." (or something similar)
2) 0 Hz should generate a "non-error" message of "Nothing to be done." (or something similar).

Thanks for the feedback Gale, I'm in full agreement with the other changes that you've made.
(I've also added the expanded GPL license information in the comment as discussed previously)
Attachments
notch-Sep-28-2010.ny
(818 Bytes) Downloaded 278 times
Learn more about Nyquist programming at audionyq.com

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10 / 11

Re: Notch Filter

Post by Gale Andrews » Wed Sep 29, 2010 9:48 am

stevethefiddle wrote:Sorry if that last post appeared rather brusk
It didn't, but thanks :)
stevethefiddle wrote:"width" is sometimes used for band pass/stop filters where it refers to the number of octaves and a higher number is a wider frequency band...I think that for accuracy the name of the Q control should be "Q" or "Q factor" rather than "Width" but by including "(higher value reduces width)" the meaning is made clear for all.
That's fine, I looked up the Nyquist Manual afterwards and came (more or less) to your conclusion. I think one of the problems is that "Q" on its own looks more confusing than "Notch Q" which is what we called it before.

I did find in the index of the Manual an entry for "Q":

q = Quarter = 1.0

so I really think "Q factor" is better and it doesn't look unreasonably wide. It also matches with the reference on the Wiki Noise Removal page to Q factor if you run notch filter at a Nyquist prompt. So can we agree to "Q factor" for the name of the control, and then the unit at the end of the slider is "Q" (there should really be a unit I think)?

Everything else is fine now with me, so I assume if no-one objects in the near future on -quality to including it in Audacity, I'll commit it.

I'm figuring that because notch filter is mentioned in the popular Wiki Noise Removal page, we should retain it on the Wiki Download Nyquist Plug-ins page at least until 2.0, and possibly even after then for people on legacy OS'es? Generally once a Nyquist plug-in is included in the major and Beta releases the practice has been not to include it on the Nyquist Plug-ins pages any longer.



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

billw58
Posts: 5832
Joined: Wed Aug 12, 2009 2:10 am
Operating System: macOS 10.15 Catalina or later

Re: Notch Filter

Post by billw58 » Wed Sep 29, 2010 1:33 pm

Gale Andrews wrote: So can we agree to "Q factor" for the name of the control, and then the unit at the end of the slider is "Q" (there should really be a unit I think)?
Gale
"Q factor" is fine as the name of the control. Technically speaking, "Q" is a dimensionless parameter. Therefore it shouldn't have a unit. The q factor of a filter is not "10 Q" it's just "10".

-- Bill

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

Re: Notch Filter

Post by steve » Wed Sep 29, 2010 4:16 pm

You took the words out of my mouth :)
Learn more about Nyquist programming at audionyq.com

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10 / 11

Re: Notch Filter

Post by Gale Andrews » Sat Dec 18, 2010 10:08 pm

steve wrote:For recent/current versions of Audacity the "(if (arrayp s)(vector.." business is not required as the (notch2 ..) function now supports stereo tracks.
I assume this is the reason this plug-in fails in 1.2.6 on stereo audio (tested on Windows 7 by generating a 440 Hz stereo sine tone and cutting a 100 Hz notch at q = 0.1). That's a shame as I thought it would be nice to update David's version on Download Nyquist Plug-ins with yours.

Do you want to produce a "legacy" compatible version with the new UI just for that page, or include the code that enables stereo processing in 1.2.6 in your version?



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

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

Re: Notch Filter

Post by steve » Sun Dec 19, 2010 5:32 am

Here's a "legacy" compatible version.
The only change to the code is that

Code: Select all

(notch2 s freq q)
has been changed to

Code: Select all

(multichan-expand #'notch2 s freq q)
I've also added a comment:

Code: Select all

;; (multichan-expand) provides legacy support for old versions of Audacity 
;; in which the (notch2) function only supports mono tracks.
I'm assuming that this will be the final version, so I've changed the file name to "notch.ny"
Attachments
notch.ny
(975 Bytes) Downloaded 326 times
Learn more about Nyquist programming at audionyq.com

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10 / 11

Re: Notch Filter

Post by Gale Andrews » Mon Dec 20, 2010 2:51 am

steve wrote:Here's a "legacy" compatible version... I'm assuming that this will be the final version, so I've changed the file name to "notch.ny"
OK, thanks. So as I understand it "Download Nyquist Plug-ins" will have the version you last attached in the post above, and that same version will also be included in 1.3.13 Beta.

The plug-ins listed on "Download Nyquist Plug-Ins" are are usually stored on audacity.sourceforge.net (so committed to the web site SVN) and usually include a text file in a zip with the .ny file. As I can't use the old text file that David wrote, here's my attempt at the replacement text:

Code: Select all

Notch filter sharply reduces the volume of audio centered on a
specified frequency. When you look at the resultant audio in 
Audacity's Analyze > Plot Spectrum, you will see a "notch" 
cut out of the audio in an area surrounding the specified 
frequency.  

Frequency: Use the slider to choose any frequency up to 10000 Hz
(default is 60 Hz). Frequencies above 10000 Hz can be entered 
by typing in the text box. You cannot enter a frequency greater
than half the sample rate of the track, because a track can 
only contain frequencies up to half its sample rate. 

Q Factor: This determines the width of the notch cut from your 
audio (default value is 1). Use the slider to choose a Q Factor
between 0.1 and 20. Values above 1 create a narrower notch, 
and values below 1 create a wider notch. Values outside the
slider range can be entered by typing in the text box (the 
Q Factor must be at least 0.01). 

Tips for hum removal: For mains hum removal, choose 60 Hz as  
"Frequency" for North America, or 50 Hz for the United Kingdom
and elsewhere. Note that significant hum on a recording will 
usually contain noisy harmonic frequencies above the fundamental
frequency of the hum. A good approach is often to apply Notch 
Filter to the fundamental hum frequency (for example 50 Hz or
60 Hz), then use Effect > Noise Removal to remove residual 
harmonics. 
Presumably some heavily abridged text based on the above could be used as the text for Notch Filter in the 1.3.13 Manual. Let me know if the above is reasonable/accurate.



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

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

Re: Notch Filter

Post by steve » Mon Dec 20, 2010 5:56 pm

The description looks accurate to me.

The only part that I would query is regarding hum removal. In many cases better results can be achieved by notching out a few of the strongest harmonics before using Noise Removal. For example, if "Plot Spectrum" shows strong peaks at 60, 180 and 300 Hz, then all three of these may be removed (one at a time) with the notch filter. For the higher harmonics it is generally better to increase the Q factor so as to lessen the damage to the audio, but the Q factor should not be raised too high as that can cause ringing (Gibbs phenomena) to occur on transients. Generally a Q of between 2 and 10 works well for "mains hum" removal with higher value being more selective, but increasing the risk of ringing. In the manual, don't think that it's worth mentioning the Gibbs phenomenon as it's rarely noticeable unless a lot of extreme filtering is applied, but it may be worth a brief mention in the wiki?
Learn more about Nyquist programming at audionyq.com

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

Re: Notch Filter

Post by kozikowski » Thu Jan 13, 2011 6:57 am

My slider would not have gone below 20Hz, but that's just me. And a job I had recently had digital trash centered around 13 KHz, which I can enter manually.

Is there a slider for dB reduction? You get the frequency and Q factor (I learned it as "Quality," the ratio of width to height) exactly right, but you want to leave some of the material behind without affecting the shape of the curve.

Also, in a bid for ease of use, how would I transfer the shape of a spike of garbage in Analyze > Plot Spectrum to the notch tool so it exactly matches?

Can I save a notch and mail it to me mum?

Koz

edgar-rft
Posts: 347
Joined: Sun Jan 20, 2008 12:03 am
Operating System: Please select

Re: Notch Filter

Post by edgar-rft » Thu Jan 13, 2011 11:18 am

kozikowski wrote:How would I transfer the shape of a spike of garbage in Analyze > Plot Spectrum to the notch tool so it exactly matches?
It makes not much sense to match exactly to the "Plot Spectrum" curve, because the "Plot Spectrum" curve contains interpolation errors from the different "windowing" functions, which you can choose in the lower left corner of the "Plot Spectrum" window. Because there is no windowing function known without errors, you will have to appoximate your notch filter settings from the curves by trial-and-error.

Here is how to get the values you need for that:
  • q = center_frequency / bandwidth
  • bandwidth = upper_cutoff_frequency - lower_cutoff_frequency
The "cutoff" frequencies are defined as the points to the left and right from the peak of the spike, where the spike has only half of its energy.

To get the center_frequency, move the mouse pointer into the spike in the "Plot Spectrum" curve, and below the curve you see:

Cursor: <number> Hz (<pitch>) = <number> dB --- Peak: <number> Hz (<pitch>) = <number> dB

The number from "Peak: <number> Hz" is the center_frequency of the spike (and the notch filter).

Now move the mouse pointer horizontally and try to match the "Cursor: <number> Hz" and "Peak: <number> Hz" as close as possible. Then write down the "dB" value form the "Cursor:" side. Do not use the dB value from the "Peak:" side, because the "Cursor:" and "Peak:" sides are computed with different algorithms, and usually have different values at the same frequency (because different algorithms produce different errors).

The dB value from "Cursor: ... = <number> dB" at the center_frequency is what I now call "maximum_peak_dB" value.

Now move the cursor from the peak of the spike downhill to the left until the "Cursor:" dB value has been fallen by -3dB to:
  • maximum_peak_dB - 3dB
Now write down the number from "Cursor: <number> Hz", this is the "lower_cutoff_frequency".

Then move the cursor from the peak of the spike downhill to the right until the "Cursor:" dB value has been fallen again by -3dB and write down the frequency number from "Cursor: <number> Hz", this is the "upper_cutoff_frequency".

Now you can compute the q-factor:
  • q = center_frequency / (upper_cutoff_frequency - lower_cutoff_frequency)
Unfortunately the "Cursor:" dB value is displayed as an integer so it is not possible with the Audacity "Plot Spectrum" window to get the exact cutoff frequency. Also different "functions" (in the lower left corner of the "Plot Spectrum" window) can produce different q-factor values, but a rough estimation of the cutoff frequencies is often enough to approximate the q-factor and then some trial-and-error is needed until the result sounds as wanted.

Keep in mind that the only sounds with a flat frequency response are "white noise" and "silence", and both sound boring.

- edgar
Last edited by edgar-rft on Thu Jan 13, 2011 11:37 am, edited 1 time in total.

Post Reply