Advertisement
STANAANDREY

morse apd

Dec 6th, 2023 (edited)
1,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. clc
  2.  
  3. % Read the audio file
  4. [inputAudio, fs] = audioread('morseCode2.wav');
  5.  
  6. % Plot the sampled data
  7. figure;
  8. subplot(2, 1, 1);
  9. plot(inputAudio);
  10. title('Input Waveform');
  11. xlabel('Sample');
  12. ylabel('Amplitude');
  13.  
  14. % Decode sound to Morse
  15. % Your code goes here!!!
  16. % Use the inputAudio and fs to process the audio and convert it to Morse code
  17.  
  18. % Example: Replace this with your Morse code generation logic
  19. % For demonstration purposes, assume the Morse code is stored in a variable 'mCode'
  20. mCode = '-.. ... .--. .-.. .- -... ... ';
  21.  
  22. % Decode Morse to text (do not change this part!!!)
  23. deco = [];
  24. mCode = [mCode ' '];  % mCode is an array containing the Morse characters to be decoded to text
  25. lCode = [];
  26.  
  27. for j = 1:length(mCode)
  28.     if (strcmp(mCode(j), ' ') || strcmp(mCode(j), '/'))
  29.         for i = double('a'):double('z')
  30.             letter = getfield(morse, char(i));
  31.             if strcmp(lCode, letter)
  32.                 deco = [deco char(i)];
  33.             end
  34.         end
  35.         for i = 0:9
  36.             numb = getfield(morse, ['nr', num2str(i)]);
  37.             if strcmp(lCode, numb)
  38.                 deco = [deco, num2str(i)];
  39.             end
  40.         end
  41.         lCode = [];
  42.     else
  43.         lCode = [lCode mCode(j)];
  44.     end
  45.     if strcmp(mCode(j), '/')
  46.         deco = [deco ' '];
  47.     end
  48. end
  49.  
  50. fprintf('Decode : %s \n', deco);
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement