FeatReq: Notch filter 'invert+mix' check box

I am processing some files containing precise sines surrounded by background noise, and some with generator artifacts such as missing or botched zero crossings (computer generated morse code program output, yuck) … I’m smoothing and buffing so that only the pure sine is left with ‘soft’ onset and NO HF clicky or LF poppy components …

Sharp 48db/octave lowpass then highpass helps does a decent job but reduces dynamic range by half — but the BEST overall technique I’ve found that preserves original amplitude is

  1. copy the audio to a new track,
  2. use Notch Filter with high Q to obliterate the tone ‘with extreme prejudice’, leaving only undesired components,
  3. invert the result,
  4. do a 50/50 mix/merge with the original.

Adding an ‘invert+mix’ feature to Notch Filter that does this as one step would also allow it also be used as a one-step adjustable Q (yet extremely narrow) bandpass filter.

Thanks kindly for a wonderful tool!

The Notch filter effect in Audacity is a simple “Nyquist” effect. http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference

Nyquist is a scripting language that has been included in Audacity and allows users to easily use custom effects, or customize existing Nyquist effects.
The thing that makes it simple is that Nyquist scripts are written in plain text, so can be written / edited in any plain text editor (such as NotePad, though the free NotePad++ is much better)

The core code for the notch filter is simply:

(notch2 sound frequency width

Where “sound” is a mono or stereo sound to be processed, “frequency” is the centre frequency of the notch, and “width” is the “q” value (narrowness) of the filter.
You can run this code in the Nyquist Prompt effect (http://manual.audacityteam.org/o/man/nyquist_prompt.html) by substituting actual values and typing or pasting the code into the Nyquist Prompt text box.
For example, for a 1000 Hz notch filter with a “q” of 2.0 you would use:

(notch2 s 1000 2.0)

Note that the letter “s” is a special character that represents the selected audio.

In order to invert a sound, all you need to do is to multiply it by -1 (minus one). The code to do this in Nyquist is:

(mult -1 sound)

where “sound” is the sound that you want to invert.
For example, to invert the audio in a wave track using the Nyquist prompt you could use:

(mult s -1)

Note again that “s” is used to represent the audio in the current track selection.

“Mixing” sounds is simply “addition”, and in Nyquist can be accomplished with the function “SUM”, so putting this all together we have:

(sum s (mult -1 (notch2 s 1000 2.0)))

Does that all make sense?

The Notch filter plug-in in your Audacity plug-ins folder can likewise be customised.

For an alternative approach, you may be interested in modifying this band stop filter: http://wiki.audacityteam.org/wiki/Nyquist_Effect_Plug-ins#Band_Stop_Filter

You could alternatively use the nyquist prompt:

(diff s (notch2 s <Freq> <Q>))

you can also cascade the notches for an even sharper slope:

(diff s (notch2 (notch2 s <Freq> <Q>) <Freq> <Q>))

Plain text file extendability with lisp syntax. Sweet! Done! My apologies for not RTFM and posting a problem rather than a solution. Thanks all for your comprehensive and immediate replies.


;nyquist plug-in
;version 1
;type process
;categories "http://lv2plug.in/ns/lv2core/#FilterPlugin"
;name "Notch Pass Filter..."
;action "Performing Notch Pass Filter..."

;control freq "Frequency" real "Hz" 60 0 10000
;control q "Q (higher value reduces width)" real "" 1 0.1 20

;; based on notch.ny by Steve Daulton and Bill Wharrie, September 2010.
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html .

;; (multichan-expand) provides legacy support for old versions of Audacity 
;; in which the (notch2) function only supports mono tracks.

  ((> freq (/ *sound-srate* 2.0))(format nil "Error:nFrequency too high for track sample rate."))
  ((< freq 0)(format nil "Error:nNegative frequency is invalid."))
  ((< q 0.01)(format nil "Error:nWidth must be at least 0.01."))
  ((= freq 0) (format nil "Nothing to be done."))
  (T (multichan-expand #'diff s (notch2 s freq q))))

No worries, Nyquist scripts are considered to be an “advanced” topic, so it’s not very prominent in the manual, but yes “sweet” :smiley:

Incidentally, the “old versions” referred to in the plug-in are now really ancient and totally obsolete, so it should be safe to disregard that and use the shorter form in the final line:

(T (diff s (notch2 s freq q))))