Question: Getting Started You will be working on this project in MATLAB (or octave-online). When you are finished with each part, submit your function in the
Getting Started
You will be working on this project in MATLAB (or octave-online). When you are finished with each part, submit your function in the quiz server for grading.
morseDecode
Download morseDecode.m and place it in your code folder.
In MATLAB, at the prompt in the Command Window, enter type morseDecode
>> type morseDecode
The functions code will be displayed in the Command Window. You DO NOT need to add or change anything in this file. Look at the code. This function accepts an audio file, of a morse code message, decodes it, and returns the string value of the message. There are four main parts in this file. It calls 3 functions which you will implement to finish this mini-project.
Section 1 processes the morse code audio file and creates a column vector of float values representing the morse code signal.
Section 2 calls the function binarySignal which converts the vector from Section 1 to a vector of logical values.
Section 3 calls the function tokenizeSignal which converts the vector from Section 2 to a matrix representing the tokens of the morse code message.
Section 4 calls the function tokenstoMessage which converts the tokens matrix from Section 3 to a string message.
Audio Files Containing Morse Code Signals
Download all of the *.wav files from the quiz server and place them in your code folder.
Note: If you are using octave-online.net you need to instead download all of the *.mat files and upload them to your online folder because octave does not support audioread.
Morse Code Files
| .wav files for MATLAB | .mat files for ocatave-online |
|---|---|
| alphabet_morse.wav | alphabet_morse.mat |
| hello_world_morse.wav | hello_world_morse.mat |
| SOS_morse.wav | SOS_morse.mat |
| mystery_morse.wav | mystery_morse.mat |
Part 1
In the Editor in MATLAB (or Octave-online) open a new file and write the function binarySignal(signal, threshold) which converts the signal represented as a column of float values into a binary signal using the following data flow algorithm below. Save your file as 'binarySignal.m'.
Apply the absolute value to the signal
Filter the signal using a moving average with a window size of 20. To perform a moving-average filter, see the help documentation for the filter function: https://www.mathworks.com/help/matlab/ref/filter.htm
Apply > threshold to the averages to return a signal that contains only 1 or 0. The output should be 1 where the signal is above the threshold and 0 otherwise.
Submit your function to the quiz server for grading.
Download SOS_Part1.mat and put it in your code folder.
In MATLAB, at the prompt in the Command Window, enter the following commands:
>> load(SOS_Part1.mat')
>> binary_signal = binarySignal(SOS_signal,0.05)
>> plot(binary_signal)
You should be able to see a plot of the binary signal as shown below:
Part 2
In the editor in MATLAB (or Octave-online) open a new file and write the function tokenizeSignal(binary_signal) which takes the binary signal from Part 1 and counts how many 0's and 1's appear in sequence. The output should be a 2D array where column 1 is how many appear and column 2 is which token it is (0 or 1). Save the file as tokenizeSignal.m
For example:
>> arr = [0; 0; 0; 1; 1; 1; 0];
>> tokenizeSignal(arr)
ans =
3 0
3 1
1 0
Hints: this can be done with or without loops. To do it without any loops you need to use array slicing, concatenation and the find and diff functions in MATLAB. Try out the following with the example arr:
>> diff(arr)
>> diff([arr; -1])
>> find(diff([arr; -1]))
>> diff(find(diff([arr; -1])))
Submit your function to the quiz server for grading.
Part 3
Download getSymbol.m and put it in your code folder.
In the editor in MATLAB (or Octave-online) open a new file and write the function tokensToMessage(tokens, unittime) which takes a set of tokens and outputs a message. Each element in tokens represents a dot, dash, short-space, long-space, or long-long-space.
Save the file as tokensToMessage.m.
The table in Figure 1 has been implemented in a getSymbol function that will translate a string of dits and dashes to a character. For example:
>> getSymbol('...')
ans =
S
>> getSymbol('---')
ans =
O
Your function tokensToMessage should loop through all of the tokens and accumulate a symbol with dots and dashes. The matrix token is a 2D matrix with two columns. The first column represents the duration of the token and the second column represents the value of the token. Implement the general algorithm presented here:
message initialized to an empty string
symbol initialized to an empty string
for each row in tokens
if token's duration > 2 * timeunit and value == 0
concatenate getSymbol(symbol) to message
if token's duration > 4 * timeunit
concatenate ' ' to message
reset symbol to empty string
else if token's duration > 2*timeunit and value == 1
concatenate '-' to symbol
else if token's duration > timeunit/2 and value == 1
concatenate '.' to symbol
else
do nothing (it is either a character separator or too short)
%after the loop check to see if there is a last symbol
if not isempty(symbol)
concatenate getSymbol(symbol) to message
Submit your function to the quiz server for grading.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
