# MP6: IIR Notch Filtering¶

Audio recordings sometimes have 60Hz hum noise, caused by leaving the microphone cable to close to a power line. This MP will explore methods for getting rid of the hum noise, especially the low-frequency harmonics. This MP was originally designed by Prof. Doug Jones at the University of Illinois.

## Exploring the Data¶

This MP will explore one audio recording in detail, so that you can see where the low-frequency peaks are. The main peak, at 120Hz, could easily be filtered out from a large number of audio files, all at once.

Notice, in the waveform above, there is a periodic component in the "silence" before and after the speech begins. There seem to be five or six periods in 0.05sec, so maybe the period is around 0.01sec, or around 100Hz. We can listen to it using the following code:

## How to debug¶

Rather than printing every plot using separate blocks for both the distributed solution and your solution, instead, each of the following blocks will include lines to plot either one or the other. In order to switch between your solution and the distributed solution, you'll need to comment out the other one.

## Searching for the noise peaks¶

First, let's plot a spectrum, and try to find the frequencies of the noise components.

• It looks like there's a huge power-line noise component at about 120Hz.
• There doesn't seem to be any 60Hz component; the recording device seems to have filtered out all energy below about 80Hz.
• There is also energy at about 180Hz, which might be the third harmonic of the power line noise, but it might also be the pitch of a female talker. Let's leave that energy in the signal.
• Instead, let's eliminate three of the other small peaks that occur between 90Hz and 120Hz.
• We'll use the "todo_findpeak" function to find the frequencies of those peaks (if you've written it).

## Creating the notch filters¶

We'll create four notch filters: one for each of the frequencies we want to eliminate. For each notch filter, we need to create zeros and poles for the Z transform, then convert them to filter coefficients.

At that scale, the poles and zeros are all right on top of each other! Let's try to zoom in.

Finally, let's create the filter coefficients. There are four filters, each of which has feedforward coefficients (b[:,k]) and feedback coefficients (a[:,k]).

## Filtering out the noise¶

Let's plot the frequency response that we would get by running all four filters, one after the other.

OK, now let's actually run all four filters, one after the other, and take a look at the resulting spectrum and signal, to see if the noise has been removed.

## Conclusion¶

That's all! This is the basic technology behind utilities like noiseremove, in case you don't feel like doing it all by hand next time.