ECE 401 Fall 2020 MP3: Ideal and Practical Filters

In this file, we're going to lowpass, bandpass, and highpass filter some EEG signals. The signals we'll be using are samples provided with the MNE package. It is recommended, but not required, that you first install MME. You can do so using the instructions on the MNE homepage. The key step is to go to a command window, and type conda env update --file environment.yml in order to create the mne environment. If you don't want to install MNE, you can do the whole MP without it, by simply avoiding the blocks of code marked Requires MNE below.

The first thing you should do is to download and install the template, from When you unzip it, you will find the following files, among others:


Here's how the debugging works. Every time one of your functions from is called, we will first use the code importlib.reload(mp3) in order to reload the most recent version of mp3. That way, if a block of code fails, you can revise the file, and try again.

Data: With MNE

Here's how the data works. If you want to use MNE to visualize the data, you first need to install the mne environment as described above. Then, every time you want to run the MNE code on this page, you'll need to do the following steps:

  1. In an operating system command window, type conda activate mne, and then jupyter notebook. That should open up your Jupyter browser, just as if you had opened it from the GUI, except it will make the following steps possible (they wouldn't be possible if you used the GUI).
  2. Open this file (mp3overview.ipynb).
  3. Go to the top of this screen, and find the Kernel menu. Under that menu, choose Change Kernel -> Python [conda env:mne].

Now you should be able to run the following block of code without errors:

Data: With or Without MNE

If you don't want to use MNE, you can run the following block of code to load the repackaged data. You should run the following block whether or not you're using MNE, because some of the blocks that follow will use this version of the data.

1. Browsing the Data

EEG data consists of 60 different voltage signals, recorded in parallel from different electrodes on the scalp. Here is a function that you can use to choose three of the signals, and plot both the signals and their power spectra:

Browsing the Data: With MNE

If you have installed MNE, you can use the plot_topomap function to see how the voltages are distributed over the scalp at each time step. Here's a function that plots the voltages as a function of location, for 25 different time steps:

Running it requires MNE. It requires that you have already run the MNE sample-loading code, up above, to load the info object that contains the spatial locations of the electrodes.

2. Running the MP

Now you're ready to run the MP. Each block of code, below, will first show you the distributed solution (distributed to you in the file solutions.hdf5), and will then run the code in your own file, to test whether or not your code works.

2.1 todo_lpf_even

This function tests whether or not you can create a lowpass filter with a specified cutoff frequency, and with even length. The distributed solution contains a 200-sample lowpass filter with a cutoff of pi/4. Notice that the loglog plot doesn't quite know what to do with the aliased part of the filter, up near $\omega=2\pi$. It isn't really designed to handle the frequency responses of digital filters like this one.