The personal website of Scott W Harden
October 16th, 2022

# Experiments in PSK-31 Synthesis

PSK-31 is a narrow-bandwidth digital mode which encodes text as an audio tone that varies phase at a known rate. To learn more about this digital mode and solve a challenging programming problem, I'm going to write a PSK-31 encoder and decoder from scratch using the C# programming language. All code created for this project is open-source, available from my PSK Experiments GitHub Repository, and released under the permissive MIT license. This page documents my progress and notes things I learn along the way.

## Encoding Bits as Phase Shifts

• PSK31 messages have a continuous carrier tone

• Symbols are represented by "symbols", each 1/31.25 seconds long

• If a symbol changes phase from its previous symbol it is a `0`, otherwise it is a `1`

## Amplitude Modulation Silences Phase Transitions

Although a continuous phase-shifting tone of constant amplitude can successfully transmit PSK31 data, the abrupt phase transitions will cause splatter. If you transmit this you will be heard, but those trying to communicate using adjacent frequencies will be highly disappointed.

Hard phase transitions (splatter) Soft phase transitions (cleaner)

To reduce spectral artifacts that result from abruptly changing phase, phase transitions are silenced by shaping the waveform envelope as a sine wave so it is silent at the transition. This way the maximum rate of phase shifts is a sine wave with a period of half the baud rate. This is why the opening of a PSK31 message (a series of logical `0` bits) sounds like two tones: It's the carrier sine wave with an envelope shaped like a sine wave with a period of 31.25/2 Hz. These two tones separated by approximately 15 Hz are visible in the spectrogram (waterfall).

## Encoding Text as Bits

Unlike ASCII (8 bits per character) and RTTY (5 bits per character), BPSK uses Varicode (1-10 bits per character) to encode text. Consecutive zeros `00` separate characters, so character codes must not contain `00` and they must start ane end with a `1` bit. Messages are flanked by a preamble (repeated `0` bits) and a postamble (repeated `1` bits).

 NUL 1010101011 SOH 1011011011 STX 1011101101 ETX 1101110111 EOT 1011101011 ENQ 1101011111 ACK 1011101111 BEL 1011111101 BS  1011111111 HT  11101111 LF  11101 VT  1101101111 FF  1011011101 CR  11111 SO  1101110101 SI  1110101011 DLE 1011110111 DC1 1011110101 DC2 1110101101 DC3 1110101111 DC4 1101011011 NAK 1101101011 SYN 1101101101 ETB 1101010111 CAN 1101111011 EM  1101111101 SUB 1110110111 ESC 1101010101 FS  1101011101 GS  1110111011 RS  1011111011 US  1101111111 SP  1 !   111111111 "   101011111 #   111110101 \$   111011011 %   1011010101 &   1010111011 '   101111111 (   11111011 )   11110111 *   101101111 +   111011111 ,   1110101 -   110101 .   1010111 /   110101111 0   10110111 1   10111101 2   11101101 3   11111111 4   101110111 5   101011011 6   101101011 7   110101101 8   110101011 9   110110111 :   11110101 ;   110111101 <   111101101 =   1010101 >   111010111 ?   1010101111 @   1010111101 A   1111101 B   11101011 C   10101101 D   10110101 E   1110111 F   11011011 G   11111101 H   101010101 I   1111111 J   111111101 K   101111101 L   11010111 M   10111011 N   11011101 O   10101011 P   11010101 Q   111011101 R   10101111 S   1101111 T   1101101 U   101010111 V   110110101 X   101011101 Y   101110101 Z   101111011 [   1010101101 \   111110111 ]   111101111 ^   111111011 _   1010111111 .   101101101 /   1011011111 a   1011 b   1011111 c   101111 d   101101 e   11 f   111101 g   1011011 h   101011 i   1101 j   111101011 k   10111111 l   11011 m   111011 n   1111 o   111 p   111111 q   110111111 r   10101 s   10111 t   101 u   110111 v   1111011 w   1101011 x   11011111 y   1011101 z   111010101 {   1010110111 |   110111011 }   1010110101 ~   1011010111 DEL 1110110101

## How to Generate a PSK Waveform

Now that we've covered the major steps of PSK31 message composition and modulation, let's go through the steps ot generate a PSK31 message in code.

### Step 1: Convert a Message to Varicode

Here's the gist of how I store my varicode table in code. Note that the `struct` has an additional `Description` field which is useful for decoding and debugging.

``````public struct VaricodeSymbol
{
public string BitString;
public int[] Bits;

public VaricodeSymbol(string symbol, string bitString, string? description = null)
{
Symbol = symbol;
BitString = bitString;
Bits = bitString.ToCharArray().Select(x => x == '1' ? 1 : 0).ToArray();
Description = description ?? string.Empty;
}
}``````
``````static VaricodeSymbol[] GetAllSymbols() => new VaricodeSymbol[]
{
new("NUL", "1010101011", "Null character"),
new("LF", "11101", "Line feed"),
new("CR", "11111", "Carriage return"),
new("SP", "1", "Space"),
new("a", "1011"),
new("b", "1011111"),
new("c", "101111"),
// etc...
};``````

I won't show how I do the message-to-varicode lookup, but it's trivial. Here's the final function I use to generate Varicode bits from a string:

``````static int[] GetVaricodeBits(string message)
{
List<int> bits = new();

// add a preamble of repeated zeros
for (int i=0; i<20; i++)

// encode each character of a message
foreach (char character in message)
{
VaricodeSymbol symbol = Lookup(character);
}

// add a postamble of repeated ones
for (int i=0; i<20; i++)

return bits.ToArray();
}``````

### Step 2: Determine Phase Shifts

Now that we have our Varicode bits, we need to generate an array to indicate phase transitions. A transition occurs every time a bit changes value form the previous bit. This code returns phase as an array of `double` given the bits from a Varicode message.

``````public static double[] GetPhaseShifts(int[] bits, double phase1 = 0, double phase2 = Math.PI)
{
double[] phases = new double[bits.Length];
for (int i = 0; i < bits.Length; i++)
{
double previousPhase = i > 0 ? phases[i - 1] : phase1;
double oppositePhase = previousPhase == phase1 ? phase2 : phase1;
phases[i] = bits[i] == 1 ? previousPhase : oppositePhase;
}
return phases;
}``````

### Step 3: Generate the Waveform

These constants will be used to define the shape of the waveform:

``````public const int SampleRate = 8000;
public const double Frequency = 1000;
public const double BaudRate = 31.25;``````

This minimal code generates a decipherable PSK-31 message, but it does not silence the phase transitions so it produces a lot of splatter. This function must be refined to shape the waveform such that phase transitions are silenced.

``````public double[] GetWaveformBPSK(double[] phases)
{
int totalSamples = (int)(phases.Length * SampleRate / BaudRate);
double[] wave = new double[totalSamples];
for (int i = 0; i < wave.Length; i++)
{
double time = (double)i / SampleRate;
int frame = (int)(time * BaudRate);
double phaseShift = phases[frame];
wave[i] = Math.Cos(2 * Math.PI * Frequency * time + phaseShift);
}
return wave;
}``````

### Step 4: Generate the Waveform with Amplitude Modulation

This is the same function as above, but with extra logic for amplitude-modulating the waveform in the shape of a sine wave to silence phase transitions.

``````public double[] GetWaveformBPSK(double[] phases)
{
int baudSamples = (int)(SampleRate / BaudRate);
double samplesPerBit = SampleRate / BaudRate;
int totalSamples = (int)(phases.Length * SampleRate / BaudRate);
double[] wave = new double[totalSamples];

// create the amplitude envelope sized for a single bit
double[] envelope = new double[(int)samplesPerBit];
for (int i = 0; i < envelope.Length; i++)
envelope[i] = Math.Sin((i + .5) * Math.PI / envelope.Length);

for (int i = 0; i < wave.Length; i++)
{
// phase modulated carrier
double time = (double)i / SampleRate;
int frame = (int)(time * BaudRate);
double phaseShift = phases[frame];
wave[i] = Math.Cos(2 * Math.PI * Frequency * time + phaseShift);

// envelope at phase transitions
int firstSample = (int)(frame * SampleRate / BaudRate);
int distanceFromFrameStart = i - firstSample;
int distanceFromFrameEnd = baudSamples - distanceFromFrameStart + 1;
bool isFirstHalfOfFrame = distanceFromFrameStart < distanceFromFrameEnd;
bool samePhaseAsLast = frame == 0 ? false : phases[frame - 1] == phases[frame];
bool samePhaseAsNext = frame == phases.Length - 1 ? false : phases[frame + 1] == phases[frame];
bool rampUp = isFirstHalfOfFrame && !samePhaseAsLast;
bool rampDown = !isFirstHalfOfFrame && !samePhaseAsNext;

if (rampUp)
wave[i] *= envelope[distanceFromFrameStart];

if (rampDown)
wave[i] *= envelope[distanceFromFrameEnd];
}

return wave;
}``````

## PSK31 Encoder Program

I wrapped the functionality above in a Windows Forms GUI that allows the user to type a message, specify frequency, baud rate, and whether or not to refine the envelope to reduce splatter, then either play or save the result. An interactive ScottPlot Chart allows the user to inspect the waveform.

## Sample PSK-31 Transmissions

These audio files encode the text The Quick Brown Fox Jumped Over The Lazy Dog 1234567890 Times! in 1kHz BPSK at various baud rates.

### Non-Standard Baud Rates

Let's see what PSK-3 sounds like. This mode encodes data at a rate of 3 bits per second. Note that Varicode characters may require up to ten bits, so this is pretty slow. On the other hand the side tones are closer to the carrier and the total bandwidth is much smaller. The message here has been shortened to just my callsign, AJ4VD.

## Encode PSK-31 In Your Browser

After implementing the C# encoder described above I created a JavaScript version (as per Atwood's Law).

## Decoding PSK-31

Considering all the steps for encoding PSK-31 transmissions are already described on this page, it doesn't require too much additional effort to create a decoder using basic software techniques. Once symbol phases are detected it's easy to work backwards: detect phase transitions (logical 0s) or repeats (logical 1s), treat consecutive zeros as a character separator, then look-up characters according to the Varicode table. The tricky bit is analyzing the source audio to generate the array of phase offsets.

The simplest way to decode PSK-31 transmissions leans on the fact that we already know the baud rate: 31.25 symbols per second, or one symbol every 256 samples at 8kHz sample rate. The audio signal can be segregated into many 256-sample bins, and processed by FFT. Once the center frequency is determined, the FFT power at this frequency can be calculated for each bin. Signal offset can be adjusted to minimize the imaginary component of the FFTs at the carrier frequency, then the real component will be strongly positive or negative, allowing phase transitions to be easily detected.

There are more advanced techniques to improve BPSK decoding, such as continuously adjusting frequency and phase alignment (synchronization). A Costas loop can help lock onto the carrier frequency while preserving its phase. Visit Simple BPSK31 Decoding with Python for an excellent demonstration of how to decode BPSK31 using these advanced techniques.

A crude C# implementation of a BPSK decoded is available on GitHub in the PSK Experiments repository

## Encoding PSK-31 in Hardware

Since BPSK is just a carrier that applies periodic 180º phase-shifts, it's easy to generate in hardware by directly modulating the signal source. A good example of this is KA7OEI's PSK31 transmitter which feeds the output of an oscillator through an even or odd number of NAND gates (from a 74HC00) to produce two signals of opposite phase.

## Quadrature Phase Shift Keying (QPSK)

Unlike the 0º and 180º phases of binary phase shift keying (BPSK), quadrature phase shift keying (QPSK) encodes extra data into each symbol by uses a larger number of phases. When QPSK-31 is used in amateur radio these extra bits aren't used to send messages faster but instead send them more reliably using convolutional coding and error correction. These additional features come at a cost (an extra 3 dB SNR is required), and in practice QPSK is not used as much by amateur radio operators.

QPSK encoding/decoding and convolutional encoding/decoding are outside the scope of this page, but excellent information exists on the Wikipedia: QPSK and in the US Naval Academy's EC314 Lesson 23: Digital Modulation document.

## PSK-31 in 2022

After all that, it turns out PSK-31 isn't that popular anymore. These days it seems the FT-8 digital mode with WSJT-X software is orders of magnitude more popular ??

## Resources

