rpitx-app-note/README.md

240 wiersze
11 KiB
Markdown

2015-11-08 13:38:47 +00:00
# Application note on using rpitx
2015-11-08 16:46:20 +00:00
The recently released <a href="https://github.com/F5OEO/rpitx">rpitx</a> by Evariste, F5OEO allows us to transmit an RF signal over GPIO18 (pin 12) of a Raspberry Pi. The software can accept an I/Q signal as an input, so now a Pi can be used as a general purpose SDR transmitter.
2015-11-08 16:48:12 +00:00
This document is about using [GNU Radio](#using-a-raspberry-pi-as-remote-software-defined-radio-peripheral-from-gnu-radio) and [csdr](#using-rpitx-with-csdr-to-modulate-streaming-input) with *rpitx*.
2015-11-08 16:46:20 +00:00
2015-11-08 16:18:16 +00:00
**Table of contents**
2015-11-08 21:47:35 +00:00
* [Using a Raspberry Pi as remote software defined radio peripheral from GNU Radio](#using-a-raspberry-pi-as-remote-software-defined-radio-peripheral-from-gnu-radio)
2015-11-08 18:54:04 +00:00
* [NFM modulator example for GNU Radio](#nfm-modulator-example-for-gnu-radio)
* [SSB modulator example for GNU Radio](#ssb-modulator-example-for-gnu-radio)
2015-11-08 21:05:38 +00:00
* [AM modulator example for GNU Radio](#am-modulator-example-for-gnu-radio)
2015-11-08 16:18:16 +00:00
* [Using rpitx with csdr to modulate streaming input](#using-rpitx-with-csdr-to-modulate-streaming-input)
2015-11-08 16:28:48 +00:00
* [Modulate from raw audio file](#modulate-from-raw-audio-file)
* [Modulate from microphone input source](#modulate-from-microphone-input-source)
* [Modulate from audio streamed from remote computer](#modulate-from-audio-streamed-from-remote-computer)
* [Using ADPCM codec to decrease network usage while streaming](#using-adpcm-codec-to-decrease-network-usage-while-streaming)
2015-11-29 10:25:10 +00:00
* [Transmitting amateur radio digital modes from remote computer](#transmitting-amateur-radio-digital-modes-from-remote-computer)
2015-11-08 16:19:05 +00:00
<br /><br />
2015-11-11 00:05:42 +00:00
![Warning](/images/bpf-warning.png?raw=true)
2015-11-08 16:46:20 +00:00
<br /><br />
The output of the Raspberry Pi GPIO 18 is a square wave, which contains harmonics.<br />
For example, if you transmit on 28 MHz, you will also transmit on:
* 28 × 3 = 84 MHz
* 28 × 5 = 140 MHz
* 28 × 7 = 196 MHz<br/>...
...and actually you may distrub some important radio communication services. Please don't do this! You can get into trouble! You have been warned.
2015-11-11 00:08:06 +00:00
In addition to the squre wave output, the spectrum is also affected by the PWM-based amplitude modulation implemented in *rpitx*.
2015-11-11 00:11:21 +00:00
* Right now it is more useful to use these examples for e.g. demonstrations on SDR transmitters<br />(as most of them use the PWM mode).
2015-11-11 00:08:06 +00:00
* If you want to connect this to a real antenna, you should use a **very good band-pass filter**!
* Please check your signal output on a proper spectrum analyzer before ever using this on the air!
* In addition, only transmit if you have a proper license to do so.
2015-11-08 16:18:16 +00:00
2015-11-08 15:37:46 +00:00
## Using a Raspberry Pi as remote software defined radio peripheral from GNU Radio
2015-11-08 15:51:45 +00:00
To do this, you will need:
* a PC running GNU Radio on Linux,
* a Raspberry Pi with *rpitx* installed,
* both connected to the same network.
We will stream the I/Q signal from the PC to the Raspberry Pi via TCP.
On the Raspberry Pi, execute:
nc -l 8011 | sudo rpitx -i- -m IQFLOAT -f 28400
* This will listen on TCP port 8011 for the I/Q signal.
* The center frequency of the transmitter will be 28400 kHz.
2015-11-08 21:11:44 +00:00
If you want it to restart everytime the connection is lost, use this command:
while true; do (nc -l 8011; dd if=/dev/zero bs=4096 count=30); done | sudo rpitx -i- -m IQFLOAT -f 28400
2015-11-08 18:54:04 +00:00
### NFM modulator example for GNU Radio
2015-11-08 15:54:10 +00:00
2015-11-08 15:51:45 +00:00
On the PC, open GNU Radio Companion, and load the flow graph in this repo at `gnuradio/nfm-rpitx`.
![NFM in GNU Radio](/images/grc-nfm.png?raw=true)
If you execute it, the I/Q signal will be streamed to the Raspberry Pi through the TCP socket.
2015-11-08 18:53:06 +00:00
* Note that the frequency translation is there on intention. On some unkown reason, the spectrum is quite distorted if our signal is centered at DC.
2015-11-08 15:51:45 +00:00
Here is the good result if received with an RTL-SDR and GQRX:
![NFM in GQRX](/images/gqrx-nfm.png?raw=true)
2015-11-08 18:54:04 +00:00
### SSB modulator example for GNU Radio
2015-11-08 15:51:45 +00:00
2015-11-08 18:53:06 +00:00
Use the flow graph in `gnuradio/ssb-rpitx`.
2015-11-08 20:41:19 +00:00
This will transmit an **USB** signal.
2015-11-08 18:53:06 +00:00
![SSB in GNU Radio](/images/grc-ssb.png?raw=true)
The spectrum of the transmitted I/Q signal looks like this:
![SSB in GNU Radio](/images/grc-ssb-running.png?raw=true)
After receiving it with RTL-SDR and GQRX:
![SSB in GQRX](/images/gqrx-ssb.png?raw=true)
2015-11-08 15:37:46 +00:00
2015-11-08 20:42:21 +00:00
If you want **LSB**, you should double-click the "Band Pass Filter" block, and change:
2015-11-08 20:41:19 +00:00
* *Low Cutoff Freq* to -3000
* *High Cutoff Freq* to -300
2015-11-08 20:41:52 +00:00
![SSB in GQRX](/images/grc-ssb-bpf.png?raw=true)
2015-11-08 20:41:19 +00:00
2015-11-08 21:05:38 +00:00
### AM modulator example for GNU Radio
Use the flow graph in `gnuradio/am-rpitx`.
This will transmit an **AM** signal.
2015-11-08 21:12:48 +00:00
* One thing that can be screwed up is **gain**. I had to play with the AGC to get it right.
2015-11-08 21:11:44 +00:00
2015-11-08 21:05:38 +00:00
![AM in GQRX](/images/grc-am.png?raw=true)
The spectrum of the transmitted I/Q signal looks like this:
2015-11-08 21:08:37 +00:00
![AM in GQRX](/images/grc-am-running.png?raw=true)
2015-11-08 21:05:38 +00:00
After receiving it with RTL-SDR and GQRX:
![AM in GQRX](/images/gqrx-am.png?raw=true)
2015-11-08 16:18:16 +00:00
## Using rpitx with csdr to modulate streaming input
2015-11-08 13:38:47 +00:00
2015-11-08 15:51:45 +00:00
<a href="https://github.com/simonyiszk/csdr">csdr</a> is a command line tool for simple DSP tasks. It can be used to build simple AM/FM/SSB receivers, and now transmitters as well, and is quite fast to setup.
2015-11-08 13:38:47 +00:00
You will need the *dev* branch of *csdr* for doing this.<br />
Setup instructions:
git clone https://github.com/simonyiszk/csdr.git
cd csdr
git fetch
git checkout dev
make && sudo make install
2015-11-08 14:57:59 +00:00
Note that it should be already done if you installed *qtcsdr* previously.
2015-11-08 13:38:47 +00:00
### Modulate from raw audio file
2015-11-08 14:31:31 +00:00
These examples will use the raw audio file `music48000.raw` and `speech48000.raw`, which is present in this repo. You can get this file by:
2015-11-08 13:38:47 +00:00
2015-11-08 13:41:57 +00:00
git clone https://github.com/ha7ilm/rpitx-app-note
2015-11-08 15:37:46 +00:00
cd rpitx-app-note; ls #There are your files.
2015-11-08 13:38:47 +00:00
2015-11-08 14:41:19 +00:00
We will play these files in a loop, you can stop it with Ctrl+C.
2015-11-08 13:38:47 +00:00
2015-11-08 13:41:57 +00:00
**Generate AM modulation:**
2015-11-08 14:41:19 +00:00
(while true; do cat music48000.raw; done) | csdr convert_i16_f | csdr gain_ff 1.0 | csdr dsb_fc | csdr add_dcoffset_cc | sudo rpitx -i- -m IQFLOAT -f 28400
2015-11-08 13:38:47 +00:00
* The part `csdr gain_ff 1.0` can be changed to increase/decrease modulation.
* The `-f 28400` at the end gives the transmit frequency in kHz.
2015-11-08 14:31:31 +00:00
**Generate USB modulation:**
2015-11-08 13:38:47 +00:00
2015-11-08 14:41:19 +00:00
(while true; do cat speech48000.raw; done) | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc 0 0.1 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
2015-11-08 13:38:47 +00:00
2015-11-08 14:31:31 +00:00
**Generate LSB modulation:**
2015-11-08 14:41:19 +00:00
(while true; do cat speech48000.raw; done) | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc -0.1 0 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
2015-11-08 14:31:31 +00:00
* It's the matter of the filter which sideband do we select:
* `csdr bandpass_fir_fft_cc -0.1 0` is the lower sideband
* `csdr bandpass_fir_fft_cc 0 0.1` is the upper sideband
2015-11-08 14:36:25 +00:00
* I have experienced that if the SSB signal is in the center of the I/Q signal, then it is not transmitted correctly. The solution was to shift it. So the exact frequency should be around: `rpitx frequency + 48000*0.2 = rpitx frequency + 9600 Hz`
2015-11-08 15:07:32 +00:00
* If you want to get some compression on the speech, you can try `csdr fastagc_ff` instead of `csdr gain_ff 2.0`.
2015-11-08 14:31:31 +00:00
**Generate NFM modulation:**
2015-11-08 14:41:19 +00:00
(while true; do cat music48000.raw; done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
2015-11-08 13:38:47 +00:00
2015-11-08 14:41:19 +00:00
**Generate WFM modulation:**
(while true; do cat music48000.raw; done) | csdr convert_i16_f | csdr gain_ff 70000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
* Frequency deviation is set much higher with `csdr gain_ff 70000`, that's the only difference between this and NFM.
2015-11-08 14:49:09 +00:00
### Modulate from microphone input source
Use this if you have a microphone connected to the Raspberry Pi via external USB audio device.<br />
You will have to get the correct ALSA device ID via `arecord -L`, it will be something like `plughw:CARD=Device,DEV=0`. You should enter as the argument of the `-D` switch of `arecord`.
#AM:
arecord -c1 -r48000 -D plughw:CARD=Device,DEV=0 -fS16_LE - | csdr convert_i16_f | csdr gain_ff 1.0 | csdr dsb_fc | csdr add_dcoffset_cc | sudo rpitx -i- -m IQFLOAT -f 28400
#USB:
arecord -c1 -r48000 -D plughw:CARD=Device,DEV=0 -fS16_LE - | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc 0 0.1 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
#LSB:
arecord -c1 -r48000 -D plughw:CARD=Device,DEV=0 -fS16_LE - | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc -0.1 0 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
#NFM:
arecord -c1 -r48000 -D plughw:CARD=Device,DEV=0 -fS16_LE - | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
#WFM:
arecord -c1 -r48000 -D plughw:CARD=Device,DEV=0 -fS16_LE - | csdr convert_i16_f | csdr gain_ff 70000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
2015-11-08 14:54:52 +00:00
2015-11-08 16:28:48 +00:00
### Modulate from audio streamed from remote computer
2015-11-08 14:54:52 +00:00
First, start the transmitter:
#AM:
nc -l 8011 | csdr convert_i16_f | csdr gain_ff 1.0 | csdr dsb_fc | csdr add_dcoffset_cc | sudo rpitx -i- -m IQFLOAT -f 28400
#USB:
nc -l 8011 | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc 0 0.1 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
#LSB:
nc -l 8011 | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc -0.1 0 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
#NFM:
nc -l 8011 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
#WFM:
nc -l 8011 | csdr convert_i16_f | csdr gain_ff 70000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
The Raspberry Pi will listen on TCP port 8011, and wait for connection.
Then, on the remote computer, execute:
arecord -fS16_LE -r48000 -c1 - | nc raspberrypi.local 8011
You should replace `raspberrypi.local` with the IP address of the Raspberry Pi (unless avahi config is the default).
2015-11-08 15:02:54 +00:00
2015-11-08 16:28:48 +00:00
### Using ADPCM codec to decrease network usage while streaming
2015-11-08 15:02:54 +00:00
Let's see an example for this on the NFM modulator. Execute on the Raspberry Pi:
nc -l 8011 | csdr decode_ima_adpcm_u8_i16 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 28400
On the PC, execute this:
arecord -fS16_LE -r48000 -c1 - | csdr encode_ima_adpcm_i16_u8 | nc raspberrypi.local 8011
2015-11-29 10:24:23 +00:00
### Transmitting amateur radio digital modes from remote computer
2015-11-29 10:32:12 +00:00
On the Raspberry Pi, run this to transmit USB:
2015-11-29 10:24:23 +00:00
nc -l 8011 | csdr convert_i16_f | csdr dsb_fc | csdr bandpass_fir_fft_cc 0 0.1 0.01 | csdr gain_ff 2.0 | csdr shift_addition_cc 0.2 | sudo rpitx -i- -m IQFLOAT -f 28400
On your PC, run:
arecord -fS16_LE -r48000 -c1 - | nc raspberrypi.local 8011
2015-11-29 10:32:12 +00:00
If you have Ubuntu on your PC, you are likely to have PulseAudio.
2015-11-29 10:24:23 +00:00
2015-11-29 10:37:53 +00:00
Run `pavucontrol` and set the recording source of `arecord` to "Monitor of" your audio output.
2015-11-29 10:24:23 +00:00
![pavucontrol](/images/pavucontrol.png?raw=true)
2015-11-29 10:32:12 +00:00
On the PC, run `fldigi`, and start to transmit:
![fldigi](/images/fldigi.png?raw=true)
2015-11-29 10:43:37 +00:00
If you don't want to listen to the transmitted signal on your PC:
sudo modprobe snd-aloop
2015-11-29 10:50:15 +00:00
This will create an ALSA loopback interface. You also have to make the appropriate changes in `pavucontrol`:
2015-11-29 10:43:37 +00:00
![pavucontrol](/images/pavucontrol-loop.png?raw=true)