Instructions | Deliverables | Walkthrough | References

Detailed Instructions (Recommended Steps in Python)

  1. Download the data file signal.dat. This is a plain text file, so you can load it into python using for line in f, or numpy.loadtxt, or a variety of other methods. Load it into python. Zero-pad the resulting array until it has a length of 1024 samples; for example, if you have it in a list, you could do
    while len(signal) < 1024:
    signal.append(0)
    Use complexspec=scipy.fftpack.fft(signal), magspec=abs(complexspec)), phasespec=[cmath.phase(x) for x in complexspec], levelspec=[20*math.log10(x) for x in magspec] to get the magnitude, phase, and level spectra (notice: the level spectrum is just the magnitude spectrum expressed in dB). Use plt.subplot and plt.stem to create stem plots of the time-domain signal, and of its magnitude, phase, and level spectra on four different subplots. Plot the magnitude and phase corresponding to the non-negative frequencies only --- you will lose points, this time, if you include any of the negative frequencies (i.e., any frequencies for which omega is greater than math.pi). Hint: figure out how many frequencies there are between 0 and math.pi; give this number a name such as Nfreqs. Create a vector freqvals=[ math.pi*n/Nfreqs for n in range(0,Nfreqs) ], and use plt.stem(freqvals,magspec[0:Nfreqs). Likewise for phasespec and levelspec.
  2. Create a length N=64 triangular window (this means that the window covers samples 0 through 63, so the midpoint of the window is sample 31.5, and its halfwidth is M=31.5; use the formula in the lecture slides, or the one in the textbook). Multiply your signal by this window using something like:
    tri_win_sig = [ tri_win[m]*signal[m] for m in range(0,64) ]
    while len(tri_win_sig) < 1024:
    tri_win_sig.append(0)
    Create a plot whose four subplots show the windowed signal, the magnitude spectrum, phase spectrum, and level spectrum of the positive frequencies only.
  3. Repeat part (b) using a Hamming window, and a Hann window.
  4. The signal consists of five sinusoids of various frequencies and amplitudes --- some are very weak, some are very strong. Look at the four different sets of spectra you've created, for rectangular, triangular, Hamming and Hann windows. Identify the frequencies (in radians/sample) and levels (in dB) of all five sinusoids, write these ten numbers in a text file, and hand in the text file with your lab submission.

Deliverables (Required)

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

  1. Four images (rectangular, triangular, Hamming and Hann windowed signals), each containing four subplots (signal, magnitude spectrum, phase spectrum, and level spectrum), with the abscissa labeled in radians/sample between 0 and pi.
  2. A text file specifying the frequencies (in radians/sample) and levels (in dB) of the five sinusoids in the signal.
  3. Your code.

Walkthrough

Here's the video walkthrough for lab 8.

References