```---
Title: Experiments in PSK-31 Synthesis
Description: How to encode and decode PSK-31 messages using C#
Date: 2022-10-16 23:26PM EST
---

# Experiments in PSK-31 Synthesis

**PSK-31 is a narrow-bandwidth digital mode which encodes text as an audio tone that varies phase at a known rate.** To learn more about this digital mode and solve a challenging programming problem, I'm going to write a PSK-31 encoder and decoder from scratch using the C# programming language. All code created for this project is open-source, available from my [PSK Experiments GitHub Repository](https://github.com/swharden/psk-experiments), and released under the permissive MIT license. This page documents my progress and notes things I learn along the way.

<a href="psk-waterfall2.jpg"><img src="psk-waterfall2.jpg"></a>

## Encoding Bits as Phase Shifts

<!--
<img src="bpsk.png" class="w-75 d-block mx-auto my-3">
-->

* PSK31 messages have a continuous carrier tone

* Symbols are represented by "symbols", each 1/31.25 seconds long

* If a symbol changes phase from its previous symbol it is a `0`, otherwise it is a `1`

<a href="theory.png"><img src="theory.png" class="d-block mx-auto"></a>

## Amplitude Modulation Silences Phase Transitions

Although a continuous phase-shifting tone of constant amplitude can successfully transmit PSK31 data, the abrupt phase transitions will cause splatter. If you transmit this you will be heard, but those trying to communicate using adjacent frequencies will be highly disappointed.

<div class="text-center">

Hard phase transitions (splatter) | Soft phase transitions (cleaner)
---|---
<img src="splatter.png">|<img src="no-splatter.png">

</div>

To reduce spectral artifacts that result from abruptly changing phase, phase transitions are silenced by shaping the waveform envelope as a sine wave so it is silent at the transition. This way the maximum rate of phase shifts is a sine wave with a period of half the baud rate. This is why the opening of a PSK31 message (a series of logical `0` bits) sounds like two tones: It's the carrier sine wave with an envelope shaped like a sine wave with a period of 31.25/2 Hz. These two tones separated by approximately 15 Hz are visible in the spectrogram (waterfall).

![](modulation.png)

## Encoding Text as Bits

**Unlike ASCII (8 bits per character) and RTTY (5 bits per character), BPSK uses [Varicode](https://en.wikipedia.org/wiki/Varicode) (1-10 bits per character) to encode text.** Consecutive zeros `00` separate characters, so character codes must not contain `00` and they must start ane end with a `1` bit. Messages are flanked by a preamble (repeated `0` bits) and a postamble (repeated `1` bits).

<table cellpadding=30 style="white-space: nowrap; font-size: .8em;" class="m-0 p-0 mx-auto"><tr><td valign=top>
<TT>NUL 1010101011</TT>
<BR><TT>SOH 1011011011</TT>
<BR><TT>STX 1011101101</TT>
<BR><TT>ETX 1101110111</TT>
<BR><TT>EOT 1011101011</TT>
<BR><TT>ENQ 1101011111</TT>
<BR><TT>ACK 1011101111</TT>
<BR><TT>BEL 1011111101</TT>
<BR><TT>BS&nbsp; 1011111111</TT>
<BR><TT>HT&nbsp; 11101111</TT>
<BR><TT>LF&nbsp; 11101</TT>
<BR><TT>VT&nbsp; 1101101111</TT>
<BR><TT>FF&nbsp; 1011011101</TT>
<BR><TT>CR&nbsp; 11111</TT>
<BR><TT>SO&nbsp; 1101110101</TT>
<BR><TT>SI&nbsp; 1110101011</TT>
<BR><TT>DLE 1011110111</TT>
<BR><TT>DC1 1011110101</TT>
<BR><TT>DC2 1110101101</TT>
<BR><TT>DC3 1110101111</TT>
<BR><TT>DC4 1101011011</TT>
<BR><TT>NAK 1101101011</TT>
<BR><TT>SYN 1101101101</TT>
<BR><TT>ETB 1101010111</TT>
<BR><TT>CAN 1101111011</TT>
<BR><TT>EM&nbsp; 1101111101</TT>
<BR><TT>SUB 1110110111</TT>
<BR><TT>ESC 1101010101</TT>
<BR><TT>FS&nbsp; 1101011101</TT>
<BR><TT>GS&nbsp; 1110111011</TT>
<BR><TT>RS&nbsp; 1011111011</TT>
<BR><TT>US&nbsp; 1101111111</TT>
<BR><TT>SP&nbsp; 1</TT>
<BR><TT>!&nbsp;&nbsp; 111111111</TT>
<BR><TT>"&nbsp;&nbsp; 101011111</TT>
<BR><TT>#&nbsp;&nbsp; 111110101</TT>
<BR><TT>\$&nbsp;&nbsp; 111011011</TT>
<BR><TT>%&nbsp;&nbsp; 1011010101</TT>
<BR><TT>&amp;&nbsp;&nbsp; 1010111011</TT>
<BR><TT>'&nbsp;&nbsp; 101111111</TT>
<BR><TT>(&nbsp;&nbsp; 11111011</TT>
<BR><TT>)&nbsp;&nbsp; 11110111</TT>
<BR><TT>*&nbsp;&nbsp; 101101111</TT>
</td><td valign=top width="33%" >
<TT>+&nbsp;&nbsp; 111011111</TT>
<BR><TT>,&nbsp;&nbsp; 1110101</TT>
<BR><TT>-&nbsp;&nbsp; 110101</TT>
<BR><TT>.&nbsp;&nbsp; 1010111</TT>
<BR><TT>/&nbsp;&nbsp; 110101111</TT>
<BR><TT>0&nbsp;&nbsp; 10110111</TT>
<BR><TT>1&nbsp;&nbsp; 10111101</TT>
<BR><TT>2&nbsp;&nbsp; 11101101</TT>
<BR><TT>3&nbsp;&nbsp; 11111111</TT>
<BR><TT>4&nbsp;&nbsp; 101110111</TT>
<BR><TT>5&nbsp;&nbsp; 101011011</TT>
<BR><TT>6&nbsp;&nbsp; 101101011</TT>
<BR><TT>7&nbsp;&nbsp; 110101101</TT>
<BR><TT>8&nbsp;&nbsp; 110101011</TT>
<BR><TT>9&nbsp;&nbsp; 110110111</TT>
<BR><TT>:&nbsp;&nbsp; 11110101</TT>
<BR><TT>;&nbsp;&nbsp; 110111101</TT>
<BR><TT>&lt;&nbsp;&nbsp; 111101101</TT>
<BR><TT>=&nbsp;&nbsp; 1010101</TT>
<BR><TT>>&nbsp;&nbsp; 111010111</TT>
<BR><TT>?&nbsp;&nbsp; 1010101111</TT>
<BR><TT>@&nbsp;&nbsp; 1010111101</TT>
<BR><TT>A&nbsp;&nbsp; 1111101</TT>
<BR><TT>B&nbsp;&nbsp; 11101011</TT>
<BR><TT>C&nbsp;&nbsp; 10101101</TT>
<BR><TT>D&nbsp;&nbsp; 10110101</TT>
<BR><TT>E&nbsp;&nbsp; 1110111</TT>
<BR><TT>F&nbsp;&nbsp; 11011011</TT>
<BR><TT>G&nbsp;&nbsp; 11111101</TT>
<BR><TT>H&nbsp;&nbsp; 101010101</TT>
<BR><TT>I&nbsp;&nbsp; 1111111</TT>
<BR><TT>J&nbsp;&nbsp; 111111101</TT>
<BR><TT>K&nbsp;&nbsp; 101111101</TT>
<BR><TT>L&nbsp;&nbsp; 11010111</TT>
<BR><TT>M&nbsp;&nbsp; 10111011</TT>
<BR><TT>N&nbsp;&nbsp; 11011101</TT>
<BR><TT>O&nbsp;&nbsp; 10101011</TT>
<BR><TT>P&nbsp;&nbsp; 11010101</TT>
<BR><TT>Q&nbsp;&nbsp; 111011101</TT>
<BR><TT>R&nbsp;&nbsp; 10101111</TT>
<BR><TT>S&nbsp;&nbsp; 1101111</TT>
<BR><TT>T&nbsp;&nbsp; 1101101</TT>
<BR><TT>U&nbsp;&nbsp; 101010111</TT>
</td><td valign=top width="33%" >
<TT>V&nbsp;&nbsp; 110110101</TT>
<BR><TT>X&nbsp;&nbsp; 101011101</TT>
<BR><TT>Y&nbsp;&nbsp; 101110101</TT>
<BR><TT>Z&nbsp;&nbsp; 101111011</TT>
<BR><TT>[&nbsp;&nbsp; 1010101101</TT>
<BR><TT>\&nbsp;&nbsp; 111110111</TT>
<BR><TT>]&nbsp;&nbsp; 111101111</TT>
<BR><TT>^&nbsp;&nbsp; 111111011</TT>
<BR><TT>_&nbsp;&nbsp; 1010111111</TT>
<BR><TT>.&nbsp;&nbsp; 101101101</TT>
<BR><TT>/&nbsp;&nbsp; 1011011111</TT>
<BR><TT>a&nbsp;&nbsp; 1011</TT>
<BR><TT>b&nbsp;&nbsp; 1011111</TT>
<BR><TT>c&nbsp;&nbsp; 101111</TT>
<BR><TT>d&nbsp;&nbsp; 101101</TT>
<BR><TT>e&nbsp;&nbsp; 11</TT>
<BR><TT>f&nbsp;&nbsp; 111101</TT>
<BR><TT>g&nbsp;&nbsp; 1011011</TT>
<BR><TT>h&nbsp;&nbsp; 101011</TT>
<BR><TT>i&nbsp;&nbsp; 1101</TT>
<BR><TT>j&nbsp;&nbsp; 111101011</TT>
<BR><TT>k&nbsp;&nbsp; 10111111</TT>
<BR><TT>l&nbsp;&nbsp; 11011</TT>
<BR><TT>m&nbsp;&nbsp; 111011</TT>
<BR><TT>n&nbsp;&nbsp; 1111</TT>
<BR><TT>o&nbsp;&nbsp; 111</TT>
<BR><TT>p&nbsp;&nbsp; 111111</TT>
<BR><TT>q&nbsp;&nbsp; 110111111</TT>
<BR><TT>r&nbsp;&nbsp; 10101</TT>
<BR><TT>s&nbsp;&nbsp; 10111</TT>
<BR><TT>t&nbsp;&nbsp; 101</TT>
<BR><TT>u&nbsp;&nbsp; 110111</TT>
<BR><TT>v&nbsp;&nbsp; 1111011</TT>
<BR><TT>w&nbsp;&nbsp; 1101011</TT>
<BR><TT>x&nbsp;&nbsp; 11011111</TT>
<BR><TT>y&nbsp;&nbsp; 1011101</TT>
<BR><TT>z&nbsp;&nbsp; 111010101</TT>
<BR><TT>{&nbsp;&nbsp; 1010110111</TT>
<BR><TT>|&nbsp;&nbsp; 110111011</TT>
<BR><TT>}&nbsp;&nbsp; 1010110101</TT>
<BR><TT>~&nbsp;&nbsp; 1011010111</TT>
<BR><TT>DEL 1110110101</TT>
</td></tr></table>

## How to Generate a PSK Waveform

Now that we've covered the major steps of PSK31 message composition and modulation, let's go through the steps ot generate a PSK31 message in code.

### Step 1: Convert a Message to Varicode

Here's the gist of how I store my varicode table in code. Note that the `struct` has an additional `Description` field which is useful for decoding and debugging.

```cs
public struct VaricodeSymbol
{
public string BitString;
public int[] Bits;

public VaricodeSymbol(string symbol, string bitString, string? description = null)
{
Symbol = symbol;
BitString = bitString;
Bits = bitString.ToCharArray().Select(x => x == '1' ? 1 : 0).ToArray();
Description = description ?? string.Empty;
}
}
```

```cs
static VaricodeSymbol[] GetAllSymbols() => new VaricodeSymbol[]
{
new("NUL", "1010101011", "Null character"),
new("LF", "11101", "Line feed"),
new("CR", "11111", "Carriage return"),
new("SP", "1", "Space"),
new("a", "1011"),
new("b", "1011111"),
new("c", "101111"),
// etc...
};
```

I won't show how I do the message-to-varicode lookup, but it's trivial. Here's the final function I use to generate Varicode bits from a string:

```cs
static int[] GetVaricodeBits(string message)
{
List<int> bits = new();

// add a preamble of repeated zeros
for (int i=0; i<20; i++)

// encode each character of a message
foreach (char character in message)
{
VaricodeSymbol symbol = Lookup(character);
}

// add a postamble of repeated ones
for (int i=0; i<20; i++)

return bits.ToArray();
}
```

### Step 2: Determine Phase Shifts

Now that we have our Varicode bits, we need to generate an array to indicate phase transitions. A transition occurs every time a bit changes value form the previous bit. This code returns phase as an array of `double` given the bits from a Varicode message.

```cs
public static double[] GetPhaseShifts(int[] bits, double phase1 = 0, double phase2 = Math.PI)
{
double[] phases = new double[bits.Length];
for (int i = 0; i < bits.Length; i++)
{
double previousPhase = i > 0 ? phases[i - 1] : phase1;
double oppositePhase = previousPhase == phase1 ? phase2 : phase1;
phases[i] = bits[i] == 1 ? previousPhase : oppositePhase;
}
return phases;
}
```

### Step 3: Generate the Waveform

These constants will be used to define the shape of the waveform:

```cs
public const int SampleRate = 8000;
public const double Frequency = 1000;
public const double BaudRate = 31.25;
```

This minimal code generates a decipherable PSK-31 message, but it does not silence the phase transitions so it produces a lot of splatter. This function must be refined to shape the waveform such that phase transitions are silenced.

```cs
public double[] GetWaveformBPSK(double[] phases)
{
int totalSamples = (int)(phases.Length * SampleRate / BaudRate);
double[] wave = new double[totalSamples];
for (int i = 0; i < wave.Length; i++)
{
double time = (double)i / SampleRate;
int frame = (int)(time * BaudRate);
double phaseShift = phases[frame];
wave[i] = Math.Cos(2 * Math.PI * Frequency * time + phaseShift);
}
return wave;
}
```

### Step 4: Generate the Waveform with Amplitude Modulation

This is the same function as above, but with extra logic for amplitude-modulating the waveform in the shape of a sine wave to silence phase transitions.

```cs
public double[] GetWaveformBPSK(double[] phases)
{
int baudSamples = (int)(SampleRate / BaudRate);
double samplesPerBit = SampleRate / BaudRate;
int totalSamples = (int)(phases.Length * SampleRate / BaudRate);
double[] wave = new double[totalSamples];

// create the amplitude envelope sized for a single bit
double[] envelope = new double[(int)samplesPerBit];
for (int i = 0; i < envelope.Length; i++)
envelope[i] = Math.Sin((i + .5) * Math.PI / envelope.Length);

for (int i = 0; i < wave.Length; i++)
{
// phase modulated carrier
double time = (double)i / SampleRate;
int frame = (int)(time * BaudRate);
double phaseShift = phases[frame];
wave[i] = Math.Cos(2 * Math.PI * Frequency * time + phaseShift);

// envelope at phase transitions
int firstSample = (int)(frame * SampleRate / BaudRate);
int distanceFromFrameStart = i - firstSample;
int distanceFromFrameEnd = baudSamples - distanceFromFrameStart + 1;
bool isFirstHalfOfFrame = distanceFromFrameStart < distanceFromFrameEnd;
bool samePhaseAsLast = frame == 0 ? false : phases[frame - 1] == phases[frame];
bool samePhaseAsNext = frame == phases.Length - 1 ? false : phases[frame + 1] == phases[frame];
bool rampUp = isFirstHalfOfFrame && !samePhaseAsLast;
bool rampDown = !isFirstHalfOfFrame && !samePhaseAsNext;

if (rampUp)
wave[i] *= envelope[distanceFromFrameStart];

if (rampDown)
wave[i] *= envelope[distanceFromFrameEnd];
}

return wave;
}
```

## PSK31 Encoder Program

I wrapped the functionality above in a Windows Forms GUI that allows the user to type a message, specify frequency, baud rate, and whether or not to refine the envelope to reduce splatter, then either play or save the result. An interactive [ScottPlot Chart](https://scottplot.net) allows the user to inspect the waveform.

* **PSK31 Encoder Source Code: [PSK Experiments on GitHub](https://github.com/swharden/psk-experiments)**

![](screenshot.png)

## Sample PSK-31 Transmissions

These audio files encode the text _The Quick Brown Fox Jumped Over The Lazy Dog 1234567890 Times!_ in 1kHz BPSK at various baud rates.

* PSK-31: [dog31.wav](dog31.wav)
* PSK-63: [dog63.wav](dog63.wav)
* PSK-125: [dog125.wav](dog125.wav)
* PSK-256: [dog256.wav](dog256.wav)

### Non-Standard Baud Rates

**Let's see what PSK-3 sounds like.** This mode encodes data at a rate of 3 bits per second. Note that Varicode characters may require up to ten bits, so this is pretty slow. On the other hand the side tones are closer to the carrier and the total bandwidth is much smaller. The message here has been shortened to just my callsign, AJ4VD.

* PSK-3: [psk3.wav](psk3.wav)

## Encode PSK-31 In Your Browser

After implementing the C# encoder described above I created a JavaScript version (as per <a href="https://en.wikipedia.org/wiki/Jeff_Atwood">Atwood's Law</a>).

* Try it on your phone or computer! [**Launch PskJS**](pskjs)

<a href="pskjs"><img src="pskjs.png" class="d-block mx-auto my-3"></a>

## Decoding PSK-31

Considering all the steps for _encoding_ PSK-31 transmissions are already described on this page, it doesn't require too much additional effort to create a _decoder_ using basic software techniques. Once symbol phases are detected it's easy to work backwards: detect phase transitions (logical 0s) or repeats (logical 1s), treat consecutive zeros as a character separator, then look-up characters according to the Varicode table. The tricky bit is analyzing the source audio to generate the array of phase offsets.

The simplest way to decode PSK-31 transmissions leans on the fact that we already know the baud rate: 31.25 symbols per second, or one symbol every 256 samples at 8kHz sample rate. The audio signal can be segregated into many 256-sample bins, and processed by FFT. Once the center frequency is determined, the FFT power at this frequency can be calculated for each bin. Signal offset can be adjusted to minimize the imaginary component of the FFTs at the carrier frequency, then the real component will be strongly positive or negative, allowing phase transitions to be easily detected.

<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>

There are more advanced techniques to improve BPSK decoding, such as continuously adjusting frequency and phase alignment (synchronization). A [Costas loop](https://en.wikipedia.org/wiki/Costas_loop) can help lock onto the carrier frequency while preserving its phase. Visit [**Simple BPSK31 Decoding with Python**](psk31-receiver.html) for an excellent demonstration of how to decode BPSK31 using these advanced techniques.

A crude C# implementation of a BPSK decoded is available on GitHub in the [PSK Experiments](https://github.com/swharden/psk-experiments) repository

![](psk-decode.png)

## Encoding PSK-31 in Hardware

Since BPSK is just a carrier that applies periodic 180º phase-shifts, it's easy to generate in hardware by directly modulating the signal source. A good example of this is [KA7OEI's PSK31 transmitter](http://www.ka7oei.com/psk_bm_tx.html) which feeds the output of an oscillator through an even or odd number of NAND gates (from a [74HC00](https://www.mouser.com/datasheet/2/308/74HC00-105628.pdf)) to produce two signals of opposite phase.

![](pic-psk31.png)

## Quadrature Phase Shift Keying (QPSK)

**Unlike the 0º and 180º phases of binary phase shift keying (BPSK), quadrature phase shift keying (QPSK) encodes extra data into each symbol by uses a larger number of phases.** When QPSK-31 is used in amateur radio these extra bits aren't used to send messages faster but instead send them more reliably using convolutional coding and error correction. These additional features come at a cost (an extra 3 dB SNR is required), and in practice QPSK is not used as much by amateur radio operators.

QPSK encoding/decoding and convolutional encoding/decoding are outside the scope of this page, but excellent information exists on the [Wikipedia: QPSK](https://en.wikipedia.org/wiki/Phase-shift_keying#Quadrature_phase-shift_keying_(QPSK)) and in the US Naval Academy's [EC314 Lesson 23: Digital Modulation](https://www.usna.edu/ECE/ec312/Lessons/wireless/EC312_Lesson_23_Digital_Modulation_Course_Notes.pdf) document.

<a href="qpsk.png"><img src="qpsk.png" class="mx-auto d-block"></a>

## PSK-31 in 2022

After all that, it turns out PSK-31 isn't that popular anymore. These days it seems the [FT-8 digital mode](https://en.wikipedia.org/wiki/FT8) with [WSJT-X software](https://physics.princeton.edu/pulsar/k1jt/wsjtx.html) is orders of magnitude more popular ??

## Resources

* [PSK Experiments](https://github.com/swharden/psk-experiments) (GitHub) - Source code for the project shown on this page

* Software: [digipan](https://www.apkfollow.com/articles/2020/06/digipan.net.html) - A Freeware Program for PSK31 and PSK63

* Software: [fldigi](http://www.w1hkj.com/) - Supports PSK31 and other digital modes

* Software: [Digital Master 780](https://swharden.com/blog/2022-10-14-ham-radio-deluxe) - A Windows application that supports PSK31 and other digital modes bundled with Ham Radio Deluxe 5.0 (the last free version)

* Software: [WinPSK](https://www.moetronix.com/ae4jy/winpsk.htm) - open source PSK31 software for Windows

* Software: [PSKCore DLL](http://www.moetronix.com/ae4jy/pskcoredll.htm) - A Windows DLL that can be included in other software to add support for PSK31

* Software: [jacobwgillespie/psk31](https://github.com/jacobwgillespie/psk31) - Example PSK31 message generate using JavaScript

* [Digital Modulation](https://www.usna.edu/ECE/ec312/Lessons/wireless/EC312_Lesson_23_Digital_Modulation_Course_Notes.pdf) (US Naval Academy, EC314 Lesson 23) - A good description of quadrature PSK and higher order phase-shift encoding.

* [PSK-31 Specification](http://www.arrl.org/psk31-spec) (ARRL) - theory, varicode table, and convolutional code table.

* [PSK31 Description](http://aintel.bi.ehu.es/psk31.html) by G3PLX is the original / official description of the digital mode.

* [PSK31: A New Radio-Teletype Mode](http://www.arrl.org/files/file/Technology/tis/info/pdf/x9907003.pdf) (1999) by Peter Martinez, G3PLX

* [PSK31 The Easy Way](https://www.vic.wicen.org.au/wp-content/uploads/2012/05/psk31.pdf) (1999) by Alan Gibbs, VK6PG

* [Wikipedia: Varicode](https://en.wikipedia.org/wiki/Varicode) includes a table of all symbols

* [PSK31 Fundamentals](http://aintel.bi.ehu.es/psk31theory.html) and [PSK31 Setup](https://myplace.frontier.com/~nb6z/psk31.htm) by Peter Martinez, G3PLX

* [Varicode](http://math0.wvstateu.edu/~baker/cs240/info/varicode.html) - West Virginia State University CS240

* [Introduction to PSK31](https://sites.google.com/site/psk31matlabproject/introduction-to-psk) by engineering students at Walla Walla University

* [Simple BPSK31](psk31-receiver.html) - a fantastic Jupyter notebook demonstrating BPSK decoding with Python

* [PySDR: Digital Modulation](https://pysdr.org/content/digital_modulation.html) - a summary of signal modulation types

* [A PIC-Based PSK31 exciter using a Balanced Modulator](http://www.ka7oei.com/psk_bm_tx.html) by Clint Turner, KA7OEI```
March 27th, 2021

