Morse Code Magic - An Algorithm by RayBurne
IMG00159.jpg
IMG00154.jpg
Morse Code!  Dude, that is so last century... 

(More like the 1840's)


Overview:

Morse Code, those annoying Dits & Dahs you often hear on old military movies.  If you have a family member into Amateur Radio, a "Ham", you may have heard Morse Code on their shortwave receivers and if that Ham has been licensed before 2003, they learned Morse Code as part of their Ham licensing.  I would encourage everyone to take a few minutes and visit the Wikipedia page for Morse Code and even listen to one of the two audio samples.

This article is about taking Morse Code sounds and signals and displaying them on a PC or other serial display.  The underlying reason is to assist with learning Morse Code or just for a fun diversion on a boring winter weekend or perhaps as a project toward earning a Merit Badge in "signaling".  The approach taken is a departure to conventional methods/algorithms and the remaining discussion will be devoted to making sense of the DITs and DAHs.


The DIT ain't king (but it does count):

Before undertaking this project, I read everything on the Internet that I could find about decoding Morse Code mechanically.  Wow, there is lots of stuff out in the Ethernet.  From Wikipedia to specialized algorithms such as "RSCW", every article stated or implied  that  "the duration of a DOT is the obvious unit of time."  But, what if this is only one approach?  What if the DAH were king of the bit stream?  Would this make a difference?  The answer is a resounding Yes.

I am talking heresy here!  If the DAH is the kingpin of the Morse Code stream, then do DITs matter?  The answer is, yes, but only their numbers... NOT their position in the stream.  The DAHs are important both in number and in position; therefore the DAH will be used as my reference element and we will keep track of the DITs, but only their numbers within each element. 

What we are now considering is the conversion of the DITs and DAHs into a single number (pointer) within a finite range... we will select our math (algorithm) to meet the constraints of our environment: in this case, the EEPROM memory of the least expensive and smallest of the PICAXE chips, the 08M2.  I have previously published the entire proof-of-concept with supporting (and member downloadable code) here: http://www.picaxeforum.co.uk/showthread.php?19123-Morse-Code-Decoding-8WPM-with-a-PICAXE-08M2
and here is a YouTube link to the 08M2 big brother the 20X2 doing decoding: http://youtu.be/9kZOqdeUl2w

The 08M2 and the 20X2 PICAXE chips are very similar and in my utilization, the 20X2 is only more capable due to the greater clock speed of the microcontroller, uC (the 08M2 is running at 32MHz and the 20X2 is running at 64MHz.)

In contemplating writing my algorithm, I approach the problem by defining my universe, or data set.  I usually use Excel to document the set and subset conditions and my Excel document in PDF form is available to members here: http://www.picaxeforum.co.uk/showthread.php?19088-Morse-Code-Decoder-for-Cheap-using-a-20X2 and PICAXE Forum membership is free.  However, I will go through a couple of examples to assist with understanding the algorithm.  The last JPG in the sequence is a snap of the Excel screen and may be helpful.

CAVEAT:

The algorithm I am about to present is a 5-bit algorithm and the 6-bit or more extensions to the Morse Code will not automatically map into this memory space (I manually mapped things like "/@.," for example.)   Additionally, my intent is to decode only the characters in the stream and NOT to decode the break between words which is included in the Morse definition.


An algorithm is just rule-based math:

The algorithm will generate a number between 1 and 255 for every Morse Code combination decoded.  For every DAH identified in the stream, a binary weight is applied based upon the position of the DAH... that is, first, second, third, fourth, or fifth element.  DITs are not weighted but are counted with DAHs to achieve a total element count of DITs + DAHs in the character. The DAH-weights are bits 3-7 in a calculated index and the elements number make up bits 0-2.

Examples:

E = "DIT" Therefore, there are no DAHs and only one element. The pointer is %00000001 Index = 1
F = "DIT DIT DAH DIT" and the DAH is in the third position (bit 5 set) Pointer = %00100100 Index = 36


My algorithm allows for the incremental and real-time calculation of the character pointer as the DIT/DAH elements comes into the uC.  When a character break occurs (no tone received for longer than a DAH-time), the software simply looks up the translation in a 256-byte table.  Because of our shotgun approach, the table looks like Swiss cheese with large holes throughout but that is OK since we designed the algorithm to work in this confinement and the table has no other purpose; which is to say, that packing the table elements in nice, adjacent cells provide no economy for this project and would complicate both the coding and the algorithm.

I am hopeful that I have presented a reason to think outside the traditional "box" and to investigate, experiment, and invent new approaches to old problems.  This approach to mechanical Morse code decoding has shown that a decoder can be built completely in software with no external timing components or tone demodulation ICs.  If you download and program your own 08M2, please be respectful of my retained commercial rights and copyrights.  By publishing this article, I am hopeful that some enterprising individual will take on the project of building an appropriate noise filtering and narrow band filter for a front-end that would allow Magic Morse to be directly connected to a shortwave receiver.

My lab-tested performance of Magic Morse on a PICAXE 20X2 shows that the system appears to be immune to what Hams call "fist" issues to a large degree.  The chip works perfectly from 05WPM to 15WPM pure and will go over 25WPM when Farnsworth timing is utilized at around 16-17WPM.)  Connect this to a simple code practice oscillator and a key and have a fantastic project to brushing up or learning Morse Code.

Regards,

Ray

Notes:
2011-09-29: Updated to include draft of the instruction manual and schematic.

*** Comments welcome ***

For the reader's convenience in assembly of this project, a limited number of 20X2 uC are available fully programmed with code to support a PC serial port (DB9/25) or  the Scott Edwards 2x16 serial LCD or the SparkFun serial LCD, all at 9600 BAUD.  Total cost, inc. USPS 3-5 day Priority Shipping for $20.  Send Ray an email for info: magic.morse@gmail.com for specifics.



Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!