Lab 1
In lab 1, you will use the short-time Fourier transform to create spectrograms of five waveform files. Here are the key things:
The ZIP Archive, and the recommended Code-Writing Process
In the ZIP archive, you will find the following directory hierarchy:
-
submitted.py -- this is the ONLY file that you
will submit, and the only file on which you will be
graded. It defines a python class
called Spectrograph (a device for creating
spectrograms) with the following ten functions that you
need to complete:
- set_nframes - compute the number of frames
- set_frames - divide the signal into frames
- set_hammingwindow - create a Hamming window
- set_wframes - window the frames
- set_timeaxis - create a time axis, with timestamps for each frame
- set_dftlength - decide how long the DFT should be
- set_zvalues - compute the Z values for the DFT, i.e., exp(-j*2*pi*k*n/dftlength)
- set_stft - compute the STFT
- set_levels - convert the STFT into decibels
- set_image - create a uint8 image from the level-STFT
- data/file{0,1,2,3,4}.wav -- these are the waveform files whose spectrograms you will compute. It is strongly suggested that, before you try uploading your code to Gradescope, you first try running your code using these waveforms. The results you should get, for file0 and file1, are provided for you! in solutions/file{0,1}.npz. If you can figure out how to make your code duplicate these values, you'll get 40 percent already. Warning: you need to get your code to compute the solutions, not copy them. Copying the solutions is cheating.
- requirements.txt lists the python packages that are used by the autograder. You can install them by typing pip3 install -r requirements.txt. If you want to use the included file save_spectrogram.png, you will also need pip3 install matplotlib. Our Gradescope image is running Python 3.6.8, and numpy 1.16.4; installing from requirements.txt will get you the right version of numpy, but not necessarily the right version of python. If you want to check what versions you have installed, you can type python3 --version and python -c 'import numpy;print(numpy.version.version)'. If you already have a different version of numpy installed, you might need to use anaconda to create a new environment with a specified numpy version; the code we're writing for this course is not so version-specific that this step is likely to be necessary, but it's possible.
- run_tests.py --- once your code is producing the right results for file0 and file1, you can try testing it on all five waveforms by typing python3 run_tests.py. This will call the test routines in tests/test_sequence.py, and compare the results to the hashed solution criteria in solutions/file{0,1,2,3,4}_criteria.json. If this gives 100-percent on your computer, but less than 100-percent on Gradescope, then the only problem you have left to solve is the weird effect of python-version mismatches between your computer and Gradescope's computer.
How to Submit
When you're ready to submit, go to Gradescope.
- Submit only the one file, submitted.py. Any other files you submit will be ignored.
- You may submit as many times as you like, until the deadline, which is the end of September 6 (warning: Gradescope says the deadline is 0:00 September 7, but that actually means the end of September 6). No deadline extensions will be granted, but you can submit as often as you like, so obviously, you should start submitting today (go ahead and use the submitted.py file that comes in the distribution! You'll get 0 points, but at least you can see how the submission process works), and then continue submitting your revised versions until you get the best score that you can.
Cheating
These things constitute cheating, and will result in a zero for the assignment:
- Copying the solutions provided in the ZIP archive, rather than trying to compute them yourself.
- Cutting and pasting from another student.
- Using any package that's not installed in the Gradescope Docker image. So, in particular, you can't use scipy or soundfile. Anyway, the autograder should make these things impossible anyway.
- Using the provided solutions as a reference, and tweaking your code until it exactly matches the provided solutions.
- Talking to other students about their solutions. Even looking at their code is fine. Only cut-and-paste is outlawed.
- Using any function that's available in numpy or the standard python library. For example, one of the functions you're supposed to write is set_hammingwindow. Numpy includes a function, numpy.hamming, that makes this task really easy. Go ahead and use it. Using numpy.hamming is explicitly NOT CHEATING.