# HCI/CprE/ComS 575: Homework #4

Your Name
< Your Email>

List of Audio Libraries and References

The following list of C / C++ libraries and references for audio processing is provided for your convenience only. You are not required to use any of these libraries / references for this homework.

- Fastest Fourier Transform in the West library.
- The Fourier Transform and its Applications: A Video Course.
- Keep It Simple, Stupid FFT library.
- Audacity. Useful for analyzing raw audio (waves) and modifying audio files (ie. stereo <--> mono).
- Aubio.
- libsndfile.
- Example code for computing the spectrogram in C: alsgram.zip.

## Part 1a: Slow DFT

Implement the Discrete Fourier Transform (DFT) in C, C++, MATLAB, Java, or Python. Implement the slow version that multiplies the transform matrix by the input vector in O(N2) time. Your code should support input vectors of size up to 1024. In addition, you must implement your own functions to deal with complex numbers.

Source

    // Insert your code here

## Part 1b: Slow IDFT

Implement the Inverse Discrete Fourier Transform (IDFT) in C, C++, MATLAB, Java, or Python. Implement the slow version that multiplies the transform matrix by the input vector in O(N2) time. Your code should support input vectors of size up to 1024. In addition, you must implement your own functions to deal with complex numbers.

Source

    // Insert your code here

## Part 2a: FFT

Implement the Fast Fourier Transform (FFT) in C, C++, MATLAB, Java, or Python. Implement the fast version that uses recursion and runs in O(n log2 n) time. Note that you are not allowed to use MATLAB's implementation nor any other existing library for this problem. Your code should support input vectors of size up to 1024. Use your code from Part 1a to cross-check your implementation. In part 2, you can use any library functions that work with complex numbers (but not in part 1).

Source

    // Insert your code here

## Part 2b: IFFT

Implement the Inverse Fast Fourier Transform (IFFT) in C, C++, MATLAB, Java, or Python. Implement the fast version that uses recursion and runs in O(n log2 n) time. Note that you are not allowed to use MATLAB's implementation nor any other existing library for this problem. Your code should support input vectors of size up to 1024. Use your code from Part 1b to cross-check your implementation. In part 2, you can use any library functions that work with complex numbers (but not in part 1).

Source

    // Insert your code here

## Part 3a: FFT check

Using your implementation from Part 2a, compute the Discrete Fourier Transform of the following vector:

Vector 'x'

####

    [0, 0.7071, 1, 0.7071, 0, -0.7071, -1, -0.7071]

Note: you may want to use sqrt(2)/2 instead of 0.7071.

Result

    // Insert your resulting vector here

Compare your output with the output generated by MATLAB's fft() method for the same vector 'x'. Include the result below, and point out any discrepancies. You may also use one of the FFT libraries above, if you choose.

Matlab Result & Analysis

    // Insert your new resulting vector here

    // Insert any comments here

## Part 3b: IFFT check

Using your implementation from Part 2b, compute the inverse Discrete Fourier Transform of the following vector:

Vector 'X'

####

    [0, -4i, 0, 0, 0, 0, 0, 4i]

Result

    // Insert your resulting vector here

Compare your output with the output generated by MATLAB's ifft() method for the same vector 'X'. Include the result below, and point out any discrepancies. You may also use one of the IFFT libraries above, if you choose.

Result & Analysis

    // Insert your new resulting vector here

    // Insert any comments here

## Part 4a

Using any FFT and IFFT implementation, compute and plot the spectrograms for the following 3 audio files. In case you are curious, these audio snippets came from a video game.

Audio Data | Spectrogram
--- | ---
ball_bounce_brick_mono |
ball_bounce_paddle_mono |
paddle_widening_mono |

Source

    // Insert your code here

## Part 4b

Repeat what you did in part 4a, but now process three audio files that you recorded while playing your favorite game. Describe how you recorded the audio and what parameters were used (e.g., sampling frequency, duration). Also, describe the parameters that you used to compute the spectrograms (you can put this in the comments for your code). Modify the HTML template so that your files are linked and your spectrograms are shown to the right of each audio file. Replace the three audio files in this folder with your own files.

Audio Data | Spectrogram
--- | ---
sound1 |
sound2 |
sound3 |

Source

    // Insert your code here

## Part 5

Your task is to write a program that can detect a single note in an audio data and print it. The program should handle audio generated by different musical instruments. The notes will be restricted to piano notes listed in this Wikipedia page (also cached here in PDF), but any of these notes may be the one. The program should print the note in the scientific notation.

##### Hint: one way to solve this problem is to perform frequency-domain analysis (e.g., using a spectrogram) of the audio data and look for the location of peaks. The highest peak should be at the frequency of the note.

##### Students with perfect pitch are not exempt from solving this problem. The note must be detected by the program and not by the programmer.

## Part 5a. Piano

Audio Data | Note | Program Output
--- | --- | ---
c4-piano.wav | C4 | Output of your program.
piano-note2.wav | B2 | Output of your program.
piano-note3.wav | F6 | Output of your program.
piano-note4.wav | Output of your program. | Output of your program.
piano-note5.wav | Output of your program. | Output of your program.
piano-note6.wav | Output of your program. | Output of your program.
piano-note7.wav | Output of your program. | Output of your program.

Source

    // Insert your code here

## Part 5b. Different Instruments

Instrument | Audio Data | Note | Program Output
--- | --- | --- | ---
Piano | c4-piano.wav | C4 | Output of your program.
Electric Guitar | c4-guitar.wav | C4 | Output of your program.
Violin | violin-note1.wav | A4 | Output of your program.
Violin | violin-note2.wav | Output of your program. | Output of your program.
Trumpet | trumpet-note1.wav | Output of your program. | Output of your program.
Trumpet | trumpet-note2.wav | Output of your program. | Output of your program.
Tuba | tuba-note1.wav | D2 | D3
Bassoon | bassoon-note1.wav | Output of your program. | Output of your program.
Marimba | marimba-note1.wav | Output of your program. | Output of your program.
Marimba | marimba-note2.wav | Output of your program. | Output of your program.

Source

    // Insert your code here

# Extra Credit 1

In this problem you have to write a program that can recognize single notes in a sequence and print them in the same order as they are played. The program should print the note in the scientific notation. There are no chords in the audio data.

### Part A. Short Piano Melodies, Single Notes

Audio Data | Notes | Program Output
--- | --- | ---
short-melody-example-1.wav | C4 C4 G4 G4 A4 A4 G4 | Output of your program.
short-melody-1.wav | Output of your program. | Output of your program.
short-melody-2.wav | Output of your program. | Output of your program.

Source

    // Insert your code here

### Part B. Short Melodies Played with Different Instruments, Single Notes

Instrument | Audio Data | Notes |
Electric Piano | electric-piano-example-1.wav | C#2 C#2 C#2 C#2 B2 B2 B2 C#3 D3 | Output of your program.
Electric Piano | short-melody-3.wav | Output of your program. | Output of your program.
Radio Tuning Signal | short-melody-4.wav | Output of your program. | Output of your program.

Source

    // Insert your code here

# Extra Credit 2

## Non-Recursive FFT

Implement a non-recursive version of the Fast Fourier Transform (FFT) in C, C++, MATLAB, Java, or Python. This is the iterative version of the algorithm that still runs in O(N log2N) time, but does not use recursion. Your code should support input vectors of size up to 1024. Once again, this must be your own implementation. Run your code on the vector from part 3a and report the result.

Source

    // Insert your code here

Result

    // Insert your resulting vector here