Detailed Instructions (Recommended Steps in Python)
- 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
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.
x=[]
with open('chorus.dat') as f:
for line in f:
x.append(float(line))
- Implement a notch filter, using code something like
this:
...where you should choose the variable
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]
omage_notch
in order to cancel the narrowband noise that was so obvious in your plots from part (1). Experiment with various values ofpole_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. - 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.
-
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 ofpole_mag
in the range ofpole_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. -
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:
Choose the cutoff,
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)
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. - 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:
- Six figures:
- 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.
- Same: Frog chorus after noise removal.
- Same: Spikeburst before noise removal.
- Same: Spikeburst after 0Hz notch filter.
- Same: Spikeburst after convolution with a rectangular-windowed highpass filter.
- Same: Spikeburst after convolution with a triangular-, Hann-, or Hamming-windowed highpass filter.
- 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.