# WSPR Code Generator

WSPR (Weak Signal Propagation Reporter) is a protocol for weak-signal radio communication. Transmissions encode a station's callsign, location (grid square), and transmitter power into a frequency-shift-keyed (FSK) signal that hops between 4 frequencies to send 162 tones in just under two minutes. Signals can be decoded with S/N as low as −34 dB! WSJT-X, the most commonly-used decoding software, reports decoded signals to wsprnet.org so propagation can be assessed all over the world.

WsprSharp is a WSPR encoding library implemented in C#. I created this library learn more about the WSPR protocol. I also made a web application (using Blazor WebAssembly) to make it easy to generate WSPR transmissions online: WSPR Code Generator

### WSPR Transmission Information

• One packet is 110.6 sec continuous wave
• Frequency shifts between 4 tones
• Each tone keys for 0.683 sec
• Tones are separated by 1.4648 Hz
• Total bandwidth is about 6 Hz
• 50 bits of information are packaged into a 162 bit message with FEC
• Transmissions always begin 1 sec after even minutes (UTC)

### Resources

```---
Title: WSPR Code Generator
Description: An online resource for generating encoded WSPR messages
Date: 2021-03-27 8PM EST
---

# WSPR Code Generator

**[WSPR](https://en.wikipedia.org/wiki/WSPR_(amateur_radio_software)) (Weak Signal Propagation Reporter) is a protocol for weak-signal radio communication.** Transmissions encode a station's callsign, location (grid square), and transmitter power into a frequency-shift-keyed (FSK) signal that hops between 4 frequencies to send 162 tones in just under two minutes. Signals can be decoded with S/N as low as −34 dB! [WSJT-X](https://physics.princeton.edu/pulsar/k1jt/wsjtx.html), the most commonly-used decoding software, reports decoded signals to [wsprnet.org](https://wsprnet.org/) so propagation can be assessed all over the world.

**[WsprSharp](https://github.com/swharden/WsprSharp) is a WSPR encoding library implemented in C#.** I created this library learn more about the WSPR protocol. I also made a web application (using Blazor WebAssembly) to make it easy to generate WSPR transmissions online: [WSPR Code Generator](https://swharden.com/software/wspr-code-generator)

[![](wspr-code-generator.png)](https://swharden.com/software/wspr-code-generator)

### WSPR Transmission Information

![](wspr-spectrogram.png)

* One packet is 110.6 sec continuous wave
* Frequency shifts between 4 tones
* Each tone keys for 0.683 sec
* Tones are separated by 1.4648 Hz
* Total bandwidth is about 6 Hz
* 50 bits of information are packaged into a 162 bit message with [FEC](https://en.wikipedia.org/wiki/Error_correction_code)
* Transmissions always begin 1 sec after even minutes (UTC)

### Resources
* [WSPR Code Generator](https://swharden.com/software/wspr-code-generator) - encode WSPR messages from your browser
* [WsprSharp](https://github.com/swharden/WsprSharp) - a .NET library for encoding and decoding WSPR transmissions using C#
* [FSKview](https://swharden.com/software/FSKview/) - spectrogram for viewing frequency-shift keyed (FSK) signals in real time
* [Anatomy of a WSPR transmission](https://swharden.com/software/FSKview/wspr/)
* [K1JT Program](http://physics.princeton.edu/pulsar/K1JT/devel.html)
* [Grid square lookup](http://www.levinecentral.com/ham/grid_square.php?Grid=FN20)
* [WSJT](https://sourceforge.net/projects/wsjt/) on SourceForge
* [WSPR Mode in WSJT-X](https://wsprnet.org/drupal/node/5563)```
December 14th, 2020

