Sunday, June 24, 2012

Ultimate Morse Code Decoder?

Over the last few weeks I started reading articles and papers about wavelet transformation to figure out how to build an ultimate Morse code decoder. Wavelets have been used since 1980's in digital signal processing and wavelet transforms are now being adopted for a vast number of applications, often replacing the conventional  Fourier transformation.

One particular application is for smoothing/denoising data based on wavelet coefficient thresholding, also called wavelet shrinkage. By adaptively thresholding the wavelet coefficients that correspond to undesired frequency components smoothing and/or denoising operations can be performed.


I stumbled on this paper from Aly, Omar and Eldherbeni few days ago. The paper describes an algorithm for extracting and localizing an RF radar pulse from a noisy background. The algorithm combines two powerful tools: the wavelet packet analysis and higher-order-statistics (HOS). The use of the proposed technique makes detection and localization of RF radar pulses possible in very low signal-to-noise ratio conditions. 

The proposed algorithm is able to detect and well localize RF radar pulses without a prior knowledge of the pulse parameters (e.g., its frequency and duration). The proposed  algorithm has been tested for SNR down to −24 dB and proved to work successfully. See figures 9 and 7 below on the results they achieved.

In my previous blog post  I used matched filter to extract Morse code pulses from noisy signals. Matched filter can be implemented  either in time or frequency domain. However,  one problem with narrow matched filter is "ringing" artifacts  - see figure 8  in the blog post. This creates uncertainty and jitter in pulse width.  According to above paper  one of the advantages of  using wavelets is possibility to obtain adapted tiling in the time-frequency plane, which is automatically generated based on the signal observation. This leads to improved time & frequency resolution compared to traditional short-time windowed Fast Fourier Transformation (SFFT) based methods.  


I found this website that provides online tools to visualize various wavelet types. Since the discovery of wavelets many years ago there has been active development and many different wavelets have been created for various purposes. This site provide very nice online visualization tool.

I created  a small noisy Morse code file using  morse.m  Octave function by Rob Frohne, KL7NA.  The above website allows only 2000 samples so I copied numbers to the above site (select "Your data" section).
Figures 1..3  below show a small noisy audio section with a "dit" tone  and start of "dah" tone and corresponding wavelet transformation (Morlet, Gaussian & Paul wavelet types) underneath.  There is also a global wavelet showing the variance by period on the right side.  The wavelet transformation values are color coded - red color is showing the highest energy at Period (scale) 8 clearly identifying where the tone starts and where it ends.  Different wavelets have slightly different properties as is quite visible looking at the figures below.

Figure 1.  Morlet Wavelet - noisy Morse code

Figure 2.  Gaussian Wavelet - noisy Morse code

Figure 3.  Paul Wavelet - noisy Morse code


As the results from previous section demonstrate Morlet type wavelets seem to provide particularly good delineation of Morse code tones in noisy signals.   I did three more visualizations with  various level of noise included in the signals.  The first one (MORSE_SNR0) below has no noise and the signal is visible as clear red color  line on wavelet power spectrum image (period = 8). It is very easy to see where the signal ends and next one starts (see the gap between samples 1450 ...1900 ). 

The following visualization (MORSE_SNR1) has approximately - 9 dB  SNR  and quite a lot of noise. The red line is still visible in the wavelet power spectrum image (period = 8). However,  noise spikes make it a bit more difficult to determine signal end and start timing. There is also other red noise signals at periods 32, 64 and 256. As these are on different wavelet periods they can be filtered out. 

The last visualization (Morse_SNR2)  has  approximately  - 12 dB SNR  and it is quite difficult to see where the tone ends and next one starts. Looking from original signal it is almost impossible to tell where the tone is.  Global wavelet shows a peak at period 8  where most of the red dots are also aligned. There are many more red areas showing noise energy peaks.


I  did another experiment with Morse code pulse train.  This is the envelope of the noisy audio signal after detection and filtering. Pulse train has some sharp edges that should correspond to high frequency components as well as longer stable plateaus corresponding low frequency components. 

I used  Haar and Gaussian wavelets in this experiment. Figure 4 and 5 below show the signal and corresponding wavelet transformation.  As expected the high frequency components are visible where the signal edges are.

Figure 4. Haar Wavelet - noisy Morse code pulse train

Notice the red high energy components between 600 - 750 ms in scale 128..512 range. This represents noise that is visible also on the time domain signal in figure 5.  In a wavelet filter implementation these  coefficients could be set to zero  to denoise the signal.

Figure 5. Gaussian Wavelet - noisy Morse code pulse train


Wavelet transformation  is a powerful signal processing tool to manipulate signals. Based on literature the wavelet transform gives better localization in the time-frequency domain than the discrete windowed Fourier transform.  Wavelets enable also flexible manipulation of the signals to remove noise, find signals buried under noise  etc. 

For a real time CW decoding software like in FLDIGI  wavelet transformation could open a whole new performance level dealing with noisy signals.  More experimentation is definitely needed to unlock this potential.

Mauri AG1LE

1 comment:

  1. Superb. Thanks for sharing. I'm also working at a CW decoder based on Goertzel algorithm, but now I have to take also in account the Wavelet option.