Morse Code Audio Decoder

Newer version!

If you've arrived here then you might prefer the newer streamlined version which adapts to the speed and frequency of the Morse code.

Introduction

This is an experimental tool for listening to, analysing and decoding International Morse code all done in Javascript using the Web Audio API. I know it works in the latest Chrome and Firefox browsers on Windows, it might work in Safari and it just can't work in Internet Explorer. No information from the microphone is transmitted to the server, but the connection to the server is encrypted nonetheless.

If you cannot produce your own Morse code sounds then try using my Morse code translator to play or download some.

Sound Source

You can either have the decoder listen to the microphone, analyse a file you upload or analyse a pre-saved sample along with some sensible parameters.

Microphone

If you choose to use the microphone then your web browser will prompt you to confirm that it is okay. If you have several microphones you will also need to choose which microphone to use: to do this in Chrome first allow access and then click on the video-camera icon in the right-hand end of the address bar; in Firefox you can choose which microphone to use at the point of permitting access. Of course this is all subject to change as it is not a common feature to use yet.

Upload

Upload an audio file from your computer.

Filename:

Samples

The following table lists some pre-recorded samples along with audio filter parameters that work well. The first three samples have been saved from the translator and are therefore very clean sounds. "Fox" was recorded through a microphone by a someone actually sending Morse code. "Inspector Morse" is the start of a British TV drama where "MORSE" was spelt out in very approximate Morse code (the decoder can't manage it). The last two are both the same sound file, first listening at 300Hz and then at 700Hz to give two different messages! Sounds processed via the microphone will not work so well as the clean samples.

Select File Speed (wpm) Min volume (dB) Max volume (dB) Min frequency (Hz) Max frequency (Hz) Volume threshold FFT size

Use the "Apply" button to change the parameters to those selected in the table. The "Play" button will play the selected file regardless.

Audio and Fourier Transform Parameters

The minimum measurable frequency is 0Hz and the maximum in this web browser is Hz (half the sampling rate of Hz). You can select the FFT size in the form: a small FFT size will give a small time resolution (good for fast Morse code) and a large FFT size will give a small frequency resolution (good for eliminating background noise) but you can't have both at once.

The chosen FFT size is giving frequency measurements (FFT size / 2). The frequency resolution is Hz (sampling rate / FFT size). The time resolution is ms (1000 * FFT size / sampling rate) which might work with wpm code at fastest (with 2 to 3 samples per dit).

Spectrogram

A spectrogram shows how the volume of each frequency band changes over time.

You can zoom in on a frequency range by adjusting the minimum and maximum frequencies. By adjusting the minimum and maximum volumes you may be able to filter out unwanted background noise (for instance, try increasing the minimum volume to -60dB).

The live spectrogram below is showing the (quantised) frequencies from Hz (at the bottom) to Hz (at the top). The pink region highlights the area that is being analysed (see below). Time progresses left to right.

to

to

Volume

We need to extract the Morse code signal tones from the sound entering the microphone. Hopefully the Morse tones will be the loudest sounds being received. Here we plot the average volume in each frequency bin over time. The chart is only displayed when the sound stops because otherwise it slows down the sound processing.

The frequency range with the maximum average volume ( of 255) is Hz (frequency bin number )

Filter

We need to set a frequency range to filter the frequency-domain data (i.e. choose which frequencies we want to focus on). We also need to set a threshold volume above which we take to mean that a signal is present. Use the button to automatically select the frequency range with the maximum average volume and to use the average volume in that range as the threshold (you may find a higher volume works better though).

The actual (quantised) frequency band which includes all of the specified range is - Hz ( frequency bins of size Hz) and is highlighted in pink on the spectrogram above. The volume threshold is (of 255).

The chart below shows the average amplitude in analysis region and the threshold in use.

to

This chart just highlights the value at the threshold and should look something like Morse code:

Translation

Given the cleaned up signal above we now need to take the timings of the "ons" and "offs", translate into dits and dahs and finally into text. The decoder does some further signal processing by asuming that if an "on" or "off" element was only 1 measurement long then it was probably due to noise and so the previous timed element is just extended.

The final stage of the decoder currently needs a clue about the speed of the Morse code: use the input box to set the speed. Given the chosen speed of wpm, the length of a dit is ms, a dah is ms and a word-space is ms.

The chart below shows the frequency of the different time intervals that are measured. Each on or off period is a multiple of the time resolution (ms). The chart updates when the sound stops because otherwise it slows down the sound processing. Turn sets on and off by clicking on the legend.

If the chart shows a clean clustering of timings then it's likely that the decoder will have made sense of the timings and you'll have a sensible message shown below. If it didn't quite work, try looking at the debugging information by hovering over each letter.

The message is:

The variation in the timings used in the last message are summarised in the following table. Note that even when a "perfect" downloaded signal is analysed, the measured variation in the durations is quite significant. This is because, relative to the speed of the Morse code, the measurements are quite infrequent.

Type Count Min (ms) Max (ms) Average (ms) Standard deviation (ms)
Dit
Dah
Dit space
Dah space
Space