Question: 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

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:

Here is the code I have, #3 wont work:

function result = binarySignal(signal, threshold)

% Converts sound wave signal into a binary signal

Parameters:

% n, an integer

% Returns:

% an integer, the factorial of n

absSignal = abs(signal);

windowsize = 20;

MovingAvg = ones(1, windowsize)/windowsize;

a = 1;

MAvg = filter(MovingAvg, a, absSignal);

result = MAvg > threshold;

end

%Part Two

function tokens = tokenizeSignal(binarySignal)

%Gives a count of 0s and 1s in binarySignal

signal = [binarySignal; -1];

findSig = find(diff(signal));

alist = [findSig(1); diff(findSig)];

tokens = [alist signal(findSig)];

end

%Part Three

function realmessage = tokensToMessage(tokens, unittime)

% Takes tokens and unittime to turn dots and dashes into letters

realmessage = ' ';

symbol = ' ';

for t = 1:numel(tokens)

q = tokens(t);

if q==0

break

end

tokenvalue = tokens(t,2);

if((q > (2*unittime)) && tokenvalue == 0)

realmessage = strcat(realmessage, getSymbol(symbol));

if j > 4*unittime

realmessage = strcat(message, {' '});

end

symbol = ' ';

elseif q > 2*unittime && tokenvalue == 1

symbol = strcat(symbol, '-');

elseif q > .5*unittime && tokenvalue == 1

q = tokens(t)

if q == 0

break

end

end

tokenvalue = tokens(t,2);

if q > 2*unittime && tokenvalue == 0

realmessage = strcat(message, getSymbol(symbol));

if j > 4*unittime

realmessage = strcat(message, {' '})

end

symbol = ' ';

elseif q > 2*unittime && tokenvalue == 1

symbol = strcat(symbol, '-');

elseif q > .5*unittime && tokenvalue == 1

symbol = strcat(symbol, '.');

end

end

if (~isempty(symbol))

realmessage = strcat(message, getSymbol(symbol));

end

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!