Notch Filtering for Tinnitus Treatment

There is some clinical evidence that notch filtering music can be useful for treating tinnitus.


Module for generating and playing sounds in real time. Provides a mechanism for generating noise and pure tones, and simultaneously sounding various combinations.
Filter design. Uses scipy.signal to make FIR filters with a given frequency response that can then be applied to music and other sounds (in realtime hopefully... not tested yet).
Simple spectral analysis tools.
Represents human hearing responses for use later in filter design.
Application (UI using traits) to measure a listener's frequency response.
Takes an input signal (file) and applies a filter.


  1. Determine the patient's frequency response.

    Provide a GUI for determining the patients frequency response. The GUI should allow the user to adjust the amplitude of a sinusoidal signal of various frequencies until they can just barely hear it. There should be a simple mode, where the system picks the frequencies, and the user simply has a single slider that they adjust, and a more advanced mode where the current response is displayed and can be adjusted.

    The end result of this is a list of frequencies and amplitudes defining the user's hearing threshold. Note that the absolute value of the amplitudes will depend on the volume adjustment of the computer. Repeating the test at a different volume setting should reproduce different results that can be brought into alignment by scaling. (This should be checked.) It should also be independent of the headphone/speaker setup.


    Poor quality sound systems and speakers/headphones can really muck this up. One should at least do an aliasing check such as suggested here. Playing the appropriate sound files should produce a continuously descending tone - any perception of ascending tones is due to aliasing artifacts from a cheap sound card.

    Finally, one should probably reproduce the test with various levels of background noise as the results are likely to depend on the presence of noise, and the resulting filter might want to be designed to take this into account.


    Note that once this is established, the same setup can be used to test the quality of headphones. Or a mic can be used, but the frequency response of the mic must also be established and removed.

  2. Determine the patient's tinitus frequency, range, and intensity.

    This is more difficult to do accurately. The patient will need to be able to adjust the frequency of the pitch and the amplitude. To simplify the procedure, you might like to do this as a bisection search. "Which sounds more like your tinnitus, A, B, or can't tell?" where signals A and B have different pitch or different intensity. This should be repeated several times, again with various noise backgrounds.

    The intensity should be determined relative to the patient's frequency response and must thus be done under the same conditions (volume setting, headphones etc.) as 1).

  3. Design the filter.

    The filter design should be fairly simple at this point. Include a smooth overall gain to compensate for hearing loss, and provide a notch filter to compensate for the tinnitus.


    Include a limit to the amount you amplify the signal by in the high-frequency region. The patient's hearing loss may prevent them from hearing a large amplification at high frequencies, but it might still be damaging to their hearing. (I have no evidence either way: it is just probably best to err on the side of caution here.)

  4. Test the filter.

    Generate noise with a power level greater than or equal to the tinnitus strength in the tinnitus region. Applying the filter to this noise should completely mask the tinnitus. Lower amplitude noise should also mask the tinnitus, but maybe not completely. (Though it might mask it completely.)

    Feedback could be obtained from the user at this point, adjusting the tinnitus location, width, and the noise background to refine the filter. My guess is it will be easier for the user to answer "With which sound do you hear less tinnitus: A or B?" than the previous ones if the tinnitus almost vanishes in one of them.

Fourier Analysis

Our first task is to see the nature of a signal, so we can understand if the notch filter is working. Note that simply applying an FFT to the full signal will produce a very noisy frequency spectrum. The noise can be reduced by either smoothing, or applying a window

Playing Sounds

To play sounds "live" we use the pyaudio library which wraps PortAudio.


On older versions of Mac OS X < 10.7 you will need to build your own version of pyaudio to enable non-blocking operation (which might be important to avoid sound distortion if your program is CPU bound on a single core.) See python_setup for more details.

A sound is defined by a sample string, and when the sound is played, that string is repeatedly sent to the output in a separate thread (allowing for multiple sounds to be played simultaneously). One problem with this is that I do not know of a clean way to exit the interpreter and closing the threads because the atexit() handlers are called only after all threads have shutdown. See:

I am also having problems shutting down non-blocking streams. It seems that the call to stream.stop_stream() is the issue... perhaps there is a bug in pyaudio.