[raspberry-vi] SDR In The Command-Line

  • From: "Glenn K0LNY" <glennervin@xxxxxxxxxxxx>
  • To: <raspberry-vi@xxxxxxxxxxxxx>
  • Date: Fri, 15 Jan 2021 12:46:25 -0600

Hi All,
Here's the link to, and the article where I got the info for getting rtl-sdr 
dongle to work on my rPI in the CLI:
https://cloudacm.com/?p203

December 4, 2017 

Patrick Gilfeather
In this post I'll be giving some background and install steps on RTL-SDR. SDR 
stands for software defined radio and has been in use since the 1970s. 
Traditional
radio processing is handled by hardware components like oscillators, 
regulators, and mixers. SDR replaces these functions with digital computer 
processing.
RTL-SDR is a device that was originally designed to receive digital television 
transmissions, namely DVB-T TV using the RTL2832U chipset. The device is
typically contained in a USB dongle. The RTL2832U chipset was identified by 
developers as having an ability to process SDR well and subsequent tools have
been developed to enable it for such a purpose. Coupling the SDR functions with 
decoding processes, this inexpensive device can recieve and decode digital
radio transmissions using MultiMon-NG. Much of this post is based of the work 
provided here, 
https://oneguyoneblog.com/2016/08/10/decoding-p2000-raspberry-pi-rtl-sdr/shared=email&msgúil

The first item needed with be the RTL2832U chipset dongle. You should be able 
to find them for sale online. A search on Amazon for "RTL2832U chipset" will
show several options, most being under $20.

Next, we'll need to install the RTL-SDR software on the computer. The source 
can be found at 
https://github.com/osmocom/rtl-sdr.
Refer to this site for current install procedures. The following worked for my 
installation, but this may change, so check with the developer for current
steps.

git clone https://github.com/osmocom/rtl-sdr
cd rtl-sdr
mkdir build
cd build
make
sudo make install

Now we are able to test that our system is able to receive radio signals. Use 
the "rtl_test" command to check that all is working as expected. Be sure
the USB dongle is plugged in otherwise the "No supported devices found" message 
will appear. You should get this message back if all is working as expected.

Found 1 device(s):
  0:  Generic, RTL2832U, SN: XXXXXX...........

Using device 0: Generic RTL2832U
Detached kernel driver
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 
19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9
44.5 48.0 49.6 
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...

I pressed [Ctrl] + [X] to end the process, but the USB device was still active. 
If you enter in the rtl_test command again, you will get a "usb_claim_interface
error" message. I have found that either unplugging the USB dongle or closing 
the terminal window to be effective in stopping this error. Pressing [Ctrl]
+ [C] ends the process and reattaches the kernel driver so there is no need to 
unplug the dongle or close the terminal window.

To tune the receiver and play audio back, I used the following command that 
pipe aplay to the rtl_fm command. I'm tuning to the local NOAA weather broadcast
station KHB60 located on Cougar Mountain, near Issaquah WA. It's listed as 
operating on 100 Watts at 162.55 Mhz Narrow FM, however I get better tuning
at 162.541 Mhz. I used a filter width of 8.4 Khz

rtl_fm -M fm -f 162.541M -s 22k | play -t raw -r 22k -es -b 16 -c 1 -V1 -

Here is a command to tune to the same channel, but this time I'll save the data 
received by the dongle instead.

rtl_fm -M fm -f 162.541M -s 22k "/home/local/Desktop/RTL-SDR/NOAA-KHB60.raw"
play -t raw -r 22k -es -b 16 -c 1 "/home/local/Desktop/RTL-SDR/NOAA-KHB60.raw"

Now I'll clean up the audio with some SoX processing. I'll filter off the upper 
frequencies and then apply or noise filter profile. Then I'll wrap it up
with another upper frequency filter.