# Seven Years of QRSS Plus

### Early Days of QRSS Grabber Websites

In the early 2010s when I started to become active in the QRSS community, one of my favorite grabber websites was I2NDT's QRSS Knights Grabber Compendium. I remember checking that website from my laptop during class several times throughout the day to see if my signal was making it out of Gainesville, Florida. I also recall many nights at the bench tweaking my transmitter and looking at all the grabs from around the world trying to spot my signal.

A common problem with QRSS grabber websites was the persistance of outdated grabber images. Whenever a grabber uploaded a new spectrogram image it replaced the previous one, but when a grabber stopped uploading new images the old one would remain. Most uploaded spectrograms have a date written in small text in the corner, but at a glance (and especially in thumbnails) it was difficult to identify which grabber images were current and which were outdated.

The back-end of QRSS Plus was redesigned in 2016 when I changed hosting companies. The new company allowed me to execute python scripts on the server, so I was no longer limited by the constraints of PHP. I redesigned QRSS Plus to download, hash, and store images every 10 minutes. This allowed QRSS Plus to display a running history of the last several grabs for each grabber, as well as support automated image stacking (averaging the last several images together to improve visualization of weak, repetitive signals). This solution is still limited by CPU time (the number of CPU seconds per day is capped by my hosting company), but continuously operating QRSS Plus does not occupy a large portion of that time.

### QRSS Plus Activity in 2020

I started logging grabber updates in September 2018, allowing me to reflect on the last few years of grabber activity. It takes a lot of effort to set-up and maintain a quality QRSS grabber, and the enthusiasm and dedication of the QRSS community is impressive and inspiring!

In 2020 our community saw 155 active grabber stations! On average there were more than 60 active stations running on any given day, and the number of active stations is visibly increasing with time.

In 2020 QRSS Plus analyzed a mean of 6,041 spectrograms per day. In total, QRSS Plus analyzed over 2.2 million spectrograms this year!

This bar graph depicts the top 50 most active grabber stations ranked according to their total unique spectrogram upload count. Using this metric grabbers that update once every 10 minutes will appear to have twice as many unique grabber images as those which upload a unique image every 20 minutes.

Many QRSS grabber operators maintain multiple stations, and I think those operators deserve special attention! This year's winner for the most active contributor goes to David Hassall (WA5DJJ) who alone is responsible for 15.26% of the total number of uploaded spectrograms in 2020 🏆

The top 25 contributors with the greatest number of unique uploads in 2020 were (in order): WA5DJJ, WD4ELG, W6REK, G3VYZ, KL7L, G4IOG, W4HBK, G3YXM, HB9FXX, PA2OHH, EA8BVP, G0MQW, SA6BSS, WD4AH, 7L1RLL, VA3ROM, VE7IGH, DL4DTL, K5MO, LA5GOA, VE3GTC, AJ4VD, K4RCG, GM4SFW, and OK1FCX.

I want to recognize Andy (G0FTD) for doing an extraordinary job maintaining the QRSS Plus website over the last several years! Although I (AJ4VD) created and maintain the QRSS Plus back-end, once it is set-up it largely operates itself. The QRSS grabber list, on the other hand, requires frequent curation. Andy has done a fantastic job monitoring the QRSS Knights mailing list and updating the grabber list in response to updates posted there so it always contains the newest grabbers and uses the latest URLs. On behalf of everyone who enjoys using QRSS Plus, thank you for your work Andy!

### The Future of QRSS Plus

Today QRSS Plus is functional, but I think its front-end could be greatly improved. It is written using vanilla JavaScript, but I think moving to a front-end framework like React makes a lot of sense. Currently PHP generates HTML containing grabber data when the page is requested, but a public JSON API would make a lot of sense and make QRSS Plus it easier to develop and test. From a UX standpoint, the front-end could benefit from a simpler design that displays well on mobile and desktop browsers. I think the usability of historical grabs could be greatly improved as well. From a back-end perspective, I'd much prefer to run the application using a service like Azure or AWS rather than lean on a traditional personal website hosting plan to manage the downloads and image processing. Automatic creation of 8-hour (stitched and compressed) grabber frames seems feasible as well. It is unlikely I will work toward these improvements soon, but if you are a front-end web developer interested in working on a public open-source project, send me an email and I'd be happy to discuss how we can improve QRSS Plus together!

QRSS is a growing hobby, and if the rise in grabbers over the last few years is an indication of what the next few years will look like, I'm excited to see where the hobby continues to go! I encourage you to consider running a grabber (and to encourage others to do the same), and to continue to thank all the grabber operators and maintainers out there who make this hobby possible.

### Notes and Resources

• Data includes Jan 1 2020 through Dec 11 2020
• Stations with <1000 unique uploads were excluded from most analyses
• Summary data (a table of unique images per day per station) is available: qrss-plus-2020.xlsx
• Bar graphs, scatter plots, and line charts were created with ScottPlot
• QRSS Plus is open source on GitHub
• FSKview is a new QRSS and WSPR Spectrogram Viewer for Windows
```---
title: Seven Years of QRSS Plus
date: 2020-12-14 21:16:00
---

# Seven Years of QRSS Plus

### Early Days of QRSS Grabber Websites

In the early 2010s when I started to become active in the QRSS community, one of my favorite grabber websites was [I2NDT's QRSS Knights Grabber Compendium](https://digilander.libero.it/i2ndt/grabber/grabber-compendium.htm). I remember checking that website from my laptop during class several times throughout the day to see if my signal was making it out of Gainesville, Florida. I also recall many nights at the bench tweaking my transmitter and looking at all the grabs from around the world trying to spot my signal.

A common problem with QRSS grabber websites was the persistance of outdated grabber images. Whenever a grabber uploaded a new spectrogram image it replaced the previous one, but when a grabber stopped uploading new images the old one would remain. Most uploaded spectrograms have a date written in small text in the corner, but at a glance (and especially in thumbnails) it was difficult to identify which grabber images were current and which were outdated.

The back-end of QRSS Plus was redesigned in 2016 when I changed hosting companies. The new company allowed me to execute python scripts on the server, so I was no longer limited by the constraints of PHP. I redesigned QRSS Plus to download, hash, and store images every 10 minutes. This allowed QRSS Plus to display a running history of the last several grabs for each grabber, as well as support automated image stacking (averaging the last several images together to improve visualization of weak, repetitive signals). This solution is still limited by CPU time (the number of CPU seconds per day is capped by my hosting company), but continuously operating QRSS Plus does not occupy a large portion of that time.

### QRSS Plus Activity in 2020

I started logging grabber updates in September 2018, allowing me to reflect on the last few years of grabber activity. It takes a lot of effort to set-up and maintain a quality QRSS grabber, and the enthusiasm and dedication of the QRSS community is impressive and inspiring!

<div class="text-center">

![](grabbers-per-day.png)

</div>

In 2020 our community saw ***155 active grabber stations***! On average there were more than 60 active stations running on any given day, and the number of active stations is visibly increasing with time.

<div class="text-center">

![](grabs-per-day.png)

</div>

In 2020 QRSS Plus analyzed a mean of 6,041 spectrograms per day. In total, QRSS Plus analyzed over ***2.2 million spectrograms*** this year!

<div class="text-center">

</div>

This bar graph depicts the top 50 most active grabber stations ranked according to their total unique spectrogram upload count. Using this metric grabbers that update once every 10 minutes will appear to have twice as many unique grabber images as those which upload a unique image every 20 minutes.

<div class="text-center">

</div>

Many QRSS grabber operators maintain multiple stations, and I think those operators deserve special attention! This year's winner for the most active contributor goes to David Hassall (WA5DJJ) who alone is responsible for 15.26% of the total number of uploaded spectrograms in 2020 🏆

The top 25 contributors with the greatest number of unique uploads in 2020 were (in order): WA5DJJ, WD4ELG, W6REK, G3VYZ, KL7L, G4IOG, W4HBK, G3YXM, HB9FXX, PA2OHH, EA8BVP, G0MQW, SA6BSS, WD4AH, 7L1RLL, VA3ROM, VE7IGH, DL4DTL, K5MO, LA5GOA, VE3GTC, AJ4VD, K4RCG, GM4SFW, and OK1FCX.

I want to recognize Andy (G0FTD) for doing an extraordinary job maintaining the QRSS Plus website over the last several years! Although I (AJ4VD) created and maintain the QRSS Plus back-end, once it is set-up it largely operates itself. The QRSS grabber list, on the other hand, requires frequent curation. Andy has done a fantastic job monitoring the [QRSS Knights mailing list](https://groups.io/g/qrssknights) and updating the grabber list in response to updates posted there so it always contains the newest grabbers and uses the latest URLs. On behalf of everyone who enjoys using QRSS Plus, thank you for your work Andy!

### The Future of QRSS Plus

Today QRSS Plus is functional, but I think its front-end could be greatly improved. It is written using vanilla JavaScript, but I think moving to a front-end framework like React makes a lot of sense. Currently PHP generates HTML containing grabber data when the page is requested, but a public JSON API would make a lot of sense and make QRSS Plus it easier to develop and test. From a UX standpoint, the front-end could benefit from a simpler design that displays well on mobile and desktop browsers. I think the usability of historical grabs could be greatly improved as well. From a back-end perspective, I'd much prefer to run the application using a service like Azure or AWS rather than lean on a traditional personal website hosting plan to manage the downloads and image processing. Automatic creation of 8-hour (stitched and compressed) grabber frames seems feasible as well. It is unlikely I will work toward these improvements soon, but if you are a front-end web developer interested in working on a public open-source project, send me an email and I'd be happy to discuss how we can improve QRSS Plus together!

QRSS is a growing hobby, and if the rise in grabbers over the last few years is an indication of what the next few years will look like, I'm excited to see where the hobby continues to go! I encourage you to consider running a grabber (and to encourage others to do the same), and to continue to thank all the grabber operators and maintainers out there who make this hobby possible.

### Notes and Resources
* Data includes Jan 1 2020 through Dec 11 2020
* Stations with <1000 unique uploads were excluded from most analyses
* Summary data (a table of unique images per day per station) is available: [qrss-plus-2020.xlsx](qrss-plus-2020.xlsx)
* Bar graphs, scatter plots, and line charts were created with [ScottPlot](https://swharden.com/scottplot)
* [FSKview](https://swharden.com/software/FSKview) is a new QRSS and WSPR Spectrogram Viewer for Windows```
October 3rd, 2020

