Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- % Read the audio file
- [inputAudio, fs] = audioread('morseCode2.wav');
- % Plot the sampled data
- figure;
- subplot(2, 1, 1);
- plot(inputAudio);
- title('Input Waveform');
- xlabel('Sample');
- ylabel('Amplitude');
- % Decode sound to Morse
- % Your code goes here!!!
- % Use the inputAudio and fs to process the audio and convert it to Morse code
- % Example: Replace this with your Morse code generation logic
- % For demonstration purposes, assume the Morse code is stored in a variable 'mCode'
- mCode = '-.. ... .--. .-.. .- -... ... ';
- % Decode Morse to text (do not change this part!!!)
- deco = [];
- mCode = [mCode ' ']; % mCode is an array containing the Morse characters to be decoded to text
- lCode = [];
- for j = 1:length(mCode)
- if (strcmp(mCode(j), ' ') || strcmp(mCode(j), '/'))
- for i = double('a'):double('z')
- letter = getfield(morse, char(i));
- if strcmp(lCode, letter)
- deco = [deco char(i)];
- end
- end
- for i = 0:9
- numb = getfield(morse, ['nr', num2str(i)]);
- if strcmp(lCode, numb)
- deco = [deco, num2str(i)];
- end
- end
- lCode = [];
- else
- lCode = [lCode mCode(j)];
- end
- if strcmp(mCode(j), '/')
- deco = [deco ' '];
- end
- end
- fprintf('Decode : %s \n', deco);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement