Homework 4

CprE 5750: Computational Perception

Name: Student Name
Email: student@iastate.edu

This homework must be submitted as a zip file containing all code files, images, and audio files. The HTML file may need to be modified to include all code and files.

Supporting material can be found on the class webpage.

The following is a list of tools/info/libraries that may or may not be useful towards the completion of this homework or exploration of the topic

image

Question 1: Signal Processing Onramp

For this part complete the Matlab signal processing onramp tutorial posted here. Take four screenshots as you complete this course (around 30%, 60%, 100% done, as well as your certificate). Link these photos below to prove that you did the course.

Screenshots

image

image

image

image


Question 2a: 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 (You are not allowed to use a library for complex number arithmetic, you should only need to implement +, -, and *)

Source Code


Question 2b: 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 (You are not allowed to use a library for complex number arithmetic, you should only need to implement +, -, and *)

Source Code


Question 3a: 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(Nlog2N) 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 2a to cross-check your implementation. In part 3, you can yse any library functions that work with complex numbers (but not in part 2).

Source Code


Question 3b: 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(Nlog2N) 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 2b to cross-check your implementation. In part 3, you can use any library functions that work with complex numbers (but not in part 2).

Source Code


Question 4a: FFT Check

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

Note: This function is a sine wave sampled every π/8 radians, you may choose to calculate this vector with more decimal places.

Slow DFT

FFT

Compare your output with the output generated by MATLAB’s fft() method for the same vector. 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


Question 4b: IFFT Check

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

Slow IDFT

IFFT

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

Matlab Result

Analysis


Question 5a: MATLAB Spectrograms

In this section you will try to replicate MATLAB’s spectrogram function in MATLAB without using either the stft function or the spectrogram function. You may use the FFT implementation provided in MATLAB.

You will use your implementation to plot two audio files. The first audio file will be provided to you, but the second you will have to record yourself. You can do this in Audacity or any other program you like that produces WAV files. Describe how the file was recorded (i.e. sampling rate, duration, description, etc.) as well as the parameters used in the spectrogram in comments in your code.

Hint: Read MATLAB’s documentation of the spectrogram function. This will help you find the default parameters of the function and what windowing function it uses. (Implementing the default parameters is sufficient for this problem).

Audio Data Spectrogram
image
image

Source Code


Question 5b: Custom Implementation Spectrograms

Now you will implement the spectrogram function from above in a programming language of your choice using your FFT implementation from Question 3. As before, the default parameters matlab uses are sufficient.

Use this implementation to plot two audio files. The first audio file will be provided to you, but the second you will have to record yourself. You can do this in Audacity or any other program you like that produces WAV files. Describe how the file was recorded (i.e. sampling rate, duration, description, etc.) as well as the parameters used in the spectrogram in comments in your code.

Audio Data Spectrogram
image
image

Source Code


Question 6a: Detecting morse code letters made of dots

Morse Code

In this problem, using a language of your choice, you will parse audio files that contain a single morse code letter consisting only of dots, and print the letter to the console.

Take a screenshot of the output of your code running in the terminal and include it in the table below.

Hint: It is recommended that you use a spectrogram and/or fft function to visualize the files. While this problem may be solvable without them, using them in your solution will build up to later problems where it will be necessary.

Note: From here on in the homework, you may use any FFT implementation that suits your fancy, whether it be your own or a library, so long as it is made clear how to run your code for the purposes of grading.

Morse Audio Output
image
image
image
image

Source Code


Question 6b: Detecting letters made of dashes

Take a screenshot of the output of your code running in the terminal. In this problem, using a language of your choice, you will parse audio files that contain a single morse code letter consisting only of dashes, and print the letter to the console.

Take a screenshot of the output of your code running in the terminal and include it in the table below.

Hint: It is recommended that you use a spectrogram and/or fft function to visualize the files. While this problem may be solvable without them, using them in your solution will build up to later problems where it will be necessary.