# The New Age of QRSS

• Install spectrogram software like FSKview
• Inspect the spectrogram to decode callsigns visually
• Join the QRSS Knights mailing list to learn what's new
• Go to QRSS Plus to see QRSS signals around the world
• Design and build a circuit (or buy a kit) to transmit QRSS

QRSS allows miniscule amounts of power to send messages enormous distances. For example, 200 mW QRSS transmitters are routinely spotted on QRSS grabbers thousands of miles away. The key to this resilience lies in the fact that spectrograms can be designed which average several seconds of audio into each pixel. By averaging audio in this way, the level of the noise (which is random and averages toward zero) falls below the level of the signal, allowing visualization of signals on the spectrogram which are too deep in the noise to be heard by ear.

If you have a radio and a computer, you can view QRSS! Connect your radio to your computer's microphone, then run a spectrogram like FSKview to visualize that audio as a spectrogram. The most QRSS activity is on 30m within 100 Hz of 10.140 MHz, so set your radio to upper sideband (USB) mode and tune to 10.1387 MHz so QRSS audio will be captured as 1.4 kHz audio tones.

FSKview is radio frequency spectrogram software for viewing QRSS and WSPR simultaneously. I wrote FSKview to be simple and easy to use, but it's worth noting that Spectrum Lab, Argo, LOPORA, and QRSSpig are also popular spectrogram software projects used for QRSS, with the last two supporting Linux and suitable for use on the Raspberry Pi.

QRSS transmitters can be extraordinarily simple because they just transmit a single tone which shifts between two frequencies. The simplicity of QRSS transmitters makes them easy to assemble as a kits, or inexpensively designed and built by those first learning about RF circuit design. The simplest designs use a crystal oscillator (typically a Colpitts configuration) followed by a buffer stage and a final amplifier (often Class C configuration using a 2N7000 N-channel MOSFET or 2N2222 NPN transistor). Manual frequency adjustments are achieved using a variable capacitor, supplemented in this case with twisted wire to act as a simple but effective variable capacitor for fine frequency tuning within the 100 Hz QRSS band. Frequency shift keying to transmit call signs is typically achieved using a microcontroller to adjust voltage on a reverse-biased diode (acting as a varactor) to modulate capacitance and shift resonant frequency of the oscillator. Following a low-pass filter (typically a 3-pole Chebyshev design) the signal is then sent to an antenna.

QRP Labs is a great source for QRSS kits. The kit pictured above and below is one of their earliest kits (the 30/40/80/160m QRSS Kit), but they have created many impressive new products in the last several years. Some of their more advanced QRSS kits leverage things like direct digital synthesis (DDS), GPS time synchronization, and the ability to transmit additional digital modes like Hellschreiber and WSPR.

Atmospheric phenomena and other special conditions can often be spotted in QRSS spectrograms. One of the most common special cases are radio frequency reflections off of airplanes resulting in the radio waves arriving at the receiver simultaneously via two different paths (a form of multipath propagation). Due to the Doppler shift from the airplane approaching the receiver the signal from the reflected path appears higher frequency than the direct path, and as the airplane flies over and begins heading away the signal from the reflected path decreases in frequency relative to the signal of the direct path. The image below is one of my favorites, captured by Andy (G0FTD) in the 10m QRSS band. QRSS de W4HBK is a website that has many blog posts about rare and special grabs, demonstrating effects of meteors and coronal mass ejections on QRSS signals.

## QRSS Transmitters are Not Beacons

Radio beacons send continuous, automated, unattended, one-way transmissions without specific reception targets. In contrast, QRSS transmitters are only intended to be transmitting when the control operator is available to control them, and the recipients are known QRSS grabbers around the world. To highlight the distinction from radio beacons, QRSS transmitters are termed Manned Experimental Propagation Transmitters (MEPTs). Users in the United States will recall that the FCC (in Part 97.203) confines operation of radio beacons to specific regions of the radio spectrum and disallows operation of beacons below 28 MHz. Note that amateur radio beacons typically operate up to 100 W which is a power level multiple orders of magnitude greater than QRSS transmitters. MEPTs, in contrast, can transmit in any portion of the radio frequency spectrum where CW operation is permitted.

## The New Age of QRSS

To receive QRSS, configure your radio for uper sideband using a dial frequency from the table below and QRSS will be audible as 1-2 kHz audio tones. This radio configuration is identical to the recommendation by WSPRnet for receiving WSPR using WSJT-X software, allowing QRSS and WSPR to be monitored simultaneously.

The entire QRSS band is approximately 200 Hz wide centered on the QRSS frequencies listed in the table below. Testing and experimentation is encouraged in the 100 Hz below the listed frequency, and the upper portion is typically used for more stable transmitters. An exception is the 10m band where the QRSS band is 400 Hz wide, extending ±200 Hz from the center frequency listed below.

Band QRSS Frequency (±100 Hz) USB Dial Frequency (Hz) Audio Frequency (Hz)
600m 476,100 474,200 1,900
160m 1,837,900 1,836,600 1,300
80m 3,569,900 ⭐ popular 3,568,600 1,300
60m 5,288,550 5,287,200 1,350
40m 7,039,900 ⭐ popular 7,038,600 1,300
30m 10,140,000 🌟 most popular 10,138,700 1,300
22m 13,555,400 13,553,900 1,300
20m 14,096,900 ⭐ popular 14,095,600 1,300
17m 18,105,900 18,104,600 1,300
15m 21,095,900 21,094,600 1,300
12m 24,925,900 24,924,600 1,300
10m 28,125,700 28,124,600 1,100
6m 50,294,300 50,293,000 1,300

⚠️ WARNING: It may not be legal for you to transmit on these frequencies. Check license requirements and regulations for your region before transmitting QRSS.

⚠️ WARNING: These frequencies sometimes change based upon community discussion. Frequency tables can be found on the Knights QRSS Wiki. Outdated or alternate frequencies include 160m (1,843,200 Hz), 80m (3,593,900 Hz), 12m (24,890,800 Hz), 10m (28,000,800 Hz and 28,322,000 ±500 Hz), and 6m (50,000,900 Hz). Experimentation on 10m is encouraged in the 100Hz above the band.

When tuning your radio your dial frequency may be lower than the QRSS frequency. If you are using upper-sideband (USB) mode, you have to tune your radio dial 1.4 kHz below the QRSS band to hear QRSS signals as a 1.4 kHz tone. Recommended dial frequencies in the table above are suitable for receiving QRSS and WSPR.

The QRSS Knights is a group of QRSS enthusiasts who coordinate events and discuss experiments over email. The group is kind and welcoming to newcomers, and those interested in learning more about QRSS are encouraged to join the mailing list.

## Resources

• QRSS and You by KA7OEI is another classic summary of QRSS.

• Weak Signal Propagation Reporter (WSPR) is a low power radio protocol that typically operates adjacent to the QRSS bands and provides automated decoding of callsign, power, and location information. Read more at http://wsprnet.org

• The QRSS Adventure by Dave Hassall (WA5DJJ) has circuit designs and commentary spanning far back into the early days of QRSS. His 1,164,000,000 Miles per Watt Test is extraordinary!

• QRSS de W4HBK website by Bill Houghton (W4HBK) contains many useful blog posts about advanced QRSS topics. The website also has many examples of special grabs depicting rare events and atmospheric phenomena.

• Hans Summers' website (the founder of QRP Labs) has many excellent resources related to RF design and early work in the QRSS space.

• Simple QRP Equipment by Onno (PA2OHH) is a collection of fantastic resources related to QRSS transmission, reception, and software design.

• Electronics & HAM Radio Blog by Eldon Brown (WA0UWH) has many fantastic articles about QRSS. Eldon's SMT band-edge transmitter inspired me to make a SMT QRSS transmitter many years later.

• Dave Richards, AA7EE has a fantastic website documenting many amateur radio topics including QRSS. This website has the prettiest pictures of circuit boards you'll ever see.

• My QRSS Hardware GitHub page collects notes and resources related to QRSS transmitter and receiver design.

