# Arduino RTTY decoder

**URL:** <https://forum.arduino.cc/t/arduino-rtty-decoder/82177>\
**Category:** Showcase\
**Created:** [December 18, 2011, 10:17pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177 "2011-12-18T22:17:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [December 18, 2011, 10:17pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/1 "2011-12-18T22:17:13Z")

</div>

I guess this is the correct place to put this...  
FFT code from: [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155](http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155)  
This program decoders 45.4 RTTY on analog 0 and outputs it to the serial console.  
It has quite a bit of limitations.  
RTTY shift has to be between 160-182hz.  
It has to be ~45.4 baud.  
The decode output has errors in it and its just a proof of concept but still cool.  
--edit--  
Also the RTTY center frequency has to be 300hz +/- 10

```arduino
#include <avr/pgmspace.h>
#include "fixfft.h"
#include "fix_fft.cpp"
#define THRESH 27 //Bit threshold adjust for best decode
#define CHK(x) (sqrt(real[x] * real[x] + imag[x] * imag[x])) Convert FFT output to more usable form
#define PCK(ar) (ar[0] | ar[1]<<1 | ar[2] << 2 | ar[3] << 3 | ar[4] << 4) //Pack bits into byte
unsigned char lookup[] = { //Baudot lookup table
  ' ', 'E' , ' ', 'A', ' ', 'S', 'I', 'U',
  '\n', 'D', 'R', 'J', 'N', 'F', 'C', 'K',
  'T', 'Z', 'L', 'W', 'H', 'Y', 'P', 'Q',
  'O', 'B', 'G', 0, 'M', 'X', 'V', 0, ' ', 
  '3', '\n', '-', ' ', '`', '8', '7',
  '\r', ' ', '4', ' ', ',', '!', ':', '(',
  '5', '+', ')', '2', '

```

, '6', '0', '1',  
&nbsp;'9', '?', '&', 0, '.', '/', ';', 0};  
&nbsp;int toffset=0; //Symbols and numbers shift

void setup(){  
&nbsp;Serial.begin(115200); //115200 baud output  
&nbsp;digitalWrite(A0, 1); //Turn this off depending on input source

}  
void loop(){  
&nbsp;char bits[6]={0,0,0,0,0};  
&nbsp;char real[32],imag[32];  
&nbsp;int ticker = 0;  
&nbsp;unsigned char pbyte;  
&nbsp;for(int a = 0;a \< 16;a++){  
&nbsp; &nbsp;real[a] = (analogRead(A0)-512) / 4; //Get samples  
&nbsp; &nbsp;imag[a] = 0;  
&nbsp; &nbsp;delayMicroseconds(780);  
&nbsp;}  
&nbsp;fix\_fft(real, imag, 4, 0); //Preform FFT  
&nbsp; &nbsp;if(CHK(6) \> THRESH){ //Got a start bit?  
&nbsp; &nbsp; for(int b = 0;b \< 5;b++){ &nbsp;//Yes - start collecting bits  
&nbsp; &nbsp; delay(7); //For timing  
&nbsp; &nbsp; for(int a = 0;a \< 16;a++){  
&nbsp; &nbsp;real[a] = (analogRead(A0)-512) / 4; //Get more samples  
&nbsp; &nbsp;imag[a] = 0;  
&nbsp; &nbsp;delayMicroseconds(780);  
&nbsp;}  
&nbsp; &nbsp;fix\_fft(real, imag, 4, 0); //Preform FFT  
&nbsp; &nbsp;bits[b] = (CHK(6) \> THRESH)? 0:1; //Check if we got a 1 or a 0  
// &nbsp; &nbsp;bits[b] = (CHK(7) \> THRESH)? 1:0;  
&nbsp; &nbsp;}  
&nbsp; &nbsp;pbyte = PCK(bits); //Pack the byte  
&nbsp; &nbsp;if(pbyte == 0x1B){toffset=0x20; pbyte=0;} //Handle character set shift  
&nbsp; &nbsp;if(pbyte == 0x1F){toffset=0x00; pbyte=0;}  
&nbsp; &nbsp;Serial.print(lookup[pbyte+toffset]); //Print output  
&nbsp; &nbsp;ticker++;  
&nbsp; &nbsp;//if(ticker\>60){ticker=0; Serial.println();}  
/\* for(int b = 0;b\< 5;b++){  
&nbsp; &nbsp;  
&nbsp;}\*/  
// &nbsp;Serial.println();  
&nbsp;delay(12); //For timing  
&nbsp;}

}

```arduino

```

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [December 18, 2011, 10:51pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/2 "2011-12-18T22:51:11Z")

</div>

Well done.

I have a soft spot for RTTY as it was my first project that I ever sold. It was back in 1975 and before the days of micro processors gave you cheap peripherals. It was all done with TTL and produced a video output onto a TV screen. It contained about 40 chips. It was the first time most people had seen writing on a TV and they complained about the vertical scrolling it did.

Anyway this is certainly a lot simpler than my effort,  
well done again.

---

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [December 19, 2011, 12:47am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/3 "2011-12-19T00:47:54Z")

</div>

> Grumpy\_Mike:  
> Well done.
> 
> I have a soft spot for RTTY as it was my first project that I ever sold. It was back in 1975 and before the days of micro processors gave you cheap peripherals. It was all done with TTL and produced a video output onto a TV screen. It contained about 40 chips. It was the first time most people had seen writing on a TV and they complained about the vertical scrolling it did.
> 
> Anyway this is certainly a lot simpler than my effort,  
> well done again.

Thank you.  
BTW Another limitation is the center frequency needs to be around 300hz +/- 10

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 11, 2012, 4:34pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/4 "2012-01-11T16:34:00Z")

</div>

> smeezekitty:  
> BTW Another limitation is the center frequency needs to be around 300hz +/- 10

No way to change this value?

---

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [January 12, 2012, 1:17am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/5 "2012-01-12T01:17:07Z")

</div>

It should be possible to change the center freq by increasing the sampling frequency reducing

```cpp
delayMicroseconds(780);

```

on both lines but increasing the number of total samples is required to maintain timings. Also, if you increase the number of samples, the number of FFT bits will have to be proportionally increased.

```cpp
fix_fft(real, imag, /*-->*/4/*<--*/, 0);

```

then

```cpp
CHK(6)

```

would have to be increased to the correct FFT bin number.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 12, 2012, 9:05am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/6 "2012-01-12T09:05:49Z")

</div>

I've calculate the values in an empiric way.  
Later I'll do some tests.. but I don't understand how to find the FFT bit number for the CHK() function

---

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [January 12, 2012, 8:06pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/7 "2012-01-12T20:06:55Z")

</div>

> Istevene:  
> I've calculate the values in an empiric way.  
> Later I'll do some tests.. but I don't understand how to find the FFT bit number for the CHK() function

This calculation could be wrong.  
FFT bin width = ((Samplerate / 2) / (NumberOfSamples / 2)) \* 2  
CHK value = (SpaceFrequency / FFT bin width)  
Then round CHK to the nearest integer.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 18, 2012, 7:45am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/8 "2012-01-18T07:45:32Z")

</div>

Thanks for your help 🙂  
by the way is not working, I'll try something else.

---

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [January 18, 2012, 8:35am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/9 "2012-01-18T08:35:11Z")

</div>

> Istevene:  
> Thanks for your help 🙂  
> by the way is not working, I'll try something else.

Its quite particular and alittle difficult to get it to work.  
But it is proof of concept only.

---

<div class="post-metadata">

**Author:** ![terryking228](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terryking228/32/214478_2.png) [@terryking228](https://forum.arduino.cc/u/terryking228)\
**Post date:** [January 21, 2012, 11:40pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/10 "2012-01-21T23:40:21Z")

</div>

Hi, Since you are only looking at two frequencies, aren't there digital filtering algorithms that are less compute-intensive than FFT?? (Not that I know how to do this!)

I cheated and started with a simple PLL and then coded stuff. In 1975. In 6502 assembler . 🙂 History...

Signals are still fun!

---

<div class="post-metadata">

**Author:** ![smeezekitty](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@smeezekitty](https://forum.arduino.cc/u/smeezekitty)\
**Post date:** [January 22, 2012, 12:57am UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/11 "2012-01-22T00:57:23Z")

</div>

> terryking228:  
> Hi, Since you are only looking at two frequencies, aren't there digital filtering algorithms that are less compute-intensive than FFT?? (Not that I know how to do this!)
> 
> I cheated and started with a simple PLL and then coded stuff. In 1975. In 6502 assembler . 🙂 History...
> 
> Signals are still fun!

Probably. I know very little about DSP though.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:31pm UTC](https://forum.arduino.cc/t/arduino-rtty-decoder/82177/12 "2021-05-06T12:31:32Z")

</div>

Closed on May 6, 2021, 12:31pm UTC


