Python Forum
Morse Code Practice Script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Morse Code Practice Script
#1
I created this script for myself which I thought I would share for those interested in learning or improving their Morse Code skills. I have not included all possible tests, but if you follow the menu items, 1 than 2 than 3, you should be o.k. The script will create a group of 5 random characters per word depending on the file type selected. The number of 'words' is determined by line 45, in this case it is set for 10 words, though for myself, I set it for 500 or (range(2500)).

The 'Words per minute' (wpm) are based on the formula from the ARRL (American Radio Relay League) site located here:
http://www.arrl.org/files/file/Technology/x9004008.pdf.

I suggest not going above 70 wpm because, at least for my sound system, it becomes to distorted.

As for the frequency, I would suggest starting with 400 and adjusting from there to suit your tastes. This value must be given in Hertz.

The file 'code_file.txt' will be created in the working directory.

One final note, although I've included all characters in the standard Morse Code, there is one that I had to skip and that is the single 'close quote' or back slant quote. There is no equivalent on the keyboard, so I tried to use the Unicode equivalent, but this raises an error I can't figure out how to correct (see line 98).

EDIT: The error has been corrected in the included code posted here

Lastly, if you don't want to see the answer printed on screen, comment out line 168.

As always any comments, critisisms, improvements are appreciated.

Enjoy.

If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#2
QSL
Reply
#3
next, i'd like a program to take audio in, in real time, and decode all morse code streams being heard (with SSB wide filters, you often get many streams), showing each stream as a separate horizontally scrolling line. if the streams are too close, i can understand them not being separated. but it is amazing what DSP (software) can do that hardware (filters) cannot for separating signals, even with wide bandwidths (due to high modulation rates).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Morse to text: https://code.google.com/archive/p/morse-...ult/source
(don't think it's python)
there are .py files...
Reply
#5
Did you try the configparser module for the configuration?
Reply
#6
(Jan-24-2018, 10:46 AM)league55 Wrote: Did you try the configparser module for the configuration?

I did not, no. I had thought about a config file at the beginning, but there didn't seem to be enough options to justify one.

Quote:next, i'd like a program to take audio in, in real time, and decode all morse code streams being heard (with SSB wide filters, you often get many streams), showing each stream as a separate horizontally scrolling line.

There are certainly some very good programs out there that do just that and encompass several, if not all, digital modes (including Morse).

Quote:Morse to text:

Come on Larz, that's just flat out cheating Angel
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
No, It's a fun project.
I'm a big cw fan, though haven't been on air for quite some time.
When I am, I like QRP, and use a Yaesu FT-817 with an Alexloop antenna.
Lots of fun.
Reply
#8
Another thought is that words(>18wpm) and words(<18wmp) look a lot like two objects of the Words class. They have all (or nearly all) of their attributes in common and the values of the attributes are just different. But I don't know whether defining a class for just two objects would be worth it. Maybe if there were some reason to make that wmp value a (variable) attribute too, or to have one for a minimum and one for a maximum value, but I don't know enough about the use case to know whether that even makes any sense. (E.g. you can define a Birthday class and overload the __add__ and __radd__ operators to add two birthdays together with the expression birthday1 + birthday2, but why? I don't know if I'm talking about the same kind of folly here.)
Reply
#9
in morse to text you don't know the wpm in advance but can figure out dits and dahs to an extent ... enough to evaluate them where the speed remains close over some number of them. the real fun happens when two signals are so close that their sidebands overlap. even more fun happens when a 3rd signal is near these 2. then it is not a simple as cutting off the sidebands between 2 signals as you would destroy the middle signal. you need to demod the 2 outer signals (demod whatever comes through ok) and reproduce it and subtract. you now have a "2nd layer" of signals to demod and decode. this can work to some extent because morse code and A1 modulation is actually very redundant. don't expect to do much with overlapping digital signals in use today.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
Just an update, I made some changes to the original code posted above (thought it was better than re-posting the entire code again).

Line 98: added the 'single close quote' (\u00b4) back into the punc string, so it now reads:
punc = '.,?`!/()&:;=+-_$@\u00b4'    # ยด = '\u00b4'
Line 164: added encoding to the open statement, so it now reads:
with open('code_file.txt', 'r', encoding='utf-8') as file:
I will try and run it on Linux this weekend to make sure in works on that OS as well.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best Practice to Pass a Variable Between Two Classes? MIPython 9 5,278 Apr-11-2018, 05:35 PM
Last Post: MIPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020