```---
title: The New Age of QRSS
date: 2020-10-03 22:08:00
---

# The New Age of QRSS

> **TLDR: Get Started with QRSS**
> * Install spectrogram software like [FSKview](https://swharden.com/software/FSKview)
> * Inspect the spectrogram to decode callsigns visually
> * Join the [QRSS Knights](https://groups.io/g/qrssknights) mailing list to learn what's new
> * Design and build a circuit (or [buy a kit](https://www.qrp-labs.com/)) to transmit QRSS

**QRSS allows miniscule amounts of power to send messages enormous distances.** For example, 200 mW QRSS transmitters are routinely spotted on QRSS grabbers thousands of miles away. The key to this resilience lies in the fact that spectrograms can be designed which average several seconds of audio into each pixel. By averaging audio in this way, the level of the noise (which is random and averages toward zero) falls below the level of the signal, allowing visualization of signals on the spectrogram which are too deep in the noise to be heard by ear.

<div class="text-center img-border">

![](lopora-signals2.jpg)

</div>

**If you have a radio and a computer, you can view QRSS!** Connect your radio to your computer's microphone, then run a spectrogram like [FSKview](https://swharden.com/software/FSKview/) to visualize that audio as a spectrogram. The most QRSS activity is on 30m within 100 Hz of 10.140 MHz, so set your radio to upper sideband (USB) mode and tune to 10.1387 MHz so QRSS audio will be captured as 1.4 kHz audio tones.

**[FSKview](https://swharden.com/software/FSKview/) is radio frequency spectrogram software for viewing QRSS and WSPR simultaneously.** I wrote [FSKview](https://swharden.com/software/FSKview/) to be simple and easy to use, but it's worth noting that [Spectrum Lab](https://www.qsl.net/dl4yhf/spectra1.html),  [Argo](https://digilander.libero.it/i2phd/argo/), [LOPORA](https://www.qsl.net/pa2ohh/11lop.htm), and [QRSSpig](https://gitlab.com/hb9fxx/qrsspig) are also popular spectrogram software projects used for QRSS, with the last two supporting Linux and suitable for use on the Raspberry Pi.

<div class="text-center">

![](fskview.png)

</div>

**QRSS transmitters can be extraordinarily simple because they just transmit a single tone which shifts between two frequencies.** The simplicity of QRSS transmitters makes them easy to assemble as a kits, or inexpensively designed and built by those first learning about RF circuit design. The simplest designs use a crystal oscillator (typically a [Colpitts](https://en.wikipedia.org/wiki/Colpitts_oscillator) configuration) followed by a buffer stage and a final amplifier (often [Class C](https://en.wikipedia.org/wiki/Power_amplifier_classes#Class_C) configuration using a 2N7000 N-channel MOSFET or 2N2222 NPN transistor). Manual frequency adjustments are achieved using a variable capacitor, supplemented in this case with twisted wire to act as a simple but effective variable capacitor for fine frequency tuning within the 100 Hz QRSS band. Frequency shift keying to transmit call signs is typically achieved using a microcontroller to adjust voltage on a reverse-biased diode (acting as a [varactor](https://en.wikipedia.org/wiki/Varicap)) to modulate capacitance and shift resonant frequency of the oscillator. Following a low-pass filter (typically a 3-pole [Chebyshev](https://en.wikipedia.org/wiki/Chebyshev_filter) design) the signal is then sent to an antenna.

<div class="text-center img-medium">

![](qrp-labs-kit-schematic.jpg)

</div>

**[QRP Labs](https://www.qrp-labs.com/) is a great source for QRSS kits.** The kit pictured above and below is one of their earliest kits (the 30/40/80/160m QRSS Kit), but they have created many impressive new products in the last several years. Some of their more advanced QRSS kits leverage things like direct digital synthesis (DDS), GPS time synchronization, and the ability to transmit additional digital modes like Hellschreiber and WSPR.

<div class="text-center img-border img-medium">

![](qrp-labs-kit-photo.jpg)

</div>

<div class="text-center img-medium">

![](rf-reflection-airplane.png)

</div>

<div class="text-center img-medium img-border">

![](rf-reflection-airplane.jpg)

</div>

## QRSS Transmitters are Not Beacons

Radio beacons send continuous, automated, unattended, one-way transmissions without specific reception targets. In contrast, QRSS transmitters are only intended to be transmitting when the control operator is available to control them, and the recipients are known QRSS grabbers around the world. To highlight the distinction from radio beacons, QRSS transmitters are termed ***Manned Experimental Propagation Transmitters (MEPTs)***. Users in the United States will recall that the FCC (in Part 97.203) confines operation of radio beacons to specific regions of the radio spectrum and disallows operation of beacons below 28 MHz. Note that amateur radio beacons typically operate up to 100 W which is a power level multiple orders of magnitude greater than QRSS transmitters. MEPTs, in contrast, can transmit in any portion of the radio frequency spectrum where CW operation is permitted.

## The New Age of QRSS

**To receive QRSS, configure your radio for uper sideband using a dial frequency from the table below and QRSS will be audible as 1-2 kHz audio tones.** This radio configuration is identical to the recommendation by [WSPRnet](https://www.wsprnet.org) for receiving WSPR using WSJT-X software, allowing QRSS and WSPR to be monitored simultaneously.

**The entire QRSS band is approximately 200 Hz wide** centered on the QRSS frequencies listed in the table below. Testing and experimentation is encouraged in the 100 Hz below the listed frequency, and the upper portion is typically used for more stable transmitters. An exception is the 10m band where the QRSS band is 400 Hz wide, extending ±200 Hz from the center frequency listed below.

<div class="text-center">
<div class="d-inline-block mx-auto text-start">

Band | QRSS Frequency (±100 Hz)     | USB Dial Frequency (Hz)   | Audio Frequency (Hz)
-----|------------------------------|---------------------------|-----------------------
600m | 476,100						| 474,200					| 1,900
160m | 1,837,900					| 1,836,600					| 1,300
80m  | 3,569,900 ⭐ _popular_		| 3,568,600					| 1,300
60m  | 5,288,550					| 5,287,200					| 1,350
40m  | 7,039,900 ⭐ _popular_		| 7,038,600					| 1,300
30m  | 10,140,000 🌟 _most popular_	| 10,138,700				| 1,300
22m  | 13,555,400					| 13,553,900				| 1,300
20m  | 14,096,900 ⭐ _popular_		| 14,095,600				| 1,300
17m  | 18,105,900					| 18,104,600				| 1,300
15m  | 21,095,900					| 21,094,600				| 1,300
12m  | 24,925,900					| 24,924,600				| 1,300
10m  | 28,125,700					| 28,124,600				| 1,100
6m   | 50,294,300					| 50,293,000				| 1,300

</div>
</div>

* [WSPR and QRSS frequencies](https://g6nhu.co.uk/frequencies.html) by Keith (G6NHU)

> **⚠️ WARNING:** It may not be legal for you to transmit on these frequencies. Check license requirements and regulations for your region before transmitting QRSS.

> **⚠️ WARNING:** These frequencies sometimes change based upon community discussion. Frequency tables can be found on the [Knights QRSS Wiki](https://groups.io/g/qrssknights/wiki/3964). Outdated or alternate frequencies include 160m (1,843,200 Hz), 80m (3,593,900 Hz), 12m (24,890,800 Hz), 10m (28,000,800 Hz and 28,322,000 ±500 Hz), and 6m (50,000,900 Hz). Experimentation on 10m is encouraged in the 100Hz above the band.

**When tuning your radio your dial frequency may be lower than the QRSS frequency.** If you are using upper-sideband (USB) mode, you have to tune your radio dial 1.4 kHz _below_ the QRSS band to hear QRSS signals as a 1.4 kHz tone. Recommended dial frequencies in the table above are suitable for receiving QRSS and WSPR.

**The [QRSS Knights](https://groups.io/g/qrssknights) is a group of QRSS enthusiasts** who coordinate events and discuss experiments over email. The group is kind and welcoming to newcomers, and those interested in learning more about QRSS are encouraged to join the mailing list.

## Resources

* Weak Signal Propagation Reporter (WSPR) is a low power radio protocol that typically operates adjacent to the QRSS bands and provides automated decoding of callsign, power, and location information. Read more at http://wsprnet.org

* [The QRSS Adventure](http://www.zianet.com/dhassall/QRSS_A.html) by Dave Hassall (WA5DJJ) has circuit designs and commentary spanning far back into the early days of QRSS. His [ 1,164,000,000 Miles per Watt Test](http://www.zianet.com/dhassall/BILLIONMPW.html) is extraordinary!

* [QRSS de W4HBK](http://pensacolasnapper.blogspot.com/) website by Bill Houghton (W4HBK) contains many useful blog posts about advanced QRSS topics. The website also has many examples of special grabs depicting rare events and atmospheric phenomena.

* [Hans Summers' website](http://www.hanssummers.com/) (the founder of [QRP Labs](https://www.qrp-labs.com/)) has many excellent resources related to RF design and early work in the QRSS space.

* [Simple QRP Equipment](https://www.qsl.net/pa2ohh/) by Onno  (PA2OHH) is a collection of fantastic resources related to QRSS transmission, reception, and software design.

* [Electronics & HAM Radio Blog](http://wa0uwh.blogspot.com/) by Eldon Brown (WA0UWH) has many fantastic articles about QRSS. Eldon's SMT band-edge transmitter inspired me to make a SMT QRSS transmitter many years later.

* [Dave Richards, AA7EE](https://aa7ee.wordpress.com/) has a fantastic website documenting many amateur radio topics including QRSS. This website has the prettiest pictures of circuit boards you'll ever see.

<div class="text-center img-border">

</div>```
September 5th, 2016

# VHF Frequency Counter with PC Interface

Projects I build often involve frequency synthesis, and one of the most useful tools to have around is a good frequency counter. I love the idea of being able to access / log / analyze frequency readings on my computer. Commercial frequency counters can be large, expensive, and their calibration is a chicken-and-egg problem (you need a calibrated frequency counter to calibrate a frequency reference you use to calibrate a frequency counter!). For about the cost of a latte I made a surprisingly good frequency frequency counter (which directly counts >100 MHz without dividing-down the input signal) by blending a SN74LV8154 dual 16-bit counter (which can double as a 32-bit counter, \$1.04 on mouser) and an ATMega328 microcontroller (\$3.37 on Mouser).

Although these two chips are all you need to count something, the accuracy of your counts depend on your gate. If you can generate a signal of 1 pulse per second (1PPS), you can count anything, but your accuracy depends on the accuracy of your 1PPS signal. To eliminate the need for calibration (and to provide the 1PPS signal with the accuracy of an atomic clock) I'm utilizing the 1PPS signal originating from a GPS unit which I already had distributed throughout my shack (using a 74HC240 IC as a line driver). If you don't have a GPS unit, consider getting one! I'm using a NEO-6M module (\$17.66 on Amazon) to generate the 1PPS gate, and if you include its cost we're up to \$22.07. Also, all of the code for this project (schematics, C that runs on the microcontroller, and a Python to interact with the serial port) is shared on GitHub! You may be wondering, "why do GPS units have incredibly accurate 1PPS signals?" It's a good question, but a subject for another day. For now, trust me when I say they're fantastically accurate (but slightly less precise due to jitter) if you're interested in learning more read up on GPS timing.

This is the general idea behind how this frequency counter works. It's so simple! It's entirely digital, and needs very few passive components. sn74lv8154 is configured in 32-bit mode (by chaining together its two 16-bit counters, see the datasheet for details) and acts as the front-end directly taking in the measured frequency. This chip is "rare" in the sense I find very few internet projects using it, and they're not available on ebay. However they're cheap and plentiful on mouser, so I highly encourage others to look into using it! The datasheet isn’t very clear about its maximum frequency, but in my own tests I was able to measure in excess of 100 MHz from a breadboarded circuit! This utilized two cascaded ICS501 PLL frequency multiplier ICs to multiply a signal I had available (the 11.0592 MHz crystal the MCU was running from) by ten, yielding 110 MHz, which it was able to measure (screenshot is down on the page).

The 1PPS gate signal is generated from an inexpensive GPS module available on Amazon. I've hinted at the construction of this device before and made a post about how to send output signals like the 1PPS signal generated here throughout your shack via coax using a line driver, so I won't re-hash all of those details here. I will say that this module has only VCC, GND, and TX/RX pins, so to get access to the 1PPS signal you have to desolder the SMT LED and solder a wire to its pad. It requires a bit of finesse. If you look closely, you can see it in this picture (purple wire).

I first built this device on a breadboard, and despite the rats nest of wires it worked great! Look closely and you can see the ICS501 frequency multiplier ICs I wrote about before. In this case it's measuring the 10x multiplied crystal frequency clocking the MCU (11 MHz -> 110 MHz) and reporting these readings every 1 second to the computer via a serial interface.

Frequency measurements of the VHF signal are reported once per second. Measurements are transmitted through a USB serial adapter, and captured by a Python script. Note that I'm calling this signal VHF because it's >30 MHz. I am unsure if this device will work up to 300 MHz (the border between VHF and UHF), but I look forward to testing that out! Each line contains two numbers: the actual count of the counter (which is configured to simply count continuously and overflow at 2^32=4,294,967,296), and the gated count (calculated by the microcontroller) which is the actual frequency in Hz.

This screenshot shows that my ~11.05 MHz crystal is actually running at 11,061,669.4 Hz. See how I capture the 0.4 Hz unit at the end? That level of precision is the advantage of using this VHF-capable counter in conjunction with a 10x frequency multiplier!

Once I confirmed everything was working, I built this device in a nice enclosure. I definitely splurge every few months and buy extruded split body aluminum enclosures in bulk (ebay), but they're great to have on hand because they make projects look so nice. I added some rubber feet (cabinet bumpers from Walmart), drilled holes for all the connectors with a continuous step drill bit, made a square hole for the serial port using a nibbler, and the rest is pretty self-evident. Labels are made with a DYMO LetraTag (Target) and clear labels (Target, Amazon) using a style inspired by PA2OHH. I tend to build one-off projects like this dead-bug / Manhattan style.

