PSK Modem

Matt Roberts - matt-at-kk5jy-dot-net

Published: 2016-11-09

Updated: 2016-11-30

The Last of the Big-Three Modes - As a Modem

This is a companion project to the RTTY Modem and CW Modem projects.  These projects all use an Arduino UNO to encode and decode a specific digital mode and are designed for connection to a transciever.  They are proof-of-concept designs, all of which demonstrate that typical HF digital modes do not require powerful PCs with elaborate software packages.  This time, the modem is for PSK-31.

The main idea of these projects is to provide a digital mode interface that can be used with a simple terminal program, yet sufficiently full-featured to be integrated into more complex software packages, if desired.  The modem converts the characters being typed in the terminal into outgoing data in the chosen mode, to modulate the radio.  It also decodes the audio signals from the radio and converts these into readable text.  The interface includes an escaping mechanism that allows commands and queries to be inserted into the byte stream, so that one serial or USB connection can simultaneously pass both data and command communication between the modem and its host.

These are the first building blocks in a modular system of components that will provide a low-power portable digital terminal for amateur radio transcievers.  The PSK modem described below provides a prototype interface for BPSK-31 on-air operation.  The modem can also be configured for faster PSK modes, if desired.

All of these modem projects support reading audio data from the radio receiver, and in the case of the PSK modem, this is the only demodulator option.  After searching for a proper PSK demodulator IC, I found that it was just as simple (and far more flexible) to use the UNO's A/D input, combined with some DSP techniques, to provide the demodulator functions.  Intefacing the Arduino with audio input signals is described in great detail in the RTTY Modem article, and the input circuit design used here is identical.

Arduino UNO
Buffer Amp
Figure 1: Arduino UNO
Figure 2: Audio Input
Buffer Circuit
The Hardware

Like the other modems, the hardware for the project includes a few essential elements:
The hardware for this project was relatively simple.  The input amplifier reads line-level signals from the radio's audio output line, and amplifies them to fit within the zero to +5V range expected by the Arduino's A/D port.  This is then centered around +2.5V, so that the A/D can read the entire AC cycle of the incoming signal.  The buffer amplifier is identical to the one used in the other modem projects, and is shown in Figure 2.

The Arduino isn't well-known for being able to generate sinusoidal output.  However, there are some techniques that can be used to form sinusoids.  One is to generate a square-wave, and filter it.  This worked well enough for RTTY, but PSK-31 requires a whole new level of cleanliness in the transmitted signals, so this approach didn't work well for PSK.  In particular, forming the raised-cosine transitions on either side of each phase inversion is quite difficult to do cleanly in hardware as the filtering required to form the modulated wave shape is rather intense.  There are other more direct ways to generate a sinusoidal output, including a dedicated DAC circuit, or an R-2R DAC made from a resistive ladder, and other such approaches.

There is another option for generating smooth sinusoidal output, which is to use the PWM function of the AVR chip, configured to generate a square wave well above the audio range, then adjusting the duty cycle to form a sinusoid at a much lower frequency.  As the duty cycle is varied, the average output voltage can be moved throughout the period of a carrier wave cycle.  This technique more fully utilizes the native waveform and timing generation modules within the AVR processor, and only requires one output pin to source the audio signal.  This is the technique I settled on, and the resulting audio is extremely clean when the voltage is smoothed by a 4th-order passive bandpass filter.  The higher-frequency square-wave components are removed by the filter, shown in Figure 3, which uses four identical resistors and four identical capacitors.  The zero to +5V output range of the Arduino is also attenuated by the filter, producing a roughly line-level AC output signal.  The 4th order filter (4th order = four reactive components) provides a sufficiently clean signal for on-air operation, without causing unnecessary attenuation.

Figure 3: Audio Output Filter
for 1500Hz Carrier
A nice article comparing several different waveform generation options is available at the makezine website.

The filter itself is a simple design.  There are two high-pass stages and two low-pass stages, in alternating pairs.  The cutoff for each stage is the same, which should provide a fairly narrow response centered on 1500Hz.  A PSK signal is a single tone, with varying phase, so a narrow filter is entirely appropriate.  Depending on the impedance of the input circuit to the transmitter, it might be advantageous to use a buffer amplifier between the filter output and the radio, or alternatively, an active band-pass filter could be used.

This technique worked so well that I will probably update the RTTY modem project to use a similar modulator when AFSK output is used.

Two output pins are used to control sending.  One will control the PTT line of the radio, while the other generates the output data, as described above.  The PTT output should be used to drive an n-channel FET or NPN BJT for T/R control of the radio.  This is a very standard keying interface scheme.  For those who are accustomed to using the VOX function of their radio (or the VOX function of a SignaLink) for T/R control, the PTT line can be disabled, or simply used to run an LED transmit indicator.

The Firmware

