File Exchange

image thumbnail

Morse Code

version (14.1 KB) by Fahad Al Mahmood
This converts text to playable morse code in wav format.


Updated 08 Jun 2005

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

MORSE converts text to playable morse code in wav format.



If the wave file name is specified, then the funtion will output a wav file with that file name. If only text is specified, then the function will only play the morse code wav file without saving it to a wav file.


morse('How are you doing my friend?','morsecode.wav');

Cite As

Fahad Al Mahmood (2021). Morse Code (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (15)

Dr. W. Kurt Dobson

Thank you very much. Turns out the FCC requires one to transmit morse code under the FCC CFR 47 rules for experimental wireless stations. Saved me a bunch of time. Thank you!

John Rogers

Thanks Fahad--I like it.
I had to make changes to run in R2017a. Change the last five lines to:
at the end:

if exist('file','var')

Antonio tenorio

genial aporte

Sandeep Kaur

can anyone tell me how to convert speech to text?


Nice little useful program for training your morse skills:)

I updated the code a little, if anyone is interested... (feel free to add it to the original):

To have smaller spaces between letters, change line 33 from lsp = wav(6176:23022); to lsp = wav(6176:16022);

To add danish letters æ,ø,å (can be done for any additional signs, and I probably will later), add
AE = [Dit;ssp;Dah;ssp;Dit;ssp;Dah]; % danish Æ .-.-
OE = [Dah;ssp;Dah;ssp;Dah;ssp;Dit]; % danish Ø ---.
AA = [Dit;ssp;Dah;ssp;Dah;ssp;Dit;ssp;Dah]; % danish Å .--.-
and change
vars ={'period','comma','question','slash_'}; to
vars ={'period','comma','question','slash_','AE','OE','AA'};
and change
elseif ismember(text(i),'.,?/')
x = findstr(text(i),'.,?/');
elseif ismember(text(i),'.,?/ÆØÅ')
x = findstr(text(i),'.,?/ÆØÅ');

to modify the speed, a resampling is added in the last part (just after the loop):
morsecode=resample(morsecode,Fs,15000); % resample to Fs/15000
if the numberused is higher than Fs, the speed will be higher, if it is lower, the speed will be lower...

Chirag Bhatt

Hi , While running this program , I found the following error,
??? Index exceeds matrix dimensions.

Error in ==> morse at 23
text = varargin{1};
My version is 7.2(R2006a)
What I have to do?

Chris Knox

Elvin Hai

It's a great program! May I know how the data in the wav.mat was obtained?

Craig Miller K3OOL

Nice program. Brute force method of generating Morse code but it works very well.

senthil raj

hou to convert text into speech more efficiently

J Cea

To convert morse audio into text, do a search for "cw get"

mani khan

how to convert wave file to .mat extension

Osamah Rawashdeh

Awesome, usefull for creating ringtones for my cellphone ... ( SMS, MMS, CQ CQ CQ , etc)

Carlo Cauyan

is there a code that does the opposite of this? convert a morse code audio into a alphanumeric message...a reply is greatly appreciated

joe schmoe

Pretty neat, though it has little use now-a-days

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Morse/Demorse unleashed, demorse

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!