Morse Audio Output
image
image
image

Source Code


Question 7a: Recognizing individual numbers

In this part you will write code to recognize morse code numbers in provided audio files. Although we only provide 5 test cases, the digits in these test cases are random, meaning your code should be able to classify any of the 10 digits. This will also be useful in following parts of the assignment.

Your code should print the number contained in the audio file to the terminal.

Take a screenshot of the output of your code running in the terminal.

Morse Audio Output
image
image
image
image
image

Source Code


Question 7b: Recognizing individual letters

In this part you will write code to recognize morse code letters in provided audio files. Although we only provide 5 test cases, the letters in these test cases are random, meaning your code should be able to classify any of the 26 letters. This will also be useful in following parts of the assignment.

Your code should print the letter contained in the audio file to the terminal.

Take a screenshot of the output of your code running in the terminal.

Morse Audio Output
image
image
image
image
image

Source Code


Question 8a: Word parsing

You will be provided with 4 audio files each containing either a word or a letter in morse code.

Write code to parse these words/sequences of numbers and print them to the console along with the frequency in Hz at which they are encoded. Note: Do not lose your mind trying to find the exact frequency, you will be considered correct if your answer is within +/- 50Hz.

Include screenshots of the output of your code in the table below.

Morse Audio Output
image
image
image
image

Source Code


Question 8b: Sentence parsing

You will be provided with 4 audio files each containing sentences with both words and sequences of numbers in morse code.

Write code to parse these sentences and print them to the console along with the frequency in Hz at which they are encoded. Note: Do not lose your mind trying to find the exact frequency, you will be considered correct if your answer is within +/- 50Hz.

Include screenshots of the output of your code in the table below.

Morse Audio Output
image
image
image
image

Source Code


Question 9a: Morse Synthesis - characters

Write a program that outputs an audio file containing morse code based on an input letter/number and frequency in Hz.

Your outputs should be saved in the output/p9 folder as "char1-4.wav".

Morse Audio Output
N, 800Hz
O, 750Hz
P, 600Hz
3, 575Hz

Source Code


Question 9b: Morse Synthesis - sentences

Write a program that outputs an audio file containing morse code based on an input sentence and frequency in Hz.

Your outputs should be saved in the output/p9 folder as "sentence1-2.wav".

Morse Audio Output
HOMEWORK FOUR 5750, 625Hz
WORKING WITH AUDIO IS FUN, 775Hz

Source Code


Question 10: Classical Cryptography

In this part you will use your accumulated knowledge and code to implement a classical method for sending coded messages, the Caesar Cipher.

The caesar cipher consists of assigning each letter in the alphabet a number, 0-25, then encoding each character in the message as a new character using the formula.

newIndex = (index + 3)%26

Learn more here: https://en.wikipedia.org/wiki/Caesar_cipher.

Your code should take an audio file containing an unencoded message as input, and output an audio file of the same message encoded with the caesar cipher at a different random frequency between 500-800Hz.

Morse Audio Output

Source Code


Question Extra Credit 1: Split overlapped messages

Write a program that takes as input an audio file containing two overlayed morse code messages at different frequencies and prints the message contained in both to the terminal.

Include a screenshot of your output in the table below.

Hint: The morse code messages will show up in different places on the spectrogram.

Overlaped Audio Terminal Output
image

Source Code


Question Extra Credit 2: Generate overlapped messages

Write a program that takes as input two sentences, converts them into morse code audio and overlays them. Essentially the reverse operation of Extra Credit 1.

The two messages should be synthesized at separate frequencies with minimal harmonics so they are able to be parsed later. They should also be at audible frequencies.

Include the audio file output in the table below.

Your code from the previous question should be able to decode the audio file you generate in this part, which will be useful for testing.

Message 1 Message 2 Terminal Output
DO OR DO NOT THERE IS NO TRY A WAY THERE ALWAYS IS

Source Code


This document was last modified on 2026-03-12.