sox -t raw -r 22k -es -b 16 -c 1 "/home/local/Desktop/RTL-SDR/NOAA-KHB60.raw" 
"/home/local/Desktop/RTL-SDR/NOAA-KHB60.wav" sinc -5k 
sox "/home/local/Desktop/RTL-SDR/NOAA-KHB60_NoiseProfile.wav" -n noiseprof 
"/home/local/Desktop/RTL-SDR/NOAA-KHB60_NoiseProfile.prof"
sox "/home/local/Desktop/RTL-SDR/NOAA-KHB60.wav" 
"/home/local/Desktop/RTL-SDR/NOAA-KHB60_NoiseFiltered.wav" noisered 
"/home/local/Desktop/RTL-SDR/NOAA-KHB60_NoiseProfile.prof"
0.075 sinc -2k 

This removed a significant amount of noise from the audio. You can see a stark 
contrast between the two in these spectrograms.

12/NOAA-KHB60-1024x354

It is more common for radio transmissions to be momentary, versus constant in 
the NOAA sample above. During radio silence, there is background noise that
is received. If we were to record these transmissions using the command from 
above, we would end up with a lot of noise. To eliminate this we'll use a
squelch function in rtl-sdr. This will removed background noise during radio 
silence and make listening less bothersome. Here is the command I used after
some trial and error to capture RF transmissions with squelch

rtl_fm -M fm -f 167703400 -l 160 -s 22k - | play -r 22k -t raw -e s -b 16 -c 1 
-V1 -
rtl_fm -M fm -f 167703400 -l 160 -s 22k 
"/home/local/Desktop/RTL-SDR/Ballard_Digital_Squelch_160.raw"
sox -t raw -r 22k -e s -b 16 -c 1 
"/home/local/Desktop/RTL-SDR/Ballard_Digital_Squelch_160.raw" 
"/home/local/Desktop/RTL-SDR/Ballard_Digital_Squelch_160.wav"
silence 1 0.2 0.5% -1 0.2 0.5% 

The first line uses RTL_FM to tune to a narrow FM channel at 167.7034 Mhz with 
a 22 Khz sample rate. The squelch level is set at 160 after some testings,
this produced the best results. The raw results are piped to SoX that plays it 
at a 22 Khz rate with 16 bit resolution on a mono audio channel. SoX treats
the data as signed-integer encoded. Lastly the verbosity of the output of the 
SoX command is set to failure messages only. The results are live listening
of radio signal on the speaker.

The second line uses RTL_FM the same way, but this time saves the data to a raw 
file. Instead no verbosity is set and it works with the raw file and saves
the output file as a wav file. There are gaps of silence in the audio when the 
squelch is active. I used the silence command to truncate the gaps of silence
so I'm left for nothing but the actual transmissions.

Now to use RTL_FM as a channel scanner. This command will sweep through three 
frequencies and stop at a frequency that is actively transmitting. I'll use
SoX afterward to convert the data to a wav file and remove the silence.

rtl_fm -M fm -f 167703400 -f 167453900 -f 167702900 -l 200 -s 22k - | play -r 
22k -t raw -e s -b 16 -c 1 -V1 -
rtl_fm -M fm -f 167703400 -f 167453900 -f 167702900 -l 200 -s 22k 
"/home/local/Desktop/RTL-SDR/Ballard_Scanner.raw"
sox -t raw -r 22k -e s -b 16 -c 1 
"/home/local/Desktop/RTL-SDR/Ballard_Scanner.raw" 
"/home/local/Desktop/RTL-SDR/Ballard_Scanner.wav" silence 1 0.2 0.5%
-1 0.2 0.5% 

These inexpensive radio receivers along with SDR give the public access to a 
resource that has historically been only available to the privileged. There
are public services that are transmitted and these should be available to the 
public without the need to purchase expensive dedicated equipment. Using
a small $20 USB radio receiver turns the tide in favor of the general 
population. I'm glad to see that this is available to young people and will 
inspire
them to help all of us.

--------------------------------------------------------------------------------


Raspberry Pi,
Research And Development
article end

=========================================================== 
The raspberry-vi mailing list 
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi 
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and 
attitudes expressed by the subscribers to this list do not reflect those of the 
Foundation.

Mike Ray, list creator, January 2013

Other related posts:

  • » [raspberry-vi] SDR In The Command-Line - Glenn K0LNY