Audacity advanced noise removal

Hello,

About what I am doing:

I am a college student and I am working with raw audio data. My current project involves trying to find a very specific audio “tune” (it is short, lasts a maximum of 2 minutes) somewhere within 55 minute audio files, and may not be in every audio file event we have (it doesn’t happen a lot basically). When trying to find a solution my boss pointed me into looking at FFT’s and eventually asked me to try running a file through Audacity’s noise removal to see what would happen (he likes the program). Doing so made the FFT’s much nicer to work with and overall look like something we can use as a correlation to find our events much easier.

My question/problem:

Running each file through audacity is not something we are looking to do as the goal is to have this process automated (false positives are fine, as long as it finds our events). So I started looking around and found this :
http://wiki.audacityteam.org/wiki/How_Noise_Removal_Works

which also led to this:

http://en.wikipedia.org/wiki/Noise_gate

While these are helpful, they will not produce the nicer results of putting the files through audacity and doing a noise removal. I’m not asking for specific code (we code in IDL so I doubt anyone would have a noise removal code written in IDL just laying around anyways) or anything, but more of if anyone could tell me more about how audacity does their noise removal (as long as that doesn’t mean breaking any laws or something of course).

Thanks,
-Avon

PS - attached are 2 files. “afteraudacity” are graphs of the FFT’s after audacity’s noise removal process. “before audacity” is a graph of the FFT where an event happens. the red horizontal line is something I graphed to see what was happening during my noise gate code, since it’s not fully functional at the moment (although I can see that it won’t produce the desired effects).
beforeaudacity.png
afteraudacity.png

Not at all. Audacity is open source software - if you know C++ I can direct you to the actual DSP code.

I’m not really clear about this - Your spectrum plots all appear to focus on frequencies below 250Hz ? That seems to a bit low for a “tune”.

So you have some sort of “sound event” that is buried within a mass of noise, and you are trying to pick out the “event” from the noise?

Have you looked at “Spectral Subtraction”?
Unfortunately Audacity does not have a spectral subtraction effect, but it is available in Reaper through their “ReaFIR” plug-in. I think that plug-in should work in the Windows version of Audacity, but without the real time capability (Audacity does not do “real time”).

I have taken a course on C programming, and I know that C++ and C are very close so I would probably be able to read the code.

I used the word tune liberally, while in fact it is not what one would classify as an actual tune, it’s just what we call it here in the lab I work in. Event is the better word to classify it as. Our event is very short, ranging from 30 seconds to 2 minutes (very rare), and it is classified as going from ~100Hz and dropping down to ~60Hz (so imagine a high pitch whistle slowly dropping down in pitch, assuming it could be audible to the human ear).

Essentially yes, this is what I’m trying to do. We want to make a process that we can then automate through all of the data files we have and give us back all the files that have events (false positives are okay). There are a large amount of files to look through and going through all of them by hand one by one is very tedious and time consuming. As you can see on the “beforeaudacity” graph there is a huge spike at the 60Hz frequency, this is due to the instrument, I was told there would have been a spike like that somewhere within the frequency no matter what, apparently they settled for it being at 60Hz.

I will make sure to look into spectral subtraction and see what I can find out about it.

As you might have guessed, I am not too familiar with the manipulation of audio, especially when it comes down to having to do everything step by step (taking FFT’s and such instead of a pre-written program doing that process for me).

The frequency range 60 to 100 Hz is low pitch, and clearly audible to the human ear. :confused:
Human hearing range is typically quoted as 20 Hz to 20,000 Hz, though for adults it is more likely to be around 20 Hz to 16000 Hz.

If you are in the US, that may be due to mains hum
Regardless of where it is coming from, if it is precisely and consistently 60 Hz then you could remove that by using a narrow “notch filter”.
Audacity includes a notch filter (Effect menu, below the dividing line). The “q” control sets the width of the notch - use a high value for a narrow notch.
For digital processing, “biquad filters” are generally better (able to be deeper and narrower) than FFT filters.
The following code can be run in the Nyquist Prompt effect and will produce a very narrow notch (q = 20) at 60 Hz.

(notch2 s 60 20)

For a less narrow notch, change the last number (20) to a smaller value. For a narrower notch, change it to a higher value.


As you know that your “event” is in the frequency range 60 to 100 Hz, the easiest way to eliminate noise from outside of that range would be to use a 60 Hz to 100 Hz band pass filter. It probably does not really matter if this is an FFT or IIR filter, but should ideally have a reasonably steep slope between pass bands and the stop band.
An example, again using Nyquist code, could be to apply a high pass filter from a bit below 60 Hz followed by a low pass filter at a bit above 100 Hz. This will attenuate frequencies outside of the “event” frequency range:

(lowpass8
  (highpass8 s 50)
  120)

The above code applies two 8th order Butterworth filter (48 dB per octave). The high pass filter has a corner frequency (-3dB cut-off point) at 50 Hz and the low pass filter has a corner frequency of 120 Hz.

There is no reason why this has to be run as a Nyquist effect, but Nyquist scripts provide a simple and convenient way to develop customised effects in Audacity. There is also a standalone version of Nyquist that can be run from the command line: Nyquist Info or of course you could implement the filters in a different programming language.

The notch and band pass Nyquist filters can be combined to run in one pass:

(lowpass8
  (highpass8
    (notch2 s 60 20)
    50)
  120)

If this code was made into a Nyquist Effect plug-in (Missing features - Audacity Support) then it could be applied to a batch of files by using it in a “Chain” (Audacity Manual).
Note: Nyquist effects in Audacity may use a lot of memory when run on long tracks. This does not affect all Nyquist commands and does not apply to standalone Nyquist, but if you wish to use Nyquist commands in Audacity on long files then you should check that memory use is not too excessive.

Once you have eliminated noise from outside of the “event” signal range and have eliminated the 60 Hz spike, you may be able to detect the “event” by simply looking for where the amplitude of the remaining signal crosses above the background noise level. (See SoundFinder: Audacity Manual)
Again, Sound Finder is written in Nyquist, so it could be customised to suit your needs.

Thank you for all of the information.

Oops, my bad, I thought I was told it wasn’t audible but I guess I miss heard. The data I’m working with I haven’t worked with before and this project was originally not intended for me, so I am still learning about the data and such.

I assume it is from a powerline connected to the instrument, however, the instrument itself is not in the US, it is in the south pole so that there is minimal human contact/interference while the instrument records data.

I had looked at buttersworth filters earlier, however I did not specify an order when I was testing them(the function defaulted to 1st order I believe). I assume 8th order will create the steep slope that you mentioned.

Yes. A first order Butterworth filter has a slope of 6 dB per octave. A 2nd oder → 12 dB/oct. 4th order → 24 dB/oct. 8th order → 48dB/oct. I’m sure you get the idea :wink:

I was wondering where you learned about manipulating audio? I’m assuming that your name being in red means that you are part of the audacity team. In my advanced math classes we talked about how concepts we learned could be used for such things, but didn’t actually apply it like that.

I was also wondering if you knew how I might create a notch filter in C (we don’t actually use C in the lab, but the language we use is quite similar), or maybe a place that might describe how to do so well.

And thanks for all the wonderful information, now I need to find out how to correctly apply it all in order to get desirable results :laughing:

The red name is because I’m an administrator of this forum (I am also part of the Audacity support team).
There’s a lot of good information about digital filters here: http://www.dspguide.com/ch14.htm
See also: http://www.dspguide.com/ch19.htm