The firmware consists of a simple program or "sketch" that does the timing and decoding functions.  For reception, the audio from the radio is passed through a simple buffer circuit, as described above.  The signal is sampled at a high rate and DSP techniques applied to recover the PSK tone.  The receiver uses a one-wavelength delay line to recover a single frequency from the incoming signal.  By default, this frequency is 1500Hz, but this can be changed in the sketch.  This delay line is integrated to form an envelope signal, which is the DC equivalent of the tone strength.  Each time the PSK signal generates a zero, the phase inverts, which causes the envelope to fall to near zero.  It is these dips in the envelope that are detected by the firmware and used to reconstruct the stream of ones and zeroes.  This stream contains the varicode that is then decoded into ASCII and sent to the user terminal.

For transmitting, the UNO approximates a sinusoid as described above, by quickly manipulating the duty cycle of a PWM output.  The UNO contains three hardware timer modules, but Timer0 is used for measuring delays internal to the firmware.  Timer1 is the only 16-bit timer, so it is used to manipulate the PWM value of the third timer, Timer2.  Timer2 generates the 62kHz PWM signal that is then modulated to closely approximate a sinusoid at the center frequency configured for the modem, with the 62kHz components being removed by the BPF described above.  Because Timer2 is the only available timer that can be used to generate the 62kHz PWM signal needed, the transmit audio must be configured to emit from either pin 11 or pin 3 on the UNO.


Operating the unit is straightforward.  Just connect to the controller through a serial terminal program or the serial monitor in the Arduino environment.  When you type characters, the transmitter is enabled, and the modem will send the text you type.  When you are done typing, the radio will automatically go back into receive mode after a short delay, and the decoder will attempt to decode incoming characters.  This is very VOX-like operation.  For those who are familiar with CW operation, the behavior is similar to semi-QSK.

The command interface is documented below, and commands can be sent inline with the text.  When a proper #command; sequence is sent, the terminal will respond appropriately.  E.g., sending #ECHO; might return a response of #OK:ECHO=0;.  If a bad command is typed, e.g., #DOG;, the terminal returns #ERR:DOG;.  Any characters sent to the controller outside of the "hash-semicolon" wrapper are interpreted as text to send.  Characters sent from the controller to the PC outside of the wrapper should be treated as received text from the decoder.

The current firmware provides several command and configuration messages: The idea of the command interface is to provide a way to make it easy to integrate into another application, but straightforward enough to be used from a so-called dumb terminal application.

Figure 3: PSK Output Spectrum
First Impressions

The firmware sends and receives PSK-31 flawlessly when connected back-to-back with to an FlDigi instance via audio patch cables.  An on-air test is definitely the next step, since the controlled tests have worked out well.  An example of the spectral purity of the transmitted signal is shown in Figure 3, which is the waterfall display of Fldigi while receiving the output of the UNO modem sending a CQ signal.

Conclusions, Ongoing Work, ...

This project is a good first step towards a stand-alone terminal.  A display and keyboard connection for all of these modems is next, but to be fair, a Raspberry Pi running miniterm is more than enough of a terminal to drive the modem.  This project is still in its early stages, with plenty of room for optimization.  The receiver logic works well, but it is very broad, with poor selectivity.  In order to obtain good performance in a poor S/N environment, the algorithm requires a very narrow and linear preselector filter.  The UNO doesn't have enough CPU power to do this, although other hardware might.  The next improvement needed is to tune the algorithm to make it more selective without requiring a preselector.  So the firmware should be considred a first draft at this point.

An Arduino Mega 2560 should have enough memory to allow the three modem types (CW, RTTY, PSK-31) to be combined into a single multimode unit.  This would provide a very inexpensive dedicated digital-mode interface using DSP techinques.  There are some other tiny computers available, such as the Teensy, that can generate true sinusoidal outputs.  It might be fun to port the code to a part like that to see if it can generate clean output without requiring any filters.  Such a board might also be able to hold a combined multimode firmware, and its much faster ALU and clock speed should be able to use higher-precision mathematics to provide enhanced performance in a noisy environment.

The modem needs some kind of tuning indicator.  A quarter-wavelength delay line should be able to easily generate a tuning indicator ouptut, as long as the extra math operations don't exceed the CPU resources.

Having now built a couple of different PSK-31 receiver designs, I am somewhat disappointed in PSK as a mode in general.  Phase-shift keying sounds like a nice upgrade to FSK, and was even pitched as such by the creator of PSK-31 in his original ARRL article on the subject.  And no doubt, the PSK modes have become quite popular for casual narrow-band contacts.  However, all of the practical demodulator designs treat the PSK signal as an amplitude-modulated mode, just like CW or Hellschreiber.  The on-air signal is PSK, but the first step in the demodulation process is to convert this into an envelope signal, which is by definition an amplitude-modulated waveform.  This envelope has to be processed by dynamic threshold calculations (effectively an AGC circuit) to determine the transition between mark and space, which puts it precisely within the family of AM modulation schemes, giving it the same challenges when doing signal recovery in the presence of varying S/N ratio.  This explains why PSK-31 does not do well in the presence of rapid fade.  FSK, by comparison, always has a fixed threshold, which is where the frequency deviation is zero.  The amplitude of the frequency error is irrelevant, as long as it can reliablly trigger the hysteresis logic at the appropriate times.  So this project, while rewarding, has given me a new-found respect for FSK modes, and an understanding of why so many of our newer high-performance digital modes are FSK modes at their core.

