Notch Filter (wiki)

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)
notch-Sep-28-2010.ny (818 Bytes)

It didn’t, but thanks :slight_smile:

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.


“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

You took the words out of my mouth :slight_smile:

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?


Here’s a “legacy” compatible version.
The only change to the code is that

(notch2 s freq q)

has been changed to

(multichan-expand #'notch2 s freq q)

I’ve also added a comment:

;; (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”
notch.ny (975 Bytes)

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 (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:

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: 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 

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.


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?

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?


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: Hz () = dB — Peak: Hz () = dB

The number from “Peak: Hz” is the center_frequency of the spike (and the notch filter).

Now move the mouse pointer horizontally and try to match the “Cursor: Hz” and “Peak: 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: … = 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: 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: 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

Copy the whole audio track into a second audio track and apply the “notch” filter to only one of both tracks. Now during playback you can use the “volume” sliders of both audio tracks to adjust the “notch” amount in real-time. Finally mix both tracks into one track again.

Everything else probably makes not much sense as long as Audacity has no real-time-preview effects.

  • edgar

“Notch” filters are supposed to be bottomless pits, getting ever deeper and narrower as the centre frequency is approached.
You can “fake” a bottom to the notch as described in Edgar’s post by mixing in a proportion of unprocessed signal.
In some circumstances this can cause unexpected responses either side of the notch due to the notch filter causing phase shift.

For a “proper” filter that selectively cuts to a given level, a narrow band-cut filter should be used.
I’ve got a plug-in for this somewhere, but if you want to try modifying notch.ny

the filter code of a notch filter is:

(notch2 signal hz [q])

the filter code for a “band” filter is:

(eq-band signal hz gain width)

There’s probably not much point trying to notch out audio below 20 Hz, but having a range from 0 to 10000 Hz makes the slider move in sensible steps when you click to the side of the slider knob.

No, but you can “write” the frequency and Q settings.
(I don’t mean “write” in the computer sense of “save”, but in the old fashioned sense of pen and paper).

Do they still make those? Does it come with an usb interface in the case you want to hook it up to the computer?

Does it come with an usb interface

Please. There’s an app for that.

The Notch Filter is now available for download on the Audacity wiki.