Instructions | Deliverables | Walkthrough |

Detailed Instructions (Recommended Steps in Python)

  1. The signal file chorus.dat contains five seconds of a frog chorus digitally recorded with a sampling rate of 20 kHz at the Cibolo Nature Center in Boerne, Texas on the evening of March 21, 2007. The recorded signal has been corrupted by a (synthetic) sinusoidal interference. Your goal is to remove this interference using a notch filter so that you can hear the natural sounds. Load the file. Unlike in lab 8, this file contains newlines between numbers, so you'll need to load it using something like
    x=[]
    with open('chorus.dat') as f:
    for line in f:
    x.append(float(line))
    Create a figure showing the time domain signal, its magnitude spectrum zero-padded to 1024 samples, its phase spectrum, and its level spectrum. IMPORTANT: Include only positive frequencies (513 of them). Label the frequency axis in radians/sample, from 0 to pi.
  2. Implement a notch filter, using code something like this:
    a1 = -2*pole_mag*cos(omega_notch)
    a2 = pole_mag.^2
    b0 = 1
    b1 = -2*cos(omega_notch)
    b2 = 1
    y = np.zeros(len(x))
    y[1] = b0*x[1]
    y[2] = -a1*y[1] + b0*x[2] + b1*x[1];
    for n in range(3,len(x)):
    y[n] = b0*x[n]+b1*x[n-1]+b2*x[n-2]-a1*y[n-1]-a2*y[n-2]
    ...where you should choose the variable omage_notch in order to cancel the narrowband noise that was so obvious in your plots from part (1). Experiment with various values of pole_mag in the range between 0.9 and 0.9999, to see what works best. When you are satisfied with your result, plot the filtered time-domain signal, magnitude spectrum, phase spectrum, and level spectrum, and hand in the figure.
  3. The signal file spikeburst.dat contains two seconds of raw data from a single-channel neural recording (with a sampling rate of 40 kHz) from the trigeminal nucleus in a rat's brain as it responds to whisker stimulation. This data is provided courtesy of Dr. Aniket Kaloti and Professor Mitra Hartmann from Northwestern University, and they should be acknowledged in any use of the data. Load and plot the data; you will observe huge low-frequency fluctuations in the signal around the stimulation time. (Those big bumps aren't spikes, but unwanted electrical signals or artifacts!) Plot the time-domain signal, magnitude spectrum, phase spectrum, and level spectrum. All spectra should be computed using an FFT zero-padded to 1024 samples, then showing only the positive frequencies 513 of them). Label the frequency axis in radians/sample.
  4. Create a notch filter, similar to the one you created in part (2), but with a center frequency of omega_notch=0. Experiment with different values of pole_mag in the range of pole_mag in the range between 0.9 and 0.9999, to see what works best. When you are satisfied with your result, plot the filtered time-domain signal, magnitude spectrum, phase spectrum, and level spectrum, and hand in the figure.
  5. OK, it's possible to eliminate the low-frequency artifact using a notch filter at zero Hertz, but it's also possible to use an FIR highpass filter to do the same thing. Try it. Create a 129-tap FIR highpass filter by creating a delta function and a lowpass filter, then subtracting them:
    delta = np.zeros(129)
    delta[65] = 1
    lowpass = [ omega_c/math.pi if n==0 else math.sin(omega_c*n)/(math.pi*n) for n in range(-64,129) ]
    highpass = [ delta[n]-lowpass[n] for n in range(0,129) ]
    highpassfiltered = np.convolve(spikeburst,highpass)
    Choose the cutoff, omega_c, by examining the figures you created in parts (3) and (4). Remember that a highpass filter passes everything above the cutoff frequency, and removes everything below it. When you are satisfied with your result, plot the filtered time-domain signal, magnitude spectrum, phase spectrum, and level spectrum, and hand in the figure.
  6. Repeat part (5), but window the high-pass filter using a Hamming, Hann, or triangular window (your choice: any one of those three is fine).

Deliverables (Required)

By 4/11/2017 23:59, upload to compass a zip file named MYNAME_LAB9.ZIP containing the following things:

  1. Six figures:
    1. Time-domain signal, magnitude spectrum, phase spectrum, and level spectrum of the frog chorus before noise removal, with only the positive frequencies shown, and with frequency axis labeled in radians/sample.
    2. Same: Frog chorus after noise removal.
    3. Same: Spikeburst before noise removal.
    4. Same: Spikeburst after 0Hz notch filter.
    5. Same: Spikeburst after convolution with a rectangular-windowed highpass filter.
    6. Same: Spikeburst after convolution with a triangular-, Hann-, or Hamming-windowed highpass filter.
  2. Your code.

Walkthrough

No walkthrough this week, but notice that you should be able to re-use your plotting function from last week -- the only thing that's new this week is the notch filter.