One of the nice features of PSK-31 is its incredible spectral purity.  A properly-adjusted PSK-31 transmission occupies almost exactly 31.25Hz of space, with no detectable keying sidebands.  This is particularly true on a noisy HF channel where any trace of keying artifacts are buried well below the noise floor.  This kind of spectral efficiency allows many PSK signals to operate in close proximity to each other without harmful interference, and even when high power levels are used.  It also allows the receiver to use a very narrow filter around the signal, without harming the detector performance, as the receiver does not depend on keying subbands outside the 31.25Hz channel for proper signal detection.  By comparison, a typical RTTY FSK signal tends to be rich with keying artifacts, even for a properly-configured transmitter that is free from overdriving.

However, PSK-31's spectral purity is not without cost.  Each phase transition in PSK-31 is shaped using a raised cosine function, so that whenever a transition is to take place, the amplitude of the carrier is tapered quickly but smoothly to zero, and the inversion takes place when the shape function is zero or near zero.  Then the amplitude is similarly reverse-tapered back to 1.0, but with inverted phase.  This wave shaping does wonders for spectral purity, but it also adds "mush" to the state transition.  If the phase were simply inverted, without any bit-shaping, the coherent detector response would be dampened then reexcited back to full amplitude very quickly and sharply, giving a very distinct voltage (level) change in the envelope detector, with a generous first derivatve value that would enhance performance in the presence of noise.  The raised cosine shaping applied at the transmitter removes a much (but not all) of this damping effect, providing a more gentle response in the envelope detection at the receiver.  Normally this isn't a problem, but as the S/N ratio drops, the shaped signal quickly reaches a point where the phase shift is so indistinct that it is not detected, which cause a single bit error.  Because PSK doesn't shift on every bit, but just on the zero bits, a single bit error can domino into other bits causing more than one bit of damage to the data stream.  The effect I am describing is called Intersymbol Interference and its effects are well documented.  RTTY could use a raised cosine shaping just like PSK-31, and its spectral purity would be greatly improved, however the PSK and RTTY designers chose different engineering trade-offs.

Veteran CW operators are very familiar with this trade-off.  In recent decades there has been considerable discussion on the proper attack timing to use for CW envelope generation in transmitters.  Short rise time in a CW envelope makes a very distinct and sharp transition that is easy to hear, even in the presence of noise.  Unfortunately, very fast attack times generate keying sidebands, known as "key clicks," which cause interference to adjacent channels.  Longer transition times generate much cleaner output, that causes far less interference to adjacent channels.  The trade off is the same, however, because long attack times cause "mushy" CW sound for the intended receiver, and this causes the CW signal to be more difficult to recieve in suboptimal S/N conditions.  When a computer is trying to demodulate a carrier, whether it is ASK (CW and FH), FSK (RTTY), or PSK, the problem for the computer is the same.  As the transitions become less distinct because of longer attack or generous wave shaping, the more difficult it becomes for the receiver to accurately demodulate the signal in the presence of noise.  This is the big trade-off.  PSK-31 chose outstanding spectral purity at the cost of good noise performance.  It is an engineering decision, but given that PSK was designed for HF use, it might have been better to use a somewhat sharper wave shaping function to help performance in poor S/N environments.

Some of the newer modes like Olivia are trying to find a much better balance to modulation techniques.  Such modes combine the superior FM detection designs with optimally spaced carriers, bit-shaping, and MFSK to produce signals that are spectrally pure, but still have generous robustness in the presence of noise.  Such modes tend to be much wider than the bit-shaped PSK modes of similar bit rate, but they are more robust, and retain excellent spectral purity.  Many utilize complex FEC layers, which makes them more complicated to implement than PSK-31 or RTTY, but the performance improvements are substantial.  Time permitting, I may try to adapt a GPL implementation of Olivia to work on an Arduino or Teensy.

Software Downloads

The firmware for the PSK modem is available in source form, and can be read and uploaded to an Arduino by the Arduino Software.  This is definitely a work-in-progress, so updates will be posted here as the firmware is improved.

PSK Modem Downloads  (Click Here)

The source is being released under the GPL version 3, which is also available on the download page.

2016-11-11 - Update command documentation, add support for HASH messages.

2016-11-10 - Minor bugfixes.

2016-11-09 - Initial release.


Arduino - Open-source hardware and embedded development tools.
SparkFun - Supplier for Arduino boards and hardware.
AdaFruit - Another good source for Arduino hardware.

Copyright (C) 2016 by Matt Roberts, All Rights Reserved.