I super-glued a female header to the aluminum frame to make in-circuit serial programming (ICSP) easy. I can't believe I never thought to do this before! Programming (and reprogramming) was so convenient. I'm going to start doing this with every enclosed project I build from now on. FYI I'm using a USBTiny ISP (\$10.99, Amazon) to do the programming (no longer the BusPirate, it's too slow) like I describe here for 64-bit Windows 7 (although I'm now using Windows 10 and it works the same).

The front of the device has LEDs indicating power, serial transmission, and gating. Without a 1PPS gate, the device is set to send a count (of 0) every 5 seconds. In this case, the TX light will illuminate. If a gate is detected, the TX and GATE LEDs will illuminate simultaneously. In reality I just drilled 3 holes when I really needed two, so I had to make-up a function for the third LED (d'oh!)

The back of the device has serial output, frequency input, gate input, and power. Inside is a LM7805 voltage regulator, and careful attention was paid to decoupling and keeping ripple out of the power supply (mostly so our gate input wouldn't be affected). I'm starting to get in the habit of labeling all serial output ports with the level (TTL vs CMOS, which makes a HUGE difference as MAX232 level converter may be needed, or a USB serial adapter which is capable of reading TTL voltages), as well as the baud rate (119200), byte size (8), parity (N), and stop bit (1). _I just realized there's a typo! The label should read 8N1. I don't feel like fixing it, so I'll use a marker to turn the 2 into an 8. _I guess I'm only human after all.

I should have tried connecting all these things before I drilled the holes. I got so lucky that everything fit, with about 2mm to spare between those BNC jacks. Phew!

This is an easy test frequency source. I have a dozen canned oscillators of various frequencies. This is actually actually a voltage controlled oscillator (VCO) with adjustment pin (not connected), and it won't be exactly 50 MHz without adjustment. It's close enough to test with though! As this is >30 MHz, we can call the signal VHF.

You can see on the screen it's having no trouble reading the ~50 MHz frequency. You'll notice I'm using RealTerm (with a good write-up on sparkfun) which is my go-to terminal program instead of HyperTerminal (which really needs to go away forever). In reviewing this photo, I'm appreciating how much unpopulated room I have on the main board. I'm half tempted to build-in a frequency multiplier circuit, and place it under control of the microcontroller such that if an input frequency from 1-20MHz is received, it will engage the 10x multiplier. That's a mod for another day though! Actually, since those chips are SMT, if I really wanted to do this I would make this whole thing a really small SMT PCB and greatly simplify construction. That sounds like a project for another day though...None

Before closing it up I added some extra ripple protection on the primary counter chip. There's a 560 uH series inductor with the power supply, followed by a 100 nF capacitor parallel with ground. I also added ferrite beads to the MCU power line and gate input line. I appreciate how the beads are unsecured and that this is a potential weakness in the construction of this device (they're heavy, so consider what would happen if you shook this enclosure). However, anything that would yank-away cables in the event of shaking the device would probably also break half the other stuff in this thing, so I think it's on par with the less-than-rugged construction used for all the other components in this device. It will live a peaceful life on my shelf. I am not concerned.

This is the final device counting frequency and continuously outputting the result to my computer. In the background you can see the 12V power supply (yellow) indicating it is drawing only 20 mA, and also the GPS unit is in a separate enclosure on the bottom right. Click here to peek inside the GPS 1PPS enclosure.

I'm already loving this new frequency counter! It's small, light, and nicely enclosed (meaning it's safe from me screwing with it too much!). I think this will prove to be a valuable piece of test equipment in my shack for years to come. I hope this build log encourages other people to consider building their own equipment. I learned a lot from this build, saved a lot of money not buying something commercial, had a great time making this device, and I have a beautiful piece of custom test equipment that does exactly what I want.

## Source Code

Microcontroller code (AVR-GCC), schematics, and a Python script to interface with the serial port are all available on this project's GitHub page

## Afterthought: Using without GPS

One of the great advantages of this project is that it uses GPS for an extremely accurate 1 PPS signal, but what options exist to adapt this project to not rely on GPS? The GPS unit is expensive (though still <\$20) and GPS lock is not always feasible (underground, in a Faraday cage, etc). Barring fancy things like dividing-down rubidium frequency standards or oven controlled oscillators, consider having your microcontroller handle the gating using either interrupts and timers precisely configured to count seconds. Since this project uses a serial port with a 11.0592 MHz crystal, your 1PPS stability will depend on the stability of your oscillator (which is pretty good!). Perhaps more elegantly you could use a 32.768 kHz crystal oscillator to create a 1 PPS signal. This frequency can be divided by 2 over and over to yield 1 Hz perfectly. This is what most modern wristwatches do. Many AVRs have a separate oscillator which can accomodate a 32 kHz crystal and throw interrupts every 1 second without messing with the system clock. Alternatively, the 74GC4060 (a 14 stage ripple counter) can divide 32k into 1 Hz and even can be arranged as an oscillator (check the datasheet). It would be possible to have both options enabled (local clock and GPS) and only engage the local clock if the GPS signal is absent. If anyone likes the idea of this simple VHF frequency counter with PC interface but doesn't want to bother with the GPS, there are plenty of options to have something almost as accurate. That really would cut the cost of the final device down too, keeping it under the \$5 mark.

## Update: Integrating Counter Serial Output with GPS Serial Output

The NEO-M8 GPS module is capable of outputting serial data at 9600 baud and continuously dumps NEMA formatted GPS data. While this isn't really useful for location information (whose frequency counter requires knowing latitude and longitude?) it's great for tracking things like signal strength, fix quality, and number of satellites. After using this system to automatically log frequency of my frequency reference, I realized that sometimes I'd get 1-2 hours of really odd data (off by kHz, not just a few Hz). Power cycling the GPS receiver fixes the problem, so my guess it that it's a satellite issue. If I combine the GPS RX and counter in 1 box, I could detect this automatically and have the microcontroller power cycle the GPS receiver (or at the least illuminate a red error LED). I don't feel like running 2 USB serial adapters continuously. I don't feel like programming my AVR to listen to the output from the GPS device (although that's probably the correct way to do things). Instead I had a simpler idea that worked really well, allowing me to simultaneously log serial data from my GPS unit and microcontroller (frequency counter) using 1 USB serial adapter.

The first thing I did was open up the frequency counter and reconnect my microcontroller programmer. This is exactly what I promised myself I wouldn't do, and why I have a nice enclosure in the first place! Scott, stop fidgeting with things! The last time I screwed this enclosure together I considered adding super glue to the screw threads to make sure I didn't open it again. I'll keep my modifications brief! For now, this is a test of a concept. When it's done, I'll revert the circuitry to how it was and close it up again. I'll take what I learn and build it into future projects.

I peeked at the serial signals of both the frequency counter (yellow) and the GPS unit output (blue). To my delight, there was enough dead space that I thought I could stick both in the same signal. After a code modification, I was able to tighten it up a lot, so the frequency counter never conflicts with the GPS unit by sending data at the same time.

I had to slow the baud rate to 9600, but I programmed it to send fewer characters. This leaves an easy ~50ms padding between my frequency counter signal and the GPS signal. Time to mix the two! This takes a little thought, as I can't just connect the two wires together. Serial protocol means the lines are usually high, and only pulled down when data is being sent. I had to implement an active circuit.

Using a few components, I built an AND gate to combine signals from the two serial lines. For some reason it took some thought before I realized an AND gate was what I needed here, but it makes sense. The output is high (meaning no serial signal) only when both inputs are high (no serial signals on the input). When either signal drops low, the output drops low. This is perfect. My first thought was that I'd need a NOR gate, but an inverted AND gate is a NOR gate.

Here's my quick and dirty implementation. A reminder again is that this will be removed after this test. For now, it's good enough.

After connecting the GPS serial output and frequency counter serial output to the AND gate (which outputs to the computer), I instantly got the result I wanted!

RealTerm shows that both inputs are being received. It's a mess though. If you want to know what everything is, read up on NEMA formatted GPS data.

I whipped-up a python program to parse, display, and log key information. This display updates every 1 second. The bottom line is what is appended to the log file on ever read. It's clunky, but again this is just for testing and debugging. I am eager to let this run for as long as I can (days?) so I can track how changes in satellite signal / number / fix quality influence measured frequency.

```---
title: VHF Frequency Counter with PC Interface
date: 2016-09-05 17:34:44
tags: amateur radio, circuit, python, old
---

# VHF Frequency Counter with PC Interface

**Projects I build often involve frequency synthesis, and one of the most useful tools to have around is a good frequency counter.** I love the idea of being able to access / log / analyze frequency readings on my computer. Commercial frequency counters can be large, expensive, and their calibration is a chicken-and-egg problem (you need a calibrated frequency counter to calibrate a frequency reference you use to calibrate a frequency counter!). **For about the cost of a latte I made a surprisingly good frequency frequency counter (which directly counts >100 MHz without dividing-down the input signal)** by blending a SN74LV8154 dual 16-bit counter (which can double as a 32-bit counter, [\$1.04 on mouser](http://www.mouser.com/Search/Refine.aspx?Keyword=sn74lv8154&Ns=Pricing%7c0&FS=True)) and an ATMega328 microcontroller ([\$3.37 on Mouser](http://www.mouser.com/Semiconductors/Integrated-Circuits-ICs/Embedded-Processors-Controllers/Microcontrollers-MCU/8-bit-Microcontrollers-MCU/_/N-a86lo?P=1z0y33r&Keyword=atmega328p&Ns=Pricing%7c0&FS=True)).

**Although these two chips are all you need to count something, the accuracy of your counts depend on your gate.** If you can generate a signal of 1 pulse per second (1PPS), you can count anything, but your accuracy depends on the accuracy of your 1PPS signal. To eliminate the need for calibration (and to provide the 1PPS signal with the accuracy of an atomic clock) I'm utilizing the 1PPS signal originating from a GPS unit which I already had distributed throughout my shack ([using a 74HC240 IC as a line driver](https://www.swharden.com/wp/2016-08-20-breadboard-line-driver-module/)). If you don't have a GPS unit, consider getting one! I'm using a NEO-6M module ([\$17.66 on Amazon](https://www.amazon.com/Andoer-AeroQuad-Multirotor-Quadcopter-Aircraft/dp/B00RCP9MLY)) to generate the 1PPS gate, and if you include its cost we're up to \$22.07. Also,** all of the code for this project (schematics, C that runs on the microcontroller, and a Python to interact with the serial port) is [shared on GitHub](https://github.com/swharden/AVR-projects/tree/master/ATMega328%202016-09-04%20SN74LV8154)!** You may be wondering, "why do GPS units have incredibly accurate 1PPS signals?" It's a good question, but a subject for another day. For now, trust me when I say they're fantastically accurate (but slightly less precise due to jitter) if you're interested in learning more read up on [GPS timing](https://www.u-blox.com/sites/default/files/products/documents/Timing_AppNote_%28GPS.G6-X-11007%29.pdf).

<div class="text-center">

[![](pc-frequency-counter-schem_thumb.jpg)](pc-frequency-counter-schem.png)

</div>

**This is the general idea behind how this frequency counter works.** It's so simple! It's entirely digital, and needs very few passive components. sn74lv8154 is configured in 32-bit mode (by chaining together its two 16-bit counters, [see the datasheet for details](http://www.ti.com/lit/ds/symlink/sn74lv8154.pdf)) and acts as the front-end directly taking in the measured frequency. This chip is "rare" in the sense I find very few internet projects using it, and they're not available on ebay. However they're cheap and plentiful on mouser, so I highly encourage others to look into using it! The datasheet isn’t very clear about its maximum frequency, but in my own tests I was able to measure in excess of 100 MHz from a breadboarded circuit! This utilized [two cascaded ICS501 PLL frequency multiplier ICs to multiply a signal](https://www.swharden.com/wp/2016-08-31-ics501-simple-frequency-multiplier/) I had available (the 11.0592 MHz crystal the MCU was running from) by ten, yielding 110 MHz, which it was able to measure (screenshot is down on the page).

<div class="text-center">

[![](neo-60-gps-1pps_thumb.jpg)](neo-60-gps-1pps.jpg)

</div>

**The 1PPS gate signal is generated from an inexpensive GPS module [available on Amazon](https://www.amazon.com/Andoer-AeroQuad-Multirotor-Quadcopter-Aircraft/dp/B00RCP9MLY).** I've hinted at the construction of this device before and [made a post](https://www.swharden.com/wp/2016-08-20-breadboard-line-driver-module/) about how to send output signals like the 1PPS signal generated here throughout your shack via coax using a line driver, so I won't re-hash all of those details here. I will say that this module has only VCC, GND, and TX/RX pins, so to get access to the 1PPS signal you have to desolder the SMT LED and solder a wire to its pad. It requires a bit of finesse. If you look closely, [you can see it in this picture](https://www.swharden.com/wp/2016-08-20-breadboard-line-driver-module/#jp-carousel-5918) (purple wire).

<div class="text-center img-border">

[![](IMG_8207_thumb.jpg)](IMG_8207.jpg)

</div>

**I first built this device on a breadboard, and despite the rats nest of wires it worked great!** Look closely and you can see the ICS501 frequency multiplier ICs [I wrote about before](https://www.swharden.com/wp/2016-08-31-ics501-simple-frequency-multiplier/). In this case it's measuring the 10x multiplied crystal frequency clocking the MCU (11 MHz -> 110 MHz) and reporting these readings every 1 second to the computer via a serial interface.

<div class="text-center img-border">

[![](ss_thumb.jpg)](ss.png)

</div>

**Frequency measurements of the VHF signal are reported once per second. Measurements are transmitted through a USB serial adapter, and captured by a Python script.** Note that I'm calling this signal [VHF](https://en.wikipedia.org/wiki/Very_high_frequency) because it's >30 MHz. I am unsure if this device will work up to 300 MHz (the border between VHF and UHF), but I look forward to testing that out! Each line contains two numbers: the actual count of the counter (which is configured to simply count continuously and overflow at 2^32=4,294,967,296), and the gated count (calculated by the microcontroller) which is the actual frequency in Hz.

>  This screenshot shows that my ~11.05 MHz crystal is actually running at 11,061,669.4 Hz. See how I capture the 0.4 Hz unit at the end? That level of precision is the advantage of using this VHF-capable counter in conjunction with a 10x frequency multiplier!

**Once I confirmed everything was working, I built this device in a nice enclosure.** I definitely splurge every few months and buy extruded split body aluminum enclosures in bulk ([ebay](http://www.ebay.com/sch/i.html?_nkw=extruded+split+body+aluminum+enclosure)), but they're great to have on hand because they make projects look so nice. I added some rubber feet (cabinet bumpers from Walmart), drilled holes for all the connectors with a continuous step drill bit, made a square hole for the serial port using a [nibbler](https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dtools&field-keywords=Nickel+Plated+Nibbling+Tool), and the rest is pretty self-evident. Labels are made with a DYMO LetraTag (Target) and clear labels (Target, Amazon) using a style [inspired by PA2OHH](http://www.qsl.net/pa2ohh/tlabels.htm). I tend to build one-off projects like this dead-bug / Manhattan style.

<div class="text-center img-border">

[![](IMG_8277_thumb.jpg)](IMG_8277.jpg)
[![](IMG_8282_thumb.jpg)](IMG_8282.jpg)

</div>

**I super-glued a female header to the aluminum frame to make in-circuit serial programming (ICSP) easy.** I can't believe I never thought to do this before! Programming (and reprogramming) was so convenient. I'm going to start doing this with every enclosed project I build from now on. FYI I'm using a USBTiny ISP ([\$10.99, Amazon](https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=usbtiny+isp)) to do the programming (no longer the BusPirate, it's too slow) [like I describe here for 64-bit Windows 7](https://www.swharden.com/wp/2013-05-07-avr-programming-in-64-bit-windows-7/) (although I'm now using Windows 10 and it works the same).

<div class="text-center img-border">

[![](IMG_8330_thumb.jpg)](IMG_8330.jpg)

</div>

**The front of the device** has LEDs indicating power, serial transmission, and gating. Without a 1PPS gate, the device is set to send a count (of 0) every 5 seconds. In this case, the TX light will illuminate. If a gate is detected, the TX and GATE LEDs will illuminate simultaneously. In reality I just drilled 3 holes when I really needed two, so I had to make-up a function for the third LED (d'oh!)

<div class="text-center img-border">

[![](IMG_8286_thumb.jpg)](IMG_8286.jpg)

</div>

**The back of the device** has serial output, frequency input, gate input, and power. Inside is a LM7805 voltage regulator, and careful attention was paid to decoupling and keeping ripple out of the power supply (mostly so our gate input wouldn't be affected). I'm starting to get in the habit of labeling all serial output ports with the level (TTL vs CMOS, which makes a HUGE difference as MAX232 level converter may be needed, or a USB serial adapter which is capable of reading TTL voltages), as well as the baud rate (119200), byte size (8), parity (N), and stop bit (1). _I just realized there's a typo! The label should read 8N1. I don't feel like fixing it, so I'll use a marker to turn the 2 into an 8. _I guess I'm only human after all.

<div class="text-center img-border">

[![](IMG_8297_thumb.jpg)](IMG_8297.jpg)

</div>

**I should have tried connecting all these things before I drilled the holes.** I got _so_ lucky that everything fit, with about 2mm to spare between those BNC jacks. Phew!

<div class="text-center img-border">

[![](IMG_8316_thumb.jpg)](IMG_8316.jpg)

</div>

**This is an easy test frequency source.** I have a dozen [canned oscillators](https://en.wikipedia.org/wiki/Crystal_oscillator) of various frequencies. This is actually actually a voltage controlled oscillator ([VCO](https://en.wikipedia.org/wiki/Voltage-controlled_oscillator)) with adjustment pin (not connected), and it won't be exactly 50 MHz without adjustment. It's close enough to test with though! As this is >30 MHz, we can call the signal [VHF](https://en.wikipedia.org/wiki/Very_high_frequency).

<div class="text-center img-border">

[![](IMG_8318_thumb.jpg)](IMG_8318.jpg)

</div>

**You can see on the screen it's having no trouble reading the ~50 MHz frequency.** You'll notice I'm using [RealTerm](http://realterm.sourceforge.net/) (with a [good write-up on sparkfun](https://learn.sparkfun.com/tutorials/terminal-basics/real-term-windows)) which is my go-to terminal program instead of HyperTerminal (which really needs to go away forever). In reviewing this photo, I'm appreciating how much unpopulated room I have on the main board. I'm half tempted to build-in a frequency multiplier circuit, and place it under control of the microcontroller such that if an input frequency from 1-20MHz is received, it will engage the 10x multiplier. That's a mod for another day though! Actually, since those chips are SMT, if I really wanted to do this I would make this whole thing a really small SMT PCB and greatly simplify construction. That sounds like a project for another day though...[None](https://www.swharden.com/wp/wp-content/uploads/2016/09/IMG_8316.jpg)

<div class="text-center img-border">

[![](IMG_8335_thumb.jpg)](IMG_8335.jpg)

</div>

**Before closing it up I added some extra ripple protection on the primary counter chip.** There's a 560 uH series inductor with the power supply, followed by a 100 nF capacitor parallel with ground. I also added [ferrite beads](https://en.wikipedia.org/wiki/Ferrite_bead) to the MCU power line and gate input line. I appreciate how the beads are unsecured and that this is a potential weakness in the construction of this device (they're heavy, so consider what would happen if you shook this enclosure). However, anything that would yank-away cables in the event of shaking the device would probably also break half the other stuff in this thing, so I think it's on par with the less-than-rugged construction used for all the other components in this device. It will live a peaceful life on my shelf. I am not concerned.

<div class="text-center img-border">

[![](IMG_8335_thumb.jpg)](IMG_8335.jpg)

</div>

**This is the final device counting frequency and continuously outputting the result to my computer.** In the background you can see the 12V power supply (yellow) indicating it is drawing only 20 mA, and also the GPS unit is in a separate enclosure on the bottom right. [Click here to peek inside](https://www.swharden.com/wp/2016-08-20-breadboard-line-driver-module/#jp-carousel-5918) the GPS 1PPS enclosure.

<div class="text-center img-border">

[![](IMG_8344_thumb.jpg)](IMG_8344.jpg)

</div>

**I'm already loving this new frequency counter!** It's small, light, and nicely enclosed (meaning it's safe from me screwing with it too much!). I think this will prove to be a valuable piece of test equipment in my shack for years to come. I hope this build log encourages other people to consider building their own equipment. I learned a lot from this build, saved a lot of money not buying something commercial, had a great time making this device, and I have a beautiful piece of custom test equipment that does _exactly_ what I want.

## Source Code

Microcontroller code (AVR-GCC), schematics, and a Python script to interface with the serial port are all available on [this project's GitHub page](https://github.com/swharden/AVR-projects/blob/master/ATMega328%202016-09-04%20SN74LV8154/main.c)

## Afterthought: Using without GPS

One of the great advantages of this project is that it uses GPS for an extremely accurate 1 PPS signal, but what options exist to adapt this project to not rely on GPS? The GPS unit is expensive (though still <\$20) and GPS lock is not always feasible (underground, in a Faraday cage, etc). Barring fancy things like dividing-down rubidium frequency standards or oven controlled oscillators, consider having your microcontroller handle the gating using either [interrupts and timers precisely configured to count seconds](https://www.swharden.com/wp/2011-06-19-using-timers-and-counters-to-clock-seconds/). Since this project uses a serial port with a 11.0592 MHz crystal, your 1PPS stability will depend on the stability of your oscillator (which is pretty good!). Perhaps more elegantly you could use a 32.768 kHz crystal oscillator to create a 1 PPS signal. This frequency can be divided by 2 over and over to yield 1 Hz perfectly. This is what most modern wristwatches do. Many AVRs have a separate oscillator which can accomodate a 32 kHz crystal and throw interrupts every 1 second without messing with the system clock. Alternatively, the [74GC4060](http://www.nxp.com/documents/data_sheet/74HC_HCT4060_Q100.pdf) (a 14 stage ripple counter) can divide 32k into 1 Hz and even can be arranged as an oscillator (check the datasheet). It would be possible to have both options enabled (local clock and GPS) and only engage the local clock if the GPS signal is absent. If anyone likes the idea of this simple VHF frequency counter with PC interface but doesn't want to bother with the GPS, there are plenty of options to have something _almost_ as accurate. That really would cut the cost of the final device down too, keeping it under the \$5 mark.

## Update: Integrating Counter Serial Output with GPS Serial Output

The NEO-M8 GPS module is [capable of outputting serial data](https://www.u-blox.com/sites/default/files/NEO-M8_DataSheet_(UBX-13003366).pdf) at 9600 baud and continuously dumps [NEMA formatted](http://www.gpsinformation.org/dale/nmea.htm) GPS data. While this isn't really useful for location information (whose frequency counter requires knowing latitude and longitude?) it's great for tracking things like signal strength, fix quality, and number of satellites. After using this system to automatically log frequency of my frequency reference, I realized that sometimes I'd get 1-2 hours of really odd data (off by kHz, not just a few Hz). Power cycling the GPS receiver fixes the problem, so my guess it that it's a satellite issue. If I combine the GPS RX and counter in 1 box, I could detect this automatically and have the microcontroller power cycle the GPS receiver (or at the least illuminate a red error LED). I don't feel like running 2 USB serial adapters continuously. I don't feel like programming my AVR to listen to the output from the GPS device (although that's probably the _correct_ way to do things).  Instead I had a simpler idea that worked really well, allowing me to simultaneously log serial data from my GPS unit and microcontroller (frequency counter) using 1 USB serial adapter.

<div class="text-center img-border">

[![](IMG_8401_thumb.jpg)](IMG_8401.jpg)

</div>

**The first thing I did was open up the frequency counter and reconnect my microcontroller programmer.** This is exactly what I promised myself I wouldn't do, and why I have a nice enclosure in the first place! Scott, stop fidgeting with things! The last time I screwed this enclosure together I considered adding super glue to the screw threads to make sure I didn't open it again. I'll keep my modifications brief! For now, this is a test of a concept. When it's done, I'll revert the circuitry to how it was and close it up again. I'll take what I learn and build it into future projects.

<div class="text-center img-border">

[![](IMG_8402_thumb.jpg)](IMG_8402.jpg)

</div>

**I peeked at the serial signals of both the frequency counter (yellow) and the GPS unit output (blue).** To my delight, there was enough dead space that I thought I could stick both in the same signal. After a code modification, I was able to tighten it up a lot, so the frequency counter never conflicts with the GPS unit by sending data at the same time.

<div class="text-center img-border">

[![](IMG_8403_thumb.jpg)](IMG_8403.jpg)

</div>

**I had to slow the baud rate to 9600, but I programmed it to send fewer characters.** This leaves an easy ~50ms padding between my frequency counter signal and the GPS signal. Time to mix the two! This takes a little thought, as I can't just connect the two wires together. Serial protocol means the lines are usually high, and only pulled down when data is being sent. I had to implement an active circuit.

<div class="text-center img-border img-small">

[![](FullSizeRender-2_thumb.jpg)](FullSizeRender-2.jpg)

</div>

**Using a few components, I built an AND gate to combine signals from the two serial lines.** For some reason it took some thought before I realized an AND gate was what I needed here, but it makes sense. The output is high (meaning no serial signal) only when both inputs are high (no serial signals on the input). When either signal drops low, the output drops low. This is perfect. My first thought was that I'd need a NOR gate, but an inverted AND gate _is_ a NOR gate.

<div class="text-center img-border">

[![](IMG_8404_thumb.jpg)](IMG_8404.jpg)

</div>

**Here's my quick and dirty implementation.** A reminder again is that this will be removed after this test. For now, it's good enough.

<div class="text-center img-border">

[![](IMG_8405_thumb.jpg)](IMG_8405.jpg)

</div>

**After connecting** the GPS serial output and frequency counter serial output to the AND gate (which outputs to the computer), I instantly got the result I wanted!

<div class="text-center img-border">

![](serial-combine.jpg)

</div>

**RealTerm shows that both inputs are being received.** It's a mess though. If you want to know what everything is, read up on [NEMA formatted](http://www.gpsinformation.org/dale/nmea.htm) GPS data.

<div class="text-center img-border">

[![](combined-python_thumb.jpg)](combined-python.png)

</div>

**I whipped-up a python program to parse, display, and log key information.** This display updates every 1 second. The bottom line is what is appended to the log file on ever read. It's clunky, but again this is just for testing and debugging. I am eager to let this run for as long as I can (days?) so I can track how changes in satellite signal / number / fix quality influence measured frequency.```
Pages